Re: Fix for 687162, CVS HEAD doesn't compile with Cygwin/gcc

Ralph Giles <[email protected]>
Newsgroups gmane.comp.printing.ghostscript.patches
Message-ID <[email protected]>
On Mon, Dec 01, 2003 at 04:54:09PM +0000, Ralph Giles wrote:

> I've committed a version using the generic types as in Alex's original patch. If you would verify 
> that this restores the build, I'll close the bug.

Ray informs me that more recent versions of cygwin do include stdint.h and something (probably 
sys/types.h) pulls it in automatically. This reveals a general flaw in our scheme, because genconf 
is compiled with CCAUX rather than CC_ and doesn't see the -DHAVE_STDINT_H passed by the configure 
script in the autoconf makefile, leading to redundant activation of the fallback and type 
conflicts.

One work around is to add GCFLAGS to the definition of CCAUX in the autoconf makefile, and 
probably unix-gcc.mak as well.

However, Russell suggested creating a stdint_.h instead. This is pretty much per-policy, but the 
main advantage is that the genarch et al needn't include it. I think I like this solution better, 
because it's more explicit about the types being required. If there are no objections, I'll check 
this in.

The main drawback of this approach is someone deciding someday the genconf needs to include 
stdint_.h.

Proposed log message:

It turns out that more recent versions of Cygwin do provide stdint.h and it can be pulled in 
through other headers. This can cause type conflicts when compiling genconf in the autoconf build 
because it uses the CCAUX compiler definition which doesn't pass on the -DHAVE_STDINT_H argument 
that protects this code.

As a solution, we move all the stdint.h type definition code to a portability header, stdint_.h. 
This should not be included in files built with CCAUX.

End of log message.

_______________________________________________
gs-code-review mailing list
[email protected]
http://www.ghostscript.com/mailman/listinfo/gs-code-review
stdint_h.diff (text/plain, 10.6 KB)
Index: src/lib.mak
===================================================================
RCS file: /cvs/ghostscript/gs/src/lib.mak,v
retrieving revision 1.150
diff -u -r1.150 lib.mak
--- src/lib.mak	20 Nov 2003 23:01:41 -0000	1.150
+++ src/lib.mak	1 Dec 2003 21:58:20 -0000
@@ -90,6 +90,7 @@
 math__h=$(GLSRC)math_.h $(std_h) $(vmsmath_h)
 memory__h=$(GLSRC)memory_.h $(std_h)
 stat__h=$(GLSRC)stat_.h $(std_h)
+stdint__h=$(GLSRC)stdint_.h $(std_h)
 stdio__h=$(GLSRC)stdio_.h $(std_h)
 string__h=$(GLSRC)string_.h $(std_h)
 time__h=$(GLSRC)time_.h $(std_h) $(gconfig__h)
@@ -470,7 +471,7 @@
 slzwx_h=$(GLSRC)slzwx.h
 smd5_h=$(GLSRC)smd5.h $(md5_h)
 sarc4_h=$(GLSRC)sarc4.h $(scommon_h)
-sjbig2_h=$(GLSRC)sjbig2.h $(scommon_h)
+sjbig2_h=$(GLSRC)sjbig2.h $(stdint__h) $(scommon_h)
 spdiffx_h=$(GLSRC)spdiffx.h
 spngpx_h=$(GLSRC)spngpx.h
 spprint_h=$(GLSRC)spprint.h
@@ -1361,7 +1362,7 @@
 	$(ADDMOD) $(GLD)sjbig2 -include $(GLD)libjbig2.dev
 
 $(GLOBJ)sjbig2.$(OBJ) : $(GLSRC)sjbig2.c $(AK) \
- $(memory__h) $(stdio__h) $(gserror_h) $(gserrors_h) $(gdebug_h) \
+ $(stdint__h) $(memory__h) $(stdio__h) $(gserror_h) $(gserrors_h) $(gdebug_h) \
  $(sjbig2_h) $(strimpl_h)
 	$(GLJBIG2CC) $(GLO_)sjbig2.$(OBJ) $(C_) $(GLSRC)sjbig2.c
 
