Changeset 5729


Ignore:
Timestamp:
Jan 18, 2007, 3:11:20 AM (18 years ago)
Author:
Gary Byers
Message:

Handle ivars, class creation/initialization differently for ObjC 2.0.

File:
1 edited

Legend:

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

    r5696 r5729  
    295295
    296296
     297
     298 
     299
     300
    297301(defun make-objc-class-object-slots-vector (class meta)
    298302  (let* ((n (1+ (length (extract-instance-effective-slotds meta))))
     
    386390
    387391(defmethod (setf class-direct-slots) :before (dslotds (class objc::objc-class))
     392  #-apple-objc-2.0
    388393  (let* ((foreign-dslotds
    389394          (loop for d in dslotds
     
    394399                         (return
    395400                           (ash (%objc-class-instance-size c)
    396                             3))))))
     401                                3))))))
    397402    (unless
    398       (dolist (d foreign-dslotds t)
    399         (if (not (foreign-direct-slot-definition-bit-offset d))
    400           (return nil)))
    401       (set-objc-foreign-direct-slot-offsets foreign-dslotds bit-offset))))
     403        (dolist (d foreign-dslotds t)
     404          (if (not (foreign-direct-slot-definition-bit-offset d))
     405            (return nil)))
     406      (set-objc-foreign-direct-slot-offsets foreign-dslotds bit-offset)))
     407  #+apple-objc-2.0
     408  ;; Add ivars for each foreign direct slot, then ask the runtime for
     409  ;; the ivar's byte offset.  (Note that the ObjC 2.0 ivar initialization
     410  ;; protocol doesn't seem to offer support for bitfield-valued ivars.)
     411  (dolist (dslotd dslotds)
     412    (when (typep dslotd 'foreign-direct-slot-definition)
     413      (let* ((string (lisp-defined-slot-name-to-objc-slot-name (slot-definition-name dslotd)))
     414             (type (foreign-slot-definition-foreign-type dslotd))
     415             (encoding (progn
     416                         (ensure-foreign-type-bits type)
     417                         (encode-objc-type type)))
     418             (size (ceiling (foreign-type-bits type) 8))
     419             (align (round (log (ceiling (foreign-type-alignment type) 8) 2))))
     420        (with-cstrs ((name string)
     421                     (encoding encoding))
     422          (unless (eql #$NO (#_class_addIvar class name size align encoding))
     423            (with-macptrs ((ivar (#_class_getInstanceVariable class name)))
     424              (unless (%null-ptr-p ivar)
     425                (let* ((offset (#_ivar_getOffset ivar)))
     426                  (setf (foreign-direct-slot-definition-bit-offset dslotd)
     427                        (ash offset 3)))))))))))
     428
    402429                                               
    403430
     
    437464                (pref ivar :objc_ivar.ivar_offset) (ash offset -3))
    438465          (incf offset (foreign-type-bits type))))))))
     466 
     467 
    439468
    440469(defun %objc-ivar-offset-in-class (name c)
     
    742771  (declare (ignore initargs))
    743772  (unless (slot-value class 'foreign)
     773    #-apple-objc-2.0
    744774    (multiple-value-bind (ivars instance-size)
    745775        (%make-objc-ivars class)
    746       (%add-objc-class class ivars instance-size))))
     776      (%add-objc-class class ivars instance-size))
     777    #+apple-objc-2.0
     778    (%add-objc-class class)))
    747779
    748780(defmethod shared-initialize ((instance objc:objc-object) slot-names
Note: See TracChangeset for help on using the changeset viewer.