Changeset 380


Ignore:
Timestamp:
Jan 24, 2004, 3:34:57 PM (21 years ago)
Author:
Gary Byers
Message:

Work harder to determine if an instance really is an instance.

File:
1 edited

Legend:

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

    r230 r380  
    6565  (unless (logtest #$_CLS_RESOLV (pref classptr :objc_class.info))
    6666    (external-call "__objc_resolve_class_links" :void)))
     67
     68
    6769
    6870(let* ((objc-class-map (make-splay-tree #'%ptr-eql
     
    233235       ;; in the thread that's going to process events.  Looking up a
    234236       ;; symbol in the library should cause it to be initialized
     237       (open-shared-library "/System/Library/Frameworks/CoreFoundation.framework/CoreFoundation")
    235238       (open-shared-library "/System/Library/Frameworks/Cocoa.framework/Cocoa")
    236239       (let* ((current (#_CFRunLoopGetCurrent))
     
    11371140             (values (objc-instance-p parent))))))
    11381141
     1142
     1143#+apple-objc
     1144(defun zone-pointer-size (p)
     1145  (with-macptrs ((zone (#_malloc_zone_from_ptr p)))
     1146    (unless (%null-ptr-p zone)
     1147      (let* ((size (ff-call (pref zone :malloc_zone_t.size)
     1148                            :address zone
     1149                            :address p
     1150                            :int)))
     1151        (declare (fixnum size))
     1152        (unless (zerop size)
     1153          size)))))
     1154 
     1155(defun %objc-instance-class-index (p)
     1156  #+apple-objc
     1157  (let* ((instance-apparent-size (zone-pointer-size p)))
     1158    (when (and instance-apparent-size (not (eql instance-apparent-size 0)))
     1159      (locally (declare (fixnum instance-apparent-size))
     1160          (with-macptrs ((parent (pref p :objc_object.isa)))
     1161            (let* ((idx (objc-class-id parent)))
     1162              (when idx
     1163                (let* ((parent-size (if idx (pref parent :objc_class.instance_size))))
     1164                  (if (eql (- (ash (ash (the fixnum (+ parent-size 17)) -4) 4) 2)
     1165                           instance-apparent-size)
     1166                    idx)))))))))
     1167  #+gnu-objc
     1168  (with-macptrs ((parent (pref p objc_object.class_pointer)))
     1169    (objc-class-id-parent)))
     1170
    11391171;;; If an instance, return (values :INSTANCE <class>).
    11401172;;; If a class, return (values :CLASS <metaclass>).
Note: See TracChangeset for help on using the changeset viewer.