Re: NULL pointer or objptr should not pass the validity check.
jason <[email protected]> Sun, 12 May 2013 22:27:01 +0800
| Newsgroups | gmane.comp.lang.ml.mlton.devel |
|---|---|
| Message-ID | <[email protected]> |
I need to take some more investigation on it to see when and where the NULL pointer is introduced to the heap. Thank you for explanation on it. 在 2013-5-11,下午6:48,Matthew Fluet <[email protected]> 写道: > On Thu, May 9, 2013 at 5:27 AM, 吴佳森 <[email protected]> wrote: >> When I was porting the MLton, I met two segment faults. And after careful >> inspection on the trace, I made following changes to runtime/gc/objptr.c and >> runtime/gc/pointer.c. >> >> The changes are about deciding whether the given pointer or objptr is valid. >> The original code only check the last few bits must be zero, and hence NULL >> pointer is also considered valid. I don't think NULL pointer should pass the >> check hence made the changes. >> >> I am not sure if I'm correct on the judgement because I guess if may also be >> some problem elsewhere that introduce the NULL pointer to GC. >> >> Could someone please have a check on it? I would appreciate any feed back >> for it. Thank you very much. > > The isObjptr and isPointer functions are used by the garbage collector > to distinguish true pointers to ML objects from other data that is > packed into a pointer-sized field (and that could, sometimes, be a > true pointer). The canonical example is a type like: > > (int * int) option > > The SOME variant must be represented as a pointer to the (int * int) > tuple, but the NONE variant can be represented by a pointer-sized word > with non-zero low bits. > > This should always be the case --- either the word being inspected by > isObjptr/isPointer is a true pointer or it has non-zero low bits. I > don't believe that it these functions should ever be called on NULL. > > I think the better choice would be to add: > assert (0 != p) > > If these functions are being called on NULL, then the heap has been > corrupted at some earlier point. Returning 'false' and treating the > NULL as a non-pointer will simply mask the corruption for a little > longer. > > ------------------------------------------------------------------------------ > Learn Graph Databases - Download FREE O'Reilly Book > "Graph Databases" is the definitive new guide to graph databases and > their applications. This 200-page book is written by three acclaimed > leaders in the field. The early access version is available now. > Download your free book today! http://p.sf.net/sfu/neotech_d2d_may > _______________________________________________ > MLton-devel mailing list > [email protected]; [email protected] > https://lists.sourceforge.net/lists/listinfo/mlton-devel ------------------------------------------------------------------------------ Learn Graph Databases - Download FREE O'Reilly Book "Graph Databases" is the definitive new guide to graph databases and their applications. This 200-page book is written by three acclaimed leaders in the field. The early access version is available now. Download your free book today! http://p.sf.net/sfu/neotech_d2d_may _______________________________________________ MLton-devel mailing list [email protected]; [email protected] https://lists.sourceforge.net/lists/listinfo/mlton-devel