Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!husc6!bbn!uwmcsd1!ig!agate!jell-o!lippin From: lippin@jell-o.berkeley.edu (The Apathist) Newsgroups: comp.sys.mac.programmer Subject: A Tale of Two Bugs Message-ID: <9976@agate.BERKELEY.EDU> Date: 15 May 88 00:07:06 GMT References: <4421@dasys1.UUCP> <3384@pasteur.Berkeley.Edu> Sender: usenet@agate.BERKELEY.EDU Reply-To: lippin@jell-o.UUCP (Tom Lippincott, ..ucbvax!bosco!lippin) Organization: Authorized Service, Incorporated Lines: 41 I've been working on a custom MDEF, changing the InvertRect calls to paint & redraw so it will work on color monitors. I thought it was working, but I kept having an uneasy feeling when I finished selecting an item with it. After watching it closely a few times, I figured out why: the menu wasn't blinking when I let up the mouse. With some difficulty, I tracked down this problem -- part of it is Apple's fault, and part is the fault of Lightspeed C. Apple's problem is that to make an item blink, MenuSelect calls the MDEF with whichitem pointng to the low-memory global ToolScratch, which alternately contains zero and the number of the item selected. From my understanding of the rules for ToolScratch, this is bound to lose; any toolbox call that the MDEF makes may stomp all over it. But I guess some stingy Apple programmer wanted to save a couple of bytes of stack space. However, I seem to have been lucky. Nothing I called was messing up ToolScratch. Here's where LSC comes in. It's using ToolScratch too, and dumps the address of the MDEF into it during its code resource initialization code. And thus making the same mistake Apple did: that address could easily be trashed before it's used. I don't know of any truly safe place LSC could have used instead, but if there isn't, I'll let them have one: just take the last four bytes of ApplScratch. If more space is needed, put a handle there. They can save/restore it to avoid reentrancy problems, and it will break few existing sources. It need not break *any* future sources if it was *documented*, like the use of ToolScratch should have been. These problems are in LSC 2.15 and the 5.0 system software. What versions will they *not* be in? --Tom Lippincott ..ucbvax!math!lippin lippin@math.berkeley.edu "Well, you can't eat that raw!" --Mrs. Premise