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]

Re: [GCC PATCH]: add tests for pthread initialization macros


Kaveh, Bruce -

As Kaveh said, since this applies more to glibc than to a
particular OS, the test should be for glibc, not Linux.
So, instead, use:

select = 'This file is part of the GNU C Library';

It would also be useful to try to detect when this might be necessary,
perhaps also:

 select = "^#[ \t]*define[ \t]+PTHREAD_(MUTEX|COND)INITIALIZER"
            "[ \t\\\n]+" '\{\{0,\}\}';

I have chosen a "select" approach, as there are in fact some more initializers to fix.

A few comments:
* this is really two sed expressions, so for clarity it would be better
 to remove the newline and add in another ``sed = ''.
* I do not know for sure whether running sed (1 fork + 1 exec) is
 cheaper or more expensive than two forks, an additional pipe and
 an extra pass through the data.  I am only sure that this is going
 to be either more or less expensive than two separate "format"
 fixes.  :)

It would be true with one sed expression for sure.  With two
sed expressions, I am uncertain.  With three, it is most likely
best to go ahead and use sed.  Just my guessing here.  It
is likely going to depend upon a particular OS and sed
implementation.  But we have to decide for all platforms.

In new revision of the patch, a fix for PTHREAD_RWLOCK_INITIALIZER is also introduced. As there will be perhaps two more sed commands, I think that we should stick with sed. However, each pattern has now its own sed command.


Attached patch has been bootstrapped on x86_64-pc-linux-gnu.

With regards to the testcase, I agree we should add any glibc extra
bits you want to test.  If you want to apply a patch over mine, please
do so.  I'm going to install my testcase as "obvious" in a day or two
so that people have time to comment.  After that you can add yours.

Please note, that in the test, a "#define _XOPEN_SOURCE 500" is needed before #include <pthread.h> to activate PTHREAD_RWLOCK_INITIALIZER test.

And just for information, remaining faulty initializers in my glibc are:

# if __WORDSIZE == 64
#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
 { { 0, 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP } }
#  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
 { { 0, 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP } }
#  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
 { { 0, 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP } }
# else
#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
 { { 0, 0, 0, PTHREAD_MUTEX_RECURSIVE_NP } }
#  define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \
 { { 0, 0, 0, PTHREAD_MUTEX_ERRORCHECK_NP } }
#  define PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP \
 { { 0, 0, 0, PTHREAD_MUTEX_ADAPTIVE_NP } }
# endif

and

#  if __WORDSIZE == 64
...
#  else
#   define PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP \
 { { 0, 0, 0, 0, 0, 0, PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP } }
#  endif
# endif

In each case, one or two trailing zeros are missing after PTHREAD_MUTEX_*_NP.

Thanks for review,
Uros.
Index: tests/base/pthread.h
===================================================================
--- tests/base/pthread.h	(revision 117283)
+++ tests/base/pthread.h	(working copy)
@@ -56,6 +56,21 @@
 #endif  /* ALPHA_PTHREAD_INIT_CHECK */
 
 
+#if defined( GLIBC_MUTEX_INIT_CHECK )
+This file is part of the GNU C Library.
+#define PTHREAD_MUTEX_INITIALIZER \
+  { { 0, 0, 0, 0, 0, 0 } }
+#define PTHREAD_COND_INITIALIZER { { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }
+# if __WORDSIZE == 64
+#  define PTHREAD_RWLOCK_INITIALIZER \
+  { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }
+# else
+#  define PTHREAD_RWLOCK_INITIALIZER \
+  { { 0, 0, 0, 0, 0, 0, 0, 0 } }
+# endif
+#endif  /* GLIBC_MUTEX_INIT_CHECK */
+
+
 #if defined( PTHREAD_PAGE_SIZE_CHECK )
 extern int __page_size;
 #endif  /* PTHREAD_PAGE_SIZE_CHECK */
Index: fixincl.x
===================================================================
--- fixincl.x	(revision 117283)
+++ fixincl.x	(working copy)
@@ -2,11 +2,11 @@
  * 
  * DO NOT EDIT THIS FILE   (fixincl.x)
  * 
- * It has been AutoGen-ed  Wednesday September 27, 2006 at 08:16:42 PM EDT
+ * It has been AutoGen-ed  Thursday September 28, 2006 at 10:49:36 PM CEST
  * From the definitions    inclhack.def
  * and the template file   fixincl
  */
