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]

checksum test for fixincluding


Someone suggested this and it seemed like a reasonable thing to verify
(pretty much) that only a specific version of a file should be fixed.
I used the BSD check sum, so there is a 1/65000 chance of a false positive.
Incorporating md5sum seemed over the top.
Index: fixincludes/ChangeLog
===================================================================
--- fixincludes/ChangeLog	(revision 218991)
+++ fixincludes/ChangeLog	(working copy)
@@ -1,9 +1,20 @@
+2013-12-07  Bruce Korb  <bkorb@gnu.org>
+
+	* fixincludes/fixincl.tpl: add handling for "sum" selection
+	criteria and clean up layout
+	* fixincludes/fixlib.h: enumerate TT_CKSUM test type
+	* fixincludes/fixincl.c (fix_applies): add code to handle
+	the new test type
+	(cksum_test): function to handle it
+	* fixincludes/README: doc it and remove explanations from
+	more than a decade ago.
+
 2014-12-15  Uros Bizjak  <ubizjak@gmail.com>
 
 	* server.c (server_setup): Check return value of
 	getcwd and in case of error set buff[0] to 0.
 
 2014-10-21  Uros Bizjak  <ubizjak@gmail.com>
 
 	* inclhack.def (glibc_c99_inline_4): Add pthread.h to files.
 	* fixincl.x: Regenerate.
Index: fixincludes/README
===================================================================
--- fixincludes/README	(revision 218991)
+++ fixincludes/README	(working copy)
@@ -1,30 +1,10 @@
 
-FIXINCLUDES OPERATION
-=====================
-
-See also:  http://autogen.SourceForge.net/fixinc.html
-
-The set of fixes required was distilled down to just the data required
-to specify what needed to happen for each fix.  Those data were edited
-into a file named fixincludes/inclhack.def.  A program called AutoGen
-(http://autogen.SourceForge.net) uses these definitions to instantiate
-several different templates that then produces code for a fixinclude
-program (fixincl.x) and a shell script to test its functioning.  On
-certain platforms (viz. those that do not have functional bidirectional
-pipes), the fixincl program is split into two.  This should only concern
-you on DOS and BeOS.
-
-Regards,
-	Bruce <bkorb@gnu.org>
-
-
-
 GCC MAINTAINER INFORMATION
 ==========================
 
 If you are having some problem with a system header that is either
 broken by the manufacturer, or is broken by the fixinclude process,
 then you will need to alter or add information to the include fix
 definitions file, ``inclhack.def''.  Please also send relevant
 information to gcc-bugs@gcc.gnu.org, gcc-patches@gcc.gnu.org and,
 please, to me:  bkorb@gnu.org.
@@ -76,27 +56,33 @@
     identify the files with "files = " entries.  If you use fnmatch(3C)
     wild card characters in a "files" entry, be certain that the first
     "files" entry has no such character.  Otherwise, the "make check"
     machinery will attempt to create files with those characters in the
     name.  That is inconvenient.
 
 3.  It is relatively expensive to fire off a process to fix a source
     file, therefore write apply tests to avoid unnecessary fix
     processes.  The preferred apply tests are "select", "bypass", "mach"
-    and "c-test" because they are performed internally:
+    "sum", and "c-test" because they are performed internally:
 
     * select - Run a regex on the contents of the file being considered.
                All such regex-es must match.  Matching is done with
                extended regular expressions.
 
     * bypass - Run a regex on the contents of the file being considered.
                No such regex may match.
 
+    * sum    - Select a specific version of a file that has a matching
+               check sum.  The BSD version of checksum ["sum(1BSD)"]
+               is used.  Each "sum" entry should contain exactly three
+               space separated tokens:  the sum, some number and the
+               basename of the file.  The "some number" is ignored.
+
     * c_test - call a function in fixtests.c.  See that file.
 
     * files  - the "fnmatch" pattern of the file(s) to examine for
                the issue.  There may be several copies of this attribute.
                If the header lives in a /usr/include subdirectory, be
                sure to include that subdirectory in the name. e.g. net/if.h
 
     * mach   - Match the output of config.guess against a series of fnmatch
                patterns.  It must match at least one of the patterns, unless
Index: fixincludes/fixincl.c
===================================================================
--- fixincludes/fixincl.c	(revision 218991)
+++ fixincludes/fixincl.c	(working copy)
@@ -591,18 +591,71 @@
   if (p_test->p_test_regex == 0)
     fprintf (stderr, "fixincl ERROR RE not compiled:  `%s'\n",
              p_test->pz_test_text);
 #endif
   if (xregexec (p_test->p_test_regex, pz_data, 0, 0, 0) == 0)
     return APPLY_FIX;
   return SKIP_FIX;
 }
 
