Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!mimsy!mojo!russotto From: russotto@eng.umd.edu (Matthew T. Russotto) Newsgroups: comp.sys.mac.programmer Subject: Re: Identifying real handles Message-ID: <1990Jun5.141748.28953@eng.umd.edu> Date: 5 Jun 90 14:17:48 GMT References: <7426@ucdavis.ucdavis.edu> Sender: news@eng.umd.edu (The News System) Organization: College of Engineering, Maryversity of Uniland, College Park Lines: 40 In article <7426@ucdavis.ucdavis.edu> lim@iris.ucdavis.edu (Lloyd Lim) writes: >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. Check to see if the handle itself is below BufPtr or MemTop or whatever variable you feel is appropriate. If it's below that, there should never be a bus error. Then do validity checks on *address, and check to see if IT is below BufPtr or MemTop. Then call HandleZone. -- Matthew T. Russotto russotto@eng.umd.edu russotto@wam.umd.edu ][, ][+, ///, ///+, //e, //c, IIGS, //c+ --- Any questions?