+
+(defmethod reader-function ((class struct-class) &rest args)
+ (declare (ignore args))
+ #'(lambda (location &optional (offset 0) weak-p)
+ (declare (ignore weak-p))
+ (let ((instance (sap-ref-sap location offset)))
+ (unless (null-pointer-p instance)
+ (ensure-proxy-instance class instance :weak t)))))
+
+(defmethod callback-from-alien-form (form (class struct-class) &rest args)
+ `(ensure-proxy-instance ',(class-name class) ,form :weak t))
+
+(defmethod callback-cleanup-form (form (class struct-class) &rest args)
+ (declare (ignore class))
+ `(invalidate-instance ,form))
+
+
+;;; Pseudo type for structs which are inlined in other objects
+
+(defmethod size-of ((type (eql 'inlined)) &rest args)
+ (declare (ignore type))
+ (foreign-size (first args)))
+
+(defmethod reader-function ((type (eql 'inlined)) &rest args)
+ (declare (ignore type))
+ (destructuring-bind (class) args
+ #'(lambda (location &optional (offset 0) weak-p)
+ (declare (ignore weak-p))
+ (ensure-proxy-instance class
+ (reference-foreign class (sap+ location offset))))))
+
+(defmethod writer-function ((type (eql 'inlined)) &rest args)
+ (declare (ignore type))
+ (destructuring-bind (class) args
+ #'(lambda (instance location &optional (offset 0))
+ (copy-memory (foreign-location instance) (foreign-size class) (sap+ location offset)))))
+
+(defmethod destroy-function ((type (eql 'inlined)) &rest args)
+ (declare (ignore args))
+ #'(lambda (location &optional (offset 0))
+ (declare (ignore location offset))))
+
+(export 'inlined)