Path: utzoo!utgpu!watserv1!watmath!att!ucbvax!ucdavis!iris!lim From: lim@iris.ucdavis.edu (Lloyd Lim) Newsgroups: comp.sys.mac.programmer Subject: Identifying real handles Message-ID: <7426@ucdavis.ucdavis.edu> Date: 4 Jun 90 13:44:08 GMT Sender: usenet@ucdavis.ucdavis.edu Reply-To: lim@iris.ucdavis.edu (Lloyd Lim) Organization: U.C. Davis - Department of Electrical Engineering and Computer Science Lines: 39 This is perhaps not the best thing to do on a Mac but 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. Currently, I use the following code: Boolean ValidHandle(address) register long address; { register Boolean valid; register THz heapZone; valid = FALSE; if (address && !(address & 1)) { heapZone = HandleZone(address); if (!MemError() && (heapZone == SystemZone() || heapZone == ApplicZone())) { valid = TRUE; } } return(valid); } The problem is that this routine can get passed any arbitrary long and that some values seem to cause a bus error with HandleZone. I say "seem" because I haven't been able to find a value which causes a bus error in a test program but bus errors do occur in the real situation if enough values are examined. The real situation is practically unobservable. Any ideas on a better way? If you try doing extra checking before calling HandleZone, you'll get bus errors right away when you do (*(Ptr) address). If there is a solution that isn't right 100% of the time but doesn't cause bus errors, that would also be ok. +++ Lloyd Lim Internet: lim@iris.ucdavis.edu (128.120.57.20) Compuserve: 72647,660 US Mail: 146 Lysle Leach Hall, U.C. Davis, Davis, CA 95616