Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!apple!well!odawa From: odawa@well.sf.ca.us (Michael Odawa) Newsgroups: comp.sys.mac.programmer Subject: Re: Identifying real handles Message-ID: <18379@well.sf.ca.us> Date: 6 Jun 90 21:31:48 GMT References: <7426@ucdavis.ucdavis.edu> Reply-To: odawa@well.sf.ca.us (Michael Odawa) Organization: Simple Software, Mill Valley, CA Lines: 46 In article <7426@ucdavis.ucdavis.edu> lim@iris.ucdavis.edu (Lloyd Lim) writes: > ...I need to be able to tell if some arbitrary long is a real handle in > the System heap or the current app heap. I want to keep it relatively clean > so I don't want to go looking through the heap's internal structures...The > problem is that this routine can get passed any arbitrary long and that some > values seem to cause a bus error with HandleZone....Any ideas on a better > way? You have to make a range check against the high end of your memory. Here's something you might add to your code: { register Boolean valid; register THz heapZone; valid = FALSE; if (address && !(address & 1)) { if (address < long(**ApplicZone.BkLim)) { /***** Add this line *****/ heapZone = HandleZone(address); if (!MemError() && (heapZone == SystemZone() || heapZone == ApplicZone())) { valid = TRUE; } } return(valid); } A different check (which I do in my version of ValidHandle) might be to determine whether the tag byte on the block header (the first of the eight bytes which preceed the address) contained 0x8x, as documented in IM II-24: if (address < long(**ApplicZone.BkLim)) if ((*(ptr)(address - 8) & 0x80) != 0) valid = TRUE; Of course, we have not even begun to discuss problems with 24-bit vs 32-bit addressing schemes. So perhaps we ought to preceed our code by address = (long)StripAddress((ptr)address); ----- Michael Odawa Simple Software odawa@well.sf.ca.us