Ignore:
Timestamp:
Jun 1, 2009, 7:55:14 AM (10 years ago)
Author:
gb
Message:

Export *OBJC-DESCRIPTION-MAX-LENGTH*, default it to 1024 (truncate
NSObject #/descriptions that're longer than this if it's set.
Don't call #/description on ObjC instances that look like they haven't
been initialized yet (things that have at least 1 non-zero byte are
assumed to have been through initialization.) Can still fail (if
an error occurs halfway through initialization and we try to print
the object), but less likely.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/objc-bridge/objc-support.lisp

    r11915 r12176  
    381381
    382382
     383
     384
     385(defparameter *objc-description-max-length* 1024 "Limit on the length of NSObject description strings if non-NIL.")
     386
     387
     388(defun initialized-nsobject-p (nsobject)
     389  (or (objc-class-p nsobject)
     390      (objc-metaclass-p nsobject)
     391      (let* ((class (#/class nsobject))
     392             (isize (%objc-class-instance-size class)))
     393        (declare (fixnum isize))
     394        (do* ((i (record-length :id) (1+ i)))
     395             ((= i isize))
     396          (declare (fixnum i))
     397          (unless (zerop (the (unsigned-byte 8) (%get-unsigned-byte nsobject i)))
     398            (return t))))))
     399 
    383400(defun nsobject-description (nsobject)
    384401  "Returns a lisp string that describes nsobject.  Note that some
    385402NSObjects describe themselves in more detail than others."
    386   (with-autorelease-pool
    387       (lisp-string-from-nsstring  (#/description nsobject))))
     403  (if (initialized-nsobject-p nsobject)
     404    (with-autorelease-pool
     405        (let* ((desc (#/description nsobject)))
     406          (if (or (null *objc-description-max-length*)
     407                  (< (#/length desc) *objc-description-max-length*))
     408            (lisp-string-from-nsstring desc)
     409            (ns:with-ns-range (r 0 *objc-description-max-length*)
     410              (format nil "~a[...]"(lisp-string-from-nsstring (#/substringWithRange: desc r)))))))
     411    ""))
     412
    388413
    389414
Note: See TracChangeset for help on using the changeset viewer.