[Pcre-svn] [114] code/trunk: Remove length argument from pc…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [114] code/trunk: Remove length argument from pcre2_config; give width if where==NULL.
Revision: 114
          http://www.exim.org/viewvc/pcre2?view=rev&revision=114
Author:   ph10
Date:     2014-10-15 17:44:12 +0100 (Wed, 15 Oct 2014)


Log Message:
-----------
Remove length argument from pcre2_config; give width if where==NULL.

Modified Paths:
--------------
    code/trunk/doc/pcre2api.3
    code/trunk/src/pcre2.h.in
    code/trunk/src/pcre2_config.c
    code/trunk/src/pcre2_internal.h
    code/trunk/src/pcre2_jit_test.c
    code/trunk/src/pcre2_string_utils.c
    code/trunk/src/pcre2grep.c
    code/trunk/src/pcre2test.c


Modified: code/trunk/doc/pcre2api.3
===================================================================
--- code/trunk/doc/pcre2api.3    2014-10-15 15:57:49 UTC (rev 113)
+++ code/trunk/doc/pcre2api.3    2014-10-15 16:44:12 UTC (rev 114)
@@ -203,7 +203,7 @@
 .sp
 .B int pcre2_pattern_info(const pcre2 *\fIcode\fP, uint32_t \fIwhat\fP, void *\fIwhere\fP);
 .sp
-.B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP, PCRE2_SIZE \fIlength\fP);
+.B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP);
 .fi
 .
 .
@@ -746,7 +746,7 @@
 .SH "CHECKING BUILD-TIME OPTIONS"
 .rs
 .sp
-.B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP, PCRE2_SIZE \fIlength\fP);
+.B int pcre2_config(uint32_t \fIwhat\fP, void *\fIwhere\fP);
 .P
 The function \fBpcre2_config()\fP makes it possible for a PCRE2 client to
 discover which optional features have been compiled into the PCRE2 library. The
@@ -757,12 +757,11 @@
 .P
 The first argument for \fBpcre2_config()\fP specifies which information is
 required. The second argument is a pointer to memory into which the information
-is placed, with the final argument giving the length of this memory in bytes.
-For calls that return numerical values, \fIwhere\fP should point to
-appropriately aligned memory, with \fIlength\fP set to at least the "sizeof"
-the data type.
+is placed. If NULL is passed, the function returns the number of bytes that are
+needed for the requested information. For calls that return numerical values,
+\fIwhere\fP should point to appropriately aligned memory.
 .P
-The returned value from \fBpcre2_config()\fP is zero on success, or the
+The returned value from \fBpcre2_config()\fP is non-negative on success, or the
 negative error code PCRE2_ERROR_BADOPTION if the value in the first argument is
 not recognized. The following information is available:
 .sp
@@ -780,10 +779,12 @@
 .sp
   PCRE2_CONFIG_JITTARGET
 .sp
-FIXME: this needs sorting out once JIT is implemented.
-If JIT support is available, the string contains the name of the architecture
-for which the JIT compiler is configured, for example "x86 32bit (little endian
-+ unaligned)". If JIT support is not available, FIXME.
+The \fIwhere\fP argument should point to a buffer that is at least 64 code
+units long. It is filled with a string that contains the name of the
+architecture for which the JIT compiler is configured, for example "x86 32bit
+(little endian + unaligned)". If JIT support is not available,
+PCRE2_ERROR_BADOPTION is returned, otherwise the length of the string, in code 
+units, is returned.
 .sp
   PCRE2_CONFIG_LINKSIZE
 .sp
@@ -848,7 +849,8 @@
 The \fIwhere\fP argument should point to a buffer that is at least 24 code
 units long. If PCRE2 has been compiled without Unicode support, this is filled
 with the text "Unicode not supported". Otherwise, the Unicode version string
-(for example, "7.0.0") is returnd. The string is zero-terminated.
+(for example, "7.0.0") is inserted. The string is zero-terminated. The function 
+returns the length of the string in code units.
 .sp
   PCRE2_CONFIG_UNICODE
 .sp
