-(defmethod initialize-instance ((object gobject) &rest initargs)
- (unless (slot-boundp object 'location)
- ;; Extract initargs which we should pass directly to the GObeject
- ;; 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+)))))
+(defmethod make-proxy-instance ((class gobject-class) location &rest initargs)
+ (declare (ignore location initargs))
+ (if (slot-value class 'instance-slots-p)
+ (error "Objects of class ~A has instance slots and should only be created with MAKE-INSTANCE" class)
+ (call-next-method)))
+
+(defparameter +gparameter-gvalue-offset+
+ (max (size-of 'pointer) (type-alignment '(unsigned-byte 64))))
+(defparameter +gparameter-size+
+ (+ +gparameter-gvalue-offset+ +gvalue-size+))
+
+(defmethod allocate-foreign ((object gobject) &rest initargs)
+ (let ((init-slots ()))
+ (flet ((value-from-initargs (slotd)
+ (loop
+ with slot-initargs = (slot-definition-initargs slotd)
+ for (initarg value) on initargs by #'cddr
+ when (find initarg slot-initargs)
+ do (return (values value t)))))
+
+ (loop
+ for slotd in (class-slots (class-of object))
+ when (and
+ (eq (slot-definition-allocation slotd) :property)
+ (construct-only-property-p slotd))
+ do (multiple-value-bind (value initarg-p) (value-from-initargs slotd)
+ (cond
+ (initarg-p (push (cons slotd value) init-slots))
+ ((slot-definition-initfunction slotd)
+ (push
+ (cons slotd (funcall (slot-definition-initfunction slotd)))
+ init-slots))))))
+
+ (cond
+ (init-slots
+ (let* ((num-slots (length init-slots)))
+ (with-memory (params (* num-slots +gparameter-size+))
+ (loop
+ with string-writer = (writer-function 'string)
+ for (slotd . value) in init-slots
+ as param = params then (pointer+ param +gparameter-size+)
+ as type = (slot-definition-type slotd)
+ as pname = (slot-definition-pname slotd)
+ do (funcall string-writer pname param)
+ (gvalue-init
+ (pointer+ param +gparameter-gvalue-offset+) type value))
+
+ (unwind-protect
+ (%gobject-newv (type-number-of object) num-slots params)
+