[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: RE-MACL- Fill a heap handle
- To: randal.jones@applelink.apple.com, MACDTS@AppleLink.Apple.COM
- Subject: Re: RE-MACL- Fill a heap handle
- From: Bill St. Clair <bill>
- Date: Wed, 14 Nov 90 10:26:44 -0500
- Cc: INFO-MACL@CAMBRIDGE.APPLE.COM
- In-reply-to: Your message of 13 Nov 90 15:25:00 +0000. <4573271@AppleLink.Apple.COM>
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)