Refactor pcre2posix.c so as not to #include pcre2_internal.h.

This commit is contained in:
Philip.Hazel 2016-05-14 16:35:20 +00:00
parent 517cd43ff6
commit 8f4e7c84b4
3 changed files with 47 additions and 10 deletions

View File

@ -102,6 +102,10 @@ additions).
23. RunTest.bat was missing a "set type" line for test 22. 23. RunTest.bat was missing a "set type" line for test 22.
24. The pcre2posix.c file was including pcre2_internal.h, and using some
"private" knowledge of the data structures. This is unnecessary; the code has
been re-factored and no longer includes pcre2_internal.h.
Version 10.21 12-January-2016 Version 10.21 12-January-2016
----------------------------- -----------------------------

View File

@ -242,8 +242,15 @@ Unicode doesn't go beyond 0x0010ffff. */
#define MAX_UTF_CODE_POINT 0x10ffff #define MAX_UTF_CODE_POINT 0x10ffff
/* Compile-time errors are added to this value. As they are documented, it /* Compile-time positive error numbers (all except UTF errors, which are
should probably never be changed. */ negative) start at this value. It should probably never be changed, in case
some application is checking for specific numbers. There is a copy of this
#define in pcre2posix.c (which now no longer includes this file). Ideally, a
way of having a single definition should be found, but as the number is
unlikely to change, this is not a pressing issue. The original reason for
having a base other than 0 was to keep the absolute values of compile-time and
run-time error numbers numerically different, but in the event the code does
not rely on this. */
#define COMPILE_ERROR_BASE 100 #define COMPILE_ERROR_BASE 100

View File

@ -58,16 +58,41 @@ previously been set. */
# define PCRE2POSIX_EXP_DEFN __declspec(dllexport) # define PCRE2POSIX_EXP_DEFN __declspec(dllexport)
#endif #endif
/* We include pcre2.h before pcre2_internal.h so that the PCRE2 library
functions are declared as "import" for Windows by defining PCRE2_EXP_DECL as /* Compile-time error numbers start at this value. It should probably never be
"import". This is needed even though pcre2_internal.h itself includes pcre2.h, changed. This #define is a copy of the one in pcre2_internal.h. */
because it does so after it has set PCRE2_EXP_DECL to "export" if it is not
already set. */ #define COMPILE_ERROR_BASE 100
/* Standard C headers */
#include <ctype.h>
#include <limits.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/* PCRE2 headers */
#include "pcre2.h" #include "pcre2.h"
#include "pcre2_internal.h"
#include "pcre2posix.h" #include "pcre2posix.h"
/* When compiling with the MSVC compiler, it is sometimes necessary to include
a "calling convention" before exported function names. (This is secondhand
information; I know nothing about MSVC myself). For example, something like
void __cdecl function(....)
might be needed. In order so make this easy, all the exported functions have
PCRE2_CALL_CONVENTION just before their names. It is rarely needed; if not
set, we ensure here that it has no effect. */
#ifndef PCRE2_CALL_CONVENTION
#define PCRE2_CALL_CONVENTION
#endif
/* Table to translate PCRE2 compile time error codes into POSIX error codes. /* Table to translate PCRE2 compile time error codes into POSIX error codes.
Only a few PCRE2 errors with a value greater than 23 turn into special POSIX Only a few PCRE2 errors with a value greater than 23 turn into special POSIX
codes: most go to REG_BADPAT. The second table lists, in pairs, those that codes: most go to REG_BADPAT. The second table lists, in pairs, those that
@ -302,11 +327,12 @@ rc = pcre2_match((const pcre2_code *)preg->re_pcre2_code,
if (rc >= 0) if (rc >= 0)
{ {
size_t i; size_t i;
PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(md);
if ((size_t)rc > nmatch) rc = (int)nmatch; if ((size_t)rc > nmatch) rc = (int)nmatch;
for (i = 0; i < (size_t)rc; i++) for (i = 0; i < (size_t)rc; i++)
{ {
pmatch[i].rm_so = md->ovector[i*2]; pmatch[i].rm_so = ovector[i*2];
pmatch[i].rm_eo = md->ovector[i*2+1]; pmatch[i].rm_eo = ovector[i*2+1];
} }
for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1; for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
return 0; return 0;