Hi,

At Wed, 27 Jul 2005 10:56:18 +0900,
nobuyoshi nakada wrote in [ruby-talk:149645]:
> > |I think it's not enough; printf() format specifiers for VALUE
> > |would have to be changed.
> > 
> > Should we use %p for all the case?  Or it isn't enough?
> 
> I expect %p to work, but am not certain all old platforms
> support %p.  And VALUEs may need to be casted to pointers.
> 
> Also, id2ref() in gc.c assumes unsigned long is long enough to
> hold pointers, and SIZEOF_LONG_LONG and LONG_LONG are defined
> if __int64 is available.

Oops, missing/vsnprintf.c didn't support %p where void* is
bigger than long.


Index: missing/vsnprintf.c =================================================================== RCS file: /cvs/ruby/src/ruby/missing/vsnprintf.c,v retrieving revision 1.9 diff -U2 -p -r1.9 vsnprintf.c --- missing/vsnprintf.c 23 Jul 2005 01:02:17 -0000 1.9 +++ missing/vsnprintf.c 27 Jul 2005 02:13:37 -0000 @@ -65,4 +65,9 @@ #define u_short unsigned short #define u_int unsigned int +#ifdef HAVE_LONG_LONG +#define quad_t LONG_LONG +#define u_quad_t unsigned LONG_LONG +#define _HAVE_SANE_QUAD_ 1 +#endif #if !defined(HAVE_STDARG_PROTOTYPES) @@ -423,4 +428,61 @@ BSD__ultoa(val, endp, base, octzero, xdi } +#ifdef _HAVE_SANE_QUAD_ +/* + * Convert an unsigned long long to ASCII for printf purposes, returning + * a pointer to the first character of the string representation. + * Octal numbers can be forced to have a leading zero; hex numbers + * use the given digits. + */ +static char * +__uqtoa(val, endp, base, octzero, xdigs) + register u_quad_t val; + char *endp; + int base, octzero; + char *xdigs; +{ + register char *cp = endp; + quad_t sval; + + switch (base) { + case 10: + if (val < 10) { + *--cp = to_char(val); + return (cp); + } + if (val > LLONG_MAX) { + *--cp = to_char(val % 10); + sval = val / 10; + } else + sval = val; + do { + *--cp = to_char(sval % 10); + sval /= 10; + } while (sval != 0); + break; + + case 8: + do { + *--cp = to_char(val & 7); + val >>= 3; + } while (val); + if (octzero && *cp != '0') + *--cp = '0'; + break; + + case 16: + do { + *--cp = xdigs[val & 15]; + val >>= 4; + } while (val); + break; + + default: /* oops */ + break; + } + return (cp); +} +#endif + #ifdef FLOATING_POINT #include <math.h> @@ -790,12 +852,19 @@ fp_begin: _double = va_arg(ap, double); * -- ANSI X3J11 */ +#if SIZEOF_LONG < SIZEOF_VOIDP + uqval = (u_quad_t)va_arg(ap, void *); +#else ulval = (u_long)va_arg(ap, void *); +#endif base = 16; xdigs = "0123456789abcdef"; +#if SIZEOF_LONG < SIZEOF_VOIDP + flags |= QUADINT; +#else #ifdef _HAVE_SANE_QUAD_ - flags = (flags & ~QUADINT) | HEXPREFIX; -#else /* _HAVE_SANE_QUAD_ */ - flags = (flags) | HEXPREFIX; + flags &= ~QUADINT; #endif /* _HAVE_SANE_QUAD_ */ +#endif + flags |= HEXPREFIX; ch = 'x'; goto nosign;
-- Nobu Nakada