[Pcre-svn] [106] code/trunk/src: Create default compile and …

Top Page
Delete this message
Author: Subversion repository
Date:  
To: pcre-svn
Subject: [Pcre-svn] [106] code/trunk/src: Create default compile and match contexts as constant static data.
Revision: 106
          http://www.exim.org/viewvc/pcre2?view=rev&revision=106
Author:   ph10
Date:     2014-10-11 18:05:18 +0100 (Sat, 11 Oct 2014)


Log Message:
-----------
Create default compile and match contexts as constant static data.

Modified Paths:
--------------
    code/trunk/src/pcre2_compile.c
    code/trunk/src/pcre2_context.c
    code/trunk/src/pcre2_dfa_match.c
    code/trunk/src/pcre2_internal.h
    code/trunk/src/pcre2_match.c


Modified: code/trunk/src/pcre2_compile.c
===================================================================
--- code/trunk/src/pcre2_compile.c    2014-10-11 15:56:25 UTC (rev 105)
+++ code/trunk/src/pcre2_compile.c    2014-10-11 17:05:18 UTC (rev 106)
@@ -7333,7 +7333,6 @@
 {
 BOOL utf;                               /* Set TRUE for UTF mode */
 pcre2_real_code *re = NULL;             /* What we will return */
-pcre2_compile_context default_context;  /* For use if no context given */
 compile_block cb;                       /* "Static" compile-time data */
 const uint8_t *tables;                  /* Char tables base pointer */


@@ -7390,11 +7389,8 @@

/* A NULL compile context means "use a default context" */

-if (ccontext == NULL)
- {
- PRIV(compile_context_init)(&default_context, TRUE);
- ccontext = &default_context;
- }
+if (ccontext == NULL)
+ ccontext = (pcre2_compile_context *)(&PRIV(default_compile_context));

/* A zero-terminated pattern is indicated by the special length value
PCRE2_ZERO_TERMINATED. Otherwise, we make a copy of the pattern and add a zero,

Modified: code/trunk/src/pcre2_context.c
===================================================================
--- code/trunk/src/pcre2_context.c    2014-10-11 15:56:25 UTC (rev 105)
+++ code/trunk/src/pcre2_context.c    2014-10-11 17:05:18 UTC (rev 106)
@@ -127,60 +127,58 @@
 }



-PCRE2_EXP_DEFN void
-PRIV(compile_context_init)(pcre2_compile_context *ccontext, BOOL defmemctl)
-{
-if (defmemctl)
- {
- ccontext->memctl.malloc = default_malloc;
- ccontext->memctl.free = default_free;
- ccontext->memctl.memory_data = NULL;
- }
-ccontext->stack_guard = NULL;
-ccontext->tables = PRIV(default_tables);
-ccontext->parens_nest_limit = PARENS_NEST_LIMIT;
-ccontext->newline_convention = NEWLINE_DEFAULT;
-ccontext->bsr_convention = BSR_DEFAULT;
-}
+/* A default compile context is set up to save having to initialize at run time
+when no context is supplied to the compile function. */

+const pcre2_compile_context PRIV(default_compile_context) = {
+  { default_malloc, default_free, NULL },
+  NULL,
+  PRIV(default_tables),
+  BSR_DEFAULT,
+  NEWLINE_DEFAULT,
+  PARENS_NEST_LIMIT };     


+/* The create function copies the default into the new memory, but must
+override the default memory handling functions if a gcontext was provided. */
+
PCRE2_EXP_DEFN pcre2_compile_context * PCRE2_CALL_CONVENTION
pcre2_compile_context_create(pcre2_general_context *gcontext)
{
pcre2_compile_context *ccontext = PRIV(memctl_malloc)(
sizeof(pcre2_real_compile_context), (pcre2_memctl *)gcontext);
if (ccontext == NULL) return NULL;
-PRIV(compile_context_init)(ccontext, FALSE);
+*ccontext = PRIV(default_compile_context);
+if (gcontext != NULL)
+ *((pcre2_memctl *)ccontext) = *((pcre2_memctl *)gcontext);
return ccontext;
}


-PCRE2_EXP_DEFN void
-PRIV(match_context_init)(pcre2_match_context *mcontext, BOOL defmemctl)
-{
-if (defmemctl)
- {
- mcontext->memctl.malloc = default_malloc;
- mcontext->memctl.free = default_free;
- mcontext->memctl.memory_data = NULL;
- }
-#ifdef HEAP_MATCH_RECURSE
-mcontext->stack_memctl = mcontext->memctl;
+/* A default match context is set up to save having to initialize at run time
+when no context is supplied to a match function. */
+
+const pcre2_match_context PRIV(default_match_context) = {
+ { default_malloc, default_free, NULL },
+#ifdef HEAP_MATCH_RECURSE
+ { default_malloc, default_free, NULL },
#endif
-mcontext->callout = NULL;
-mcontext->callout_data = NULL;
-mcontext->match_limit = MATCH_LIMIT;
-mcontext->recursion_limit = MATCH_LIMIT_RECURSION;
-}
+ NULL,
+ NULL,
+ MATCH_LIMIT,
+ MATCH_LIMIT_RECURSION };
+
+/* The create function copies the default into the new memory, but must
+override the default memory handling functions if a gcontext was provided. */

-
PCRE2_EXP_DEFN pcre2_match_context * PCRE2_CALL_CONVENTION
pcre2_match_context_create(pcre2_general_context *gcontext)
{
pcre2_match_context *mcontext = PRIV(memctl_malloc)(
sizeof(pcre2_real_match_context), (pcre2_memctl *)gcontext);
if (mcontext == NULL) return NULL;
-PRIV(match_context_init)(mcontext, FALSE);
+*mcontext = PRIV(default_match_context);
+if (gcontext != NULL)
+ *((pcre2_memctl *)mcontext) = *((pcre2_memctl *)gcontext);
return mcontext;
}


Modified: code/trunk/src/pcre2_dfa_match.c
===================================================================
--- code/trunk/src/pcre2_dfa_match.c    2014-10-11 15:56:25 UTC (rev 105)
+++ code/trunk/src/pcre2_dfa_match.c    2014-10-11 17:05:18 UTC (rev 106)
@@ -3068,7 +3068,6 @@
   pcre2_match_context *mcontext, int *workspace, size_t wscount)
 {
 const pcre2_real_code *re = (const pcre2_real_code *)code;
-pcre2_match_context default_context;  /* For use if no context given */


PCRE2_SPTR start_match;
PCRE2_SPTR end_subject;
@@ -3149,10 +3148,7 @@
/* A NULL match context means "use a default context" */

if (mcontext == NULL)
- {
- PRIV(match_context_init)(&default_context, TRUE);
- mcontext = &default_context;
- }
+ mcontext = (pcre2_match_context *)(&PRIV(default_match_context));

/* If restarting after a partial match, do some sanity checks on the contents
of the workspace. */

Modified: code/trunk/src/pcre2_internal.h
===================================================================
--- code/trunk/src/pcre2_internal.h    2014-10-11 15:56:25 UTC (rev 105)
+++ code/trunk/src/pcre2_internal.h    2014-10-11 17:05:18 UTC (rev 106)
@@ -1785,12 +1785,12 @@
 #define MAX_NON_UTF_CHAR (0xffffffffU >> (32 - PCRE2_CODE_UNIT_WIDTH))



-/* Internal shared data tables. These are tables that are used by more than one
+/* Internal shared data tables and variables. These are used by more than one
of the exported public functions. They have to be "external" in the C sense,
-but are not part of the PCRE2 public API. Although the data for some of the
-tables is identical in all libraries, they must have different names so that
-multiple libraries can be simultaneously linked to a single application.
-However, UTF-8 tables are needed only when compiling the 8-bit library. */
+but are not part of the PCRE2 public API. Although the data for some of them is
+identical in all libraries, they must have different names so that multiple
+libraries can be simultaneously linked to a single application. However, UTF-8
+tables are needed only when compiling the 8-bit library. */

 #if PCRE2_CODE_UNIT_WIDTH == 8
 extern const int              PRIV(utf8_table1)[];
@@ -1800,39 +1800,43 @@
 extern const uint8_t          PRIV(utf8_table4)[];
 #endif


-#define _pcre2_OP_lengths         PCRE2_SUFFIX(_pcre2_OP_lengths_)
-#define _pcre2_default_tables     PCRE2_SUFFIX(_pcre2_default_tables_)
-#define _pcre2_hspace_list        PCRE2_SUFFIX(_pcre2_hspace_list_)
-#define _pcre2_vspace_list        PCRE2_SUFFIX(_pcre2_vspace_list_)
-#define _pcre2_ucd_caseless_sets  PCRE2_SUFFIX(_pcre2_ucd_caseless_sets_)
-#define _pcre2_ucd_records        PCRE2_SUFFIX(_pcre2_ucd_records_)
-#define _pcre2_ucd_stage1         PCRE2_SUFFIX(_pcre2_ucd_stage1_)
-#define _pcre2_ucd_stage2         PCRE2_SUFFIX(_pcre2_ucd_stage2_)
-#define _pcre2_ucp_gbtable        PCRE2_SUFFIX(_pcre2_ucp_gbtable_)
-#define _pcre2_ucp_gentype        PCRE2_SUFFIX(_pcre2_ucp_gentype_)
-#define _pcre2_ucp_typerange      PCRE2_SUFFIX(_pcre2_ucp_typerange_)
-#define _pcre2_unicode_version    PCRE2_SUFFIX(_pcre2_unicode_version_)
-#define _pcre2_utt                PCRE2_SUFFIX(_pcre2_utt_)
-#define _pcre2_utt_names          PCRE2_SUFFIX(_pcre2_utt_names_)
-#define _pcre2_utt_size           PCRE2_SUFFIX(_pcre2_utt_size_)
+#define _pcre2_OP_lengths              PCRE2_SUFFIX(_pcre2_OP_lengths_)
+#define _pcre2_default_compile_context PCRE2_SUFFIX(_pcre2_default_compile_context_)
+#define _pcre2_default_match_context   PCRE2_SUFFIX(_pcre2_default_match_context_)
+#define _pcre2_default_tables          PCRE2_SUFFIX(_pcre2_default_tables_)
+#define _pcre2_hspace_list             PCRE2_SUFFIX(_pcre2_hspace_list_)
+#define _pcre2_vspace_list             PCRE2_SUFFIX(_pcre2_vspace_list_)
+#define _pcre2_ucd_caseless_sets       PCRE2_SUFFIX(_pcre2_ucd_caseless_sets_)
+#define _pcre2_ucd_records             PCRE2_SUFFIX(_pcre2_ucd_records_)
+#define _pcre2_ucd_stage1              PCRE2_SUFFIX(_pcre2_ucd_stage1_)
+#define _pcre2_ucd_stage2              PCRE2_SUFFIX(_pcre2_ucd_stage2_)
+#define _pcre2_ucp_gbtable             PCRE2_SUFFIX(_pcre2_ucp_gbtable_)
+#define _pcre2_ucp_gentype             PCRE2_SUFFIX(_pcre2_ucp_gentype_)
+#define _pcre2_ucp_typerange           PCRE2_SUFFIX(_pcre2_ucp_typerange_)
+#define _pcre2_unicode_version         PCRE2_SUFFIX(_pcre2_unicode_version_)
+#define _pcre2_utt                     PCRE2_SUFFIX(_pcre2_utt_)
+#define _pcre2_utt_names               PCRE2_SUFFIX(_pcre2_utt_names_)
+#define _pcre2_utt_size                PCRE2_SUFFIX(_pcre2_utt_size_)


-extern const uint8_t          PRIV(OP_lengths)[];
-extern const uint8_t          PRIV(default_tables)[];
-extern const uint32_t         PRIV(hspace_list)[];
-extern const uint32_t         PRIV(vspace_list)[];
-extern const uint32_t         PRIV(ucd_caseless_sets)[];
-extern const ucd_record       PRIV(ucd_records)[];
-extern const uint8_t          PRIV(ucd_stage1)[];
-extern const uint16_t         PRIV(ucd_stage2)[];
-extern const uint32_t         PRIV(ucp_gbtable)[];
-extern const uint32_t         PRIV(ucp_gentype)[];
-#ifdef SUPPORT_JIT
-extern const int              PRIV(ucp_typerange)[];
-#endif
-extern const char            *PRIV(unicode_version);
-extern const ucp_type_table   PRIV(utt)[];
-extern const char             PRIV(utt_names)[];
-extern const size_t           PRIV(utt_size);
+extern const uint8_t                   PRIV(OP_lengths)[];
+extern const pcre2_compile_context     PRIV(default_compile_context);
+extern const pcre2_match_context       PRIV(default_match_context);
+extern const uint8_t                   PRIV(default_tables)[];
+extern const uint32_t                  PRIV(hspace_list)[];
+extern const uint32_t                  PRIV(vspace_list)[];
+extern const uint32_t                  PRIV(ucd_caseless_sets)[];
+extern const ucd_record                PRIV(ucd_records)[];
+extern const uint8_t                   PRIV(ucd_stage1)[];
+extern const uint16_t                  PRIV(ucd_stage2)[];
+extern const uint32_t                  PRIV(ucp_gbtable)[];
+extern const uint32_t                  PRIV(ucp_gentype)[];
+#ifdef SUPPORT_JIT                     
+extern const int                       PRIV(ucp_typerange)[];
+#endif                                
+extern const char                     *PRIV(unicode_version);
+extern const ucp_type_table            PRIV(utt)[];
+extern const char                      PRIV(utt_names)[];
+extern const size_t                    PRIV(utt_size);


/* Mode-dependent macros and hidden and private structures are defined in a
separate file so that pcre2test can include them at all supported widths. When
@@ -1855,12 +1859,10 @@
is available. */

 #define _pcre2_auto_possessify       PCRE2_SUFFIX(_pcre2_auto_possessify_)
-#define _pcre2_compile_context_init  PCRE2_SUFFIX(_pcre2_compile_context_init_)
 #define _pcre2_find_bracket          PCRE2_SUFFIX(_pcre2_find_bracket_)
 #define _pcre2_is_newline            PCRE2_SUFFIX(_pcre2_is_newline_)
 #define _pcre2_jit_free              PCRE2_SUFFIX(_pcre2_jit_free_)
 #define _pcre2_jit_get_size          PCRE2_SUFFIX(_pcre2_jit_get_size_)
-#define _pcre2_match_context_init    PCRE2_SUFFIX(_pcre2_match_context_init_)
 #define _pcre2_memctl_malloc         PCRE2_SUFFIX(_pcre2_memctl_malloc_)
 #define _pcre2_ord2utf               PCRE2_SUFFIX(_pcre2_ord2utf_)
 #define _pcre2_strcmp                PCRE2_SUFFIX(_pcre_strcmp_)
@@ -1874,13 +1876,11 @@
 #define _pcre2_xclass                PCRE2_SUFFIX(_pcre2_xclass_)


 extern void  _pcre2_auto_possessify(PCRE2_UCHAR *, BOOL, const compile_block *);
-extern void  _pcre2_compile_context_init(pcre2_compile_context *, BOOL);
 extern PCRE2_SPTR _pcre2_find_bracket(PCRE2_SPTR, BOOL, int);
 extern BOOL  _pcre2_is_newline(PCRE2_SPTR, uint32_t, PCRE2_SPTR, uint32_t *,
                BOOL);
 extern void  _pcre2_jit_free(void *, pcre2_memctl *);
 extern size_t _pcre2_jit_get_size(void *);
-extern void  _pcre2_match_context_init(pcre2_match_context *, BOOL);
 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);


Modified: code/trunk/src/pcre2_match.c
===================================================================
--- code/trunk/src/pcre2_match.c    2014-10-11 15:56:25 UTC (rev 105)
+++ code/trunk/src/pcre2_match.c    2014-10-11 17:05:18 UTC (rev 106)
@@ -6352,7 +6352,6 @@
 const uint8_t *start_bits = NULL;


const pcre2_real_code *re = (const pcre2_real_code *)code;
-pcre2_match_context default_context; /* For use if no context given */

BOOL anchored;
BOOL firstline;
@@ -6440,10 +6439,7 @@
/* A NULL match context means "use a default context" */

if (mcontext == NULL)
- {
- PRIV(match_context_init)(&default_context, TRUE);
- mcontext = &default_context;
- }
+ mcontext = (pcre2_match_context *)(&PRIV(default_match_context));

/* These two settings are used in the code for checking a UTF string that
follows immediately afterwards. Other values in the mb block are used only