*** /usr/include/pthread.h Wed Jan 5 14:09:41 2000 --- /u/bkorb/tools/gcc/_b/stage1-gcc/include/pthread.h Fri Jan 21 15:10:36 2005 *************** *** 1,3 **** --- 1,12 ---- + /* DO NOT EDIT THIS FILE. + + It has been auto-edited by fixincludes from: + + "/usr/include/pthread.h" + + This had to be done to correct non-standard usages in the + original, manufacturer supplied header file. */ + /* * Copyright (c) 1997-1998 by Sun Microsystems, Inc. * All rights reserved. *************** *** 82,92 **** * should be consistent with the definition for pthread_mutex_t). */ /* = DEFAULTMUTEX */ ! #define PTHREAD_MUTEX_INITIALIZER {{0, 0, 0, 0}, {{{0}}}, 0} ! #define PTHREAD_COND_INITIALIZER {{{0}, 0}, 0} /* = DEFAULTCV */ ! #define PTHREAD_RWLOCK_INITIALIZER {0, 0, 0, {0, 0, 0}, {0, 0}, {0, 0}} /* cancellation type and state */ #define PTHREAD_CANCEL_ENABLE 0x00 --- 91,111 ---- * should be consistent with the definition for pthread_mutex_t). */ /* = DEFAULTMUTEX */ ! #ifdef __LP64 ! # define GCC_PAD64_INITIALIZER 0 ! #else ! # define GCC_PAD64_INITIALIZER { 0.0 } ! #endif ! /* the following initializers are tuned for ! sys/types.h version 1.66 SMI */ ! #define PTHREAD_MUTEX_INITIALIZER \ ! {{0,0,0,0}, {{{0,0,0,0,0,0,0,0}}}, GCC_PAD64_INITIALIZER} ! #define PTHREAD_COND_INITIALIZER \ ! {{{0,0,0,0}, 0}, GCC_PAD64_INITIALIZER} ! #define PTHREAD_RWLOCK_INITIALIZER \ ! {0,0,0, {0,0,0}, {0,0}, {0,0}} /* cancellation type and state */ #define PTHREAD_CANCEL_ENABLE 0x00 Index: inclhack.def =================================================================== RCS file: /cvsroot/gcc/gcc/fixincludes/inclhack.def,v retrieving revision 1.16 diff -b -B -u -p -r1.16 inclhack.def --- inclhack.def 26 Nov 2004 22:00:51 -0000 1.16 +++ inclhack.def 21 Jan 2005 23:23:37 -0000 @@ -2525,50 +2537,25 @@ fix = { /* - * Sun Solaris 2.5.1, 2.6 defines PTHREAD_{MUTEX|COND}_INITIALIZER - * incorrectly, so we replace them with versions that correspond to - * the definition. We also explicitly name this fix "1" and the next - * fix "2" because this one does not deal with the last field. This - * fix needs to run before the next. - */ -fix = { - hackname = solaris_mutex_init_1; - select = '@\(#\)pthread.h' "[ \t]+1.1[0-9][ \t]+9[567]/[0-9/]+ SMI"; - files = pthread.h; - sed = "/define[ \t]*PTHREAD_MUTEX_INI/s/{0, 0,/{{{0}, 0}, {{{0}}},/\n" - "/define[ \t]*PTHREAD_COND_INI/s/{0,/{{{0},0},/"; - test_text = - '#ident "@(#)pthread.h 1.16 97/05/05 SMI"'"\n" - "#define PTHREAD_MUTEX_INITIALIZER\t{0, 0, 0}\n" - "#define PTHREAD_COND_INITIALIZER\t{0, 0} /* */\n"; -}; - - -/* - * Sun Solaris defines PTHREAD_MUTEX_INITIALIZER with a trailing - * "0" for the last field of the pthread_mutex_t structure, which is - * 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 + * Sun Solaris mutilates mutex initializers. Mostly, this is a consequence + * of initializing a "upad64_t" on a 32 bit platform with a single zero. + * Unfortunately, this is actually a union of a "double" and a couple of + * ints. The double is first. Therefore, it needs to be: { 0.0 } + * There are other problems, too, in the older older versions. */ fix = { - hackname = solaris_mutex_init_2; - select = '@\(#\)pthread.h' "[ \t]+1.[0-9]+[ \t]+[0-9/]+ SMI"; + hackname = solaris_pthread; + mach = "sparc*-sun*-solaris*"; files = pthread.h; - c_fix = format; - c_fix_arg = "#if __STDC__ - 0 == 0 && !defined(_NO_LONGLONG)\n" - "%0\n" - "#else\n" - "%1, {0}}%3\n" - "#endif"; - c_fix_arg = "(^#define[ \t]+PTHREAD_(MUTEX|COND)_INITIALIZER[ \t]+\\{.*)" - ",[ \t]*0\\}" "(|[ \t].*)$"; - test_text = - '#ident "@(#)pthread.h 1.26 98/04/12 SMI"'"\n" - "#define PTHREAD_MUTEX_INITIALIZER\t{{{0},0}, {{{0}}}, 0}\n" - "#define PTHREAD_COND_INITIALIZER\t{{{0}, 0}, 0}\t/* DEFAULTCV */\n" - "#define PTHREAD_RWLOCK_INITIALIZER\t" - "{0, 0, 0, {0, 0, 0}, {0, 0}, {0, 0}}"; + c-fix = pthread_init; + test-text = <<- EOTestText + `echo '#pragma ident "@(#)types.h 1.74 03/08/07 SMI"' >> sys/types.h` + #define PTHREAD_MUTEX_INITIALIZER \\ + {XXX} + #define PTHREAD_COND_INITIALIZER {XXX} + #define PTHREAD_RWLOCK_INITIALIZER \\ + {XXX} + EOTestText; }; Index: fixfixes.c =================================================================== RCS file: /cvsroot/gcc/gcc/fixincludes/fixfixes.c,v retrieving revision 1.3 diff -b -B -u -p -r1.3 fixfixes.c --- fixfixes.c 27 Oct 2004 20:13:57 -0000 1.3 +++ fixfixes.c 21 Jan 2005 23:23:37 -0000 @@ -71,7 +71,8 @@ typedef struct { _FT_( "format", format_fix ) \ _FT_( "machine_name", machine_name_fix ) \ _FT_( "wrap", wrap_fix ) \ - _FT_( "gnu_type", gnu_type_fix ) + _FT_( "gnu_type", gnu_type_fix ) \ + _FT_( "pthread_init", pthread_init_fix ) #define FIX_PROC_HEAD( fix ) \ @@ -167,6 +168,138 @@ typedef __%s_TYPE__ %s_t;\n\ return text += rm[0].rm_eo; } +/* + * Emit the pthread initializers + */ +static const char* +emit_pthread_init (const char* text, + regmatch_t* rm, + int types_rev, + int have_pad ) +{ + static const char z_pad64_init[] = +"#ifdef __LP64\n\ +# define GCC_PAD64_INITIALIZER 0\n\ +#else\n\ +# define GCC_PAD64_INITIALIZER { 0.0 }\n\ +#endif\n/* the following initializers are tuned for\n\ + sys/types.h version 1.%d SMI */\n"; + + static const char z_mutex[] = "MUTEX"; + static const char z_cond[] = "COND"; + static const char z_rwlock[] = "RWLOCK"; + + typedef struct initializers_s { + const char* pz_mutex; + const char* pz_cond; + const char* pz_rwlock; + } initializers_t; + + static initializers_t types_51 = { + "\\\n\t{{{0,0,0,0}, 0}, {{0,0,0,0,0,0,0,0}}, GCC_PAD64_INITIALIZER}", + "\\\n\t{{{0,0,0,0}, 0}, GCC_PAD64_INITIALIZER}", + "\\\n\t** BOGUS **" + }; + + static initializers_t types_63 = { + "\\\n\t{{{0,0,0,0}, 0}, {{0,0,0,0,0,0,0,0}}, GCC_PAD64_INITIALIZER}", + "\\\n\t{{{0,0,0,0}, 0}, GCC_PAD64_INITIALIZER}", + "\\\n\t{0,0,0, {0,0,0}, {0,0}, {0,0}}" + }; + + static initializers_t types_66 = { + "\\\n\t{{0,0,0,0}, {{{0,0,0,0,0,0,0,0}}}, GCC_PAD64_INITIALIZER}", + "\\\n\t{{{0,0,0,0}, 0}, GCC_PAD64_INITIALIZER}", + "\\\n\t{0,0,0, {0,0,0}, {0,0}, {0,0}}" + }; + + static initializers_t types_69 = { + "\\\n\t{{0,0,0,0,0}, {{{0,0,0,0,0,0,0,0}}}, GCC_PAD64_INITIALIZER}", + "\\\n\t{{{0,0,0,0}, 0, 0}, GCC_PAD64_INITIALIZER}", + "\\\n\t{0,0,0, {0,0,0}, {0,0}, {0,0}}" + }; + + static initializers_t types_74 = { + "\\\n\t{{0, 0, 0, DEFAULT_TYPE, _MUTEX_MAGIC}, {{{0,0,0,0,0,0,0,0}}}, \\\n\ +\t\tGCC_PAD64_INITIALIZER}", + + "\\\n\t{{{0,0,0,0}, 0, 0}, GCC_PAD64_INITIALIZER}", + + "\\\n\t{0, DEFAULT_TYPE, _RWL_MAGIC, \\\n\ +\t\tPTHREAD_MUTEX_INITIALIZER, \\\n\ +\t\tPTHREAD_COND_INITIALIZER, \\\n\ +\t\tPTHREAD_COND_INITIALIZER}" + }; + + static initializers_t types_84 = { + "\\\n\t{{0, 0, 0, DEFAULT_TYPE, _MUTEX_MAGIC}, {{{0,0,0,0,0,0,0,0}}}, \\\n\ +\t\tGCC_PAD64_INITIALIZER}", + + "\\\n\t{{{0,0,0,0}, _DEFAULT_TYPE, _COND_MAGIC}, GCC_PAD64_INITIALIZER}", + + "\\\n\t{0, DEFAULT_TYPE, _RWL_MAGIC, \\\n\ +\t\tPTHREAD_MUTEX_INITIALIZER, \\\n\ +\t\tPTHREAD_COND_INITIALIZER, \\\n\ +\t\tPTHREAD_COND_INITIALIZER}" + }; + + initializers_t* pi; + + /* Write out everything to the end of the name just located, + plus one more for the whitespace character */ + if (have_pad) + { + fwrite (text, rm[0].rm_eo + 1, 1, stdout); + } + else + { + int name_len = rm[0].rm_eo - rm[0].rm_so; + const char* pz = text + rm[0].rm_so; + + fwrite (text, rm[0].rm_so, 1, stdout); + printf (z_pad64_init, types_rev); + fwrite (pz, name_len + 1, 1, stdout); + } + + /* point "text" to the first character of the submatch */ + text += rm[1].rm_so; + + /* Use the character at the start of the first submatch as our struct type */ + switch (types_rev) + { + case 51: pi = &types_51; break; + case 63: pi = &types_63; break; + case 66: pi = &types_66; break; + case 69: pi = &types_69; break; + case 74: pi = &types_74; break; + case 84: pi = &types_84; break; + default: + fprintf (stderr, "unknown sys/types.h version: 1.%d\n", types_rev); + return text + (rm[0].rm_eo - rm[1].rm_so); + } + + /* the first character tells us which structure type to emit */ + switch (*text) + { + case 'M': fputs (pi->pz_mutex, stdout); break; + case 'C': fputs (pi->pz_cond, stdout); break; + case 'R': fputs (pi->pz_rwlock, stdout); break; + } + + /* Skip over the old initializer text */ + do + { + const char* pz = strchr (text+1, '\n'); + if (pz == NULL) + { + fputs ("malformed pthread initializer in pthread.h\n", stderr); + exit (EXIT_BROKEN); + } + text = pz; + } while (text[-1] == '\\'); + + return text; +} /* * Copy the `format' string to std out, replacing `%n' expressions @@ -690,6 +823,105 @@ FIX_PROC_HEAD( gnu_type_fix ) fputs (text, stdout); } +/* + * Search for multiple copies of a regular expression. Each block + * of matched text is replaced with the format string, as described + * above in `format_write'. + */ +FIX_PROC_HEAD( pthread_init_fix ) +{ + static const char zNoSysTypes[] = + "fs error %d (%s) trying to open \n\ +This is required for determining the INITIALIZER format.\n"; + + static const char zNoTypesVer[] = + "Could not locate tye sys/types ident string\n"; + + static const char z_types[] = "sys/types.h"; + static const char z_pat[] = + "^#define\tPTHREAD_(MUTEX|COND|RWLOCK)_INITIALIZER"; + + regex_t re; + regmatch_t rm[3]; + + FILE* fp = fopen (z_types, "r"); + int types_rev = 0; + int have_pad = 0; + + IGNORE_ARG(filname); + + if (fp == NULL) + { + fprintf (stderr, zNoSysTypes, errno, strerror(errno)); + exit (EXIT_BROKEN); + } + + for (;;) + { + static const char z_ident[] = "#pragma ident"; + static const char z_types[] = "\"@(#)types.h"; + char z[80]; + char* pz = fgets (z, sizeof(z), fp); + if (pz == NULL) + { + fputs (zNoTypesVer, stderr); + exit (EXIT_BROKEN); + } + + if (strncmp (pz, z_ident, sizeof(z_ident)-1) == 0) + { + /* + We've found the #pragma ident line. Scan it for the file version. + It should be something like: 1.(51|63|69|74|84) + We will skip the entry and choke if it doesn't look like that. */ + + pz += sizeof(z_ident)-1; + while (isspace (*pz)) pz++; + if (strncmp (pz, z_types, sizeof(z_types)-1) != 0) + continue; + pz += sizeof(z_types)-1; + while (isspace (*pz)) pz++; + if (strncmp (pz, "1.", 2) == 0) + pz += 2; + + do + { + if (isdigit (*pz)) + { + types_rev = (types_rev * 10) + (*pz - '0'); + } + else if (*pz == '.') + { + types_rev <<= 10; + } + else + continue; + } while (! isspace (*++pz)); + + if (strstr (pz, "SMI\"\n") == NULL) + { + types_rev = 0; + continue; + } + break; + } /* if (line matches #pragma ident) */ + } + fclose (fp); + + compile_re (z_pat, &re, 1, "pthread initializer", "pthread_init_fix"); + + while (xregexec (&re, text, 3, rm, 0) == 0) + { + text = emit_pthread_init (text, rm, types_rev, have_pad); + have_pad = 1; + } + + /* + * Dump out the rest of the file + */ + fputs (text, stdout); +} + /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =