Changeset 468


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

New OBJC-[CLASS,METACLASS,INSTANCE]-p, OBJC-OBJECT-P uses them.

Install a callback to take over _dealloc responsibilities. Doing so
seems to sometimes trigger a hang on QUIT, where the initial thread
never gets an interrupt. Maybe memory corruption, maybe something
else: need to check that (free) is the right way to free the object.

File:
1 edited

Legend:

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

    r450 r468  
    10471047
    10481048
    1049 ;;; If P is an ObjC class (or metaclass), return the class & metaclass,
    1050 ;;; else return (VALUES NIL NIL).
     1049;;; Return the "canonical" version of P iff it's a known ObjC class
    10511050(defun objc-class-p (p)
    10521051  (if (typep p 'macptr)
    1053     (let* ((id (or (objc-class-id p) (objc-metaclass-id p))))
    1054       (if id
    1055         (values (id->objc-class id) (id->objc-metaclass id))
    1056         (values nil nil)))))
     1052    (let* ((id (objc-class-id p)))
     1053      (if id (id->objc-class id)))))
     1054
     1055;;; Return the canonical version of P iff it's a known ObjC metaclass
     1056(defun objc-metaclass-p (p)
     1057  (if (typep p 'macptr)
     1058    (let* ((id (objc-metaclass-id p)))
     1059      (if id (id->objc-metaclass id)))))
    10571060
    10581061;;; If P is an ObjC instance, return a pointer to its class.
     
    10601063;;; ultimately malloc-based.
    10611064(defun objc-instance-p (p)
    1062   (and (typep p 'macptr)
    1063        #+apple-objc
    1064        (not (%null-ptr-p (#_malloc_zone_from_ptr p)))
    1065        ;; #_malloc_zone_from_pointer seems pretty robust.
    1066        ;; If it returned a non-null "zone", it's probably safe
    1067        ;; to indirect through P.
    1068        (with-macptrs ((parent (pref p
    1069                                     #+apple-objc :objc_object.isa
    1070                                     #+gnu-objc :objc_object.class_pointer)))
    1071          (or (objc-class-p parent)
    1072              (values (objc-instance-p parent))))))
     1065  (when (typep p 'macptr)
     1066    (let* ((idx (%objc-instance-class-index p)))
     1067      (if idx (id->objc-class  idx)))))
    10731068
    10741069
     
    10971092  )
    10981093
    1099 ;;; If an instance, return (values :INSTANCE <class>).
    1100 ;;; If a class, return (values :CLASS <metaclass>).
    1101 ;;; If a metaclass, return (values :METACLASS <class>).
     1094;;; If an instance, return (values :INSTANCE <class>)
     1095;;; If a class, return (values :CLASS <class>).
     1096;;; If a metaclass, return (values :METACLASS <metaclass>).
    11021097;;; Else return (values NIL NIL).
    11031098(defun objc-object-p (p)
    1104   (multiple-value-bind (class metaclass) (objc-class-p p)
    1105     (if (eql p class)
    1106       (values :class metaclass)
    1107       (if (eql p metaclass)
    1108         (values :metaclass class)
    1109         (if (setq class (objc-instance-p p))
    1110           (values :instance class)
    1111           (values nil nil))))))
     1099  (let* ((instance-p (objc-instance-p p)))
     1100    (if instance-p
     1101      (values :instance instance-p)
     1102      (let* ((class-p (objc-class-p p)))
     1103        (if class-p
     1104          (values :class class-p)
     1105          (let* ((metaclass-p (objc-metaclass-p p)))
     1106            (if metaclass-p
     1107              (values :metaclass metaclass-p)
     1108              (values nil nil))))))))
     1109
    11121110       
    11131111
     
    14191417    (free obj)))
    14201418
    1421 #+threads-problem
    14221419(def-ccl-pointers install-deallocate-hook ()
    14231420  (setf (%get-ptr (foreign-symbol-address "__dealloc")) deallocate-nsobject))
Note: See TracChangeset for help on using the changeset viewer.