[Pcre-svn] [513] code/trunk: Refactor pcre2posix.c so as not…

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [513] code/trunk: Refactor pcre2posix.c so as not to #include pcre2_internal.h.
Revision: 513
          http://www.exim.org/viewvc/pcre2?view=rev&revision=513
Author:   ph10
Date:     2016-05-14 17:35:20 +0100 (Sat, 14 May 2016)
Log Message:
-----------
Refactor pcre2posix.c so as not to #include pcre2_internal.h.


Modified Paths:
--------------
    code/trunk/ChangeLog
    code/trunk/src/pcre2_internal.h
    code/trunk/src/pcre2posix.c


Modified: code/trunk/ChangeLog
===================================================================
--- code/trunk/ChangeLog    2016-04-22 14:10:51 UTC (rev 512)
+++ code/trunk/ChangeLog    2016-05-14 16:35:20 UTC (rev 513)
@@ -102,7 +102,11 @@


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
-----------------------------


Modified: code/trunk/src/pcre2_internal.h
===================================================================
--- code/trunk/src/pcre2_internal.h    2016-04-22 14:10:51 UTC (rev 512)
+++ code/trunk/src/pcre2_internal.h    2016-05-14 16:35:20 UTC (rev 513)
@@ -242,8 +242,15 @@


#define MAX_UTF_CODE_POINT 0x10ffff

-/* Compile-time errors are added to this value. As they are documented, it
-should probably never be changed. */
+/* Compile-time positive error numbers (all except UTF errors, which are
+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


Modified: code/trunk/src/pcre2posix.c
===================================================================
--- code/trunk/src/pcre2posix.c    2016-04-22 14:10:51 UTC (rev 512)
+++ code/trunk/src/pcre2posix.c    2016-05-14 16:35:20 UTC (rev 513)
@@ -58,16 +58,41 @@
 #  define PCRE2POSIX_EXP_DEFN __declspec(dllexport)
 #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
-"import". This is needed even though pcre2_internal.h itself includes pcre2.h,
-because it does so after it has set PCRE2_EXP_DECL to "export" if it is not
-already set. */

+/* Compile-time error numbers start at this value. It should probably never be
+changed. This #define is a copy of the one in pcre2_internal.h. */
+
+#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_internal.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.
 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
@@ -302,11 +327,12 @@
 if (rc >= 0)
   {
   size_t i;
+  PCRE2_SIZE *ovector = pcre2_get_ovector_pointer(md);
   if ((size_t)rc > nmatch) rc = (int)nmatch;
   for (i = 0; i < (size_t)rc; i++)
     {
-    pmatch[i].rm_so = md->ovector[i*2];
-    pmatch[i].rm_eo = md->ovector[i*2+1];
+    pmatch[i].rm_so = ovector[i*2];
+    pmatch[i].rm_eo = ovector[i*2+1];
     }
   for (; i < nmatch; i++) pmatch[i].rm_so = pmatch[i].rm_eo = -1;
   return 0;