@@ -858,7 +860,8 @@
   PCRE2_CONFIG_VERSION
 .sp
 The \fIwhere\fP argument should point to a buffer that is at least 12 code 
-units long. It is filled with the PCRE2 version string, zero-terminated.   
+units long. It is filled with the PCRE2 version string, zero-terminated. The 
+length of the string (in code units) is returned.  
 .
 .
 .SH "COMPILING A PATTERN"


Modified: code/trunk/src/pcre2.h.in
===================================================================
--- code/trunk/src/pcre2.h.in    2014-10-15 15:57:49 UTC (rev 113)
+++ code/trunk/src/pcre2.h.in    2014-10-15 16:44:12 UTC (rev 114)
@@ -336,7 +336,7 @@
 information. */


 #define PCRE2_GENERAL_INFO_FUNCTIONS \
-PCRE2_EXP_DECL int       pcre2_config(uint32_t, void *, PCRE2_SIZE);
+PCRE2_EXP_DECL int       pcre2_config(uint32_t, void *);



/* Functions for manipulating contexts. */

Modified: code/trunk/src/pcre2_config.c
===================================================================
--- code/trunk/src/pcre2_config.c    2014-10-15 15:57:49 UTC (rev 113)
+++ code/trunk/src/pcre2_config.c    2014-10-15 16:44:12 UTC (rev 114)
@@ -61,23 +61,48 @@
 * Return info about what features are configured *
 *************************************************/


-/* Most of the requests return an int value; others require more memory and do 
-their own checks.
-
+/*
 Arguments:
   what             what information is required
   where            where to put the information
-  length           length of "where" in bytes 


 Returns:           0 if data returned
-                   PCRE2_ERROR_BADLENGTH if not enough memory
+                   >= 0 if where is NULL, giving length required
                    PCRE2_ERROR_BADOPTION if "where" not recognized
+                   or JIT target requested when JIT not enabled 
 */


 PCRE2_EXP_DEFN int PCRE2_CALL_CONVENTION
-pcre2_config(uint32_t what, void *where, size_t length)
+pcre2_config(uint32_t what, void *where)
 {
-if (length < sizeof(int)) return PCRE2_ERROR_BADLENGTH;
+if (where == NULL)  /* Requests a length */
+  {
+  switch(what)
+    {
+    default:
+    return PCRE2_ERROR_BADOPTION;  
+       
+    case PCRE2_CONFIG_BSR:
+    case PCRE2_CONFIG_JIT:
+    case PCRE2_CONFIG_LINKSIZE:
+    case PCRE2_CONFIG_NEWLINE:
+    case PCRE2_CONFIG_STACKRECURSE:
+    case PCRE2_CONFIG_UNICODE:
+    return sizeof(int); 
+  
+    case PCRE2_CONFIG_MATCHLIMIT:
+    case PCRE2_CONFIG_PARENSLIMIT:
+    case PCRE2_CONFIG_RECURSIONLIMIT:
+    return sizeof(long int);
+    
+    /* These are handled below */
+  
+    case PCRE2_CONFIG_JITTARGET:
+    case PCRE2_CONFIG_UNICODE_VERSION:
+    case PCRE2_CONFIG_VERSION:
+    break;
+    }
+  }    


switch (what)
{
@@ -102,18 +127,20 @@

   case PCRE2_CONFIG_JITTARGET:
 #ifdef SUPPORT_JIT
-  return PRIV(strcpy_c8)((PCRE2_UCHAR *)where, BYTES2CU(length), PRIV(jit_get_target)());
+    {
+    const char *v = PRIV(jit_get_target)();
+    return (where == NULL)? (int)strlen(v) : 
+      PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v);
+    }   
 #else
-  *((const char **)where) = NULL;
+  return PCRE2_ERROR_BADOPTION;
 #endif
-  break;


case PCRE2_CONFIG_LINKSIZE:
*((int *)where) = configured_link_size;
break;

case PCRE2_CONFIG_MATCHLIMIT:
- if (length < sizeof(unsigned long int)) return PCRE2_ERROR_BADLENGTH;
*((unsigned long int *)where) = MATCH_LIMIT;
break;

@@ -122,12 +149,10 @@
break;

case PCRE2_CONFIG_PARENSLIMIT:
- if (length < sizeof(unsigned long int)) return PCRE2_ERROR_BADLENGTH;
*((unsigned long int *)where) = PARENS_NEST_LIMIT;
break;

case PCRE2_CONFIG_RECURSIONLIMIT:
- if (length < sizeof(unsigned long int)) return PCRE2_ERROR_BADLENGTH;
*((unsigned long int *)where) = MATCH_LIMIT_RECURSION;
break;

@@ -146,7 +171,8 @@
 #else
     const char *v = "Unicode not supported";
 #endif
-    return PRIV(strcpy_c8)((PCRE2_UCHAR *)where, BYTES2CU(length), v);
+    return (where == NULL)? (int)strlen(v) :
+      PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v);
     }
   break;


