This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


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

fixinclues patch for HPUX11's inttypes.h



OK to commit?  

I found this patch while cleaning out some old source trees.  It is a 
fixincludes patch (both old and new style fixinclues) for a problem
in HPUX 11's inttypes.h (details in the comments).  

I don't have the patches for the generated files anymore; if someone
could generated them for me, I'd appreciate it.

                                             -gavin...


	* fixincludes: Add a HPUX 11 fix for inttypes.h.
	* fixinc/inclhack.def: Same.
	* fixinc/inclhack.sh, fixinc/fixincl.sh, fixinc/fixincl.x: Regenerate.

Index: fixincludes
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixincludes,v
retrieving revision 1.23
diff -c -r1.23 fixincludes
*** fixincludes	1999/08/03 04:06:30	1.23
--- fixincludes	1999/10/14 14:11:27
***************
*** 2970,2975 ****
--- 2970,3011 ----
    fi
  fi
  
+ # In inttypes.h on HPUX 11, the use of __CONCAT__ in the definition 
+ # of UINT32_C has undefined behavior according to ISO/ANSI:
+ # the arguments to __CONCAT__ are not macro expanded before the
+ # concatination happens so the trailing ')' in the first argument
+ # is concatinated with the 'l' in the second argument creating an
+ # invalid pp token.  The behavior of invalid pp tokens is undefined.
+ # GCC does not handle these invalid tokens the way the HP compiler does.
+ # This problem will potentially occur anytime macros are used in the
+ # arguments to __CONCAT__.  A general solution to this problem would be to 
+ # insert another layer of macro between __CONCAT__ and its use
+ # in UINT32_C.  An example of this solution can be found in the C standard.
+ # A more specific solution, the one used here, is to change the UINT32_C
+ # macro to not used macros in the arguments to __CONCAT__.
+ file=inttypes.h
+ if [ -r $file ] && [ ! -r ${LIB}/$file ]; then
+   cp $file ${LIB}/$file >/dev/null 2>&1 || echo "Can't copy $file"
+   chmod +w ${LIB}/$file 2>/dev/null
+   chmod a+r ${LIB}/$file 2>/dev/null
+ fi
+ 
+ if [ -r ${LIB}/$file ]; then
+   echo "Fixing use of __CONCAT__ in $file"
+   sed -e 's/^#define UINT32_C(__c)\([ 	]*\)__CONCAT__(__CONCAT_U__(__c),l)/#define UINT32_C(__c)\1__CONCAT__(__c,ul)/'  \
+     ${LIB}/$file > ${LIB}/${file}.sed
+   rm -f ${LIB}/$file; mv ${LIB}/${file}.sed ${LIB}/$file
+   if cmp $file ${LIB}/$file >/dev/null 2>&1; then
+     rm -f ${LIB}/$file
+   else
+     # Find any include directives that use "file".
+     for include in `egrep '^[       ]*#[    ]*include[      ]*"[^/]' ${LIB}/$file | sed -e 's/^[    ]*#[    ]*include[      ]*"\([^"]*\)".*$/\1/'`; do
+       dir=`echo $file | sed -e s'|/[^/]*$||'`
+       required="$required ${INPUT} $dir/$include ${LIB}/$dir/$include"
+     done
+   fi
+ fi
+ 
  # Some math.h files define struct exception, which conflicts with
  # the class exception defined in the C++ file std/stdexcept.h.  We
  # redefine it to __math_exception.  This is not a great fix, but I
Index: fixinc/inclhack.def
===================================================================
RCS file: /cvs/gcc/egcs/gcc/fixinc/inclhack.def,v
retrieving revision 1.35
diff -c -r1.35 inclhack.def
*** inclhack.def	1999/08/17 18:32:32	1.35
--- inclhack.def	1999/10/14 14:11:31
***************
*** 600,605 ****
--- 600,627 ----
      sed      = "s/^extern struct sigevent;/struct sigevent;/";
  };
  
+ /* 
+  * In inttypes.h on HPUX 11, the use of __CONCAT__ in the definition 
+  * of UINT32_C has undefined behavior according to ISO/ANSI:
+  * the arguments to __CONCAT__ are not macro expanded before the
+  * concatination happens so the trailing ')' in the first argument
+  * is concatinated with the 'l' in the second argument creating an
+  * invalid pp token.  The behavior of invalid pp tokens is undefined.
+  * GCC does not handle these invalid tokens the way the HP compiler does.
+  * This problem will potentially occur anytime macros are used in the
+  * arguments to __CONCAT__.  A general solution to this problem would be to 
+  * insert another layer of macro between __CONCAT__ and its use
+  * in UINT32_C.  An example of this solution can be found in the C standard.
+  * A more specific solution, the one used here, is to change the UINT32_C
+  * macro to not used macros in the arguments to __CONCAT__.
+  */
+ 
+ fix = {
+     hackname = hpux11_uint32_c;
+     files    = inttypes.h;
+     select   = "^#define UINT32_C\\(__c\\)[ \t]*__CONCAT__\\(__CONCAT_U__\\(__c\\),l\\)";
+     sed      = "s/^#define UINT32_C(__c)\\([ \t]*\\)__CONCAT__(__CONCAT_U__(__c),l)/#define UINT32_C(__c)\\1__CONCAT__(__c,ul)/";
+ };
  
  /*
   *  Determine if we're on Interactive Unix 2.2 or later, in which case we


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