Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!husc6!endor!siegel From: siegel@endor.harvard.edu (Rich Siegel) Newsgroups: comp.sys.mac.programmer Subject: Re: Bug in LSP V2.01? Message-ID: <2925@husc6.harvard.edu> Date: 21 Oct 89 03:59:07 GMT References: <3935@ethz-inf.UUCP> Sender: news@husc6.harvard.edu Reply-To: siegel@endor.UUCP (Rich Siegel) Organization: Symantec Language Products Group Lines: 41 In article <3935@ethz-inf.UUCP> schorn@inf.ethz.ch (Peter Schorn) writes: > > procedure obj.init; > procedure h(var y:integerP); begin new(y); y^:=19; end; > begin h(x); end; > > var o: obj; >begin new(o); o.init; writeLn(o.x^); end. > >Is this a compiler bug or am I doing something wrong? I'd venture to guess that you're doing something wrong. Since objects are allocated as handles (relocatable blocks), passing a field of an object as a VAR parameter to a routine that may move memory (which procedure H does, because New() calls NewPtr(), which moves memory) is a distinctly unsafe thing to do. Before calling procedure H, method O.Init should HLock(Handle(SELF)), and HUnlock(Handle(SELF)) after H returns. (That's a simplification; actually, you'll want to HGetState(), move SELF high, lock it, and then HSetState when you're done.) You may wish to define and implement a TObject.Lock() and TObject.Unlock for convenience. >Peter schorn@inf.ethz.ch or > schorn@cs.unc.edu ---Rich ~~~~~~~~~~~~~~~ Rich Siegel Staff Software Developer Symantec Corporation, Language Products Group Internet: siegel@endor.harvard.edu UUCP: ..harvard!endor!siegel "There is no personal problem which cannot be solved by sufficient application of high explosives." ~~~~~~~~~~~~~~~