-/* DO NOT CVS-MERGE THIS FILE, EITHER Wed Sep 27 20:16:42 EDT 2006
+/* DO NOT CVS-MERGE THIS FILE, EITHER Thu Sep 28 22:49:36 CEST 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 199 fixup descriptions.
+ * This file contains 200 fixup descriptions.
  *
  * See README for more information.
  *
@@ -4551,6 +4551,46 @@
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * *
  *
+ *  Description of Glibc_Mutex_Init fix
+ */
+tSCC zGlibc_Mutex_InitName[] =
+     "glibc_mutex_init";
+
+/*
+ *  File name selection pattern
+ */
+tSCC zGlibc_Mutex_InitList[] =
+  "|pthread.h|";
+/*
+ *  Machine/OS name selection pattern
+ */
+#define apzGlibc_Mutex_InitMachs (const char**)NULL
+
+/*
+ *  content selection pattern - do fix if pattern found
+ */
+tSCC zGlibc_Mutex_InitSelect0[] =
+       "This file is part of the GNU C Library.";
+
+#define    GLIBC_MUTEX_INIT_TEST_CT  1
+static tTestDesc aGlibc_Mutex_InitTests[] = {
+  { TT_EGREP,    zGlibc_Mutex_InitSelect0, (regex_t*)NULL }, };
+
+/*
+ *  Fix Command Arguments for Glibc_Mutex_Init
+ */
+static const char* apzGlibc_Mutex_InitPatch[] = { "sed",
+    "-e", "/define[ \t]*PTHREAD_MUTEX_INITIALIZER[ \t]*\\\\/,+1s/{ { 0, } }/{ { 0, 0, 0, 0, 0, 0 } }/",
+    "-e", "/define[ \t]*PTHREAD_COND_INITIALIZER/s/{ { 0, } }/{ { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }/",
+    "-e", "/define[ \t]*PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\/,/{ { 0, } }/c# if __WORDSIZE == 64\\\n\
+#  define PTHREAD_RWLOCK_INITIALIZER \\\\\\n  { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n\
+# else\\\n\
+#  define PTHREAD_RWLOCK_INITIALIZER \\\\\\n  { { 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n\
+# endif",
+    (char*)NULL };
+
+/* * * * * * * * * * * * * * * * * * * * * * * * * *
+ *
  *  Description of Pthread_Page_Size fix
  */
 tSCC zPthread_Page_SizeName[] =
@@ -8100,9 +8140,9 @@
  *
  *  List of all fixes
  */
-#define REGEX_COUNT          242
+#define REGEX_COUNT          243
 #define MACH_LIST_SIZE_LIMIT 261
-#define FIX_COUNT            199
+#define FIX_COUNT            200
 
 /*
  *  Enumerate the fixes
@@ -8218,6 +8258,7 @@
     OBSTACK_LVALUE_CAST_FIXIDX,
     OSF_NAMESPACE_A_FIXIDX,
     OSF_NAMESPACE_C_FIXIDX,
+    GLIBC_MUTEX_INIT_FIXIDX,
     PTHREAD_PAGE_SIZE_FIXIDX,
     PTHREAD_INCOMPLETE_STRUCT_ARGUMENT_FIXIDX,
     READ_RET_TYPE_FIXIDX,
@@ -8860,6 +8901,11 @@
      OSF_NAMESPACE_C_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
      aOsf_Namespace_CTests,   apzOsf_Namespace_CPatch, 0 },
 
+  {  zGlibc_Mutex_InitName,    zGlibc_Mutex_InitList,
+     apzGlibc_Mutex_InitMachs,
+     GLIBC_MUTEX_INIT_TEST_CT, FD_MACH_ONLY,
+     aGlibc_Mutex_InitTests,   apzGlibc_Mutex_InitPatch, 0 },
+
   {  zPthread_Page_SizeName,    zPthread_Page_SizeList,
      apzPthread_Page_SizeMachs,
      PTHREAD_PAGE_SIZE_TEST_CT, FD_MACH_ONLY | FD_SUBROUTINE,
Index: inclhack.def
===================================================================
--- inclhack.def	(revision 117283)
+++ inclhack.def	(working copy)
@@ -2507,6 +2507,37 @@
 };
 
 
+/*  glibc-2.3.5 defines pthread mutex initializers incorrectly,
+ *  so we replace them with versions that correspond to the
+ *  definition.
+ */
+fix = {
+    hackname = glibc_mutex_init;
+    files    = pthread.h;
+    select   = 'This file is part of the GNU C Library.';
+
+    sed      = "/define[ \t]*PTHREAD_MUTEX_INITIALIZER[ \t]*\\\\/,+1"
+               "s/{ { 0, } }/{ { 0, 0, 0, 0, 0, 0 } }/";
+    sed      = "/define[ \t]*PTHREAD_COND_INITIALIZER/"
+               "s/{ { 0, } }/{ { 0, 0, 0, 0, 0, (void *) 0, 0, 0 } }/";
+    sed      = "/define[ \t]*PTHREAD_RWLOCK_INITIALIZER[ \t]*\\\\/,"
+               "/{ { 0, } }/c# if __WORDSIZE == 64\\\n"
+               "#  define PTHREAD_RWLOCK_INITIALIZER \\\\\\n"
+               "  { { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n"
+               "# else\\\n"
+               "#  define PTHREAD_RWLOCK_INITIALIZER \\\\\\n"
+               "  { { 0, 0, 0, 0, 0, 0, 0, 0 } }\\\n"
+               "# endif";
+    
+    test_text =
+    "This file is part of the GNU C Library.\n"
+    "#define PTHREAD_MUTEX_INITIALIZER \\\\\n"
+    "  { { 0, } }\n"
+    "#define PTHREAD_COND_INITIALIZER { { 0, } }\n"
+    "# define PTHREAD_RWLOCK_INITIALIZER \\\\\n"
+    "  { { 0, } }";
+};
+
 /*
  *  Fix __page_size* declarations in pthread.h AIX 4.1.[34].
  *  The original ones fail if uninitialized externs are not common.

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