- (call-next-method)
- #+debug-ref-counting(%object-weak-ref (foreign-location object))
- #+glib2.8
- (when (slot-value (class-of object) 'instance-slots-p)
- (with-slots (location) object
- (%object-add-toggle-ref location)
- (%object-unref location))))
-
-
-(defmethod initialize-instance ((object gobject) &rest initargs)
- (unless (slot-boundp object 'location)
- ;; Extract initargs which we should pass directly to the GObject
- ;; constructor
- (let* ((slotds (class-slots (class-of object)))
- (args (when initargs
- (loop
- as (key value . rest) = initargs then rest
- as slotd = (find-if
- #'(lambda (slotd)
- (member key (slot-definition-initargs slotd)))
- slotds)
- when (and (typep slotd 'effective-property-slot-definition)
- (slot-value slotd 'construct))
- collect (progn
- (remf initargs key)
- (list
- (slot-definition-pname slotd)
- (slot-definition-type slotd)
- value))
- while rest))))
- (if args
- (let* ((string-size (size-of 'string))
- (string-writer (writer-function 'string))
- (string-destroy (destroy-function 'string))
- (params (allocate-memory
- (* (length args) (+ string-size +gvalue-size+)))))
- (loop
- for (pname type value) in args
- as tmp = params then (sap+ tmp (+ string-size +gvalue-size+))
- do (funcall string-writer pname tmp)
- (gvalue-init (sap+ tmp string-size) type value))
- (unwind-protect
- (setf
- (slot-value object 'location)
- (%gobject-newv (type-number-of object) (length args) params))
- (loop
- repeat (length args)
- as tmp = params then (sap+ tmp (+ string-size +gvalue-size+))
- do (funcall string-destroy tmp)
- (gvalue-unset (sap+ tmp string-size)))
- (deallocate-memory params)))
- (setf
- (slot-value object 'location)
- (%gobject-new (type-number-of object))))))
-
- (apply #'call-next-method object initargs))
+ (prog1
+ (call-next-method)
+ #+debug-ref-counting(%object-weak-ref (foreign-location object))
+ #+glib2.8
+ (when (slot-value (class-of object) 'instance-slots-p)
+ (with-slots (location) object
+ (%object-add-toggle-ref location)
+ (%object-unref location)))))