Changeset 5727


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

Note which protocols are actually used when walking classes. (There
doesn't seem to be a good way of finding a Protocol object pre-objc-2.0,
and we may need to test protocol compliance to disambiguate message
sends in some cases.)

File:
1 edited

Legend:

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

    r5696 r5727  
    66  (require "BRIDGE"))
    77
     8#-apple-objc-2.0
     9(progn
     10  (def-foreign-type :<CGF>loat :float)
     11  (def-foreign-type :<NSUI>nteger :unsigned)'
     12  (def-foreign-type :<NSI>nteger :signed))
     13
     14(defconstant +cgfloat-zero+
     15  #+(and apple-objc-2.0 64-bit-target) 0.0d0
     16  #-(and apple-objc-2.0 64-bit-target) 0.0f0)
    817
    918#+apple-objc
     
    2635          (return)
    2736          (funcall fn class))))))
    28          
    29 
     37
     38(defun %note-protocol (p)
     39  (with-macptrs ((cname (objc-message-send p "name" :address)))
     40    (let* ((namelen (%cstrlen cname))
     41           (name (make-string namelen)))
     42      (declare (dynamic-extent name))
     43      (%str-from-ptr cname namelen name)
     44      (unless (gethash name *objc-protocols*)
     45        (setf (gethash (subseq name 0) *objc-protocols*)
     46              (%inc-ptr p 0))))))
     47
     48(defun note-class-protocols (class)
     49  #-apple-objc-2.0
     50  (do* ((protocols (pref class :objc_class.protocols)
     51                   (pref protocols :objc_protocol_list.next)))
     52       ((%null-ptr-p protocols))
     53    (let* ((count (pref protocols :objc_protocol_list.count)))
     54      (with-macptrs ((list (pref protocols :objc_protocol_list.list)))
     55        (dotimes (i count)
     56          (with-macptrs ((p (paref list (:* (:* (:struct :<P>rotocol))) i)))
     57            (%note-protocol p))))))
     58  #+apple-objc-2.0
     59  (rlet ((p-out-count :int))
     60    (with-macptrs ((protocols (#_class_copyProtocolList class p-out-count)))
     61      (let* ((n (pref p-out-count :int)))
     62        (dotimes (i n)
     63          (with-macptrs ((p (paref protocols (:* (:* (:struct :<P>rotocol))) i)))
     64            (%note-protocol p))))
     65      (unless (%null-ptr-p protocols) (#_free protocols)))))
     66           
    3067
    3168(defun map-objc-classes (&optional (lookup-in-database-p t))
    3269  (iterate-over-objc-classes
    3370   #'(lambda (class)
     71       (note-class-protocols class)
    3472       (install-foreign-objc-class class lookup-in-database-p))))
    3573 
     
    311349
    312350                     
    313                                  
     351(defmethod print-object ((p ns:protocol) stream)
     352  (print-unreadable-object (p stream :type t)
     353    (format stream "~a (#x~x)"
     354            (%get-cstring (send p 'name))
     355            (%ptr-to-int p))))
     356
    314357                                         
    315358
Note: See TracChangeset for help on using the changeset viewer.