chiark / gitweb /
Replaced WEAK-READER-FUNCTION with optional WEAK-P argument to standard reader functions
authorespen <espen>
Mon, 6 Feb 2006 18:12:19 +0000 (18:12 +0000)
committerespen <espen>
Mon, 6 Feb 2006 18:12:19 +0000 (18:12 +0000)
glib/ffi.lisp
glib/gcallback.lisp
glib/genums.lisp
glib/glib.lisp
glib/gparam.lisp
glib/gtype.lisp
glib/proxy.lisp

index d725fa9e36be9e91375139fac155948f60b65a89..c273d5d090631b045a13b4dc755f2af8e078de46 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: ffi.lisp,v 1.22 2006/02/06 11:49:50 espen Exp $
+;; $Id: ffi.lisp,v 1.23 2006/02/06 18:12:19 espen Exp $
 
 (in-package "GLIB")
 
@@ -271,7 +271,6 @@ (def-type-method copy-from-alien-function ())
 
 (def-type-method writer-function ())
 (def-type-method reader-function ())
-(def-type-method weak-reader-function ())
 (def-type-method destroy-function ())
 
 (def-type-method unbound-value ()
@@ -348,10 +347,6 @@ (defmethod copy-from-alien-form  (form (type t) &rest args)
 (defmethod copy-from-alien-function  ((type t) &rest args)
   (apply #'from-alien-function type args))
 
-(defmethod weak-reader-function ((type symbol) &rest args)
-  (apply #'reader-function type args))
-
-
 (defmethod alien-type ((type (eql 'signed-byte)) &rest args)
   (declare (ignore type))
   (destructuring-bind (&optional (size '*)) args
@@ -393,13 +388,17 @@ (defmethod reader-function ((type (eql 'signed-byte)) &rest args)
   (destructuring-bind (&optional (size '*)) args
     (let ((size (if (eq size '*) +bits-of-int+ size)))
       (ecase size
-       (8 #'(lambda (sap &optional (offset 0)) 
+       (8 #'(lambda (sap &optional (offset 0) weak-p) 
+              (declare (ignore weak-p))
               (signed-sap-ref-8 sap offset)))
-       (16 #'(lambda (sap &optional (offset 0)) 
+       (16 #'(lambda (sap &optional (offset 0) weak-p)
+               (declare (ignore weak-p))
                (signed-sap-ref-16 sap offset)))
-       (32 #'(lambda (sap &optional (offset 0)) 
+       (32 #'(lambda (sap &optional (offset 0) weak-p) 
+               (declare (ignore weak-p)) 
                (signed-sap-ref-32 sap offset)))
-       (64 #'(lambda (sap &optional (offset 0))
+       (64 #'(lambda (sap &optional (offset 0) weak-p) 
+               (declare (ignore weak-p))
                (signed-sap-ref-64 sap offset)))))))
 
 (defmethod alien-type ((type (eql 'unsigned-byte)) &rest args)
@@ -435,13 +434,17 @@ (defmethod reader-function ((type (eql 'unsigned-byte)) &rest args)
   (destructuring-bind (&optional (size '*)) args
     (let ((size (if (eq size '*) +bits-of-int+ size)))
       (ecase size
-       (8 #'(lambda (sap &optional (offset 0)) 
+       (8 #'(lambda (sap &optional (offset 0) weak-p)
+              (declare (ignore weak-p))
               (sap-ref-8 sap offset)))
-       (16 #'(lambda (sap &optional (offset 0)) 
+       (16 #'(lambda (sap &optional (offset 0) weak-p)
+               (declare (ignore weak-p)) 
                (sap-ref-16 sap offset)))
-       (32 #'(lambda (sap &optional (offset 0)) 
+       (32 #'(lambda (sap &optional (offset 0) weak-p)
+               (declare (ignore weak-p)) 
                (sap-ref-32 sap offset)))
-       (64 #'(lambda (sap &optional (offset 0))
+       (64 #'(lambda (sap &optional (offset 0) weak-p)
+               (declare (ignore weak-p))
                (sap-ref-64 sap offset)))))))
   
   
@@ -495,7 +498,8 @@ (defmethod writer-function ((type (eql 'single-float)) &rest args)
 
 (defmethod reader-function ((type (eql 'single-float)) &rest args)
   (declare (ignore type args))
-  #'(lambda (sap &optional (offset 0)) 
+  #'(lambda (sap &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (sap-ref-single sap offset)))
 
 
@@ -523,7 +527,8 @@ (defmethod writer-function ((type (eql 'double-float)) &rest args)
 
 (defmethod reader-function ((type (eql 'double-float)) &rest args)
   (declare (ignore type args))
-  #'(lambda (sap &optional (offset 0)) 
+  #'(lambda (sap &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (sap-ref-double sap offset)))
 
 
@@ -542,7 +547,8 @@ (defmethod writer-function ((type (eql 'base-char)) &rest args)
 
 (defmethod reader-function ((type (eql 'base-char)) &rest args)
   (declare (ignore type args))
-  #'(lambda (location &optional (offset 0))
+  #'(lambda (location &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (code-char (sap-ref-8 location offset))))
 
 
@@ -636,7 +642,8 @@ (defmethod writer-function ((type (eql 'string)) &rest args)
 
 (defmethod reader-function ((type (eql 'string)) &rest args)
   (declare (ignore type args))
-  #'(lambda (location &optional (offset 0))
+  #'(lambda (location &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (unless (null-pointer-p (sap-ref-sap location offset))
        #+cmu(%naturalize-c-string (sap-ref-sap location offset))
        #+sbcl(%naturalize-utf8-string (sap-ref-sap location offset)))))
@@ -698,7 +705,8 @@ (defmethod writer-function ((type (eql 'pathname)) &rest args)
 (defmethod reader-function ((type (eql 'pathname)) &rest args)
   (declare (ignore type args))
   (let ((string-reader (reader-function 'string)))
-  #'(lambda (location &optional (offset 0))
+  #'(lambda (location &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (let ((string (funcall string-reader location offset)))
        (when string
          (parse-namestring string))))))
@@ -745,7 +753,8 @@ (defmethod writer-function ((type (eql 'boolean)) &rest args)
 (defmethod reader-function ((type (eql 'boolean)) &rest args)
   (declare (ignore type))
   (let ((reader (apply #'reader-function 'signed-byte args)))
-  #'(lambda (location &optional (offset 0))
+  #'(lambda (location &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (not (zerop (funcall reader location offset))))))
 
 
@@ -797,7 +806,8 @@ (defmethod writer-function ((type (eql 'system-area-pointer)) &rest args)
 
 (defmethod reader-function ((type (eql 'system-area-pointer)) &rest args)
   (declare (ignore type args))
-  #'(lambda (location &optional (offset 0))
+  #'(lambda (location &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (sap-ref-sap location offset)))
 
 
@@ -907,7 +917,8 @@ (defmethod reader-function ((type (eql 'callback)) &rest args)
   (declare (ignore type args))
   (let ((reader (reader-function 'pointer))
        (from-alien (from-alien-function 'callback)))
-  #'(lambda (location &optional (offset 0))
+  #'(lambda (location &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (let ((pointer (funcall reader location offset)))
        (unless (null-pointer-p pointer)
          (funcall from-alien pointer))))))
index d68483bcf4bc9de493de225efe5a962ef3d9928c..9a30a769935537859df8e0310303b60c31c1ed53 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: gcallback.lisp,v 1.27 2006/02/06 11:56:22 espen Exp $
+;; $Id: gcallback.lisp,v 1.28 2006/02/06 18:12:19 espen Exp $
 
 (in-package "GLIB")
 
@@ -59,7 +59,7 @@ (defun callback-trampoline (callback-id n-params param-values &optional
         (args (loop
                for n from 0 below n-params
                for offset from 0 by +gvalue-size+
-               collect (gvalue-weak-get (sap+ param-values offset)))))
+               collect (gvalue-get (sap+ param-values offset) t))))
     (unwind-protect
        (let ((result (apply #'invoke-callback callback-id return-type args)))
          (when return-type
index 529145290dd680c96d05d62a4fb9de766a526d36..14bff9a4f276ee06d9a510f8debd2a0d62efb683 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: genums.lisp,v 1.16 2006/02/05 15:38:57 espen Exp $
+;; $Id: genums.lisp,v 1.17 2006/02/06 18:12:19 espen Exp $
 
 (in-package "GLIB")
   
@@ -87,7 +87,8 @@ (defmethod reader-function ((type (eql 'enum)) &rest args)
   (declare (ignore type))
   (let ((reader (reader-function 'signed))
        (function (apply #'from-alien-function 'enum args)))
-    #'(lambda (location &optional (offset 0))
+    #'(lambda (location &optional (offset 0) weak-p)
+       (declare (ignore weak-p))
        (funcall function (funcall reader location offset)))))
 
 (defun enum-int (enum type)
@@ -134,7 +135,8 @@        (defmethod writer-function ((type (eql ',name)) &rest args)
        (defmethod reader-function ((type (eql ',name)) &rest args)
         (declare (ignore type args))
         (let ((reader (reader-function 'signed)))
-          #'(lambda (location &optional (offset 0))
+          #'(lambda (location &optional (offset 0) weak-p)
+              (declare (ignore weak-p))
               (,int-enum (funcall reader location offset))))))))
 
 
@@ -209,7 +211,8 @@ (defmethod reader-function ((type (eql 'flags)) &rest args)
   (declare (ignore type))
   (let ((reader (reader-function 'unsigned))
        (function (apply #'from-alien-function 'flags args)))
-    #'(lambda (location &optional (offset 0))
+    #'(lambda (location &optional (offset 0) weak-p)
+       (declare (ignore weak-p))
        (funcall function (funcall reader location offset)))))
 
 
@@ -265,7 +268,8 @@        (defmethod writer-function ((type (eql ',name)) &rest args)
        (defmethod reader-function ((type (eql ',name)) &rest args)
         (declare (ignore type args))
         (let ((reader (reader-function 'signed)))
-          #'(lambda (location &optional (offset 0))
+          #'(lambda (location &optional (offset 0) weak-p)
+              (declare (ignore weak-p))
               (,int-flags (funcall reader location offset))))))))
 
 
index 01bd66f1e4fa1c8fc9db49af29b9419f2f7aaf28..d5c68568cb8314dc673a5e96515286e50b7dd205 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: glib.lisp,v 1.31 2005/04/24 13:27:20 espen Exp $
+;; $Id: glib.lisp,v 1.32 2006/02/06 18:12:19 espen Exp $
 
 
 (in-package "GLIB")
@@ -230,7 +230,8 @@ (defmethod writer-function ((type (eql 'glist)) &rest args)
 (defmethod reader-function ((type (eql 'glist)) &rest args)
   (declare (ignore type))
   (destructuring-bind (element-type) args
-    #'(lambda (location &optional (offset 0))
+    #'(lambda (location &optional (offset 0) weak-p)
+       (declare (ignore weak-p))
        (unless (null-pointer-p (sap-ref-sap location offset))
          (map-glist 'list #'identity (sap-ref-sap location offset) element-type)))))
 
@@ -339,7 +340,8 @@ (defmethod writer-function ((type (eql 'gslist)) &rest args)
 (defmethod reader-function ((type (eql 'gslist)) &rest args)
   (declare (ignore type))
   (destructuring-bind (element-type) args
-    #'(lambda (location &optional (offset 0))
+    #'(lambda (location &optional (offset 0) weak-p)
+       (declare (ignore weak-p))
        (unless (null-pointer-p (sap-ref-sap location offset))
          (map-glist 'list #'identity (sap-ref-sap location offset) element-type)))))
 
@@ -486,7 +488,8 @@ (defmethod reader-function ((type (eql 'vector)) &rest args)
   (destructuring-bind (element-type &optional (length '*)) args
     (if (eq length '*)
        (error "Can't create reader function for vector of variable size")
-      #'(lambda (location &optional (offset 0))
+      #'(lambda (location &optional (offset 0) weak-p)
+         (declare (ignore weak-p))
          (unless (null-pointer-p (sap-ref-sap location offset))
            (map-c-vector 'vector #'identity (sap-ref-sap location offset) 
             element-type length))))))
@@ -607,7 +610,8 @@ (defmethod reader-function ((type (eql 'null-terminated-vector)) &rest args)
   (destructuring-bind (element-type) args
     (unless (eq (alien-type element-type) (alien-type 'pointer))
       (error "Elements in null-terminated vectors need to be of pointer types"))
-    #'(lambda (location &optional (offset 0))
+    #'(lambda (location &optional (offset 0) weak-p)
+       (declare (ignore weak-p))
        (unless (null-pointer-p (sap-ref-sap location offset))
          (map-0-vector 'vector #'identity (sap-ref-sap location offset) 
           element-type)))))
@@ -704,7 +708,8 @@ (defmethod writer-function ((type (eql 'counted-vector)) &rest args)
 (defmethod reader-function ((type (eql 'counted-vector)) &rest args)
   (declare (ignore type))
   (destructuring-bind (element-type) args
-    #'(lambda (location &optional (offset 0))
+    #'(lambda (location &optional (offset 0) weak-p)
+       (declare (ignore weak-p))
        (unless (null-pointer-p (sap-ref-sap location offset))
          (map-counted-vector 'vector #'identity 
           (sap-ref-sap location offset) element-type)))))
index 086d99355096cec5c2c0b48a465ff45d10a91720..8af8db1008fa5c8d17edc9550e84fa02e3e3f545 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: gparam.lisp,v 1.18 2006/02/06 11:56:22 espen Exp $
+;; $Id: gparam.lisp,v 1.19 2006/02/06 18:12:19 espen Exp $
 
 (in-package "GLIB")
 
@@ -64,13 +64,9 @@ (defun gvalue-free (gvalue &optional (unset-p t))
 (defun gvalue-type (gvalue)
   (type-from-number (sap-ref-32 gvalue 0)))
 
-(defun gvalue-get (gvalue)  
+(defun gvalue-get (gvalue &optional weak-p)
   (funcall (reader-function (gvalue-type gvalue))
-   gvalue +gvalue-value-offset+))
-
-(defun gvalue-weak-get (gvalue)  
-  (funcall (weak-reader-function (gvalue-type gvalue))
-   gvalue +gvalue-value-offset+))
+   gvalue +gvalue-value-offset+ weak-p))
 
 (defun gvalue-set (gvalue value)
   (funcall (writer-function (gvalue-type gvalue))
index 41e6da0f5c4c4cc1221007b040a0b98cb46fbf4e..4865710b521a17e2e58859c56d36aad84bc08c90 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: gtype.lisp,v 1.40 2006/02/06 11:52:24 espen Exp $
+;; $Id: gtype.lisp,v 1.41 2006/02/06 18:12:19 espen Exp $
 
 (in-package "GLIB")
 
@@ -69,7 +69,8 @@ (defmethod writer-function ((type (eql 'gtype)) &rest args)
 (defmethod reader-function ((type (eql 'gtype)) &rest args)
   (declare (ignore type args))
   (let ((reader (reader-function 'type-number)))
-    #'(lambda (location &optional (offset 0))
+    #'(lambda (location &optional (offset 0) weak-p)
+       (declare (ignore weak-p))
        (type-from-number (funcall reader location offset)))))
 
 
@@ -358,7 +359,8 @@ (defmethod copy-from-alien-function ((class ginstance-class) &rest args)
 
 (defmethod reader-function ((class ginstance-class) &rest args)
   (declare (ignore args))
-  #'(lambda (location &optional (offset 0))
+  #'(lambda (location &optional (offset 0) weak-p)
+      (declare (ignore weak-p))
       (ensure-proxy-instance class (sap-ref-sap location offset))))
 
 
index eebf8da986c05a976086a454d976cc8967f6c3aa..5bd6f920819e7738180bb5cb8b0a3e5c42ab139f 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.27 2006/02/06 12:48:40 espen Exp $
+;; $Id: proxy.lisp,v 1.28 2006/02/06 18:12:19 espen Exp $
 
 (in-package "GLIB")
 
@@ -495,7 +495,8 @@ (defmethod writer-function ((class proxy-class) &rest args)
 
 (defmethod reader-function ((class proxy-class) &rest args)
   (declare (ignore args))
-  #'(lambda (location &optional (offset 0))
+  #'(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 (reference-foreign class instance))))))
@@ -583,12 +584,14 @@ (defmethod compute-foreign-size ((class struct-class))
                         (size-of (slot-definition-type slotd))))))
     (+ size (mod size +struct-alignmen+))))
 
-(defmethod weak-reader-function ((class struct-class) &rest args)
+(defmethod reader-function ((class struct-class) &rest args)
   (declare (ignore args))
-  #'(lambda (location &optional (offset 0))
+  #'(lambda (location &optional (offset 0) weak-p)
       (let ((instance (sap-ref-sap location offset)))
        (unless (null-pointer-p instance)
-         (ensure-proxy-instance class instance :weak t)))))
+         (if weak-p
+             (ensure-proxy-instance class instance :weak t)
+           (ensure-proxy-instance class (reference-foreign class instance)))))))
 
 
 (defclass static-struct-class (struct-class)
@@ -602,6 +605,14 @@ (defmethod unreference-foreign ((class static-struct-class) location)
   (declare (ignore class location))
   nil)
 
+(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)))))
+
 
 ;;; Pseudo type for structs which are inlined in other objects
 
@@ -612,7 +623,8 @@ (defmethod size-of ((type (eql 'inlined)) &rest args)
 (defmethod reader-function ((type (eql 'inlined)) &rest args)
   (declare (ignore type))
   (destructuring-bind (class) args
-    #'(lambda (location &optional (offset 0))
+    #'(lambda (location &optional (offset 0) weak-p)
+       (declare (ignore weak-p))
        (ensure-proxy-instance class 
         (reference-foreign class (sap+ location offset))))))