Article View: comp.sys.mac
Article #23285Re: Question about WDEF routines.
From: Larry Rosenstein
Date: Mon, 04 Jan 1988 19:13
Date: Mon, 04 Jan 1988 19:13
47 lines
2301 bytes
2301 bytes
In article <7595@sunybcs.UUCP> domino@sunybcs.UUCP (Michael Domino) writes:
>
>Can someone tell me what's wrong, please? This is all in Lightspeed C.
>
>main()
>{
> WindowPtr w;
>
> ...usual init stuff...
>
> /* The window is created invisible. */
> w = GetNewWindow(windowID, NULL, (WindowPtr)(-1L));
> (WindowPeek)w->windowDefProc = NewHandle(0L);
> *((WindowPeek)w->windowDefProc) = (Ptr)WindowDef;
> ShowWindow(w);
One problem is that this code trashes the heap. It is creating a handle and
replacing the master pointer. The block that was created contains a back
pointer to the master pointer, which the Memory Manager uses when the heap
needs to be compacted.
I mentioned this to the author of the article and the editor of MacTutor.
Also, I believe there was a letter to the editor regarding this.
Unfortunately, this had no effect because in the article on tear-off menus
(a couple of months ago) the same technique was used. (I think this was the
same author.)
The correct thing to do is allocate a 6-byte handle and install a 68000 JMP
instruction in the handle, which goes to the defproc. The first 2 bytes of
such an instruction are $4EF9; the last 4 bytes should be the address of the
defproc procedure. Then you simply install the handle in the window record.
As you can see, doing the right thing doesn't take much extra code. In my
opinion, it is purely a matter of laziness on the part of the author. His
only response is to include a disclaimer saying that this technique
shouldn't be used in a real program. The end effect is that people type in
the program and it doesn't work.
--
Larry Rosenstein
Object Specialist
Apple Computer
AppleLink: Rosenstein1
UUCP: {sun, voder, nsc, mtxinu, dual}!apple!lsr
CSNET: lsr@Apple.com
Technical Details
Message-ID:
<7126@apple.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!rutgers!ucla-cs!zen!ucbvax!decvax!decwrl!pyramid!voder!apple!lsrReferences:
<7595@sunybcs.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!mnetor!uunet!husc6!rutgers!ucla-cs!zen!ucbvax!decvax!decwrl!pyramid!voder!apple!lsr From: lsr@apple.UUCP (Larry Rosenstein) Newsgroups: comp.sys.mac Subject: Re: Question about WDEF routines. Message-ID: <7126@apple.UUCP> Date: 4 Jan 88 19:13:15 GMT References: <7595@sunybcs.UUCP> Reply-To: lsr@apple.UUCP (Larry Rosenstein) Distribution: na Organization: Advanced Technology Group, Apple Computer Lines: 47