From 3005806e61162b6f55a29bd7b40fcf2bcc8c35fc Mon Sep 17 00:00:00 2001 From: espen Date: Mon, 6 Feb 2006 18:12:19 +0000 Subject: [PATCH] Replaced WEAK-READER-FUNCTION with optional WEAK-P argument to standard reader functions --- glib/ffi.lisp | 55 ++++++++++++++++++++++++++++++++--------------------- glib/gcallback.lisp | 4 ++-- glib/genums.lisp | 14 +++++++++----- glib/glib.lisp | 17 +++++++++++------ glib/gparam.lisp | 10 +++------- glib/gtype.lisp | 8 +++++--- glib/proxy.lisp | 24 +++++++++++++++++------ 7 files changed, 81 insertions(+), 51 deletions(-) diff --git a/glib/ffi.lisp b/glib/ffi.lisp index 728b643..e024d42 100644 --- a/glib/ffi.lisp +++ b/glib/ffi.lisp @@ -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 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-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 @@ (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 @@ (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 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 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 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 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 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 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 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 @@ (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)))))) diff --git a/glib/gcallback.lisp b/glib/gcallback.lisp index 6a5cbab..2d0d5a6 100644 --- a/glib/gcallback.lisp +++ b/glib/gcallback.lisp @@ -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 diff --git a/glib/genums.lisp b/glib/genums.lisp index 9baa725..224f48c 100644 --- a/glib/genums.lisp +++ b/glib/genums.lisp @@ -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) @@ -134,7 +135,8 @@ (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 @@ (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 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)))))))) diff --git a/glib/glib.lisp b/glib/glib.lisp index a2731eb..c57882a 100644 --- a/glib/glib.lisp +++ b/glib/glib.lisp @@ -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 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 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 @@ (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 @@ (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 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))))) diff --git a/glib/gparam.lisp b/glib/gparam.lisp index 7c1ab5e..fb1fef1 100644 --- a/glib/gparam.lisp +++ b/glib/gparam.lisp @@ -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-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)) diff --git a/glib/gtype.lisp b/glib/gtype.lisp index 2498302..1d2543f 100644 --- a/glib/gtype.lisp +++ b/glib/gtype.lisp @@ -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))))) @@ -358,7 +359,8 @@ (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)))) diff --git a/glib/proxy.lisp b/glib/proxy.lisp index a415dca..52e329d 100644 --- a/glib/proxy.lisp +++ b/glib/proxy.lisp @@ -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 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)))))) -- 2.11.0