Here are some proposed changes to the gnulib allocsa and vasnprintf modules prompted by the needs of porting coreutils to Tandem NSK (OSS), along with modernizing the code to use the newer macros like AC_TYPE_LONG_LONG_INT rather than the older macros like gl_AC_TYPE_LONG_LONG. I haven't tested these changes on Tandem but have compiled and run them on Debian stable x86 and in principle they look fairly safe to me.
2006-10-10 Paul Eggert <[EMAIL PROTECTED]> Port to Tandem NSK OSS, which has 64-bit signed int but at most 32-bit unsigned int. Problem reported by Matthew Woehlke in: http://lists.gnu.org/archive/html/bug-coreutils/2006-10/msg00062.html More generally, don't assume that 64-bit signed int is available if unsigned int is, and vice versa. * lib/allocsa.h (sa_alignment_longlong, sa_alignment_max): Use the more-modern HAVE_LONG_LONG_INT rather than HAVE_LONG_LONG. (sa_alignment_unsignedlonglong, sa_alignment_max): Don't assume that long long int exists if unsigned long long int does, and vice versa. * lib/printf-args.c (printf_fetchargs): Likewise. * lib/printf-args.h (TYPE_LONGLONGINT, TYPE_ULONGLONGINT): Likewise. (TYPE_COUNT_LONGLONGINT_POINTER, argument): Likewise. * lib/printf-parse.c (PRINTF_PARSE): Likewise. * lib/vasnprintf.c (VASNPRINTF): Likewise. * m4/allocsa.m4 (gl_ALLOCSA): Require AC_TYPE_LONG_LONG_INT instead of the obsolete gl_AC_TYPE_LONG_LONG. Require AC_TYPE_UNSIGNED_LONG_LONG_INT, too. * m4/vasnprintf.m4 (gl_PREREQ_PRINTF_ARGS, gl_PREREQ_PRINTF_PARSE): (gl_PREREQ_VASNPRINTF): Likewise. * modules/allocsa (Files): Add m4/ulonglong.m4. * modules/vasnprintf (Files): Likewise. Index: lib/allocsa.h =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/allocsa.h,v retrieving revision 1.6 diff -p -u -r1.6 allocsa.h --- lib/allocsa.h 8 Aug 2006 13:11:11 -0000 1.6 +++ lib/allocsa.h 11 Oct 2006 06:10:55 -0000 @@ -106,16 +106,22 @@ enum among all elementary types. */ sa_alignment_long = sa_alignof (long), sa_alignment_double = sa_alignof (double), -#ifdef HAVE_LONG_LONG - sa_alignment_longlong = sa_alignof (long long), +#ifdef HAVE_LONG_LONG_INT + sa_alignment_longlong = sa_alignof (long long int), +#endif +#ifdef HAVE_UNSIGNED_LONG_LONG_INT + sa_alignment_unsignedlonglong = sa_alignof (unsigned long long int), #endif #ifdef HAVE_LONG_DOUBLE sa_alignment_longdouble = sa_alignof (long double), #endif sa_alignment_max = ((sa_alignment_long - 1) | (sa_alignment_double - 1) -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT | (sa_alignment_longlong - 1) #endif +#ifdef HAVE_UNSIGNED_LONG_LONG_INT + | (sa_alignment_unsignedlonglong - 1) +#endif #ifdef HAVE_LONG_DOUBLE | (sa_alignment_longdouble - 1) #endif Index: lib/printf-args.c =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/printf-args.c,v retrieving revision 1.7 diff -p -u -r1.7 printf-args.c --- lib/printf-args.c 14 Sep 2006 14:18:36 -0000 1.7 +++ lib/printf-args.c 11 Oct 2006 06:10:55 -0000 @@ -56,10 +56,12 @@ printf_fetchargs (va_list args, argument case TYPE_ULONGINT: ap->a.a_ulongint = va_arg (args, unsigned long int); break; -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: ap->a.a_longlongint = va_arg (args, long long int); break; +#endif +#ifdef HAVE_UNSIGNED_LONG_LONG_INT case TYPE_ULONGLONGINT: ap->a.a_ulonglongint = va_arg (args, unsigned long long int); break; @@ -128,7 +130,7 @@ printf_fetchargs (va_list args, argument case TYPE_COUNT_LONGINT_POINTER: ap->a.a_count_longint_pointer = va_arg (args, long int *); break; -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: ap->a.a_count_longlongint_pointer = va_arg (args, long long int *); break; Index: lib/printf-args.h =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/printf-args.h,v retrieving revision 1.4 diff -p -u -r1.4 printf-args.h --- lib/printf-args.h 14 May 2005 06:03:58 -0000 1.4 +++ lib/printf-args.h 11 Oct 2006 06:10:55 -0000 @@ -47,8 +47,10 @@ typedef enum TYPE_UINT, TYPE_LONGINT, TYPE_ULONGINT, -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT TYPE_LONGLONGINT, +#endif +#ifdef HAVE_UNSIGNED_LONG_LONG_INT TYPE_ULONGLONGINT, #endif TYPE_DOUBLE, @@ -68,7 +70,7 @@ typedef enum TYPE_COUNT_SHORT_POINTER, TYPE_COUNT_INT_POINTER, TYPE_COUNT_LONGINT_POINTER -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT , TYPE_COUNT_LONGLONGINT_POINTER #endif } arg_type; @@ -87,8 +89,10 @@ typedef struct unsigned int a_uint; long int a_longint; unsigned long int a_ulongint; -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT long long int a_longlongint; +#endif +#ifdef HAVE_UNSIGNED_LONG_LONG_INT unsigned long long int a_ulonglongint; #endif float a_float; @@ -109,7 +113,7 @@ typedef struct short * a_count_short_pointer; int * a_count_int_pointer; long int * a_count_longint_pointer; -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT long long int * a_count_longlongint_pointer; #endif } Index: lib/printf-parse.c =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/printf-parse.c,v retrieving revision 1.7 diff -p -u -r1.7 printf-parse.c --- lib/printf-parse.c 14 Sep 2006 14:18:36 -0000 1.7 +++ lib/printf-parse.c 11 Oct 2006 06:10:55 -0000 @@ -382,7 +382,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRE switch (c) { case 'd': case 'i': -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT if (flags >= 16 || (flags & 4)) type = TYPE_LONGLONGINT; else @@ -397,7 +397,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRE type = TYPE_INT; break; case 'o': case 'u': case 'x': case 'X': -#ifdef HAVE_LONG_LONG +#ifdef HAVE_UNSIGNED_LONG_LONG_INT if (flags >= 16 || (flags & 4)) type = TYPE_ULONGLONGINT; else @@ -456,7 +456,7 @@ PRINTF_PARSE (const CHAR_T *format, DIRE type = TYPE_POINTER; break; case 'n': -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT if (flags >= 16 || (flags & 4)) type = TYPE_COUNT_LONGLONGINT_POINTER; else Index: lib/vasnprintf.c =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/vasnprintf.c,v retrieving revision 1.20 diff -p -u -r1.20 vasnprintf.c --- lib/vasnprintf.c 14 Sep 2006 14:18:36 -0000 1.20 +++ lib/vasnprintf.c 11 Oct 2006 06:10:55 -0000 @@ -248,7 +248,7 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *l case TYPE_COUNT_LONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longint_pointer = length; break; -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT case TYPE_COUNT_LONGLONGINT_POINTER: *a.arg[dp->arg_index].a.a_count_longlongint_pointer = length; break; @@ -322,10 +322,20 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *l { case 'd': case 'i': case 'u': -# ifdef HAVE_LONG_LONG - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) +# ifdef HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT) tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + (unsigned int) (sizeof (long long int) * CHAR_BIT + * 0.30103 /* binary -> decimal */ + ) + + 1; /* turn floor into ceil */ + else +# endif +# ifdef HAVE_UNSIGNED_LONG_LONG_INT + if (type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long int) + * CHAR_BIT * 0.30103 /* binary -> decimal */ ) + 1; /* turn floor into ceil */ @@ -352,10 +362,20 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *l break; case 'o': -# ifdef HAVE_LONG_LONG - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) +# ifdef HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT) tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + (unsigned int) (sizeof (long long int) * CHAR_BIT + * 0.333334 /* binary -> octal */ + ) + + 1; /* turn floor into ceil */ + else +# endif +# ifdef HAVE_UNSIGNED_LONG_LONG_INT + if (type == TYPE_ULONGLONGINT) + tmp_length = + (unsigned int) (sizeof (unsigned long long int) + * CHAR_BIT * 0.333334 /* binary -> octal */ ) + 1; /* turn floor into ceil */ @@ -380,10 +400,20 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *l break; case 'x': case 'X': -# ifdef HAVE_LONG_LONG - if (type == TYPE_LONGLONGINT || type == TYPE_ULONGLONGINT) +# ifdef HAVE_LONG_LONG_INT + if (type == TYPE_LONGLONGINT) + tmp_length = + (unsigned int) (sizeof (long long int) * CHAR_BIT + * 0.25 /* binary -> hexadecimal */ + ) + + 1; /* turn floor into ceil */ + else +# endif +# ifdef HAVE_UNSIGNED_LONG_LONG_INT + if (type == TYPE_ULONGLONGINT) tmp_length = - (unsigned int) (sizeof (unsigned long long) * CHAR_BIT + (unsigned int) (sizeof (unsigned long long int) + * CHAR_BIT * 0.25 /* binary -> hexadecimal */ ) + 1; /* turn floor into ceil */ @@ -527,9 +557,13 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *l switch (type) { -#ifdef HAVE_LONG_LONG +#if defined HAVE_LONG_LONG_INT || defined HAVE_UNSIGNED_LONG_LONG_INT +# ifdef HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: +# endif +# ifdef HAVE_UNSIGNED_LONG_LONG_INT case TYPE_ULONGLONGINT: +# endif *p++ = 'l'; /*FALLTHROUGH*/ #endif @@ -681,13 +715,15 @@ VASNPRINTF (CHAR_T *resultbuf, size_t *l SNPRINTF_BUF (arg); } break; -#ifdef HAVE_LONG_LONG +#ifdef HAVE_LONG_LONG_INT case TYPE_LONGLONGINT: { long long int arg = a.arg[dp->arg_index].a.a_longlongint; SNPRINTF_BUF (arg); } break; +#endif +#ifdef HAVE_UNSIGNED_LONG_LONG_INT case TYPE_ULONGLONGINT: { unsigned long long int arg = a.arg[dp->arg_index].a.a_ulonglongint; Index: m4/allocsa.m4 =================================================================== RCS file: /cvsroot/gnulib/gnulib/m4/allocsa.m4,v retrieving revision 1.3 diff -p -u -r1.3 allocsa.m4 --- m4/allocsa.m4 18 Jan 2005 13:07:56 -0000 1.3 +++ m4/allocsa.m4 11 Oct 2006 06:10:55 -0000 @@ -1,5 +1,5 @@ -# allocsa.m4 serial 3 -dnl Copyright (C) 2003-2004 Free Software Foundation, Inc. +# allocsa.m4 serial 4 +dnl Copyright (C) 2003-2004, 2006 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -10,6 +10,7 @@ AC_DEFUN([gl_ALLOCSA], dnl @ALLOCA@ and @[EMAIL PROTECTED] AC_REQUIRE([gl_FUNC_ALLOCA]) AC_REQUIRE([gl_EEMALLOC]) - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) AC_REQUIRE([gt_TYPE_LONGDOUBLE]) ]) Index: m4/vasnprintf.m4 =================================================================== RCS file: /cvsroot/gnulib/gnulib/m4/vasnprintf.m4,v retrieving revision 1.8 diff -p -u -r1.8 vasnprintf.m4 --- m4/vasnprintf.m4 18 Jan 2005 13:07:56 -0000 1.8 +++ m4/vasnprintf.m4 11 Oct 2006 06:10:55 -0000 @@ -23,7 +23,8 @@ AC_DEFUN([gl_FUNC_VASNPRINTF], AC_DEFUN([gl_PREREQ_PRINTF_ARGS], [ AC_REQUIRE([bh_C_SIGNED]) - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) AC_REQUIRE([gt_TYPE_LONGDOUBLE]) AC_REQUIRE([gt_TYPE_WCHAR_T]) AC_REQUIRE([gt_TYPE_WINT_T]) @@ -32,7 +33,8 @@ AC_DEFUN([gl_PREREQ_PRINTF_ARGS], # Prequisites of lib/printf-parse.h, lib/printf-parse.c. AC_DEFUN([gl_PREREQ_PRINTF_PARSE], [ - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) AC_REQUIRE([gt_TYPE_LONGDOUBLE]) AC_REQUIRE([gt_TYPE_WCHAR_T]) AC_REQUIRE([gt_TYPE_WINT_T]) @@ -45,7 +47,8 @@ AC_DEFUN([gl_PREREQ_PRINTF_PARSE], AC_DEFUN([gl_PREREQ_VASNPRINTF], [ AC_REQUIRE([AC_FUNC_ALLOCA]) - AC_REQUIRE([gl_AC_TYPE_LONG_LONG]) + AC_REQUIRE([AC_TYPE_LONG_LONG_INT]) + AC_REQUIRE([AC_TYPE_UNSIGNED_LONG_LONG_INT]) AC_REQUIRE([gt_TYPE_LONGDOUBLE]) AC_REQUIRE([gt_TYPE_WCHAR_T]) AC_REQUIRE([gt_TYPE_WINT_T]) Index: modules/allocsa =================================================================== RCS file: /cvsroot/gnulib/gnulib/modules/allocsa,v retrieving revision 1.6 diff -p -u -r1.6 allocsa --- modules/allocsa 14 Apr 2005 13:05:07 -0000 1.6 +++ modules/allocsa 11 Oct 2006 06:10:55 -0000 @@ -9,6 +9,7 @@ m4/allocsa.m4 m4/eealloc.m4 m4/longlong.m4 m4/longdouble.m4 +m4/ulonglong.m4 Depends-on: alloca-opt Index: modules/vasnprintf =================================================================== RCS file: /cvsroot/gnulib/gnulib/modules/vasnprintf,v retrieving revision 1.8 diff -p -u -r1.8 vasnprintf --- modules/vasnprintf 29 Sep 2004 22:10:44 -0000 1.8 +++ modules/vasnprintf 11 Oct 2006 06:10:55 -0000 @@ -14,6 +14,7 @@ m4/longdouble.m4 m4/wchar_t.m4 m4/wint_t.m4 m4/longlong.m4 +m4/ulonglong.m4 m4/intmax_t.m4 m4/stdint_h.m4 m4/inttypes_h.m4 _______________________________________________ Bug-coreutils mailing list Bug-coreutils@gnu.org http://lists.gnu.org/mailman/listinfo/bug-coreutils