[Pcre-svn] [941] code/trunk: Patches for portability.

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [941] code/trunk: Patches for portability.
Revision: 941
          http://www.exim.org/viewvc/pcre2?view=rev&revision=941
Author:   ph10
Date:     2018-06-20 18:05:31 +0100 (Wed, 20 Jun 2018)
Log Message:
-----------
Patches for portability.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/RunGrepTest
    code/trunk/src/pcre2_compile.c
    code/trunk/src/pcre2_match.c
    code/trunk/src/pcre2test.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2018-06-19 17:41:01 UTC (rev 940)
+++ code/trunk/ChangeLog    2018-06-20 17:05:31 UTC (rev 941)
@@ -74,7 +74,19 @@
 include whichever exists (stdint preferred) instead of unconditionally 
 including stdint. This makes life easier for old and non-standard systems.


+18. Further changes to improve portability, especially to old and or non-
+standard systems:

+  (a) Put all printf arguments in RunGrepTest into single, not double, quotes,
+      and use \0 not \x00 for binary zero. 
+  
+  (b) Avoid the use of C++ (i.e. BCPL) // comments.
+  
+  (c) Parameterize the use of %zu in pcre2test to make it like %td. For both of
+      these now, if using MSVC or a standard C before C99, %lu is used with a 
+      cast if necessary.  
+
+
 Version 10.31 12-February-2018
 ------------------------------



Modified: code/trunk/RunGrepTest
===================================================================
--- code/trunk/RunGrepTest    2018-06-19 17:41:01 UTC (rev 940)
+++ code/trunk/RunGrepTest    2018-06-20 17:05:31 UTC (rev 941)
@@ -4,6 +4,12 @@
 # itself. What we are checking here is the file handling and options that are
 # supported by pcre2grep. This script must be run in the build directory.


+# CODING CONVENTIONS: 
+# * Put printf arguments in single, not double quotes to avoid unwanted
+#     escaping.
+# * Use \0 for binary zero in printf, not \x0, for the benefit of older 
+#     versions.
+
 # Set the C locale, so that sort(1) behaves predictably.


LC_ALL=C
@@ -600,7 +606,7 @@
echo "RC=$?" >>testtrygrep

echo "---------------------------- Test 119 -----------------------------" >>testtrygrep
-printf "123\n456\n789\n---abc\ndef\nxyz\n---\n" >testNinputgrep
+printf '123\n456\n789\n---abc\ndef\nxyz\n---\n' >testNinputgrep
$valgrind $vjs $pcre2grep -Mo '(\n|[^-])*---' testNinputgrep >>testtrygrep
echo "RC=$?" >>testtrygrep

@@ -631,7 +637,7 @@
echo "RC=$?" >>testtrygrep

echo "---------------------------- Test 125 -----------------------------" >>testtrygrep
-printf "abcd\n" >testNinputgrep
+printf 'abcd\n' >testNinputgrep
$valgrind $vjs $pcre2grep --colour=always '(?<=\K.)' testNinputgrep >>testtrygrep
echo "RC=$?" >>testtrygrep
$valgrind $vjs $pcre2grep --colour=always '(?=.\K)' testNinputgrep >>testtrygrep
@@ -642,8 +648,8 @@
echo "RC=$?" >>testtrygrep

echo "---------------------------- Test 126 -----------------------------" >>testtrygrep
-printf "Next line pattern has binary zero\nABC\x00XYZ\n" >testtemp1grep
-printf "ABC\x00XYZ\nABCDEF\nDEFABC\n" >testtemp2grep
+printf 'Next line pattern has binary zero\nABC\0XYZ\n' >testtemp1grep
+printf 'ABC\0XYZ\nABCDEF\nDEFABC\n' >testtemp2grep
$valgrind $vjs $pcre2grep -a -f testtemp1grep testtemp2grep >>testtrygrep
echo "RC=$?" >>testtrygrep