+/* * * * * * * * * * * * *
+
+  cksum_test   check the sum of the candidate file
+  Input:  the original file contents and the file name
+  Result: APPLY_FIX if the check sum matches, SKIP_FIX otherwise
+
+  The caller may choose to reverse meaning if the sense of the test
+  is inverted.  */
+
+static int
+cksum_test (char * pz_data, tTestDesc * p_test, char * fname)
+{
+  unsigned int cksum;
+
+  if (fixinc_mode != TESTING_OFF)
+    return APPLY_FIX;
+
+  {
+    char * fnm = strrchr(fname, '/');
+    if (fnm != NULL)
+      fname = fnm + 1;
+    
+    errno = 0;
+    cksum = (unsigned int)strtoul(p_test->pz_test_text, &fnm, 10);
+    if (errno != 0)
+      return SKIP_FIX;
+
+    if (! ISSPACE(*fnm++))
+      return SKIP_FIX;
+    while (ISSPACE(*fnm)) fnm++;
+
+    if (! ISDIGIT(*fnm++))
+      return SKIP_FIX;
+    while (ISDIGIT(*fnm)) fnm++;
+
+    if (! ISSPACE(*fnm++))
+      return SKIP_FIX;
+    while (ISSPACE(*fnm)) fnm++;
+
+    if (strcmp(fnm, fname) != 0)
+      return SKIP_FIX;
+  }
+
+  {
+    unsigned int sum = 0;
+    while (*pz_data != NUL) {
+      sum = (sum >> 1) + ((sum & 1) << 15) + (unsigned)(*pz_data++);
+      sum &= 0xFFFF;
+    }
+
+    return (sum == cksum) ? APPLY_FIX : SKIP_FIX;
+  }
+}
 
 /* * * * * * * * * * * * *
 
   quoted_file_exists  Make sure that a file exists before we emit
   the file name.  If we emit the name, our invoking shell will try
   to copy a non-existing file into the destination directory.  */
 
 static int
 quoted_file_exists (const char* pz_src_path,
@@ -1001,19 +1054,27 @@
   if (pz_cmd != (char*)NULL)
     {
       free ((void*)pz_cmd);
       p_fixd->patch_args[2] = pz_cmd_save;
     }
 
   return read_fd;
 }
 #endif
-
+#ifdef DEBUG
+# define NOTE_SKIP(_ttyp)  do {                                         \
+            if (VLEVEL( VERB_EVERYTHING ))                              \
+              fprintf (stderr, z_failed, _ttyp, p_fixd->fix_name,       \
+                       pz_fname, p_fixd->test_ct - test_ct);            \
+          } while (0)
+#else
+# define NOTE_SKIP(_ttyp)
+#endif
 
 /* * * * * * * * * * * * *
  *
  *  Process the potential fixes for a particular include file.
  *  Input:  the original text of the file and the file's name
  *  Result: none.  A new file may or may not be created.
  */
 static t_bool
 fix_applies (tFixDesc* p_fixd)
