Remove length argument from pcre2_config; give width if where==NULL.

This commit is contained in:
Philip.Hazel 2014-10-15 16:44:12 +00:00
parent 722817013c
commit 7d0008d453
8 changed files with 87 additions and 62 deletions

View File

@ -203,7 +203,7 @@ document for an overview of all the PCRE2 documentation.
.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 @@ supplied, otherwise the system functions.
.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 @@ documentation has more details about these optional features.
.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 @@ compiling is available; otherwise it is set to zero.
.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 @@ heap instead of recursive function calls.
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 @@ otherwise it is set to zero. Unicode support implies UTF support.
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"

View File

@ -336,7 +336,7 @@ expanded for each width below. Start with functions that give general
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. */

View File

@ -61,23 +61,48 @@ convenient for user programs that want to test their values. */
* 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 @@ switch (what)
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 @@ switch (what)
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 @@ switch (what)
#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 @@ switch (what)
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);
}
}

View File

@ -1888,7 +1888,7 @@ extern void *_pcre2_memctl_malloc(size_t, pcre2_memctl *);
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);

View File

@ -98,11 +98,11 @@ int main(void)
{
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 @@ static int regression_tests(void)
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 @@ static int regression_tests(void)
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)

View File

@ -184,18 +184,15 @@ return c;
/* 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;

View File

@ -2379,7 +2379,7 @@ switch(letter)
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 @@ if (newline_arg != NULL)
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 */

View File

@ -5257,7 +5257,7 @@ if (arg != NULL)
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 @@ if (arg != NULL)
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(" 16-bit support\n");
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 @@ if (rc != 0)
}
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 @@ else
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 @@ if (PO(options) != DO(options) || PO(control) != DO(control))
/* 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-