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

Re: Simple question



At  1:43 PM 7/22/93 -0600, osiris@cs.utexas.edu wrote:
>If you use something like pen-state that returns a record inside an rlet
>form, and you assign the PenPat field of a the record to another variable
>and return it, are you left with a dangling pointer when the rlet is
>exited.  I.e. when the PenState record is cleaned up, are its fields
>disposed of as well?
>
>Thanks.

RLET allocates a record on the stack. Hence, this record has DYNAMIC-EXTENT.
Once you exit the dynamic extent of the RLET, the record is no longer
there. The PenPat field of the records I know of (e.g. windowRecord and
PenState) are in-line in the parent record. Hence assigning a variable
to that field will make it point at the stack, where its contents
will be clobberred as soon as you exit the dynamic extent of the
RLET. As I sent you in private mail, I recommend changing the
PAN-PATTERN method as follows so that it will do something reasonable
for color windows (return a black-and-white version of the window's
possibly color PixPat). Note that the COPY-RECORD call copies the bits
from the stack allocated "STATE" record to the more permanent (though
possibly stack allocated in PEN-PATTERN's caller) SAVE-PAT record.

(defmethod pen-pattern ((view simple-view) &optional
                        (save-pat (make-record (:pattern :storage :pointer))))
  (rlet ((state :PenState))
    (with-focused-view view
      (#_GetPenState state))
    (copy-record
     (pref state PenState.pnpat) (:pattern :storage :pointer) save-pat)))