@@ -687,25 +693,25 @@
# starts with a hyphen. These tests are run in the build directory.

echo "Testing pcre2grep newline settings"
-printf "abc\rdef\r\nghi\njkl" >testNinputgrep
+printf 'abc\rdef\r\nghi\njkl' >testNinputgrep

-printf "%c--------------------------- Test N1 ------------------------------\r\n" - >testtrygrep
+printf '%c--------------------------- Test N1 ------------------------------\r\n' - >testtrygrep
$valgrind $vjs $pcre2grep -n -N CR "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep

-printf "%c--------------------------- Test N2 ------------------------------\r\n" - >>testtrygrep
+printf '%c--------------------------- Test N2 ------------------------------\r\n' - >>testtrygrep
$valgrind $vjs $pcre2grep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep

-printf "%c--------------------------- Test N3 ------------------------------\r\n" - >>testtrygrep
+printf '%c--------------------------- Test N3 ------------------------------\r\n' - >>testtrygrep
pattern=`printf 'def\rjkl'`
$valgrind $vjs $pcre2grep -n --newline=cr -F "$pattern" testNinputgrep >>testtrygrep

-printf "%c--------------------------- Test N4 ------------------------------\r\n" - >>testtrygrep
+printf '%c--------------------------- Test N4 ------------------------------\r\n' - >>testtrygrep
$valgrind $vjs $pcre2grep -n --newline=crlf -F -f $srcdir/testdata/greppatN4 testNinputgrep >>testtrygrep

-printf "%c--------------------------- Test N5 ------------------------------\r\n" - >>testtrygrep
+printf '%c--------------------------- Test N5 ------------------------------\r\n' - >>testtrygrep
$valgrind $vjs $pcre2grep -n --newline=any "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep

-printf "%c--------------------------- Test N6 ------------------------------\r\n" - >>testtrygrep
+printf '%c--------------------------- Test N6 ------------------------------\r\n' - >>testtrygrep
$valgrind $vjs $pcre2grep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep

# It seems impossible to handle NUL characters easily in Solaris (aka SunOS).
@@ -713,10 +719,10 @@
# don't run this test under SunOS. Fudge the output so that the comparison
# works. A similar problem has also been reported for MacOS (Darwin).

-printf "%c--------------------------- Test N7 ------------------------------\r\n" - >>testtrygrep
+printf '%c--------------------------- Test N7 ------------------------------\r\n' - >>testtrygrep
uname=`uname`
if [ "$uname" != "SunOS" -a "$uname" != "Darwin" ] ; then
- printf "abc\0def" >testNinputgrep
+ printf 'abc\0def' >testNinputgrep
$valgrind $vjs $pcre2grep -na --newline=nul "^(abc|def)" testNinputgrep | sed 's/\x00/ZERO/' >>testtrygrep
echo "" >>testtrygrep
else

Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c    2018-06-19 17:41:01 UTC (rev 940)
+++ code/trunk/src/pcre2_compile.c    2018-06-20 17:05:31 UTC (rev 941)
@@ -63,8 +63,8 @@


/* Other debugging code can be enabled by these defines. */

-// #define DEBUG_SHOW_CAPTURES
-// #define DEBUG_SHOW_PARSED
+/* #define DEBUG_SHOW_CAPTURES */
+/* #define DEBUG_SHOW_PARSED */

/* There are a few things that vary with different code unit sizes. Handle them
by defining macros in order to minimize #if usage. */

Modified: code/trunk/src/pcre2_match.c
===================================================================
--- code/trunk/src/pcre2_match.c    2018-06-19 17:41:01 UTC (rev 940)
+++ code/trunk/src/pcre2_match.c    2018-06-20 17:05:31 UTC (rev 941)
@@ -45,9 +45,9 @@


/* These defines enable debugging code */