@@ -1059,45 +1120,41 @@
 
   for (p_test = p_fixd->p_test_desc, test_ct = p_fixd->test_ct;
        test_ct-- > 0;
        p_test++)
     {
       switch (p_test->type)
         {
         case TT_TEST:
           if (test_test (p_test, pz_curr_file) != APPLY_FIX) {
-#ifdef DEBUG
-            if (VLEVEL( VERB_EVERYTHING ))
-              fprintf (stderr, z_failed, "TEST", p_fixd->fix_name,
-                       pz_fname, p_fixd->test_ct - test_ct);
-#endif
+	    NOTE_SKIP("TEST");
             return BOOL_FALSE;
           }
           break;
 
         case TT_EGREP:
           if (egrep_test (pz_curr_data, p_test) != APPLY_FIX) {
-#ifdef DEBUG
-            if (VLEVEL( VERB_EVERYTHING ))
-              fprintf (stderr, z_failed, "EGREP", p_fixd->fix_name,
-                       pz_fname, p_fixd->test_ct - test_ct);
-#endif
+	    NOTE_SKIP("EGREP");
             return BOOL_FALSE;
           }
           break;
 
         case TT_NEGREP:
           if (egrep_test (pz_curr_data, p_test) == APPLY_FIX) {
-#ifdef DEBUG
-            if (VLEVEL( VERB_EVERYTHING ))
-              fprintf (stderr, z_failed, "NEGREP", p_fixd->fix_name,
-                       pz_fname, p_fixd->test_ct - test_ct);
-#endif
+	    NOTE_SKIP("NEGREP");
+            /*  Negated sense  */
+            return BOOL_FALSE;
+          }
+          break;
+
+        case TT_CKSUM:
+	  if (cksum_test (pz_curr_data, p_test, pz_curr_file) != APPLY_FIX) {
+	    NOTE_SKIP("CKSUM");
             /*  Negated sense  */
             return BOOL_FALSE;
           }
           break;
 
         case TT_FUNCTION:
           if (run_test (p_test->pz_test_text, pz_curr_file, pz_curr_data)
               != APPLY_FIX) {
 #ifdef DEBUG
Index: fixincludes/fixincl.tpl
===================================================================
--- fixincludes/fixincl.tpl	(revision 218991)
+++ fixincludes/fixincl.tpl	(working copy)
@@ -1,12 +1,15 @@
 [= AutoGen5 Template -*- Mode: C -*-
 x=fixincl.x =]
-[= (dne " * " "/* ")=]
+[=
+ (if (version-compare >= autogen-version "5.18")
+     (dne "-D" " * " "/* ")
+     (dne " * " "/* ") ) =]
  */
 /* DO NOT SVN-MERGE THIS FILE, EITHER [=
    (define re-ct 0) (define max-mach 0) (define ct 0)
    (define HACK "") (define Hack "")    (define tmp "") 
    (shell "date") =]
  *
  * You must regenerate it.  Use the ./genfixes script.
  *
  *
@@ -57,118 +60,136 @@
   See commentary at the top of fixfixes.c.
 =]
 tSCC z[=(. Hack)=]Name[] =
      "[=hackname=]";
 
 /*
  *  File name selection pattern
  */[=
 
-  IF (exist? "files")=]
+  IF (exist? "files")   =]
 tSCC z[=(. Hack)=]List[] =
   "[=  (join "\\0" (stack "files")) =]\0";[=
 
-  ELSE =]
+  ELSE                  =]
 #define z[=(. Hack)=]List (char*)NULL[=
   ENDIF (exist? "files") =]
 /*
  *  Machine/OS name selection pattern
  */[=
 
-  IF (exist? "mach")=]
+  IF (exist? "mach")    =]
 tSCC* apz[=(. Hack)=]Machs[] = {[=
     (set! ct 0) =][=
 
-    FOR mach =]
+    FOR mach            =]
         [=
       (set! tmp (get "mach"))
       (set! ct (+ ct (string-length tmp) 5))
       (kr-string tmp)=],[=
-    ENDFOR=]
+    ENDFOR              =]
         (const char*)NULL };[=
 
     (if (> ct max-mach) (set! max-mach ct)) =][=
 
-  ELSE =]
+  ELSE                  =]
 #define apz[=(. Hack)=]Machs (const char**)NULL[=
   ENDIF (exist? "mach") =][=
 
   IF (exist? "select")=]
 
 /*
  *  content selection pattern - do fix if pattern found
  */[=
-    FOR select =]
+    FOR select          =]
 tSCC z[=(. Hack)=]Select[=(for-index)=][] =
        [=(kr-string (get "select"))=];[=
-    ENDFOR select =][=
-  ENDIF =][=
+    ENDFOR select       =][=
+  ENDIF                 =][=
 
-  IF (exist? "bypass")=]
+  IF (exist? "bypass")  =]
 
 /*
  *  content bypass pattern - skip fix if pattern found
  */[=
-    FOR bypass =]
+    FOR bypass          =]
 tSCC z[=(. Hack)=]Bypass[=(for-index)=][] =
        [=(kr-string (get "bypass"))=];[=
-    ENDFOR bypass =][=
-  ENDIF =][=
+    ENDFOR bypass       =][=
+  ENDIF                 =][=
+
+  IF (exist? "sum")=][=
+     (if (not (exist? "files"))
+         (error "specifying a 'sum' requires specifying 'files'"))
+     =]
 
