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]
Other format: [Raw text]

[PATCH]: fix PTHREAD_ONCE_INIT when using -ansi


This patch fixes PTHREAD_ONCE_INIT for the -ansi case.  The problem is
similar to the other pthread initialization macros, namely that
upad64_t is typedef'ed differently when __STDC__ is defined and
therefore we need to adjust the init macro accordingly.

A couple of notes: The fix must not be applied on solaris 10, I found
several fixes in the file that used the "not_machine" statement for
solaris 10 so I followed suit and did the same here.  It seems to work
fine.  Second, the pattern matches the same text as the
solaris_once_init_1 fix so I had to update the test results for that
fix as well.

Tested by running make check in the fixincludes dir, also I ran
fixincludes on solaris10, solaris9 and solaris7 and ensured that the
correct thing was done to pthread.h on all versions.  Finally I
compiled a testcase using PTHREAD_ONCE_INIT on all three solaris
versions and was able to get a clean -W -Wall compile with and without
the -ansi flag.

Okay for all active branches?

		Thanks,
		--Kaveh



2006-09-27  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* inclhack.def (solaris_once_init_2): New fix.
	* tests/base/pthread.h: Update.

	* fixincl.x: Regenerate.

diff -rup orig/egcc-SVN20060927/fixincludes/inclhack.def egcc-SVN20060927/fixincludes/inclhack.def
--- orig/egcc-SVN20060927/fixincludes/inclhack.def	2006-09-27 00:27:08.000000000 -0400
+++ egcc-SVN20060927/fixincludes/inclhack.def	2006-09-27 11:24:13.408944123 -0400
@@ -3034,6 +3034,38 @@ fix = {
 
 
 /*
+ * Sun Solaris defines PTHREAD_ONCE_INIT with a "0" for some
+ *  fields of the pthread_once_t structure, which are of type
+ *  upad64_t, which itself is typedef'd to int64_t, but with __STDC__
+ *  defined (e.g. by -ansi) it is a union. So change the initializer
+ *  to "{0}" instead.  This test relies on solaris_once_init_1.
+ */
+fix = {
+    hackname = solaris_once_init_2;
+    select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
+    files = pthread.h;
+    /*
+     * On Solaris 10, this fix is unnecessary because upad64_t is
+     * always defined correctly regardless of the definition of the
+     * __STDC__ macro.
+     */
+    mach = '*-*-solaris2.1[0-9]*';
+    not_machine = true;
+    c_fix = format;
+    c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n"
+                "%0\n"
+                "#else\n"
+                "%1{0}, {0}, {0}, {%3}%4\n"
+                "#endif";
+    c_fix_arg = "(^#define[ \t]+PTHREAD_ONCE_INIT[ \t]+\\{\\{)"
+                "(0, 0, 0, )(PTHREAD_[A-Z_]+)(\\}\\})[ \t]*$";
+    test_text =
+    '#ident "@(#)pthread.h  1.26  98/04/12 SMI"'"\n"
+    "#define PTHREAD_ONCE_INIT\t{{0, 0, 0, PTHREAD_ONCE_NOTDONE}}\n";
+};
+
+
+/*
  * Solaris 2.5.1 and 2.6 use an outdated prototype for send & recv
  * in sys/socket.h.  This is corrected in Solaris 7 and up.
  */
diff -rup orig/egcc-SVN20060927/fixincludes/tests/base/pthread.h egcc-SVN20060927/fixincludes/tests/base/pthread.h
--- orig/egcc-SVN20060927/fixincludes/tests/base/pthread.h	2006-09-27 00:27:07.000000000 -0400
+++ egcc-SVN20060927/fixincludes/tests/base/pthread.h	2006-09-27 11:26:05.776685356 -0400
@@ -109,10 +109,25 @@ extern int __sigsetjmp (struct __jmp_buf
 
 #if defined( SOLARIS_ONCE_INIT_1_CHECK )
 #pragma ident	"@(#)pthread.h	1.37	04/09/28 SMI"
+#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)
 #define PTHREAD_ONCE_INIT	{{0, 0, 0, PTHREAD_ONCE_NOTDONE}}
+#else
+#define PTHREAD_ONCE_INIT	{{{0}, {0}, {0}, {PTHREAD_ONCE_NOTDONE}}}
+#endif
 #endif  /* SOLARIS_ONCE_INIT_1_CHECK */
 
 
+#if defined( SOLARIS_ONCE_INIT_2_CHECK )
+#ident "@(#)pthread.h  1.26  98/04/12 SMI"
+#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)
+#define PTHREAD_ONCE_INIT	{{0, 0, 0, PTHREAD_ONCE_NOTDONE}}
+#else
+#define PTHREAD_ONCE_INIT	{{{0}, {0}, {0}, {PTHREAD_ONCE_NOTDONE}}}
+#endif
+
+#endif  /* SOLARIS_ONCE_INIT_2_CHECK */
+
+
 #if defined( THREAD_KEYWORD_CHECK )
 extern int pthread_create (pthread_t *__restrict __thr,
 extern int pthread_kill (pthread_t __thr, int __signo);
diff -rup orig/egcc-SVN20060927/fixincludes/fixincl.x egcc-SVN20060927/fixincludes/fixincl.x
--- orig/egcc-SVN20060927/fixincludes/fixincl.x	2006-09-27 00:27:08.000000000 -0400
+++ egcc-SVN20060927/fixincludes/fixincl.x	2006-09-27 11:24:15.000000000 -0400
@@ -2,11 +2,11 @@
  * 
  * DO NOT EDIT THIS FILE   (fixincl.x)
  * 
- * It has been AutoGen-ed  Tuesday September 26, 2006 at 11:56:29 AM EDT
+ * It has been AutoGen-ed  Wednesday September 27, 2006 at 11:24:15 AM EDT
  * From the definitions    inclhack.def
  * and the template file   fixincl
  */
-/* DO NOT CVS-MERGE THIS FILE, EITHER Tue Sep 26 11:56:29 EDT 2006
+/* DO NOT CVS-MERGE THIS FILE, EITHER Wed Sep 27 11:24:15 EDT 2006
  *
  * You must regenerate it.  Use the ./genfixes script.
  *
@@ -15,7 +15,7 @@
  * certain ANSI-incompatible system header files which are fixed to work
  * correctly with ANSI C and placed in a directory that GNU C will search.
  *
- * This file contains 198 fixup descriptions.
+ * This file contains 199 fixup descriptions.
  *
  * See README for more information.
  *
@@ -5578,6 +5578,48 @@ static const char* apzSolaris_Once_Init_
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
  *
+ *  Description of Solaris_Once_Init_2 fix
+ */
+tSCC zSolaris_Once_Init_2Name[] =
+     "solaris_once_init_2";
+
+/*
+ *  File name selection pattern
+ */
+tSCC zSolaris_Once_Init_2List[] =
+  "|pthread.h|";
+/*
+ *  Machine/OS name selection pattern
+ */
+tSCC* apzSolaris_Once_Init_2Machs[] = {
+        "*-*-solaris2.1[0-9]*",
+        (const char*)NULL };
+
+/*
+ *  content selection pattern - do fix if pattern found
+ */
+tSCC zSolaris_Once_Init_2Select0[] =
+       "@\\(#\\)pthread.h[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI";
+
+#define    SOLARIS_ONCE_INIT_2_TEST_CT  1
+static tTestDesc aSolaris_Once_Init_2Tests[] = {
+  { TT_EGREP,    zSolaris_Once_Init_2Select0, (regex_t*)NULL }, };
+
+/*
+ *  Fix Command Arguments for Solaris_Once_Init_2
+ */
+static const char* apzSolaris_Once_Init_2Patch[] = {
+    "format",
+    "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n\
+%0\n\
+#else\n\
+%1{0}, {0}, {0}, {%3}%4\n\
+#endif",
+    "(^#define[ \t]+PTHREAD_ONCE_INIT[ \t]+\\{\\{)(0, 0, 0, )(PTHREAD_[A-Z_]+)(\\}\\})[ \t]*$",
+    (char*)NULL };
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
  *  Description of Solaris_Socket fix
  */
 tSCC zSolaris_SocketName[] =
@@ -8057,9 +8099,9 @@ static const char* apzX11_SprintfPatch[]
  *
  *  List of all fixes
  */
-#define REGEX_COUNT          241
+#define REGEX_COUNT          242
 #define MACH_LIST_SIZE_LIMIT 261
-#define FIX_COUNT            198
+#define FIX_COUNT            199
 
 /*
  *  Enumerate the fixes
@@ -8200,6 +8242,7 @@ typedef enum {
     SOLARIS_MUTEX_INIT_2_FIXIDX,
     SOLARIS_RWLOCK_INIT_1_FIXIDX,
     SOLARIS_ONCE_INIT_1_FIXIDX,
+    SOLARIS_ONCE_INIT_2_FIXIDX,
     SOLARIS_SOCKET_FIXIDX,
     SOLARIS_STDIO_TAG_FIXIDX,
     SOLARIS_UNISTD_FIXIDX,
@@ -8941,6 +8984,11 @@ tFixDesc fixDescList[ FIX_COUNT ] = {
      SOLARIS_ONCE_INIT_1_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
      aSolaris_Once_Init_1Tests,   apzSolaris_Once_Init_1Patch, 0 },
 
+  {  zSolaris_Once_Init_2Name,    zSolaris_Once_Init_2List,
+     apzSolaris_Once_Init_2Machs,
+     SOLARIS_ONCE_INIT_2_TEST_CT, FD_MACH_IFNOT | FD_SUBROUTINE,
+     aSolaris_Once_Init_2Tests,   apzSolaris_Once_Init_2Patch, 0 },
+
   {  zSolaris_SocketName,    zSolaris_SocketList,
      apzSolaris_SocketMachs,
      SOLARIS_SOCKET_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,


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