chiark / gitweb /
Disable SVG tests if librsvg is not available
[clg] / glib / proxy.lisp
index 4aeaa4c6314c06de3b240c79409f8d3025275edf..4dcc4074530933f7148ad205901029d3172cfc56 100644 (file)
@@ -20,7 +20,7 @@
 ;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 ;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-;; $Id: proxy.lisp,v 1.30 2006/02/08 21:43:33 espen Exp $
+;; $Id: proxy.lisp,v 1.32 2006/02/09 22:26:38 espen Exp $
 
 (in-package "GLIB")
 
@@ -84,7 +84,7 @@ (defmethod initialize-internal-slot-functions ((slotd effective-virtual-slot-def
        (slot-value slotd 'reader-function)
        #'(lambda (object)
           (declare (ignore object))
-          (error "Can't read slot: ~A" (slot-definition-name slotd)))
+          (error "Slot is not readable: ~A" (slot-definition-name slotd)))
        (slot-value slotd 'boundp-function)
        #'(lambda (object) (declare (ignore object)) nil))
 
@@ -163,9 +163,9 @@ (defmethod initialize-internal-slot-functions ((slotd effective-virtual-slot-def
   (setf 
    (slot-value slotd 'writer-function)
    (if (not (slot-boundp slotd 'setter))
-       #'(lambda (object)
-          (declare (ignore object))
-          (error "Can't set slot: ~A" (slot-definition-name slotd)))
+       #'(lambda (value object)
+          (declare (ignore value object))
+          (error "Slot is not writable: ~A" (slot-definition-name slotd)))
      (with-slots (setter) slotd
        (etypecase setter
         (function setter)
@@ -292,13 +292,23 @@ (defun list-invalidated-instances ()
 
 ;; TODO: add a ref-counted-proxy subclass
 (defclass proxy ()
-  ((location :allocation :special :reader foreign-location :type pointer))
+  ((location :allocation :special :type pointer))
   (:metaclass virtual-slots-class))
 
 (defgeneric instance-finalizer (object))
 (defgeneric reference-foreign (class location))
 (defgeneric unreference-foreign (class location))
 (defgeneric invalidate-instance (object))
+(defgeneric allocate-foreign (object &key &allow-other-keys))
+
+(defun foreign-location (instance)
+  (slot-value instance 'location))
+
+(defun (setf foreign-location) (location instance)
+  (setf (slot-value instance 'location) location))
+
+(defun proxy-valid-p (instance)
+  (slot-boundp instance 'location))
 
 (defmethod reference-foreign ((name symbol) location)
   (reference-foreign (find-class name) location))
@@ -316,8 +326,10 @@ (defmethod print-object ((instance proxy) stream)
        (format stream "at 0x~X" (sap-int (foreign-location instance)))
       (write-string "at \"unbound\"" stream))))
 
-(defmethod initialize-instance :around ((instance proxy) &rest initargs)
-  (declare (ignore initargs))
+(defmethod initialize-instance :around ((instance proxy) &rest initargs &key &allow-other-keys) 
+  (setf  
+   (foreign-location instance)
+   (apply #'allocate-foreign instance initargs))
   (prog1
       (call-next-method)
     (cache-instance instance)
@@ -553,7 +565,7 @@ (defmethod make-proxy-instance ((class proxy-class) location &key weak)
         (or
          (find-invalidated-instance class)
          (allocate-instance class))))
-    (setf (slot-value instance 'location) location)
+    (setf (foreign-location instance) location)
     (unless weak
       (finalize instance (instance-finalizer instance)))
     instance))
@@ -566,14 +578,12 @@ (defclass struct (proxy)
   (:metaclass proxy-class)
   (:size 0))
 
-(defmethod initialize-instance ((struct struct) &rest initargs)
+(defmethod allocate-foreign ((struct struct) &rest initargs)
   (declare (ignore initargs))
-  (unless (slot-boundp struct 'location)
-    (let ((size (foreign-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))
+  (let ((size (foreign-size (class-of struct))))
+    (if (zerop size)
+       (error "~A has zero size" (class-of struct))
+      (allocate-memory size))))
 
 
 ;;;; Metaclasses used for subclasses of struct