;; 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")
(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))
(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))
(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))
(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)
())