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

Re: Disposing appleevents



>Does lisp's garbage collection facility take care of appleevent descriptor
>records?  The code that I have looked at does dispose them sometimes, and
>sometimes it doesn't.  which is correct?
>
>Steven Dobbs
I don't believe that garbage collection ever takes care of appleevent
descriptor records for you, but stack allocation and clever macros can
help.

There are two things to be concerned about with appleevent descriptor
records:
        1) The "public" part - the :aedesc which is allocated by rlet or 
           make-record.  If you create the :aedesc with make-record, you
need to
           call dispose-record some day.
        2) The "private" part, which is allocated by the Apple Event
Manager (and         
           stored in the :aedesc record).  #_aedisposedesc should be called
when you
           are done with a discriptor.

Note that when you SEND an AppleEvent, you need to create at least two
descriptor records, but when you RECEIVE an AppleEvent, two descriptor
records are passed as parameters, and are not your responsibility
(AppleEvents will dipsose of them for you).

Now the WITH-AEDESCS macro (which seems to be un-documented but is very
useful) handles most of the work of allocting and disposing both the public
and private parts of an AppleEvent.

For example:

(with-aedescs (event reply target)
  (choose-appleevent-target target)
  (create-oapp event target)
  (send-appleevent event reply :reply-mode :no-reply))

Expands to:
(RLET ((EVENT :AEDESC :DATAHANDLE (%NULL-PTR))
       (REPLY :AEDESC :DATAHANDLE (%NULL-PTR))
       (TARGET :AEDESC :DATAHANDLE (%NULL-PTR)))
  (UNWIND-PROTECT
      (PROGN
        (CHOOSE-APPLEEVENT-TARGET TARGET)
        (CREATE-OAPP EVENT TARGET)
        (SEND-APPLEEVENT EVENT REPLY :REPLY-MODE :NO-REPLY))
    (UNLESS (%NULL-PTR-P (RREF EVENT AEDESC.DATAHANDLE))
      (REQUIRE-TRAP TRAPS:_AEDISPOSEDESC EVENT))
    (UNLESS (%NULL-PTR-P (RREF REPLY AEDESC.DATAHANDLE))
      (REQUIRE-TRAP TRAPS:_AEDISPOSEDESC REPLY))
    (UNLESS (%NULL-PTR-P (RREF TARGET AEDESC.DATAHANDLE))
      (REQUIRE-TRAP TRAPS:_AEDISPOSEDESC TARGET))))
----------------------------------------
Derek White      	      (-ex Mr. Pascal)
ATG/East        	       (AppleLink: DEREK)