Path: utzoo!attcan!uunet!lll-winken!ames!mailrus!uflorida!gatech!bloom-beacon!apple!dowdy From: dowdy@Apple.COM (Tom Dowdy) Newsgroups: comp.sys.mac.programmer Subject: Re: serious code generation bug in Lightspeed C Summary: This problem *is* documented. Message-ID: <24012@apple.Apple.COM> Date: 15 Jan 89 19:12:40 GMT References: <6275@hoptoad.uucp> <1676@helios.ee.lbl.gov> <6315@hoptoad.uucp> Organization: Apple Computer Inc, Cupertino, CA Lines: 49 In article <6315@hoptoad.uucp> tim@hoptoad.UUCP (Tim Maroney) writes: >It is silly to say that this is a well documented problem. I've read >three drafts of Inside Mac, starting with the loose-leaf binder edition >unfathomable aeons ago, and that an assignment could require locking >has never been explicitly mentioned. Yes it has. Volume II page 16 of Inside Mac says: * Assigning the result of a function that can move or purge blocks (or of any function in a package or other segment) to a field in a record referred to by a handle such as: aHandle^^.field := NewHandle(...) A problem may arise because the compiler generates code that dereferences the handle before calling NewHandle - and NewHandle may move the block containing the field. < Here endeth the lesson > It goes on to suggest to either lock the handle down, or use a temporary variable for the assignment. (Which is the approach that I usually take, as it allows for some additional sanity checking and error control in the FailNIL model) So it *is* documented. I suppose that the warning could be a bit more stern, and perhaps the compiler guides could warn you as well, but it is in the Memory Manager section, which most Mac programmers read before proceeding. But this is subtle enough that perhaps more warnings may be in order. The reason most people don't think about this is that they assume that compilers generate code from left to right as you and I read. A subtle bug that is hinted at here effects users of Object Pascal more often, but can bite others as well: If you call a function with a field from a handle based record, or Object Pascal object, as one of the parameters and the function or procedure you are calling is in another, unloaded, segment you will be in for a crash. The MPW 3.0 compilers check for this condition and warn you about it. Tom Dowdy Internet: dowdy@apple.COM Apple Computer MS:27Y AppleLink:DOWDY1 20525 Mariani Ave UUCP: {sun,voder,amdahl,decwrl}!apple!dowdy Cupertino, CA 95014 "The 'Oo-Ah' Bird is so called because it lays square eggs."