X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/clg/blobdiff_plain/09f6e23711ab7b3b8f713f0cabdaeffcc7c4ac20..cc74b2c987edc3e2bc85413e92f33e2690a32b1c:/glib/gobject.lisp?ds=sidebyside diff --git a/glib/gobject.lisp b/glib/gobject.lisp index b1c4351..bd0151f 100644 --- a/glib/gobject.lisp +++ b/glib/gobject.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: gobject.lisp,v 1.42 2006-02-04 12:15:32 espen Exp $ +;; $Id: gobject.lisp,v 1.45 2006-02-08 22:10:47 espen Exp $ (in-package "GLIB") @@ -28,6 +28,7 @@ (in-package "GLIB") ;;;; Metaclass used for subclasses of gobject (eval-when (:compile-toplevel :load-toplevel :execute) +;; (push :debug-ref-counting *features*) (defclass gobject-class (ginstance-class) ((instance-slots-p :initform nil :documentation "Non NIL if the class has slots with instance allocation"))) @@ -203,10 +204,18 @@ (defmethod shared-initialize :after ((class gobject-class) names &rest initargs) (eval-when (:compile-toplevel :load-toplevel :execute) (defclass gobject (ginstance) - () + (#+debug-ref-counting + (ref-count :allocation :alien :type int :reader ref-count)) (:metaclass gobject-class) (:gtype "GObject"))) +#+debug-ref-counting +(defmethod print-object ((instance gobject) stream) + (print-unreadable-object (instance stream :type t :identity nil) + (if (proxy-valid-p instance) + (format stream "at 0x~X (~D)" (sap-int (foreign-location instance)) (ref-count instance)) + (write-string "at \"unbound\"" stream)))) + (defun initial-add (object function initargs key pkey) (loop @@ -224,6 +233,12 @@ (defun initial-apply-add (object function initargs key pkey) initargs key pkey)) +(defmethod make-proxy-instance ((class gobject-class) location &rest initargs) + (declare (ignore location initargs)) + (if (slot-value class 'instance-slots-p) + (error "An object of class ~A has instance slots and should only be created with MAKE-INSTANCE" class) + (call-next-method))) + (defmethod initialize-instance :around ((object gobject) &rest initargs) (declare (ignore initargs)) (call-next-method) @@ -236,7 +251,7 @@ (defmethod initialize-instance :around ((object gobject) &rest initargs) (defmethod initialize-instance ((object gobject) &rest initargs) - (unless (slot-boundp object 'location) + (unless (proxy-valid-p object) ;; Extract initargs which we should pass directly to the GObject ;; constructor (let* ((slotds (class-slots (class-of object))) @@ -269,7 +284,7 @@ (defmethod initialize-instance ((object gobject) &rest initargs) (gvalue-init (sap+ tmp string-size) type value)) (unwind-protect (setf - (slot-value object 'location) + (foreign-location object) (%gobject-newv (type-number-of object) (length args) params)) (loop repeat (length args) @@ -278,7 +293,7 @@ (defmethod initialize-instance ((object gobject) &rest initargs) (gvalue-unset (sap+ tmp string-size))) (deallocate-memory params))) (setf - (slot-value object 'location) + (foreign-location object) (%gobject-new (type-number-of object)))))) (apply #'call-next-method object initargs))