This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/13575] SSIZE_MAX defined as LONG_MAX is inconsistent with ssize_t, when __WORDSIZE != 64


https://sourceware.org/bugzilla/show_bug.cgi?id=13575

--- Comment #10 from Eric Blake <eblake at redhat dot com> ---
(In reply to Florian Weimer from comment #9)

> On s390 (32-bit), it currently prints:
...

> 
> So SIZE_MAX already has the wrong type, and with your proposed change,
> SSIZE_MAX would have the wrong type as well.
> 
> I think the best approach would be to define the maximum along with
> __SSIZE_T_TYPE.

Weird that gcc spells it __SIZE_TYPE__, but __SSIZE_T_TYPE (difference in _T
and in trailing __).  But whatever.  I can't see anything predefined for
__SSIZE{_T,}_MAX{__,}, but knowing the type chosen by gcc should be sufficient
to determine the suffix, along these lines (borrowed from newlib's _intsup.h,
which has a permissive license), and modified here (but not heavily tested):

/* Determine what suffix to use for ssize_t as defined by gcc
   for this target.  We end up with
   ?(signed|unsigned) char == 0
   ?(signed|unsigned) short == 1
   ?(signed|unsigned) int == 2
   ?(signed|unsigned) short int == 3
   ?(signed|unsigned) long == 4
   ?(signed|unsigned) long int == 6
   ?(signed|unsigned) long long == 8
   ?(signed|unsigned) long long int == 10
 */
#pragma push_macro("signed")
#pragma push_macro("unsigned")
#pragma push_macro("char")
#pragma push_macro("short")
#pragma push_macro("__int20")
#pragma push_macro("int")
#pragma push_macro("long")
#undef signed
#undef unsigned
#undef char
#undef short
#undef int
#undef __int20
#undef long
#define signed +0
#define unsigned +0
#define char +0
#define short +1
#define __int20 +2
#define int +2
#define long +4
#if __SSIZE_T_TYPE >= 8 // ssize_t is long long
#define __SSIZE_MAX_SUFFIX LL
#elif __SSIZE_T_TYPE >= 4 // ssize_t is long
#define __SSIZE_MAX_SUFFIX L
#else // assume ssize_t promotes to int
#define __SSIZE_MAX_SUFFIX // no suffix needed
#endif
#undef signed
#undef unsigned
#undef char
#undef short
#undef int
#undef long
#pragma pop_macro("signed")
#pragma pop_macro("unsigned")
#pragma pop_macro("char")
#pragma pop_macro("short")
#pragma pop_macro("__int20")
#pragma pop_macro("int")
#pragma pop_macro("long")

at which point you can then use __SSIZE_MAX_SUFFIX to construct the
type-appropriate SSIZE_MAX.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]