+ :reader gobject-class-interface-p))
+ (:documentation "Metaclass for GObject-based classes."))
+
+(defun initialize-gobject-class-g-type (class)
+ (if (gobject-class-g-type-initializer class)
+ (let* ((initializer-fn-ptr (foreign-symbol-pointer (gobject-class-g-type-initializer class)))
+ (type (when initializer-fn-ptr
+ (foreign-funcall-pointer initializer-fn-ptr nil
+ g-type-designator))))
+ (if (null initializer-fn-ptr)
+ (warn "Type initializer for class '~A' (GType '~A') is invalid: foreign symbol '~A'"
+ (gobject-class-direct-g-type-name class) (class-name class) (gobject-class-g-type-initializer class))
+ (progn
+ (when (eq (gtype +g-type-invalid+) type)
+ (warn "Declared GType name '~A' for class '~A' is invalid ('~A' returned 0)"
+ (gobject-class-direct-g-type-name class) (class-name class)
+ (gobject-class-g-type-initializer class)))
+ (unless (eq (gtype (gobject-class-direct-g-type-name class)) type)
+ (warn "Declared GType name '~A' for class '~A' does not match actual GType name '~A'"
+ (gobject-class-direct-g-type-name class)
+ (class-name class)
+ (gtype-name type))))))
+ (when (zerop (gtype-id (gtype (gobject-class-direct-g-type-name class))))
+ (warn "Declared GType name '~A' for class '~A' is invalid (g_type_name returned 0)"
+ (gobject-class-direct-g-type-name class) (class-name class)))))
+
+(defun filter-from-initargs (initargs removed-key)
+ (loop
+ for (key value) on initargs by #'cddr
+ unless (eq key removed-key)
+ collect key and collect value))
+
+(defun initargs-have-base-in-superclass (initargs base-class)
+ (let ((d-s (getf initargs :direct-superclasses)))
+ (loop
+ for class in d-s
+ thereis (subtypep class base-class))))
+
+(defun compute-new-initargs-for-metaclass (initargs base-class)
+ (if (initargs-have-base-in-superclass initargs base-class)
+ initargs
+ (append (filter-from-initargs initargs :direct-superclasses)
+ (list :direct-superclasses
+ (append (getf initargs :direct-superclasses)
+ (list (find-class base-class)))))))
+
+(defmethod initialize-instance :around ((class gobject-class) &rest initargs)
+ (apply #'call-next-method class (compute-new-initargs-for-metaclass initargs 'g-object)))
+
+(defmethod reinitialize-instance :around ((class gobject-class) &rest initargs &key (direct-superclasses nil d-s-p) &allow-other-keys)
+ (declare (ignore direct-superclasses))
+ (if d-s-p
+ (apply #'call-next-method class (compute-new-initargs-for-metaclass initargs 'g-object))
+ (call-next-method)))