;; 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.8 2004-10-27 14:59:00 espen Exp $
+;; $Id: proxy.lisp,v 1.10 2004-11-03 16:18:16 espen Exp $
(in-package "GLIB")
(declare (ignore object))
(error "Can't read slot: ~A" (slot-definition-name slotd))))
(symbol #'(lambda (object)
- (funcall getter object))))))
+ (funcall getter object)))
+ (string (let ((reader (mkbinding-late getter
+ (slot-definition-type slotd) 'pointer)))
+ (setf (slot-value slotd 'reader-function)
+ #'(lambda (object)
+ (funcall reader (proxy-location object)))))))))
(unless (slot-boundp slotd 'writer-function)
(setf
(declare (ignore object))
(error "Can't set slot: ~A" (slot-definition-name slotd))))
((or symbol cons) #'(lambda (value object)
- (funcall (fdefinition setter) value object))))))
+ (funcall (fdefinition setter) value object)))
+ (string
+ (let ((writer (mkbinding-late setter 'nil 'pointer
+ (slot-definition-type slotd))))
+ (setf (slot-value slotd 'writer-function)
+ #'(lambda (value object)
+ (funcall writer (proxy-location object) value))))))))
(unless (slot-boundp slotd 'boundp-function)
(setf
(when ref
(ext:weak-pointer-value ref))))
+(defun instance-cached-p (location)
+ (gethash (system:sap-int location) *instance-cache*))
+
(defun remove-cached-instance (location)
(remhash (system:sap-int location) *instance-cache*))
(defgeneric initialize-proxy (object &rest initargs))
(defgeneric instance-finalizer (object)))
+(defmethod print-object ((instance proxy) stream)
+ (print-unreadable-object (instance stream :type t :identity nil)
+ (format stream "at 0x~X" (sap-int (proxy-location instance)))))
+
(defmethod initialize-instance :after ((instance proxy)
&rest initargs &key)
(declare (type symbol type) (type system-area-pointer location))
(let ((free (proxy-class-free class)))
#'(lambda ()
- (funcall free type location)
- (remove-cached-instance location)))))
+ (when (instance-cached-p location)
+ (remove-cached-instance location)
+ (funcall free type location))))))
(deftype-method translate-type-spec proxy (type-spec)
`(,free ',type-spec ,location)
`(funcall ',free ',type-spec ,location))))
-;; (defun proxy-instance-size (proxy)
-;; (proxy-class-size (class-of proxy)))
;;;; Metaclass used for subclasses of proxy
(defclass effective-alien-slot-definition (effective-virtual-slot-definition)
((offset :reader slot-definition-offset :initarg :offset)))
-
- (defclass effective-virtual-alien-slot-definition (effective-virtual-slot-definition)
- ())
(defmethod most-specific-proxy-superclass ((class proxy-class))
(free (setf (slot-value class 'free) (first free)))
((slot-boundp class 'free) (slot-makunbound class 'free))))
-;; (defmethod finalize-inheritance ((class proxy-class))
-;; (call-next-method)
(defmethod shared-initialize :after ((class proxy-class) names &rest initargs)
(let ((super (most-specific-proxy-superclass class)))
(unless (or (not super) (eq super (find-class 'proxy)))
(defmethod effective-slot-definition-class ((class proxy-class) &rest initargs)
(case (getf initargs :allocation)
(:alien (find-class 'effective-alien-slot-definition))
- (:virtual (find-class 'effective-virtual-alien-slot-definition))
(t (call-next-method))))
(call-next-method))
- (defmethod initialize-internal-slot-functions ((slotd effective-virtual-alien-slot-definition))
- (with-slots (getter setter type) slotd
- (when (and (not (slot-boundp slotd 'reader-function)) (stringp getter))
- (let ((reader (mkbinding-late getter type 'pointer)))
- (setf (slot-value slotd 'reader-function)
- #'(lambda (object)
- (funcall reader (proxy-location object))))))
-
- (when (and (not (slot-boundp slotd 'writer-function)) (stringp setter))
- (let ((writer (mkbinding-late setter 'nil 'pointer type)))
- (setf (slot-value slotd 'writer-function)
- #'(lambda (value object)
- (funcall writer (proxy-location object) value))))))
- (call-next-method))
-
;; TODO: call some C code to detect this a compile time
(defconstant +struct-alignmen+ 4)