-  IF (exist? "test")=]
+/*
+ *  file selection - do fix if checksum matches
+ */[=
+    FOR sum             =]
+tSCC z[=(. Hack)=]Sum[=(for-index)=][] =
+       [=(kr-string (get "sum"))=];[=
+    ENDFOR sum          =][=
+  ENDIF                 =][=
+
+  IF (exist? "test")    =]
 
 /*
  *  perform the 'test' shell command - do fix on success
  */[=
-    FOR test =]
+    FOR test            =]
 tSCC z[=(. Hack)=]Test[=(for-index)=][] =
        [=(kr-string (get "test"))=];[=
-    ENDFOR  =][=
-  ENDIF     =][=
+    ENDFOR              =][=
+  ENDIF                 =][=
 
-  IF (exist? "c_test")=]
+  IF (exist? "c_test")  =]
 
 /*
  *  perform the C function call test
  */[=
-    FOR c_test =]
+    FOR c_test          =]
 tSCC z[=(. Hack)=]FTst[=(for-index)=][] = "[=c_test=]";[=
-    ENDFOR c_test =][=
-  ENDIF =][=
+    ENDFOR c_test       =][=
+  ENDIF                 =][=
 
   IF (set! ct (+ (count "select") (count "bypass") 
               (count "test") (count "c_test")))
 
      (= ct 0)
 =]
 #define [=(. HACK)=]_TEST_CT  0
 #define a[=(. Hack)=]Tests   (tTestDesc*)NULL[=
   ELSE =]
 
 #define    [=(. HACK)=]_TEST_CT  [=(. ct)=][=
-	(set! re-ct (+ re-ct (count "select") (count "bypass"))) =]
+        (set! re-ct (+ re-ct (count "select") (count "bypass"))) =]
 static tTestDesc a[=(. Hack)=]Tests[] = {[=
 
-    FOR test =]
+    FOR test            =]
   { TT_TEST,     z[=(. Hack)=]Test[=(for-index)=],   0 /* unused */ },[=
-    ENDFOR test =][=
+    ENDFOR test         =][=
 
-    FOR c_test =]
+    FOR c_test          =]
   { TT_FUNCTION, z[=(. Hack)=]FTst[=(for-index)=],   0 /* unused */ },[=
-    ENDFOR c_test =][=
+    ENDFOR c_test       =][=
 
-    FOR bypass =]
+    FOR bypass          =]
   { TT_NEGREP,   z[=(. Hack)=]Bypass[=(for-index)=], (regex_t*)NULL },[=
-    ENDFOR bypass =][=
+    ENDFOR bypass       =][=
 
-    FOR select =]
+    FOR select          =]
   { TT_EGREP,    z[=(. Hack)=]Select[=(for-index)=], (regex_t*)NULL },[=
-    ENDFOR select =] };[=
+    ENDFOR select       =][=
+
+    FOR sum             =]
+  { TT_CKSUM,    z[=(. Hack)=]Sum[=(for-index)=], (regex_t*)NULL },[=
+    ENDFOR sum          =] };[=
   ENDIF =]
 
 /*
  *  Fix Command Arguments for [=(. Hack)=]
  */
 static const char* apz[=(. Hack)=]Patch[] = {[=
     IF   (exist? "sed")=] sed_cmd_z[=
       FOR sed=],
     "-e", [=(kr-string (get "sed"))=][=
Index: fixincludes/fixincl.x
===================================================================
--- fixincludes/fixincl.x	(revision 218991)
+++ fixincludes/fixincl.x	(working copy)
@@ -1,18 +1,18 @@
 /*  -*- buffer-read-only: t -*- vi: set ro:
- * 
+ *
  * DO NOT EDIT THIS FILE   (fixincl.x)
- * 
- * It has been AutoGen-ed  October 21, 2014 at 10:18:16 AM by AutoGen 5.16.2
+ *
+ * It has been AutoGen-ed  December 20, 2014 at 03:22:33 PM by AutoGen 5.18.5pre6
  * From the definitions    inclhack.def
  * and the template file   fixincl
  */
-/* DO NOT SVN-MERGE THIS FILE, EITHER Tue Oct 21 10:18:17 CEST 2014
+/* DO NOT SVN-MERGE THIS FILE, EITHER Sat Dec 20 15:22:33 PST 2014
  *
  * You must regenerate it.  Use the ./genfixes script.
  *
  *
  * This is part of the fixincl program used to install modified versions of
  * 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 223 fixup descriptions.
Index: fixincludes/fixlib.h
===================================================================
--- fixincludes/fixlib.h	(revision 218991)
+++ fixincludes/fixlib.h	(working copy)
@@ -155,19 +155,19 @@
     whether the fix needs to be applied or not.
     Each test has a type (from the te_test_type enumeration);
     associated test text; and, if the test is TT_EGREP or
     the negated form TT_NEGREP, a pointer to the compiled
     version of the text string.
 
     */
 typedef enum
 {
-  TT_TEST, TT_EGREP, TT_NEGREP, TT_FUNCTION
+  TT_TEST, TT_EGREP, TT_NEGREP, TT_FUNCTION, TT_CKSUM
 } te_test_type;
 
 typedef struct test_desc tTestDesc;
 
 struct test_desc
 {
   te_test_type type;
   const char *pz_test_text;
   regex_t *p_test_regex;

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