Path: utzoo!attcan!uunet!mcsun!sunic!bmc!bio.embnet.se!mats From: Mats.Sundvall@bio.embnet.se Newsgroups: comp.sys.mac.programmer Subject: HLock and Think C 4.0 Message-ID: <18.25645e4f@bio.embnet.se> Date: 17 Nov 89 18:38:55 GMT Organization: Embnet node in Sweden at Biomedical Center, University of Uppsala, Sweden Lines: 27 Just got bit by not locking a handle! Please correct me if I am totally wrong but this is what I think happend. But my diagnose raised a couple of questions. In Think C 4.0 I define an object CTime as a instance of CObject. It has some integer fields and one Str255 field. The method Setstring does a strcpy from the parameter to the field. So I compile and run the program, the first time I does a CList::Setstring the string is empty. The second time the string is there. When tracing the code I notice that the memory location for CList->mystring is moved, probably because the ANSI library is moved into memory. So I do a HLock on the CTime object and unlock it after I have done the strcpy. It works. Then I locked through the object library to see if this is the method that Think uses. I was surprised when I did not find that many HLock in their code. One difference when they copy strings is that they copy pstrings with CopyPString (that does a Blockmove). Is it safe to do a Blockmove without locking the handle? I would expect that many more HLocks should be in the code. Mats Sundvall University of Uppsala Sweden