ssize_t [patch]
Zack Weinberg
zack@wolery.cumb.org
Tue Apr 25 14:10:00 GMT 2000
On Tue, Apr 25, 2000 at 02:35:04PM -0400, Kaveh R. Ghazi wrote:
> > From: Zack Weinberg <zack@wolery.cumb.org>
> >
> > ssize_t is the return type of read(). What does read return on your
> > SunOS box?
>
> int
Then I'd better make it default to int.
AC_CHECK_TYPE doesn't autogenerate config.h.in entries... how lame.
> > This looks good. Do you want me to put in just the minimum amount of
> > glue for what I need to do, or provide a wider set of these, as sys2.h
> > does?
> > zw
>
> IMHO TYPE_MAXIMUM, and the macros it calls, are enough.
which is TYPE_MINIMUM and TYPE_SIGNED. Right.
> We probably don't need all the fallback *_MIN/*_MAX defaults unless
> somebody has a platform which complains. I don't think we really use
> any of these anywhere yet in gcc anyway, except INT_MAX.
Sounds good to me.
Here is a patch which provides (a) a default definition of ssize_t;
(b) SSIZE_MAX and UCHAR_MAX definitions in system.h; (c) the
infrastructure to define more _MAX/_MIN macros should we need them.
cpplib is already using UCHAR_MAX, and will need ssize_t/SSIZE_MAX
shortly (as in this week). Ok to commit?
zw
* configure.in: Add check for ssize_t.
* acconfig.h: Add template for ssize_t. Remove @TOP@, put
@BOTTOM@ before all the NEED_DECLARATION_* macros.
* system.h: Add TYPE_MAXIMUM, TYPE_MINIMUM, TYPE_SIGNED
macros. Provide default definitions of UCHAR_MAX and
SSIZE_MAX.
* cpplex.c: Remove default definition of UCHAR_MAX.
===================================================================
Index: configure.in
--- configure.in 2000/04/25 20:30:14 1.361
+++ configure.in 2000/04/25 21:04:14
@@ -431,6 +431,11 @@ AC_CHECK_FUNCS(strtoul bsearch putenv po
# Make sure wchar_t is available
#AC_CHECK_TYPE(wchar_t, unsigned int)
+# The default for this is int, because the default for size_t is
+# unsigned int; also, historical systems (SunOS 4) that didn't have
+# ssize_t used int in its place.
+AC_CHECK_TYPE(ssize_t, int)
+
gcc_AC_FUNC_VFPRINTF_DOPRNT
gcc_AC_FUNC_PRINTF_PTR
===================================================================
Index: acconfig.h
--- acconfig.h 2000/04/25 20:30:14 1.47
+++ acconfig.h 2000/04/25 21:04:14
@@ -23,6 +23,13 @@
/* Define as 1 if you have the stpcpy function. */
#undef HAVE_STPCPY
+/* Define to `int' if <sys/types.h> doesn't define. */
+#undef ssize_t
+
+/* autoheader does not understand GCC_NEED_DECLARATION[S]. Put all
+ NEED_DECLARATION_foobar entries _after_ the BOTTOM marker. Put all
+ other entries _before_ it. */
+@BOTTOM@
/* Whether malloc must be declared even if <stdlib.h> is included. */
#undef NEED_DECLARATION_MALLOC
@@ -94,5 +101,3 @@
/* Whether environ must be declared. */
#undef NEED_DECLARATION_ENVIRON
-
-@TOP@
===================================================================
Index: system.h
--- system.h 2000/04/25 11:21:13 1.65
+++ system.h 2000/04/25 21:04:14
@@ -236,6 +236,25 @@ extern int errno;
# endif /* defined(HOST_BITS_PER_LONG) && defined(HOST_BITS_PER_LONGLONG) */
#endif /* ! HOST_WIDEST_INT */
+/* Capability for creating _MAX and _MIN macros if they do not already
+ exist. Currently we only need SSIZE_MAX and UCHAR_MAX, but... */
+
+/* The extra casts work around common compiler bugs. */
+#define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
+/* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
+ It is necessary at least when t == time_t. */
+#define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
+ ? ~ (t) 0 << (sizeof(t) * CHAR_BIT - 1) : (t) 0))
+#define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
+
+#ifndef UCHAR_MAX
+#define UCHAR_MAX TYPE_MAXIMUM (unsigned char)
+#endif
+
+#ifndef SSIZE_MAX
+#define SSIZE_MAX TYPE_MAXIMUM (ssize_t)
+#endif
+
#ifdef TIME_WITH_SYS_TIME
# include <sys/time.h>
# include <time.h>
Index: cpplex.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cpplex.c,v
retrieving revision 1.25
diff -u -p -r1.25 cpplex.c
--- cpplex.c 2000/04/25 19:32:36 1.25
+++ cpplex.c 2000/04/25 21:04:17
@@ -1729,10 +1729,6 @@ find_position (start, limit, linep)
designated initializers, it can be constant data; otherwise, it is
set up at runtime by _cpp_init_input_buffer. */
-#ifndef UCHAR_MAX
-#define UCHAR_MAX 255 /* assume 8-bit bytes */
-#endif
-
#if (GCC_VERSION >= 2007) || (__STDC_VERSION__ >= 199901L)
#define init_chartab() /* nothing */
#define CHARTAB static const unsigned char chartab[UCHAR_MAX + 1] = {
More information about the Gcc-patches
mailing list