Re[4]: [Gc] Patches resubmission

Ivan Maidanski ivmai at mail.ru
Mon Jun 8 22:36:24 PDT 2009


Hi!

"Boehm, Hans" <hans.boehm at hp.com> wrote:
> > From: Ivan Maidanski
> > Hi!
> > 
> > "Boehm, Hans" <hans.boehm at hp.com> wrote:
> > > Thank you.  Committed.
> > > 
> > > I'm not sure about the %p in WARN calls, since the corresponding 
> > > argument is not a pointer anymore at that point.  That may 
> > eventually start generating warnings?  I checked in the whole 
> > patch, but I'm not sure those few bits were an improvement.
> > 
> > Not clear. Is "start" no longer a pointer in your copy of gc 
> > for this fragment:
> >             WARN(
> >               "GC_gww_read_dirty unexpectedly failed at %p: "
> >               "Falling back to marking all pages dirty\n", start);
> > 
> > > 
> > > Hans
> > 
> > Bye.
> > 
> The problem is that this ends up calling GC_default_warn_proc (or a replacement), whose second argument is a GC_word.  Thus the format string is used as a GC_err_printf format, with a GC_word second argument.  Since GC_word has to be the same size as a pointer, this is not a disaster.  But I'm not sure which is better.
> 
> Hans

This is not a problem, it's a solution (at least, until something like "GC_PRIdWORD" and friends are introduced as suggested in the discussion http://comments.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/2404). Strictly saying, everything else (like %d or %ld) than %p is not compatible with GC_word (which is the same size as pointer by definition). When You are directly calling GC_[log/err_]printf(), it's possible to write something like printf("%ld", (long)word_value) (this prints only the lowest part of the value on Win64), but the behavior of WARN("%ld", [(long)]word_value) (at least when WARN == GC_default_warn_proc) depends on the machine endianness if sizeof(long) < sizeof(word) (the highest part of the value would be printed on the big-endian ones).

The disadvantages of "%p" are:
- for pointers only (looks ugly for cardinal numbers);
- the output varies across compilers (typically zero-padded hex number with or w/o "0x")

I don't know which standards have "%p".

Bye.



More information about the Gc mailing list