+(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
+ (call-next-method)
+ (apply #'call-next-method class (compute-new-initargs-for-metaclass initargs 'g-object))))
+