Object finalization optimized
authorespen <espen>
Tue, 9 Nov 2004 10:10:59 +0000 (10:10 +0000)
committerespen <espen>
Tue, 9 Nov 2004 10:10:59 +0000 (10:10 +0000)
glib/gboxed.lisp
glib/gobject.lisp
glib/proxy.lisp

index 41f6243..c2daeb5 100644 (file)
@@ -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")
 
   ()
   (: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
 
     (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))
 
 
 ;;;; 
index 4005672..f41cb32 100644 (file)
@@ -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")
 
   (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)))
   ((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))
index eeecae1..9058e23 100644 (file)
@@ -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")
 
 ;;     (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))))
 
 
 
 (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))