;; TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
;; SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-;; $Id: gobject.lisp,v 1.43 2006/02/05 15:38:57 espen Exp $
+;; $Id: gobject.lisp,v 1.45 2006/02/08 22:10:47 espen Exp $
(in-package "GLIB")
;;;; Metaclass used for subclasses of gobject
(eval-when (:compile-toplevel :load-toplevel :execute)
+;; (push :debug-ref-counting *features*)
(defclass gobject-class (ginstance-class)
((instance-slots-p :initform nil
:documentation "Non NIL if the class has slots with instance allocation")))
(eval-when (:compile-toplevel :load-toplevel :execute)
(defclass gobject (ginstance)
- ()
+ (#+debug-ref-counting
+ (ref-count :allocation :alien :type int :reader ref-count))
(:metaclass gobject-class)
(:gtype "GObject")))
+#+debug-ref-counting
+(defmethod print-object ((instance gobject) stream)
+ (print-unreadable-object (instance stream :type t :identity nil)
+ (if (proxy-valid-p instance)
+ (format stream "at 0x~X (~D)" (sap-int (foreign-location instance)) (ref-count instance))
+ (write-string "at \"unbound\"" stream))))
+
(defun initial-add (object function initargs key pkey)
(loop
(defmethod initialize-instance ((object gobject) &rest initargs)
- (unless (slot-boundp object 'location)
+ (unless (proxy-valid-p object)
;; Extract initargs which we should pass directly to the GObject
;; constructor
(let* ((slotds (class-slots (class-of object)))
(gvalue-init (sap+ tmp string-size) type value))
(unwind-protect
(setf
- (slot-value object 'location)
+ (foreign-location object)
(%gobject-newv (type-number-of object) (length args) params))
(loop
repeat (length args)
(gvalue-unset (sap+ tmp string-size)))
(deallocate-memory params)))
(setf
- (slot-value object 'location)
+ (foreign-location object)
(%gobject-new (type-number-of object))))))
(apply #'call-next-method object initargs))