X-Git-Url: https://git.distorted.org.uk/~mdw/clg/blobdiff_plain/29933e836dd53611fe53d0e1e51eac1a551c0de3..508d13a773de8f6b28773d4ecfc6834feed08597:/glib/proxy.lisp diff --git a/glib/proxy.lisp b/glib/proxy.lisp index c8b2c90..7cc6f78 100644 --- a/glib/proxy.lisp +++ b/glib/proxy.lisp @@ -15,7 +15,7 @@ ;; License along with this library; if not, write to the Free Software ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -;; $Id: proxy.lisp,v 1.12 2004/11/09 10:10:59 espen Exp $ +;; $Id: proxy.lisp,v 1.14 2004/11/19 13:02:51 espen Exp $ (in-package "GLIB") @@ -365,6 +365,26 @@ (declare (ignore class args)) #'proxy-location) +(defmethod copy-from-alien-form (location (class proxy-class) &rest args) + (declare (ignore args)) + (let ((class-name (class-name class))) + `(ensure-proxy-instance ',class-name + (reference-foreign ',class-name ,location)))) + +(defmethod copy-from-alien-function ((class proxy-class) &rest args) + (declare (ignore args)) + #'(lambda (location) + (ensure-proxy-instance class (reference-foreign class location)))) + +(defmethod copy-to-alien-form (instance (class proxy-class) &rest args) + (declare (ignore args)) + `(reference-foreign ',(class-name class) (proxy-location ,instance))) + +(defmethod copy-to-alien-function ((class proxy-class) &rest args) + (declare (ignore class args)) + #'(lambda (instance) + (reference-foreign class (proxy-location instance)))) + (defmethod writer-function ((class proxy-class) &rest args) (declare (ignore args)) #'(lambda (instance location &optional (offset 0)) @@ -376,7 +396,9 @@ (defmethod reader-function ((class proxy-class) &rest args) (declare (ignore args)) #'(lambda (location &optional (offset 0)) - (ensure-proxy-instance class (sap-ref-sap location offset)))) + (let ((instance (sap-ref-sap location offset))) + (unless (null-pointer-p instance) + (ensure-proxy-instance class (reference-foreign class instance)))))) (defmethod destroy-function ((class proxy-class) &rest args) (declare (ignore args)) @@ -408,10 +430,11 @@ (defmethod initialize-instance ((struct struct) &rest initargs) (declare (ignore initargs)) - (let ((size (proxy-instance-size (class-of struct)))) - (if (zerop size) - (error "~A has zero size" (class-of struct)) - (setf (slot-value struct 'location) (allocate-memory size)))) + (unless (slot-boundp struct 'location) + (let ((size (proxy-instance-size (class-of struct)))) + (if (zerop size) + (error "~A has zero size" (class-of struct)) + (setf (slot-value struct 'location) (allocate-memory size))))) (call-next-method)) @@ -426,13 +449,6 @@ (defmethod unreference-foreign ((class struct-class) location) (deallocate-memory location)) -(defmethod reader-function ((class struct-class) &rest args) - (declare (ignore args)) - #'(lambda (location &optional (offset 0)) - (let ((instance (sap-ref-sap location offset))) - (unless (null-pointer-p instance) - (ensure-proxy-instance class (reference-foreign class instance)))))) - (defclass static-struct-class (struct-class) ())