-//#define DEBUG_FRAMES_DISPLAY
-//#define DEBUG_SHOW_OPS
-//#define DEBUG_SHOW_RMATCH
+/* #define DEBUG_FRAMES_DISPLAY */
+/* #define DEBUG_SHOW_OPS */
+/* #define DEBUG_SHOW_RMATCH */

#ifdef DEBUG_FRAME_DISPLAY
#include <stdarg.h>

Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2018-06-19 17:41:01 UTC (rev 940)
+++ code/trunk/src/pcre2test.c    2018-06-20 17:05:31 UTC (rev 941)
@@ -80,7 +80,7 @@


/* Debugging code enabler */

-// #define DEBUG_SHOW_MALLOC_ADDRESSES
+/* #define DEBUG_SHOW_MALLOC_ADDRESSES */

/* Both libreadline and libedit are optionally supported. The user-supplied
original patch uses readline/readline.h for libedit, but in at least one system
@@ -162,11 +162,16 @@
void vms_setsymbol( char *, char *, int );
#endif

-/* VC doesn't support "%td". */
-#ifdef _MSC_VER
-#define PTR_SPEC "%lu"
+/* VC and older compilers don't support %td or %zu. */
+
+#if defined(_MSC_VER) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
+#define PTR_FORM "lu"
+#define SIZ_FORM "lu"
+#define SIZ_CAST (unsigned long int)
#else
-#define PTR_SPEC "%td"
+#define PTR_FORM "td"
+#define SIZ_FORM "zu"
+#define SIZ_CAST
#endif

 /* ------------------End of system-specific definitions -------------------- */
@@ -2626,11 +2631,11 @@
   {
   if (block == NULL)
     {
-    fprintf(outfile, "** malloc() failed for %zd\n", size);
+    fprintf(outfile, "** malloc() failed for %" SIZ_FORM "\n", SIZ_CAST size);
     }
   else
     {
-    fprintf(outfile, "malloc  %5zd", size);
+    fprintf(outfile, "malloc  %5" SIZ_FORM, SIZ_CAST size);
 #ifdef DEBUG_SHOW_MALLOC_ADDRESSES
     fprintf(outfile, " %p", block);   /* Not portable */
 #endif
@@ -2660,7 +2665,7 @@
     {
     if (block == malloclist[i])
       {
-      fprintf(outfile, "    %5zd", malloclistlength[i]);
+      fprintf(outfile, "    %5" SIZ_FORM, SIZ_CAST malloclistlength[i]);
       malloclistptr--;
       for (j = i; j < malloclistptr; j++)
         {
@@ -3038,8 +3043,8 @@
   pbuffer16 = (uint16_t *)malloc(pbuffer16_size);
   if (pbuffer16 == NULL)
     {
-    fprintf(stderr, "pcre2test: malloc(%lu) failed for pbuffer16\n",
-      (unsigned long int)pbuffer16_size);
+    fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n",
+      SIZ_CAST pbuffer16_size);
     exit(1);
     }
   }
@@ -3125,8 +3130,8 @@
   pbuffer32 = (uint32_t *)malloc(pbuffer32_size);
   if (pbuffer32 == NULL)
     {
-    fprintf(stderr, "pcre2test: malloc(%lu) failed for pbuffer32\n",
-      (unsigned long int)pbuffer32_size);
+    fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n",
+      SIZ_CAST pbuffer32_size);
     exit(1);
     }
   }
@@ -4844,8 +4849,8 @@
   serial = malloc(serial_size);
   if (serial == NULL)
     {
-    fprintf(outfile, "** Failed to get memory (size %lu) for #load\n",
-      (unsigned long int)serial_size);
+    fprintf(outfile, "** Failed to get memory (size %" SIZ_FORM ") for #load\n",
+      SIZ_CAST serial_size);
     fclose(f);
     return PR_ABEND;
     }
@@ -5039,7 +5044,7 @@
         if (d == 0)
           {
           fprintf(outfile, "** Missing closing quote in hex pattern: "
-            "opening quote is at offset " PTR_SPEC ".\n", pq - buffer - 2);
+            "opening quote is at offset %" PTR_FORM ".\n", pq - buffer - 2);
           return PR_SKIP;
           }
         if (d == c) break;
