[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RE-MACL- Fill a heap handle



   How can I fill a handle in the heap with text in a LISP variable?   The form
   (with-pstrs ...) is great for small chunks of text, but how to I load a handle
   with thousands of characters?  (e.g. for use with munger or drawText).

---------------------------------------------------------------------------

; load-handle.lisp
; Code to load a Mac Handle from a Lisp 

(require :traps)

(defconstant $v_data_offset
  #+:ccl-1 8
  #+:ccl-2 7)

#+:ccl-1
(eval-when (compile load eval)
(defun %address-of (x) (%ptr-to-int x))

; Unfortunately, this is not easily user-reachable in 1.3
(defun array-data-and-offset (array)
  (cond ((or (simple-vector-p array) (simple-string-p array))
         (values array 0))
        ((vectorp array) (values (copy-seq array) 0))
        (t (error "Argument must be a vector."))))
)

(defun load-handle (string &optional handle (start 0) (end (length string)))
  (check-type string string)
  (multiple-value-bind (simple-string offset) (array-data-and-offset string)
    (let ((len (max 0 (- end start))))
      (if handle
        (_SetHandleSize :errchk :a0 handle :d0 len)
        (setq handle (_NewHandle :errchk :d0 len :a0)))
      (let ((ptr (%inc-ptr (%int-to-ptr (%address-of simple-string))
                           (+ start offset $v_data_offset))))
        #+:ccl-2 (declare (dynamic-extent ptr))
        (_BlockMove :a0 ptr :a1 (%get-ptr handle) :d0 len))))
  handle)