From 1dbf4216c7c6a8845e1831970dd1c0dc3902c4d3 Mon Sep 17 00:00:00 2001 From: espen Date: Tue, 9 Nov 2004 10:10:59 +0000 Subject: [PATCH] Object finalization optimized --- glib/gboxed.lisp | 21 ++++++++++++++------- glib/gobject.lisp | 15 ++++++++++++++- glib/proxy.lisp | 12 ++++++------ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/glib/gboxed.lisp b/glib/gboxed.lisp index 41f6243..c2daeb5 100644 --- a/glib/gboxed.lisp +++ b/glib/gboxed.lisp @@ -15,7 +15,7 @@ ;; 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: gboxed.lisp,v 1.12 2004-11-07 21:41:35 espen Exp $ +;; $Id: gboxed.lisp,v 1.13 2004-11-09 10:10:59 espen Exp $ (in-package "GLIB") @@ -29,6 +29,13 @@ () (:metaclass struct-class)) +(defmethod instance-finalizer ((instance boxed)) + (let ((location (proxy-location instance)) + (type-number (type-number-of instance))) + #'(lambda () + (remove-cached-instance location) + (%boxed-free type-number location)))) + ;;;; Metaclass for boxed classes @@ -52,19 +59,19 @@ (register-type class-name type-number))) -(defbinding %boxed-copy (type location) pointer - ((find-type-number type) type-number) +(defbinding %boxed-copy () pointer + (type-number type-number) (location pointer)) -(defbinding %boxed-free (type location) nil - ((find-type-number type) type-number) +(defbinding %boxed-free () nil + (type-number type-number) (location pointer)) (defmethod reference-foreign ((class boxed-class) location) - (%boxed-copy (class-name class) location)) + (%boxed-copy (find-type-number class) location)) (defmethod unreference-foreign ((class boxed-class) location) - (%boxed-free (class-name class) location)) + (%boxed-free (find-type-number class) location)) ;;;; diff --git a/glib/gobject.lisp b/glib/gobject.lisp index 4005672..f41cb32 100644 --- a/glib/gobject.lisp +++ b/glib/gobject.lisp @@ -15,7 +15,7 @@ ;; 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: gobject.lisp,v 1.19 2004-11-07 15:58:08 espen Exp $ +;; $Id: gobject.lisp,v 1.20 2004-11-09 10:10:59 espen Exp $ (in-package "GLIB") @@ -205,6 +205,13 @@ (call-next-method) (%object-weak-ref object)) +(defmethod instance-finalizer ((instance gobject)) + (let ((location (proxy-location instance))) + #'(lambda () + (remove-cached-instance location) + (%weak-object-unref location) + (%object-unref location)))) + (defcallback weak-notify (nil (data int) (location pointer)) (let ((object (find-cached-instance location))) @@ -218,6 +225,12 @@ ((callback weak-notify) pointer) (0 unsigned-int)) +(defbinding %object-weak-unref () nil + (location pointer) + ((callback weak-notify) pointer) + (0 unsigned-int)) + + (defbinding (%gobject-new "g_object_new") () pointer (type type-number) (nil null)) diff --git a/glib/proxy.lisp b/glib/proxy.lisp index eeecae1..9058e23 100644 --- a/glib/proxy.lisp +++ b/glib/proxy.lisp @@ -15,7 +15,7 @@ ;; 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.11 2004-11-06 21:39:58 espen Exp $ +;; $Id: proxy.lisp,v 1.12 2004-11-09 10:10:59 espen Exp $ (in-package "GLIB") @@ -224,8 +224,7 @@ ;; (unless (find-method #'unreference-foreign nil (list (class-of class) t) nil) ;; (error "No matching method for UNREFERENCE-INSTANCE when called with class ~A" class)) #'(lambda () - (when (instance-cached-p location) - (remove-cached-instance location)) + (remove-cached-instance location) (unreference-foreign class location)))) @@ -409,9 +408,10 @@ (defmethod initialize-instance ((struct struct) &rest initargs) (declare (ignore initargs)) - (setf - (slot-value struct 'location) - (allocate-memory (proxy-instance-size (class-of struct)))) + (let ((size (proxy-instance-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)) -- 2.11.0