Changeset 543


Ignore:
Timestamp:
Feb 15, 2004, 8:22:13 AM (21 years ago)
Author:
Gary Byers
Message:

ALLOCATE-INSTANCE et al: install the instance's slot-vector if it has one.
Error out (don't just return nil) if instance slot-vector is missing.
Randall's fix to WRITER-METHOD-CLASS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ccl/examples/objc-clos.lisp

    r533 r543  
    148148    (declare (fixnum type flags index))
    149149    (ecase flags
    150       (#.objc-flag-instance (gethash p *objc-object-slot-vectors*))
     150      (#.objc-flag-instance (or (gethash p *objc-object-slot-vectors*)
     151                                (error "~s has no slots." p)))
    151152      (#.objc-flag-class (id->objc-class-slots-vector index))
    152153      (#.objc-flag-metaclass (id->objc-metaclass-slots-vector index)))))
     
    703704            append (list (first l) (second l))  into new-initargs)))
    704705
     706(defun create-foreign-instance-slot-vector (class)
     707  (let* ((max 0))
     708    (dolist (slotd (class-slots class)
     709             (unless (zerop max)
     710               (allocate-typed-vector :slot-vector (1+ max) (%slot-unbound-marker))))
     711      (when (typep slotd 'standard-effective-slot-definition)
     712        (let* ((loc (slot-definition-location slotd)))
     713          (if (> loc max)
     714            (setq max loc)))))))
     715
     716               
     717                                         
    705718(defmethod allocate-instance ((class objc:objc-class) &rest initargs &key &allow-other-keys)
    706719  (unless (class-finalized-p class)
     
    713726            (apply #'%send (%send class 'alloc) (lisp-to-objc-init ks) vs))))
    714727    (unless (%null-ptr-p instance)
    715       (let* ((len (length (%wrapper-instance-slots (class-own-wrapper class))))
    716              (raw-ptr (raw-macptr-for-instance instance))
    717              (slot-vector
    718               (unless (zerop len)
    719                 (allocate-typed-vector :slot-vector (1+ len) (%slot-unbound-marker)))))
    720         (setf (slot-vector.instance slot-vector) raw-ptr)
     728      (let* ((raw-ptr (raw-macptr-for-instance instance))
     729             (slot-vector (create-foreign-instance-slot-vector class)))
     730        (when slot-vector
     731          (setf (slot-vector.instance slot-vector) raw-ptr)
     732          (setf (gethash raw-ptr *objc-object-slot-vectors*) slot-vector))
    721733        (register-canonical-objc-instance instance raw-ptr)))))
    722734
     
    852864                                &rest initargs)
    853865  (declare (ignore initargs))
    854   (find-class 'standard-reader-method))
     866  (find-class 'standard-writer-method))
    855867
    856868
Note: See TracChangeset for help on using the changeset viewer.