@@ -1800,7 +1801,7 @@
  $(gxpath_h) $(gxttf_h) $(gxttfb_h) $(gxfcache_h) $(stream_h)
 	$(GLCC) $(GLO_)gstype42.$(OBJ) $(C_) $(GLSRC)gstype42.c
 
-ttfsfnt_h=$(GLSRC)ttfsfnt.h
+ttfsfnt_h=$(GLSRC)ttfsfnt.h $(stdint__h)
 ttcommon_h=$(GLSRC)ttcommon.h
 ttconf_h=$(GLSRC)ttconf.h
 ttfinp_h=$(GLSRC)ttfinp.h
Index: src/sjbig2.c
===================================================================
RCS file: /cvs/ghostscript/gs/src/sjbig2.c,v
retrieving revision 1.4
diff -u -r1.4 sjbig2.c
--- src/sjbig2.c	17 Apr 2003 00:49:07 -0000	1.4
+++ src/sjbig2.c	1 Dec 2003 21:54:04 -0000
@@ -17,6 +17,7 @@
 /* $Id: sjbig2.c,v 1.4 2003/04/17 00:49:07 giles Exp $ */
 /* jbig2decode filter implementation -- hooks in libjbig2dec */
 
+#include "stdint_.h"
 #include "memory_.h"
 #include "stdio_.h" /* for debug printouts */
 
Index: src/sjbig2.h
===================================================================
RCS file: /cvs/ghostscript/gs/src/sjbig2.h,v
retrieving revision 1.3
diff -u -r1.3 sjbig2.h
--- src/sjbig2.h	22 Mar 2003 18:24:17 -0000	1.3
+++ src/sjbig2.h	1 Dec 2003 21:54:41 -0000
@@ -21,6 +21,7 @@
 #ifndef sjbig2_INCLUDED
 #  define sjbig2_INCLUDED
 
+#include "stdint_.h"
 #include "scommon.h"
 #include <jbig2.h>
 
Index: src/std.h
===================================================================
RCS file: /cvs/ghostscript/gs/src/std.h,v
retrieving revision 1.10
diff -u -r1.10 std.h
--- src/std.h	27 Nov 2003 02:26:10 -0000	1.10
+++ src/std.h	1 Dec 2003 21:30:03 -0000
@@ -97,51 +97,6 @@
 # endif
 #endif
 
-/* define some of the stdint.h types if they haven't been set by stdpre.h */
-#ifndef STDINT_TYPES_DEFINED
-/* 8 bit types */
-# if ARCH_SIZEOF_CHAR == 1
-typedef signed char int8_t;
-typedef unsigned char uint8_t;
-# endif
-/* 16 bit types */
-# if ARCH_SIZEOF_SHORT == 2
-typedef signed short int16_t;
-typedef unsigned short uint16_t;
-# else
-#  if ARCH_SIZEOF_INT == 2
-typedef signed int int16_t;
-typedef unsigned int uint16_t;
-#  endif
-# endif
-/* 32 bit types */
-# if ARCH_SIZEOF_INT == 4
-typedef signed int int32_t;
-typedef unsigned int uint32_t;
-# else
-#  if ARCH_SIZEOF_LONG == 4
-typedef signed long int32_t;
-typedef unsigned long uint32_t;
-#  else
-#   if ARCH_SIZEOF_SHORT == 4
-typedef signed short int32_t;
-typedef unsigned short uint32_t;
-#   endif
-#  endif
-# endif
-/* 64 bit types */
-# if ARCH_SIZEOF_INT == 8
-typedef signed int int64_t;
-typedef unsigned int uint64_t;
-# else
-#  if ARCH_SIZEOF_LONG == 8
-typedef signed long int64_t;
-typedef unsigned long uint64_t;
-#  endif
-# endif
-#  define STDINT_TYPES_DEFINED
-#endif /* STDINT_TYPES_DEFINED */
-
 /* Minimum and maximum values for the signed types. */
 /* Avoid casts, to make them acceptable to strict ANSI compilers. */
 #define min_short (-1 << (arch_sizeof_short * 8 - 1))
