chiark / gitweb /
Added :param slot allocation to gobject-class
[clg] / glib / gtype.lisp
index 87b079dd56b0eead26bfdbeb0ec5bfde40c08e4b..ae55992eee6332eb6343d0f46a44c25dd4bfff59 100644 (file)
@@ -1,5 +1,5 @@
 ;; Common Lisp bindings for GTK+ v2.0
-;; Copyright (C) 2000 Espen S. Johnsen <espejohn@online.no>
+;; Copyright (C) 2000 Espen S. Johnsen <esj@stud.cs.uit.no>
 ;;
 ;; This library is free software; you can redistribute it and/or
 ;; modify it under the terms of the GNU Lesser General Public
@@ -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: gtype.lisp,v 1.1 2000-08-14 16:44:34 espen Exp $
+;; $Id: gtype.lisp,v 1.7 2001-01-28 14:11:20 espen Exp $
 
 (in-package "GLIB")
 
@@ -38,8 +38,8 @@ (define-foreign %type-from-name () type-number
 (define-foreign type-instance-size (type) int
   ((find-type-number type) type-number))
 
-(define-foreign type-create-instance (type) pointer
-  ((find-type-number type) type-number))
+(define-foreign type-create-instance (type) pointer
+  ((find-type-number type) type-number))
 
 (define-foreign type-free-instance () nil
   (instance pointer))
@@ -171,10 +171,10 @@ (defmethod (setf slot-value-using-class)
        object))
      ((or (functionp writer) (symbolp writer))
       (funcall writer value object)
-      object)
+      value)
      (t
       (funcall (fdefinition writer) value object)
-      object))))
+      value))))
        
 
 (defmethod validate-superclass
@@ -234,7 +234,11 @@ (defmethod from-alien-initialize-instance ((instance alien-instance)
 
 (deftype-method translate-type-spec alien-instance (type-spec)
   (declare (ignore type-spec))
-  'system-area-pointer)
+  (translate-type-spec 'pointer))
+
+(deftype-method size-of alien-instance (type-spec)
+  (declare (ignore type-spec))
+  (size-of 'pointer))
 
 
 
@@ -273,11 +277,6 @@   (defmethod shared-initialize ((class alien-class) names
     (declare (ignore initargs))
     (call-next-method)
 
-    ;; For some reason I can't figure out, accessors for only the
-    ;; first direct slot in an alien class gets defined by
-    ;; PCL. Therefore it has to be done here.
-    (pcl::fix-slot-accessors class (class-direct-slots class) 'pcl::add)
-    
     (when alien-name
       (setf (alien-type-name (or name (class-name class))) (first alien-name)))
     (when size
@@ -365,7 +364,7 @@   (defmethod compute-virtual-slot-location
                            (alien::make-heap-alien-info
                             :type (alien::parse-alien-type
                                    `(function
-                                     void ,alien-type system-area-pointer))
+                                     void system-area-pointer ,alien-type))
                             :sap-form (system:foreign-symbol-address writer))))
                          (to-alien (get-to-alien-function type))
                          (cleanup  (get-cleanup-function type)))
@@ -397,7 +396,11 @@   (defmethod compute-slots ((class alien-class))
     
       ;; Reverse the direct slot definitions so the effective slots
       ;; will be in correct order.
-      (setf direct-slots (nreverse direct-slots)))
+      (setf direct-slots (reverse direct-slots))
+      ;; This nreverse caused me so much frustration that I leave it
+      ;; here just as a reminder of what not to do.
+;      (setf direct-slots (nreverse direct-slots))
+      )
     (call-next-method))
 
 
@@ -470,7 +473,8 @@ (deftype-method translate-to-alien
 
 (deftype-method translate-from-alien
     alien-object (type-spec location &optional alloc)
-  (declare (ignore alloc))
+  ;; Reference counted objects are always treated as if alloc were :reference
+  (declare (ignore alloc)) 
   `(let ((location ,location))
      (unless (null-pointer-p location)
        (ensure-alien-instance ',type-spec location))))
@@ -537,16 +541,17 @@ (deftype-method translate-to-alien
        (alien-instance-location object))))
 
 (deftype-method translate-from-alien
-    alien-structure (type-spec location &optional (alloc :dynamic))
+    alien-structure (type-spec location &optional (alloc :reference))
   `(let ((location ,location))
      (unless (null-pointer-p location)
        ,(ecase alloc
-         (:dynamic `(ensure-alien-instance ',type-spec location))
+         (:copy `(ensure-alien-instance ',type-spec location))
          (:static `(ensure-alien-instance ',type-spec location :static t))
-         (:copy `(ensure-alien-instance
-                  ',type-spec
-                  `(,(alien-copier type-spec)
-                    location ,(alien-class-size (find-class type-spec)))))))))
+         (:reference
+          `(ensure-alien-instance
+            ',type-spec
+            (,(alien-copier type-spec)
+             location ,(alien-class-size (find-class type-spec)))))))))
 
 (deftype-method cleanup-alien alien-structure (type-spec sap &optional copied)
   (when copied
@@ -577,7 +582,7 @@ (defmethod from-alien-initialize-instance ((structure alien-structure)
 ;;;; Superclass wrapping types in the glib type system
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
-  (defclass gtype (alien-object)
+  (defclass ginstance (alien-object)
     ()
     (:metaclass alien-class)
     (:size 4 #|(size-of 'pointer)|#)))
@@ -588,7 +593,7 @@ (defun %alien-instance-type-number (location)
     (sap-ref-unsigned class 0)))
 
 
-(deftype-method translate-from-alien gtype (type-spec location &optional alloc)
+(deftype-method translate-from-alien ginstance (type-spec location &optional alloc)
   (declare (ignore type-spec alloc))
   `(let ((location ,location))
      (unless (null-pointer-p location)
@@ -598,13 +603,13 @@ (deftype-method translate-from-alien gtype (type-spec location &optional alloc)
 
 
 
-;;;; Metaclass for subclasses of gtype-class
+;;;; Metaclass for subclasses of ginstance-class
 
 (eval-when (:compile-toplevel :load-toplevel :execute)
-  (defclass gtype-class (alien-class)))
+  (defclass ginstance-class (alien-class)))
 
 
-(defmethod shared-initialize ((class gtype-class) names
+(defmethod shared-initialize ((class ginstance-class) names
                              &rest initargs &key name)
   (declare (ignore initargs names))
   (call-next-method)
@@ -614,12 +619,12 @@ (defmethod shared-initialize ((class gtype-class) names
 
 
 (defmethod validate-superclass
-    ((class gtype-class) (super pcl::standard-class))
-  (subtypep (class-name super) 'gtype))
+    ((class ginstance-class) (super pcl::standard-class))
+  (subtypep (class-name super) 'ginstance))
 
 
-(defmethod allocate-alien-storage ((class gtype-class))
-  (type-create-instance (find-type-number class)))
+; (defmethod allocate-alien-storage ((class ginstance-class))
+  (type-create-instance (find-type-number class)))
 
 
 ;;;; Initializing type numbers