@@ -182,7 +208,8 @@
     const char *v = (XSTRING(Z PCRE2_PRERELEASE)[1] == 0)?
       XSTRING(PCRE2_MAJOR.PCRE2_MINOR PCRE2_DATE) :
       XSTRING(PCRE2_MAJOR.PCRE2_MINOR) XSTRING(PCRE2_PRERELEASE PCRE2_DATE);
-    return PRIV(strcpy_c8)((PCRE2_UCHAR *)where, BYTES2CU(length), v);
+    return (where == NULL)? (int)strlen(v) : 
+      PRIV(strcpy_c8)((PCRE2_UCHAR *)where, v);
     } 
   }



Modified: code/trunk/src/pcre2_internal.h
===================================================================
--- code/trunk/src/pcre2_internal.h    2014-10-15 15:57:49 UTC (rev 113)
+++ code/trunk/src/pcre2_internal.h    2014-10-15 16:44:12 UTC (rev 114)
@@ -1888,7 +1888,7 @@
 extern unsigned int _pcre2_ord2utf(uint32_t, PCRE2_UCHAR *);
 extern int   _pcre2_strcmp(PCRE2_SPTR, PCRE2_SPTR);
 extern int   _pcre2_strcmp_c8(PCRE2_SPTR, const char *);
-extern int   _pcre2_strcpy_c8(PCRE2_UCHAR *, size_t, const char *);
+extern int   _pcre2_strcpy_c8(PCRE2_UCHAR *, const char *);
 extern int   _pcre2_strlen(PCRE2_SPTR);
 extern int   _pcre2_strncmp(PCRE2_SPTR, PCRE2_SPTR, size_t);
 extern int   _pcre2_strncmp_c8(PCRE2_SPTR, const char *, size_t);