Index: src/stdint_.h
===================================================================
RCS file: src/stdint_.h
diff -N src/stdint_.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/stdint_.h	1 Dec 2003 21:29:46 -0000
@@ -0,0 +1,118 @@
+/* Copyright (C) 2003 artofcode LLC.  All rights reserved.
+  
+  This software is provided AS-IS with no warranty, either express or
+  implied.
+  
+  This software is distributed under license and may not be copied,
+  modified or distributed except as expressly authorized under the terms
+  of the license contained in the file LICENSE in this distribution.
+  
+  For more information about licensing, please refer to
+  http://www.ghostscript.com/licensing/. For information on
+  commercial licensing, go to http://www.artifex.com/licensing/ or
+  contact Artifex Software, Inc., 101 Lucas Valley Road #110,
+  San Rafael, CA  94903, U.S.A., +1(415)492-9861.
+*/
+
+/* $Id: $ */
+/* Generic substitute for stdint.h */
+
+#ifndef stdint__INCLUDED
+#  define stdint__INCLUDED
+
+/*
+ * This is here primarily because we must include std.h before
+ * any file that includes sys/types.h.
+ */
+#include "std.h"
+
+/* Some systems are guaranteed to have stdint.h
+ * but don't use the autoconf detection
+ */
+#ifndef HAVE_STDINT_H
+# ifdef __MACOS__
+#   define HAVE_STDINT_H
+# endif
+#endif
+
+/* Define some stdint.h types. The jbig2dec headers require these and 
+ * they're generally useful to have around now that there's a standard.
+ */
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+# define STDINT_TYPES_DEFINED
+#else
+# if defined(__WIN32__) /* MSVC currently doesn't provide C99 headers */
+   typedef signed char             int8_t;
+   typedef short int               int16_t;
+   typedef int                     int32_t;
+   typedef __int64                 int64_t;
+   typedef unsigned char           uint8_t;
+   typedef unsigned short int      uint16_t;
+   typedef unsigned int            uint32_t;
+   typedef unsigned __int64        uint64_t;
+#  define STDINT_TYPES_DEFINED
+# endif
+# if defined(__VMS) /* OpenVMS provides these types in inttypes.h */
+#  include <inttypes.h>
+#  define STDINT_TYPES_DEFINED
+# endif
+# if defined(__CYGWIN__)
+   /* Cygwin defines the signed versions in sys/types.h */
+   /* but uses a u_ prefix for the unsigned versions */
+   typedef u_int8_t                uint8_t;
+   typedef u_int16_t               uint16_t;
+   typedef u_int32_t               uint32_t;
+   typedef u_int64_t               uint64_t;
+#  define STDINT_TYPES_DEFINED
+# endif
+   /* other archs may want to add defines here, 
+      or use the fallbacks in std.h */
+#endif /* !HAVE_STDINT_H */
+
+/* fall back to tests based on arch.h */
+#ifndef STDINT_TYPES_DEFINED
+/* 8 bit types */
+# if ARCH_SIZEOF_CHAR == 1
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+# endif
+/* 16 bit types */
+# if ARCH_SIZEOF_SHORT == 2
+typedef signed short int16_t;
+typedef unsigned short uint16_t;
+# else
+#  if ARCH_SIZEOF_INT == 2
+typedef signed int int16_t;
+typedef unsigned int uint16_t;
+#  endif
+# endif
+/* 32 bit types */
+# if ARCH_SIZEOF_INT == 4
+typedef signed int int32_t;
+typedef unsigned int uint32_t;
+# else
+#  if ARCH_SIZEOF_LONG == 4
+typedef signed long int32_t;
+typedef unsigned long uint32_t;
+#  else
+#   if ARCH_SIZEOF_SHORT == 4
+typedef signed short int32_t;
+typedef unsigned short uint32_t;
+#   endif
+#  endif
+# endif
+/* 64 bit types */
+# if ARCH_SIZEOF_INT == 8
+typedef signed int int64_t;
+typedef unsigned int uint64_t;
+# else
+#  if ARCH_SIZEOF_LONG == 8
+typedef signed long int64_t;
+typedef unsigned long uint64_t;
+#  endif
+# endif
+#  define STDINT_TYPES_DEFINED
+#endif /* STDINT_TYPES_DEFINED */
+
+#endif /* stdint__INCLUDED */
Index: src/stdpre.h
===================================================================
RCS file: /cvs/ghostscript/gs/src/stdpre.h,v
retrieving revision 1.21
diff -u -r1.21 stdpre.h
--- src/stdpre.h	1 Dec 2003 18:19:24 -0000	1.21
+++ src/stdpre.h	1 Dec 2003 21:26:13 -0000
@@ -271,50 +271,6 @@
 #undef ushort
 #undef ulong
 