@@ -5053,8 +5058,8 @@
       {
       if (!isxdigit(c))
         {
-        fprintf(outfile, "** Unexpected non-hex-digit '%c' at offset "
-          PTR_SPEC " in hex pattern: quote missing?\n", c, pp - buffer - 2);
+        fprintf(outfile, "** Unexpected non-hex-digit '%c' at offset %"
+          PTR_FORM " in hex pattern: quote missing?\n", c, pp - buffer - 2);
         return PR_SKIP;
         }
       if (*pp == 0)
@@ -5065,8 +5070,8 @@
       d = *pp;
       if (!isxdigit(d))
         {
-        fprintf(outfile, "** Unexpected non-hex-digit '%c' at offset "
-          PTR_SPEC " in hex pattern: quote missing?\n", d, pp - buffer - 1);
+        fprintf(outfile, "** Unexpected non-hex-digit '%c' at offset %"
+          PTR_FORM " in hex pattern: quote missing?\n", d, pp - buffer - 1);
         return PR_SKIP;
         }
       c = toupper(c);
@@ -5470,8 +5475,8 @@


   if (rc != 0)
     {
-    fprintf(outfile, "** Pattern conversion error at offset %zu: ",
-      converted_length);
+    fprintf(outfile, "** Pattern conversion error at offset %" SIZ_FORM ": ",
+      SIZ_CAST converted_length);
     convert_return = print_error_message(rc, "", "\n")? PR_SKIP:PR_ABEND;
     }


@@ -5903,8 +5908,8 @@
 if (cb->callout_string != NULL)
   {
   uint32_t delimiter = CODE_UNIT(cb->callout_string, -1);
-  fprintf(outfile, "Callout (%lu): %c",
-    (unsigned long int)cb->callout_string_offset, delimiter);
+  fprintf(outfile, "Callout (%" SIZ_FORM "): %c",
+    SIZ_CAST cb->callout_string_offset, delimiter);
   PCHARSV(cb->callout_string, 0,
     cb->callout_string_length, utf, outfile);
   for (i = 0; callout_start_delims[i] != 0; i++)
@@ -6103,12 +6108,12 @@
       }
     else if (length2 != length)
       {
-      fprintf(outfile, "Mismatched substring lengths: %lu %lu\n",
-        (unsigned long int)length, (unsigned long int)length2);
+      fprintf(outfile, "Mismatched substring lengths: %"
+        SIZ_FORM " %" SIZ_FORM "\n", SIZ_CAST length, SIZ_CAST length2);
       }
     fprintf(outfile, "%2dC ", n);
     PCHARSV(copybuffer, 0, length, utf, outfile);
-    fprintf(outfile, " (%lu)\n", (unsigned long)length);
+    fprintf(outfile, " (%" SIZ_FORM ")\n", SIZ_CAST length);
     }
   }


@@ -6158,12 +6163,12 @@
       }
     else if (length2 != length)
       {
-      fprintf(outfile, "Mismatched substring lengths: %lu %lu\n",
-        (unsigned long int)length, (unsigned long int)length2);
+      fprintf(outfile, "Mismatched substring lengths: %"
+        SIZ_FORM " %" SIZ_FORM "\n", SIZ_CAST length, SIZ_CAST length2);
       }
     fprintf(outfile, "  C ");
     PCHARSV(copybuffer, 0, length, utf, outfile);
-    fprintf(outfile, " (%lu) %s", (unsigned long)length, nptr);
+    fprintf(outfile, " (%" SIZ_FORM ") %s", SIZ_CAST length, nptr);
     if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber);
       else fprintf(outfile, " (non-unique)\n");
     }
