-(defmethod boxed-proxy-to-native ((type g-boxed-cstruct-wrapper-info) proxy)
- (let* ((native-structure-type (g-boxed-cstruct-wrapper-info-cstruct type))
- (native-structure (foreign-alloc native-structure-type)))
- (iter (for slot in (g-boxed-cstruct-wrapper-info-slots type))
- (setf (foreign-slot-value native-structure native-structure-type slot)
- (slot-value proxy slot)))
- (prog1 (g-boxed-copy (g-boxed-info-g-type type) native-structure)
- (foreign-free native-structure))))
-
-(defmethod boxed-native-to-proxy ((type g-boxed-cstruct-wrapper-info) native-structure)
- (let* ((native-structure-type (g-boxed-cstruct-wrapper-info-cstruct type))
- (proxy-structure-type (g-boxed-info-name type))
- (proxy (make-instance proxy-structure-type)))
- (iter (for slot in (g-boxed-cstruct-wrapper-info-slots type))
- (setf (slot-value proxy slot)
- (foreign-slot-value native-structure native-structure-type slot)))
- proxy))
-
-(defmethod boxed-read-values-from-native ((type g-boxed-cstruct-wrapper-info) proxy native-structure)
- (let ((native-structure-type (g-boxed-cstruct-wrapper-info-cstruct type)))
- (iter (for slot in (g-boxed-cstruct-wrapper-info-slots type))
- (setf (slot-value proxy slot)
- (foreign-slot-value native-structure native-structure-type slot)))))
-
-(defmethod boxed-write-values-to-native-and-free ((type g-boxed-cstruct-wrapper-info) proxy native-structure)
- (let ((native-structure-type (g-boxed-cstruct-wrapper-info-cstruct type)))
- (iter (for slot in (g-boxed-cstruct-wrapper-info-slots type))
- (setf (foreign-slot-value native-structure native-structure-type slot)
- (slot-value proxy slot)))))
+(defmethod make-foreign-type ((info g-boxed-cstruct-wrapper-info) &key return-p)
+ (make-instance 'boxed-cstruct-foreign-type :info info :return-p return-p))
+
+(defun memcpy (target source bytes)
+ (iter (for i from 0 below bytes)
+ (setf (mem-aref target :uchar i)
+ (mem-aref source :uchar i))))
+
+(defmethod boxed-copy-fn ((info g-boxed-cstruct-wrapper-info) native)
+ (if (g-boxed-info-g-type info)
+ (g-boxed-copy (g-boxed-info-g-type info) native)
+ (let ((copy (foreign-alloc (g-boxed-cstruct-wrapper-info-cstruct info))))
+ (memcpy copy native (foreign-type-size (g-boxed-cstruct-wrapper-info-cstruct info)))
+ copy)))
+
+(defmethod boxed-free-fn ((info g-boxed-cstruct-wrapper-info) native)
+ (if (g-boxed-info-g-type info)
+ (g-boxed-free (g-boxed-info-g-type info) native)
+ (foreign-free native)))
+
+(defmethod translate-to-foreign (proxy (type boxed-cstruct-foreign-type))
+ (if (null proxy)
+ (null-pointer)
+ (let* ((info (g-boxed-foreign-info type))
+ (native-structure-type (g-boxed-cstruct-wrapper-info-cstruct info)))
+ (with-foreign-object (native-structure native-structure-type)
+ (iter (for slot in (g-boxed-cstruct-wrapper-info-slots info))
+ (setf (foreign-slot-value native-structure native-structure-type slot)
+ (slot-value proxy slot)))
+ (values (boxed-copy-fn info native-structure) proxy)))))
+
+(defmethod free-translated-object (native-structure (type boxed-cstruct-foreign-type) proxy)
+ (when proxy
+ (let* ((info (g-boxed-foreign-info type))
+ (native-structure-type (g-boxed-cstruct-wrapper-info-cstruct info)))
+ (iter (for slot in (g-boxed-cstruct-wrapper-info-slots info))
+ (setf (slot-value proxy slot)
+ (foreign-slot-value native-structure native-structure-type slot)))
+ (boxed-free-fn info native-structure))))
+
+(defmethod translate-from-foreign (native-structure (type boxed-cstruct-foreign-type))
+ (unless (null-pointer-p native-structure)
+ (let* ((info (g-boxed-foreign-info type))
+ (native-structure-type (g-boxed-cstruct-wrapper-info-cstruct info))
+ (proxy-structure-type (g-boxed-info-name info))
+ (proxy (make-instance proxy-structure-type)))
+ (iter (for slot in (g-boxed-cstruct-wrapper-info-slots info))
+ (setf (slot-value proxy slot)
+ (foreign-slot-value native-structure native-structure-type slot)))
+ (when (g-boxed-foreign-return-p type)
+ (boxed-free-fn info native-structure))
+ proxy)))
+
+(defmethod cleanup-translated-object-for-callback ((type boxed-cstruct-foreign-type) proxy native-structure)
+ (when proxy
+ (let* ((info (g-boxed-foreign-info type))
+ (native-structure-type (g-boxed-cstruct-wrapper-info-cstruct info)))
+ (iter (for slot in (g-boxed-cstruct-wrapper-info-slots info))
+ (setf (foreign-slot-value native-structure native-structure-type slot)
+ (slot-value proxy slot))))))