-/* Some systems are guaranteed to have stdint.h
- * but don't use the autoconf detection
- */
-#ifndef HAVE_STDINT_H
-# ifdef __MACOS__
-#   define HAVE_STDINT_H
-# endif
-#endif
-
-/* Define some stdint.h types. The jbig2dec headers require these and 
- * they're generally useful to have around now that there's a standard.
- */
-#ifdef HAVE_STDINT_H
-# include <stdint.h>
-# define STDINT_TYPES_DEFINED
-#else
-# if defined(__WIN32__) /* MSVC currently doesn't provide C99 headers */
-   typedef signed char             int8_t;
-   typedef short int               int16_t;
-   typedef int                     int32_t;
-   typedef __int64                 int64_t;
-   typedef unsigned char           uint8_t;
-   typedef unsigned short int      uint16_t;
-   typedef unsigned int            uint32_t;
-   typedef unsigned __int64        uint64_t;
-#  define STDINT_TYPES_DEFINED
-# endif
-# if defined(__VMS) /* OpenVMS provides these types in inttypes.h */
-#  include <inttypes.h>
-#  define STDINT_TYPES_DEFINED
-# endif
-# if defined(__CYGWIN__)
-   /* Cygwin defines the signed versions in sys/types.h */
-   /* but uses a u_ prefix for the unsigned versions */
-   typedef u_int8_t                uint8_t;
-   typedef u_int16_t               uint16_t;
-   typedef u_int32_t               uint32_t;
-   typedef u_int64_t               uint64_t;
-#  define STDINT_TYPES_DEFINED
-# endif
-   /* other archs may want to add defines here, 
-      or use the fallbacks in std.h */
-#endif /* STDINT_H */
-
 /*
  * Define a Boolean type.  Even though we would like it to be
  * unsigned char, it pretty well has to be int, because
Index: src/ttfsfnt.h
===================================================================
RCS file: /cvs/ghostscript/gs/src/ttfsfnt.h,v
retrieving revision 1.4
diff -u -r1.4 ttfsfnt.h
--- src/ttfsfnt.h	20 Nov 2003 20:52:25 -0000	1.4
+++ src/ttfsfnt.h	1 Dec 2003 21:27:10 -0000
@@ -27,6 +27,8 @@
 
 #ifndef sfntIncludes
 #define sfntIncludes
+
+#include "stdint_.h" /* make sure stdint types are available */
                             
 typedef   uint8_t    uint8; /* 8-bit unsigned integer */
 typedef    int8_t     int8; /* 8-bit signed integer */
@@ -34,9 +36,9 @@
 typedef   int16_t    int16; /* 16-bit signed integer */
 typedef  uint32_t   uint32; /* 32-bit unsigned integer */
 typedef   int32_t    int32; /* 32-bit signed integer */
-#if 0
+#if 0
 typedef   int32_t    Fixed; /* 16.16 32-bit signed fixed-point number */
-#endif
+#endif
 typedef   int16_t    FUnit; /* Smallest measurable distance in em space (16-bit signed integer) */
 typedef   int16_t    FWord; /* 16-bit signed integer that describes a quantity in FUnits */
 typedef  uint16_t   uFWord; /* 16-bit unsigned integer that describes a quantity in FUnits */
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.