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 728b643..e024d42 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")
 
 
 (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 ()
 (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
   (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)
   (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)))))))
   
   
 
 (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)))
 
 
 
 (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)))
 
 
 
 (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))))
 
 
 
 (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)))))
 (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))))))
 (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))))))
 
 
 
 (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)))
 
 
   (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 6a5cbab..2d0d5a6 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 @@
         (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 9baa725..224f48c 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 @@
   (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)
        (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))))))))
 
 
   (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)))))
 
 
        (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 a2731eb..c57882a 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")
 (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)))))
 
 (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)))))
 
   (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))))))
   (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)))))
 (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 7c1ab5e..fb1fef1 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")
 
 (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 2498302..1d2543f 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 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)))))
 
 
 
 (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 a415dca..52e329d 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")
 
 
 (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 @@ will not be released when the proxy is garbage collected."))
                         (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 @@ will not be released when the proxy is garbage collected."))
   (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 @@ will not be released when the proxy is garbage collected."))
 (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))))))