@@ -6188,7 +6193,7 @@
     {
     fprintf(outfile, "%2dG ", n);
     PCHARSV(gotbuffer, 0, length, utf, outfile);
-    fprintf(outfile, " (%lu)\n", (unsigned long)length);
+    fprintf(outfile, " (%" SIZ_FORM ")\n", SIZ_CAST length);
     PCRE2_SUBSTRING_FREE(gotbuffer);
     }
   }
@@ -6232,7 +6237,7 @@
     {
     fprintf(outfile, "  G ");
     PCHARSV(gotbuffer, 0, length, utf, outfile);
-    fprintf(outfile, " (%lu) %s", (unsigned long)length, nptr);
+    fprintf(outfile, " (%" SIZ_FORM ") %s", SIZ_CAST length, nptr);
     if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber);
       else fprintf(outfile, " (non-unique)\n");
     PCRE2_SUBSTRING_FREE(gotbuffer);
@@ -6973,8 +6978,8 @@
       }
     if (n > nsize)
       {
-      fprintf(outfile, "Replacement buffer setting (%lu) is too large "
-        "(max %lu)\n", (unsigned long int)n, (unsigned long int)nsize);
+      fprintf(outfile, "Replacement buffer setting (%" SIZ_FORM ") is too "
+        "large (max %" SIZ_FORM ")\n", SIZ_CAST n, SIZ_CAST nsize);
       return PR_OK;
       }
     nsize = n;
@@ -7177,7 +7182,7 @@
       capcount = check_match_limit(pp, arg_ulen, PCRE2_ERROR_DEPTHLIMIT,
         "depth");
       }
-       
+
     if (capcount == 0)
       {
       fprintf(outfile, "Matched, but offsets vector is too small to show all matches\n");
@@ -7556,7 +7561,7 @@
         {
         PCRE2_SIZE startchar;
         PCRE2_GET_STARTCHAR(startchar, match_data);
-        fprintf(outfile, " at offset %lu", (unsigned long int)startchar);
+        fprintf(outfile, " at offset %" SIZ_FORM, SIZ_CAST startchar);
         }
       fprintf(outfile, "\n");
       break;
@@ -8217,15 +8222,15 @@
     if (rlim.rlim_cur > rlim.rlim_max)
       {
       fprintf(stderr,
-        "pcre2test: requested stack size %luM is greater than hard limit %lu\n",
-        (unsigned long int)stack_size,
-        (unsigned long int)(rlim.rlim_max));
+        "pcre2test: requested stack size %luMiB is greater than hard limit "
+          "%luMiB\n", (unsigned long int)stack_size,
+          (unsigned long int)(rlim.rlim_max));
       exit(1);
       }
     rc = setrlimit(RLIMIT_STACK, &rlim);
     if (rc != 0)
       {
-      fprintf(stderr, "pcre2test: setting stack size %luM failed: %s\n",
+      fprintf(stderr, "pcre2test: setting stack size %luMiB failed: %s\n",
         (unsigned long int)stack_size, strerror(errno));
       exit(1);
       }
@@ -8357,8 +8362,8 @@
     pbuffer16 = (uint16_t *)malloc(pbuffer16_size);
     if (pbuffer16 == NULL)
       {
-      fprintf(stderr, "pcre2test: malloc(%lu) failed for pbuffer16\n",
-        (unsigned long int)pbuffer16_size);
+      fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n",
+        SIZ_CAST pbuffer16_size);
       yield = 1;
       goto EXIT;
       }
@@ -8372,8 +8377,8 @@
     pbuffer32 = (uint32_t *)malloc(pbuffer32_size);
     if (pbuffer32 == NULL)
       {
-      fprintf(stderr, "pcre2test: malloc(%lu) failed for pbuffer32\n",
-        (unsigned long int)pbuffer32_size);
+      fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n",
+        SIZ_CAST pbuffer32_size);
       yield = 1;
       goto EXIT;
       }