- (let ((slotds (class-slots (class-of object)))
- (names (make-array 0 :adjustable t :fill-pointer t))
- (values (make-array 0 :adjustable t :fill-pointer t)))
-
- (loop
- as tmp = initargs then (cddr tmp) while tmp
- as key = (first tmp)
- as value = (second tmp)
- 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))
- do (let ((type (find-type-number (slot-definition-type slotd))))
- (vector-push-extend (slot-definition-pname slotd) names)
- (vector-push-extend (gvalue-new type value) values)
- (remf initargs key)))
-
- (setf
- (slot-value object 'location)
- (if (zerop (length names))
- (%gobject-new (type-number-of object))
- (%gobject-newvv (type-number-of object) (length names) names values)))
-
-; (map 'nil #'gvalue-free values)
- )
-
+ ;; Extract initargs which we should pass directly to the GObeject
+ ;; constructor
+ (let* ((slotds (class-slots (class-of object)))
+ (args (loop
+ as tmp = initargs then (cddr tmp) while tmp
+ as key = (first tmp)
+ as value = (second tmp)
+ 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)))))
+ (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)))))
+
+ (%object-weak-ref object)