Modified: code/trunk/src/pcre2_jit_test.c
===================================================================
--- code/trunk/src/pcre2_jit_test.c    2014-10-15 15:57:49 UTC (rev 113)
+++ code/trunk/src/pcre2_jit_test.c    2014-10-15 16:44:12 UTC (rev 114)
@@ -98,11 +98,11 @@
 {
     int jit = 0;
 #if defined SUPPORT_PCRE2_8
-    pcre2_config_8(PCRE2_CONFIG_JIT, &jit, sizeof(int));
+    pcre2_config_8(PCRE2_CONFIG_JIT, &jit);
 #elif defined SUPPORT_PCRE2_16
-    pcre2_config_16(PCRE2_CONFIG_JIT, &jit, sizeof(int));
+    pcre2_config_16(PCRE2_CONFIG_JIT, &jit);
 #elif defined SUPPORT_PCRE2_32
-    pcre2_config_32(PCRE2_CONFIG_JIT, &jit, sizeof(int));
+    pcre2_config_32(PCRE2_CONFIG_JIT, &jit);
 #endif
     if (!jit) {
         printf("JIT must be enabled to run pcre_jit_test\n");
@@ -1123,11 +1123,11 @@
     still considered successful from pcre_jit_test point of view. */


 #if defined SUPPORT_PCRE2_8
-    pcre2_config_8(PCRE2_CONFIG_JITTARGET, &cpu_info, 128 * sizeof(PCRE2_UCHAR8));
+    pcre2_config_8(PCRE2_CONFIG_JITTARGET, &cpu_info);
 #elif defined SUPPORT_PCRE2_16
-    pcre2_config_16(PCRE2_CONFIG_JITTARGET, &cpu_info, 128 * sizeof(PCRE2_UCHAR16));
+    pcre2_config_16(PCRE2_CONFIG_JITTARGET, &cpu_info);
 #elif defined SUPPORT_PCRE2_32
-    pcre2_config_32(PCRE2_CONFIG_JITTARGET, &cpu_info, 128 * sizeof(PCRE2_UCHAR32));
+    pcre2_config_32(PCRE2_CONFIG_JITTARGET, &cpu_info));
 #endif


     printf("Running JIT regression tests\n");
@@ -1137,11 +1137,11 @@
     printf("\n");


 #if defined SUPPORT_PCRE2_8
-    pcre2_config_8(PCRE2_CONFIG_UNICODE, &utf, sizeof(int));
+    pcre2_config_8(PCRE2_CONFIG_UNICODE, &utf);
 #elif defined SUPPORT_PCRE2_16
-    pcre2_config_16(PCRE2_CONFIG_UNICODE, &utf, sizeof(int));
+    pcre2_config_16(PCRE2_CONFIG_UNICODE, &utf);
 #elif defined SUPPORT_PCRE2_32
-    pcre2_config_32(PCRE2_CONFIG_UNICODE, &utf, sizeof(int));
+    pcre2_config_32(PCRE2_CONFIG_UNICODE, &utf);
 #endif


     if (!utf)


Modified: code/trunk/src/pcre2_string_utils.c
===================================================================
--- code/trunk/src/pcre2_string_utils.c    2014-10-15 15:57:49 UTC (rev 113)
+++ code/trunk/src/pcre2_string_utils.c    2014-10-15 16:44:12 UTC (rev 114)
@@ -184,18 +184,15 @@


 /* Arguments:
   str1     buffer to receive the string
-  length   length of buffer in code units
   str2     8-bit string to be copied


 Returns:   the number of code units used (excluding trailing zero)
-           PCRE2_ERROR_BADLENGTH (a negative number) if buffer is too small
 */              


int
-PRIV(strcpy_c8)(PCRE2_UCHAR *str1, size_t length, const char *str2)
+PRIV(strcpy_c8)(PCRE2_UCHAR *str1, const char *str2)
{
PCRE2_UCHAR *t = str1;
-if (strlen(str2) >= length - 1) return PCRE2_ERROR_BADLENGTH;
while (*str2 != 0) *t++ = *str2++;
*t = 0;
return t - str1;

Modified: code/trunk/src/pcre2grep.c
===================================================================
--- code/trunk/src/pcre2grep.c    2014-10-15 15:57:49 UTC (rev 113)
+++ code/trunk/src/pcre2grep.c    2014-10-15 16:44:12 UTC (rev 114)
@@ -2379,7 +2379,7 @@
   case 'V':
     {
     unsigned char buffer[128];
-    (void)pcre2_config(PCRE2_CONFIG_VERSION, buffer, 128);
+    (void)pcre2_config(PCRE2_CONFIG_VERSION, buffer);
     fprintf(stdout, "pcre2grep version %s\n", buffer);
     } 
   pcre2grep_exit(0);
@@ -3026,7 +3026,7 @@


else
{
- (void)pcre2_config(PCRE2_CONFIG_NEWLINE, &endlinetype, sizeof(endlinetype));
+ (void)pcre2_config(PCRE2_CONFIG_NEWLINE, &endlinetype);
}

/* Interpret the text values for -d and -D */

Modified: code/trunk/src/pcre2test.c
===================================================================
--- code/trunk/src/pcre2test.c    2014-10-15 15:57:49 UTC (rev 113)
+++ code/trunk/src/pcre2test.c    2014-10-15 16:44:12 UTC (rev 114)
@@ -5257,7 +5257,7 @@
   switch (coptlist[i].type)
     {
     case CONF_BSR:
-    (void)PCRE2_CONFIG(coptlist[i].value, &rc, sizeof(rc));
+    (void)PCRE2_CONFIG(coptlist[i].value, &rc);
     printf("%s\n", rc? "ANYCRLF" : "ANY");
     break;


@@ -5272,12 +5272,12 @@
     break;


     case CONF_INT:
-    (void)PCRE2_CONFIG(coptlist[i].value, &yield, sizeof(yield));
+    (void)PCRE2_CONFIG(coptlist[i].value, &yield);
     printf("%d\n", yield);
     break;


     case CONF_NL:
-    (void)PCRE2_CONFIG(coptlist[i].value, &rc, sizeof(rc));
+    (void)PCRE2_CONFIG(coptlist[i].value, &rc);
     print_newline_config(rc, TRUE);
     break;
     }
@@ -5316,7 +5316,7 @@
 printf("  32-bit support\n");
 #endif


-(void)PCRE2_CONFIG(PCRE2_CONFIG_UNICODE, &rc, sizeof(rc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_UNICODE, &rc);
if (rc != 0)
{
printf(" UTF and UCP support (");
@@ -5325,7 +5325,7 @@
}
else printf(" No UTF or UCP support\n");

-(void)PCRE2_CONFIG(PCRE2_CONFIG_JIT, &rc, sizeof(rc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_JIT, &rc);
if (rc != 0)
{
printf(" Just-in-time compiler support: ");
@@ -5337,20 +5337,20 @@
printf(" No just-in-time compiler support\n");
}

-(void)PCRE2_CONFIG(PCRE2_CONFIG_NEWLINE, &rc, sizeof(rc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_NEWLINE, &rc);
 print_newline_config(rc, FALSE);
-(void)PCRE2_CONFIG(PCRE2_CONFIG_BSR, &rc, sizeof(rc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_BSR, &rc);
 printf("  \\R matches %s\n", rc? "CR, LF, or CRLF only" :
                                  "all Unicode newlines");
-(void)PCRE2_CONFIG(PCRE2_CONFIG_LINKSIZE, &rc, sizeof(rc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_LINKSIZE, &rc);
 printf("  Internal link size = %d\n", rc);
-(void)PCRE2_CONFIG(PCRE2_CONFIG_PARENSLIMIT, &lrc, sizeof(lrc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_PARENSLIMIT, &lrc);
 printf("  Parentheses nest limit = %ld\n", lrc);
-(void)PCRE2_CONFIG(PCRE2_CONFIG_MATCHLIMIT, &lrc, sizeof(lrc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_MATCHLIMIT, &lrc);
 printf("  Default match limit = %ld\n", lrc);
-(void)PCRE2_CONFIG(PCRE2_CONFIG_RECURSIONLIMIT, &lrc, sizeof(lrc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_RECURSIONLIMIT, &lrc);
 printf("  Default recursion depth limit = %ld\n", lrc);
-(void)PCRE2_CONFIG(PCRE2_CONFIG_STACKRECURSE, &rc, sizeof(rc));
+(void)PCRE2_CONFIG(PCRE2_CONFIG_STACKRECURSE, &rc);
 printf("  Match recursion uses %s", rc? "stack" : "heap");


printf("\n");
@@ -5391,11 +5391,9 @@

/* Get the PCRE2 and Unicode version number and JIT target information. */

-PCRE2_CONFIG(PCRE2_CONFIG_VERSION, version, sizeof(VERSION_TYPE)*VERSION_SIZE);
-PCRE2_CONFIG(PCRE2_CONFIG_UNICODE_VERSION, uversion,
- sizeof(VERSION_TYPE)*VERSION_SIZE);
-PCRE2_CONFIG(PCRE2_CONFIG_JITTARGET, jittarget,
- sizeof(VERSION_TYPE)*VERSION_SIZE);
+PCRE2_CONFIG(PCRE2_CONFIG_VERSION, version);
+PCRE2_CONFIG(PCRE2_CONFIG_UNICODE_VERSION, uversion);
+PCRE2_CONFIG(PCRE2_CONFIG_JITTARGET, jittarget);

/* Get buffers from malloc() so that valgrind will check their misuse when
debugging. They grow automatically when very long lines are read. The 16-