1 /*************************************************
2 * PCRE2 testing program *
3 *************************************************/
5 /* PCRE2 is a library of functions to support regular expressions whose syntax
6 and semantics are as close as possible to those of the Perl 5 language. In 2014
7 the API was completely revised and '2' was added to the name, because the old
8 API, which had lasted for 16 years, could not accommodate new requirements. At
9 the same time, this testing program was re-designed because its original
10 hacked-up (non-) design had also run out of steam.
12 Written by Philip Hazel
13 Original code Copyright (c) 1997-2012 University of Cambridge
14 Rewritten code Copyright (c) 2016-2018 University of Cambridge
16 -----------------------------------------------------------------------------
17 Redistribution and use in source and binary forms, with or without
18 modification, are permitted provided that the following conditions are met:
20 * Redistributions of source code must retain the above copyright notice,
21 this list of conditions and the following disclaimer.
23 * Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
27 * Neither the name of the University of Cambridge nor the names of its
28 contributors may be used to endorse or promote products derived from
29 this software without specific prior written permission.
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
33 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
35 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
36 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
38 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
39 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 POSSIBILITY OF SUCH DAMAGE.
42 -----------------------------------------------------------------------------
46 /* This program supports testing of the 8-bit, 16-bit, and 32-bit PCRE2
47 libraries in a single program, though its input and output are always 8-bit.
48 It is different from modules such as pcre2_compile.c in the library itself,
49 which are compiled separately for each code unit width. If two widths are
50 enabled, for example, pcre2_compile.c is compiled twice. In contrast,
51 pcre2test.c is compiled only once, and linked with all the enabled libraries.
52 Therefore, it must not make use of any of the macros from pcre2.h or
53 pcre2_internal.h that depend on PCRE2_CODE_UNIT_WIDTH. It does, however, make
54 use of SUPPORT_PCRE2_8, SUPPORT_PCRE2_16, and SUPPORT_PCRE2_32, to ensure that
55 it references only the enabled library functions. */
69 #if defined NATIVE_ZOS
71 /* That header is not included in the main PCRE2 distribution because other
72 apparatus is needed to compile pcre2test for z/OS. The header can be found in
73 the special z/OS distribution, which is available from www.zaconsultants.net or
74 from www.cbttape.org. */
81 /* Debugging code enabler */
83 /* #define DEBUG_SHOW_MALLOC_ADDRESSES */
85 /* Both libreadline and libedit are optionally supported. The user-supplied
86 original patch uses readline/readline.h for libedit, but in at least one system
87 it is installed as editline/readline.h, so the configuration code now looks for
88 that first, falling back to readline/readline.h. */
90 #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
91 #if defined(SUPPORT_LIBREADLINE)
92 #include <readline/readline.h>
93 #include <readline/history.h>
95 #if defined(HAVE_EDITLINE_READLINE_H)
96 #include <editline/readline.h>
98 #include <readline/readline.h>
103 /* Put the test for interactive input into a macro so that it can be changed if
104 required for different environments. */
106 #define INTERACTIVE(f) isatty(fileno(f))
109 /* ---------------------- System-specific definitions ---------------------- */
111 /* A number of things vary for Windows builds. Originally, pcretest opened its
112 input and output without "b"; then I was told that "b" was needed in some
113 environments, so it was added for release 5.0 to both the input and output. (It
114 makes no difference on Unix-like systems.) Later I was told that it is wrong
115 for the input on Windows. I've now abstracted the modes into macros that are
116 set here, to make it easier to fiddle with them, and removed "b" from the input
117 mode under Windows. The BINARY versions are used when saving/restoring compiled
120 #if defined(_WIN32) || defined(WIN32)
121 #include <io.h> /* For _setmode() */
122 #include <fcntl.h> /* For _O_BINARY */
123 #define INPUT_MODE "r"
124 #define OUTPUT_MODE "wb"
125 #define BINARY_INPUT_MODE "rb"
126 #define BINARY_OUTPUT_MODE "wb"
129 #define isatty _isatty /* This is what Windows calls them, I'm told, */
130 #endif /* though in some environments they seem to */
131 /* be already defined, hence the #ifndefs. */
133 #define fileno _fileno
136 /* A user sent this fix for Borland Builder 5 under Windows. */
139 #define _setmode(handle, mode) setmode(handle, mode)
145 #include <sys/time.h> /* These two includes are needed */
146 #include <sys/resource.h> /* for setrlimit(). */
147 #if defined NATIVE_ZOS /* z/OS uses non-binary I/O */
148 #define INPUT_MODE "r"
149 #define OUTPUT_MODE "w"
150 #define BINARY_INPUT_MODE "rb"
151 #define BINARY_OUTPUT_MODE "wb"
153 #define INPUT_MODE "rb"
154 #define OUTPUT_MODE "wb"
155 #define BINARY_INPUT_MODE "rb"
156 #define BINARY_OUTPUT_MODE "wb"
162 void vms_setsymbol( char *, char *, int );
165 /* VC and older compilers don't support %td or %zu. */
167 #if defined(_MSC_VER) || !defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L
168 #define PTR_FORM "lu"
169 #define SIZ_FORM "lu"
170 #define SIZ_CAST (unsigned long int)
172 #define PTR_FORM "td"
173 #define SIZ_FORM "zu"
177 /* ------------------End of system-specific definitions -------------------- */
179 /* Glueing macros that are used in several places below. */
181 #define glue(a,b) a##b
182 #define G(a,b) glue(a,b)
184 /* Miscellaneous parameters and manifests */
186 #ifndef CLOCKS_PER_SEC
188 #define CLOCKS_PER_SEC CLK_TCK
190 #define CLOCKS_PER_SEC 100
194 #define CFORE_UNSET UINT32_MAX /* Unset value for startend/cfail/cerror fields */
195 #define CONVERT_UNSET UINT32_MAX /* Unset value for convert_type field */
196 #define DFA_WS_DIMENSION 1000 /* Size of DFA workspace */
197 #define DEFAULT_OVECCOUNT 15 /* Default ovector count */
198 #define JUNK_OFFSET 0xdeadbeef /* For initializing ovector */
199 #define LOCALESIZE 32 /* Size of locale name */
200 #define LOOPREPEAT 500000 /* Default loop count for timing */
201 #define MALLOCLISTSIZE 20 /* For remembering mallocs */
202 #define PARENS_NEST_DEFAULT 220 /* Default parentheses nest limit */
203 #define PATSTACKSIZE 20 /* Pattern stack for save/restore testing */
204 #define REPLACE_MODSIZE 100 /* Field for reading 8-bit replacement */
205 #define VERSION_SIZE 64 /* Size of buffer for the version strings */
207 /* Make sure the buffer into which replacement strings are copied is big enough
208 to hold them as 32-bit code units. */
210 #define REPLACE_BUFFSIZE 1024 /* This is a byte value */
212 /* Execution modes */
215 #define PCRE16_MODE 16
216 #define PCRE32_MODE 32
218 /* Processing returns */
220 enum { PR_OK, PR_SKIP, PR_ABEND };
222 /* The macro PRINTABLE determines whether to print an output character as-is or
223 as a hex value when showing compiled patterns. is We use it in cases when the
224 locale has not been explicitly changed, so as to get consistent output from
225 systems that differ in their output from isprint() even in the "C" locale. */
228 #define PRINTABLE(c) ((c) >= 64 && (c) < 255)
230 #define PRINTABLE(c) ((c) >= 32 && (c) < 127)
233 #define PRINTOK(c) ((use_tables != NULL && c < 256)? isprint(c) : PRINTABLE(c))
235 /* We have to include some of the library source files because we need
236 to use some of the macros, internal structure definitions, and other internal
237 values - pcre2test has "inside information" compared to an application program
238 that strictly follows the PCRE2 API.
240 Before including pcre2_internal.h we define PRIV so that it does not get
241 defined therein. This ensures that PRIV names in the included files do not
242 clash with those in the libraries. Also, although pcre2_internal.h does itself
243 include pcre2.h, we explicitly include it beforehand, along with pcre2posix.h,
244 so that the PCRE2_EXP_xxx macros get set appropriately for an application, not
245 for building the library. */
247 #define PRIV(name) name
248 #define PCRE2_CODE_UNIT_WIDTH 0
250 #include "pcre2posix.h"
251 #include "pcre2_internal.h"
253 /* We need access to some of the data tables that PCRE2 uses. Defining
254 PCRE2_PCRETEST makes some minor changes in the files. The previous definition
255 of PRIV avoids name clashes. */
257 #define PCRE2_PCRE2TEST
258 #include "pcre2_tables.c"
259 #include "pcre2_ucd.c"
261 /* 32-bit integer values in the input are read by strtoul() or strtol(). The
262 check needed for overflow depends on whether long ints are in fact longer than
263 ints. They are defined not to be shorter. */
265 #if ULONG_MAX > UINT32_MAX
266 #define U32OVERFLOW(x) (x > UINT32_MAX)
268 #define U32OVERFLOW(x) (x == UINT32_MAX)
271 #if LONG_MAX > INT32_MAX
272 #define S32OVERFLOW(x) (x > INT32_MAX || x < INT32_MIN)
274 #define S32OVERFLOW(x) (x == INT32_MAX || x == INT32_MIN)
277 /* When PCRE2_CODE_UNIT_WIDTH is zero, pcre2_internal.h does not include
278 pcre2_intmodedep.h, which is where mode-dependent macros and structures are
279 defined. We can now include it for each supported code unit width. Because
280 PCRE2_CODE_UNIT_WIDTH was defined as zero before including pcre2.h, it will
281 have left PCRE2_SUFFIX defined as a no-op. We must re-define it appropriately
282 while including these files, and then restore it to a no-op. Because LINK_SIZE
283 may be changed in 16-bit mode and forced to 1 in 32-bit mode, the order of
284 these inclusions should not be changed. */
287 #undef PCRE2_CODE_UNIT_WIDTH
289 #ifdef SUPPORT_PCRE2_8
290 #define PCRE2_CODE_UNIT_WIDTH 8
291 #define PCRE2_SUFFIX(a) G(a,8)
292 #include "pcre2_intmodedep.h"
293 #include "pcre2_printint.c"
294 #undef PCRE2_CODE_UNIT_WIDTH
296 #endif /* SUPPORT_PCRE2_8 */
298 #ifdef SUPPORT_PCRE2_16
299 #define PCRE2_CODE_UNIT_WIDTH 16
300 #define PCRE2_SUFFIX(a) G(a,16)
301 #include "pcre2_intmodedep.h"
302 #include "pcre2_printint.c"
303 #undef PCRE2_CODE_UNIT_WIDTH
305 #endif /* SUPPORT_PCRE2_16 */
307 #ifdef SUPPORT_PCRE2_32
308 #define PCRE2_CODE_UNIT_WIDTH 32
309 #define PCRE2_SUFFIX(a) G(a,32)
310 #include "pcre2_intmodedep.h"
311 #include "pcre2_printint.c"
312 #undef PCRE2_CODE_UNIT_WIDTH
314 #endif /* SUPPORT_PCRE2_32 */
316 #define PCRE2_SUFFIX(a) a
318 /* We need to be able to check input text for UTF-8 validity, whatever code
319 widths are actually available, because the input to pcre2test is always in
320 8-bit code units. So we include the UTF validity checking function for 8-bit
323 extern int valid_utf(PCRE2_SPTR8, PCRE2_SIZE, PCRE2_SIZE *);
325 #define PCRE2_CODE_UNIT_WIDTH 8
327 #define PCRE2_SPTR PCRE2_SPTR8
328 #include "pcre2_valid_utf.c"
329 #undef PCRE2_CODE_UNIT_WIDTH
332 /* If we have 8-bit support, default to it; if there is also 16-or 32-bit
333 support, it can be selected by a command-line option. If there is no 8-bit
334 support, there must be 16-bit or 32-bit support, so default to one of them. The
335 config function, JIT stack, contexts, and version string are the same in all
336 modes, so use the form of the first that is available. */
338 #if defined SUPPORT_PCRE2_8
339 #define DEFAULT_TEST_MODE PCRE8_MODE
340 #define VERSION_TYPE PCRE2_UCHAR8
341 #define PCRE2_CONFIG pcre2_config_8
342 #define PCRE2_JIT_STACK pcre2_jit_stack_8
343 #define PCRE2_REAL_GENERAL_CONTEXT pcre2_real_general_context_8
344 #define PCRE2_REAL_COMPILE_CONTEXT pcre2_real_compile_context_8
345 #define PCRE2_REAL_CONVERT_CONTEXT pcre2_real_convert_context_8
346 #define PCRE2_REAL_MATCH_CONTEXT pcre2_real_match_context_8
348 #elif defined SUPPORT_PCRE2_16
349 #define DEFAULT_TEST_MODE PCRE16_MODE
350 #define VERSION_TYPE PCRE2_UCHAR16
351 #define PCRE2_CONFIG pcre2_config_16
352 #define PCRE2_JIT_STACK pcre2_jit_stack_16
353 #define PCRE2_REAL_GENERAL_CONTEXT pcre2_real_general_context_16
354 #define PCRE2_REAL_COMPILE_CONTEXT pcre2_real_compile_context_16
355 #define PCRE2_REAL_CONVERT_CONTEXT pcre2_real_convert_context_16
356 #define PCRE2_REAL_MATCH_CONTEXT pcre2_real_match_context_16
358 #elif defined SUPPORT_PCRE2_32
359 #define DEFAULT_TEST_MODE PCRE32_MODE
360 #define VERSION_TYPE PCRE2_UCHAR32
361 #define PCRE2_CONFIG pcre2_config_32
362 #define PCRE2_JIT_STACK pcre2_jit_stack_32
363 #define PCRE2_REAL_GENERAL_CONTEXT pcre2_real_general_context_32
364 #define PCRE2_REAL_COMPILE_CONTEXT pcre2_real_compile_context_32
365 #define PCRE2_REAL_CONVERT_CONTEXT pcre2_real_convert_context_32
366 #define PCRE2_REAL_MATCH_CONTEXT pcre2_real_match_context_32
369 /* ------------- Structure and table for handling #-commands ------------- */
371 typedef struct cmdstruct {
376 enum { CMD_FORBID_UTF, CMD_LOAD, CMD_NEWLINE_DEFAULT, CMD_PATTERN,
377 CMD_PERLTEST, CMD_POP, CMD_POPCOPY, CMD_SAVE, CMD_SUBJECT, CMD_UNKNOWN };
379 static cmdstruct cmdlist[] = {
380 { "forbid_utf", CMD_FORBID_UTF },
381 { "load", CMD_LOAD },
382 { "newline_default", CMD_NEWLINE_DEFAULT },
383 { "pattern", CMD_PATTERN },
384 { "perltest", CMD_PERLTEST },
386 { "popcopy", CMD_POPCOPY },
387 { "save", CMD_SAVE },
388 { "subject", CMD_SUBJECT }};
390 #define cmdlistcount (sizeof(cmdlist)/sizeof(cmdstruct))
392 /* ------------- Structures and tables for handling modifiers -------------- */
394 /* Table of names for newline types. Must be kept in step with the definitions
395 of PCRE2_NEWLINE_xx in pcre2.h. */
397 static const char *newlines[] = {
398 "DEFAULT", "CR", "LF", "CRLF", "ANY", "ANYCRLF", "NUL" };
400 /* Structure and table for handling pattern conversion types. */
402 typedef struct convertstruct {
407 static convertstruct convertlist[] = {
408 { "glob", PCRE2_CONVERT_GLOB },
409 { "glob_no_starstar", PCRE2_CONVERT_GLOB_NO_STARSTAR },
410 { "glob_no_wild_separator", PCRE2_CONVERT_GLOB_NO_WILD_SEPARATOR },
411 { "posix_basic", PCRE2_CONVERT_POSIX_BASIC },
412 { "posix_extended", PCRE2_CONVERT_POSIX_EXTENDED },
413 { "unset", CONVERT_UNSET }};
415 #define convertlistcount (sizeof(convertlist)/sizeof(convertstruct))
417 /* Modifier types and applicability */
419 enum { MOD_CTC, /* Applies to a compile context */
420 MOD_CTM, /* Applies to a match context */
421 MOD_PAT, /* Applies to a pattern */
422 MOD_PATP, /* Ditto, OK for Perl test */
423 MOD_DAT, /* Applies to a data line */
424 MOD_PD, /* Applies to a pattern or a data line */
425 MOD_PDP, /* As MOD_PD, OK for Perl test */
426 MOD_PND, /* As MOD_PD, but not for a default pattern */
427 MOD_PNDP, /* As MOD_PND, OK for Perl test */
428 MOD_CHR, /* Is a single character */
429 MOD_CON, /* Is a "convert" type/options list */
430 MOD_CTL, /* Is a control bit */
431 MOD_BSR, /* Is a BSR value */
432 MOD_IN2, /* Is one or two unsigned integers */
433 MOD_INS, /* Is a signed integer */
434 MOD_INT, /* Is an unsigned integer */
435 MOD_IND, /* Is an unsigned integer, but no value => default */
436 MOD_NL, /* Is a newline value */
437 MOD_NN, /* Is a number or a name; more than one may occur */
438 MOD_OPT, /* Is an option bit */
439 MOD_SIZ, /* Is a PCRE2_SIZE value */
440 MOD_STR }; /* Is a string */
442 /* Control bits. Some apply to compiling, some to matching, but some can be set
443 either on a pattern or a data line, so they must all be distinct. There are now
444 so many of them that they are split into two fields. */
446 #define CTL_AFTERTEXT 0x00000001u
447 #define CTL_ALLAFTERTEXT 0x00000002u
448 #define CTL_ALLCAPTURES 0x00000004u
449 #define CTL_ALLUSEDTEXT 0x00000008u
450 #define CTL_ALTGLOBAL 0x00000010u
451 #define CTL_BINCODE 0x00000020u
452 #define CTL_CALLOUT_CAPTURE 0x00000040u
453 #define CTL_CALLOUT_INFO 0x00000080u
454 #define CTL_CALLOUT_NONE 0x00000100u
455 #define CTL_DFA 0x00000200u
456 #define CTL_EXPAND 0x00000400u
457 #define CTL_FINDLIMITS 0x00000800u
458 #define CTL_FRAMESIZE 0x00001000u
459 #define CTL_FULLBINCODE 0x00002000u
460 #define CTL_GETALL 0x00004000u
461 #define CTL_GLOBAL 0x00008000u
462 #define CTL_HEXPAT 0x00010000u /* Same word as USE_LENGTH */
463 #define CTL_INFO 0x00020000u
464 #define CTL_JITFAST 0x00040000u
465 #define CTL_JITVERIFY 0x00080000u
466 #define CTL_MARK 0x00100000u
467 #define CTL_MEMORY 0x00200000u
468 #define CTL_NULLCONTEXT 0x00400000u
469 #define CTL_POSIX 0x00800000u
470 #define CTL_POSIX_NOSUB 0x01000000u
471 #define CTL_PUSH 0x02000000u /* These three must be */
472 #define CTL_PUSHCOPY 0x04000000u /* all in the same */
473 #define CTL_PUSHTABLESCOPY 0x08000000u /* word. */
474 #define CTL_STARTCHAR 0x10000000u
475 #define CTL_USE_LENGTH 0x20000000u /* Same word as HEXPAT */
476 #define CTL_UTF8_INPUT 0x40000000u
477 #define CTL_ZERO_TERMINATE 0x80000000u
481 #define CTL_DEBUG (CTL_FULLBINCODE|CTL_INFO) /* For setting */
482 #define CTL_ANYINFO (CTL_DEBUG|CTL_BINCODE|CTL_CALLOUT_INFO)
483 #define CTL_ANYGLOB (CTL_ALTGLOBAL|CTL_GLOBAL)
485 /* Second control word */
487 #define CTL2_SUBSTITUTE_EXTENDED 0x00000001u
488 #define CTL2_SUBSTITUTE_OVERFLOW_LENGTH 0x00000002u
489 #define CTL2_SUBSTITUTE_UNKNOWN_UNSET 0x00000004u
490 #define CTL2_SUBSTITUTE_UNSET_EMPTY 0x00000008u
491 #define CTL2_SUBJECT_LITERAL 0x00000010u
492 #define CTL2_CALLOUT_NO_WHERE 0x00000020u
493 #define CTL2_CALLOUT_EXTRA 0x00000040u
495 #define CTL2_NL_SET 0x40000000u /* Informational */
496 #define CTL2_BSR_SET 0x80000000u /* Informational */
498 /* These are the matching controls that may be set either on a pattern or on a
499 data line. They are copied from the pattern controls as initial settings for
500 data line controls. Note that CTL_MEMORY is not included here, because it does
501 different things in the two cases. */
503 #define CTL_ALLPD (CTL_AFTERTEXT|\
513 #define CTL2_ALLPD (CTL2_SUBSTITUTE_EXTENDED|\
514 CTL2_SUBSTITUTE_OVERFLOW_LENGTH|\
515 CTL2_SUBSTITUTE_UNKNOWN_UNSET|\
516 CTL2_SUBSTITUTE_UNSET_EMPTY)
518 /* Structures for holding modifier information for patterns and subject strings
519 (data). Fields containing modifiers that can be set either for a pattern or a
520 subject must be at the start and in the same order in both cases so that the
521 same offset in the big table below works for both. */
523 typedef struct patctl { /* Structure for pattern modifiers. */
524 uint32_t options; /* Must be in same position as datctl */
525 uint32_t control; /* Must be in same position as datctl */
526 uint32_t control2; /* Must be in same position as datctl */
527 uint32_t jitstack; /* Must be in same position as datctl */
528 uint8_t replacement[REPLACE_MODSIZE]; /* So must this */
530 uint32_t stackguard_test;
532 uint32_t convert_type;
533 uint32_t convert_length;
534 uint32_t convert_glob_escape;
535 uint32_t convert_glob_separator;
536 uint32_t regerror_buffsize;
537 uint8_t locale[LOCALESIZE];
543 typedef struct datctl { /* Structure for data line modifiers. */
544 uint32_t options; /* Must be in same position as patctl */
545 uint32_t control; /* Must be in same position as patctl */
546 uint32_t control2; /* Must be in same position as patctl */
547 uint32_t jitstack; /* Must be in same position as patctl */
548 uint8_t replacement[REPLACE_MODSIZE]; /* So must this */
549 uint32_t startend[2];
552 int32_t callout_data;
553 int32_t copy_numbers[MAXCPYGET];
554 int32_t get_numbers[MAXCPYGET];
557 uint8_t copy_names[LENCPYGET];
558 uint8_t get_names[LENCPYGET];
561 /* Ids for which context to modify. */
563 enum { CTX_PAT, /* Active pattern context */
564 CTX_POPPAT, /* Ditto, for a popped pattern */
565 CTX_DEFPAT, /* Default pattern context */
566 CTX_DAT, /* Active data (match) context */
567 CTX_DEFDAT }; /* Default data (match) context */
569 /* Macros to simplify the big table below. */
571 #define CO(name) offsetof(PCRE2_REAL_COMPILE_CONTEXT, name)
572 #define MO(name) offsetof(PCRE2_REAL_MATCH_CONTEXT, name)
573 #define PO(name) offsetof(patctl, name)
574 #define PD(name) PO(name)
575 #define DO(name) offsetof(datctl, name)
577 /* Table of all long-form modifiers. Must be in collating sequence of modifier
578 name because it is searched by binary chop. */
580 typedef struct modstruct {
588 static modstruct modlist[] = {
589 { "aftertext", MOD_PNDP, MOD_CTL, CTL_AFTERTEXT, PO(control) },
590 { "allaftertext", MOD_PNDP, MOD_CTL, CTL_ALLAFTERTEXT, PO(control) },
591 { "allcaptures", MOD_PND, MOD_CTL, CTL_ALLCAPTURES, PO(control) },
592 { "allow_empty_class", MOD_PAT, MOD_OPT, PCRE2_ALLOW_EMPTY_CLASS, PO(options) },
593 { "allow_surrogate_escapes", MOD_CTC, MOD_OPT, PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES, CO(extra_options) },
594 { "allusedtext", MOD_PNDP, MOD_CTL, CTL_ALLUSEDTEXT, PO(control) },
595 { "alt_bsux", MOD_PAT, MOD_OPT, PCRE2_ALT_BSUX, PO(options) },
596 { "alt_circumflex", MOD_PAT, MOD_OPT, PCRE2_ALT_CIRCUMFLEX, PO(options) },
597 { "alt_verbnames", MOD_PAT, MOD_OPT, PCRE2_ALT_VERBNAMES, PO(options) },
598 { "altglobal", MOD_PND, MOD_CTL, CTL_ALTGLOBAL, PO(control) },
599 { "anchored", MOD_PD, MOD_OPT, PCRE2_ANCHORED, PD(options) },
600 { "auto_callout", MOD_PAT, MOD_OPT, PCRE2_AUTO_CALLOUT, PO(options) },
601 { "bad_escape_is_literal", MOD_CTC, MOD_OPT, PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL, CO(extra_options) },
602 { "bincode", MOD_PAT, MOD_CTL, CTL_BINCODE, PO(control) },
603 { "bsr", MOD_CTC, MOD_BSR, 0, CO(bsr_convention) },
604 { "callout_capture", MOD_DAT, MOD_CTL, CTL_CALLOUT_CAPTURE, DO(control) },
605 { "callout_data", MOD_DAT, MOD_INS, 0, DO(callout_data) },
606 { "callout_error", MOD_DAT, MOD_IN2, 0, DO(cerror) },
607 { "callout_extra", MOD_DAT, MOD_CTL, CTL2_CALLOUT_EXTRA, DO(control2) },
608 { "callout_fail", MOD_DAT, MOD_IN2, 0, DO(cfail) },
609 { "callout_info", MOD_PAT, MOD_CTL, CTL_CALLOUT_INFO, PO(control) },
610 { "callout_no_where", MOD_DAT, MOD_CTL, CTL2_CALLOUT_NO_WHERE, DO(control2) },
611 { "callout_none", MOD_DAT, MOD_CTL, CTL_CALLOUT_NONE, DO(control) },
612 { "caseless", MOD_PATP, MOD_OPT, PCRE2_CASELESS, PO(options) },
613 { "convert", MOD_PAT, MOD_CON, 0, PO(convert_type) },
614 { "convert_glob_escape", MOD_PAT, MOD_CHR, 0, PO(convert_glob_escape) },
615 { "convert_glob_separator", MOD_PAT, MOD_CHR, 0, PO(convert_glob_separator) },
616 { "convert_length", MOD_PAT, MOD_INT, 0, PO(convert_length) },
617 { "copy", MOD_DAT, MOD_NN, DO(copy_numbers), DO(copy_names) },
618 { "debug", MOD_PAT, MOD_CTL, CTL_DEBUG, PO(control) },
619 { "depth_limit", MOD_CTM, MOD_INT, 0, MO(depth_limit) },
620 { "dfa", MOD_DAT, MOD_CTL, CTL_DFA, DO(control) },
621 { "dfa_restart", MOD_DAT, MOD_OPT, PCRE2_DFA_RESTART, DO(options) },
622 { "dfa_shortest", MOD_DAT, MOD_OPT, PCRE2_DFA_SHORTEST, DO(options) },
623 { "dollar_endonly", MOD_PAT, MOD_OPT, PCRE2_DOLLAR_ENDONLY, PO(options) },
624 { "dotall", MOD_PATP, MOD_OPT, PCRE2_DOTALL, PO(options) },
625 { "dupnames", MOD_PATP, MOD_OPT, PCRE2_DUPNAMES, PO(options) },
626 { "endanchored", MOD_PD, MOD_OPT, PCRE2_ENDANCHORED, PD(options) },
627 { "expand", MOD_PAT, MOD_CTL, CTL_EXPAND, PO(control) },
628 { "extended", MOD_PATP, MOD_OPT, PCRE2_EXTENDED, PO(options) },
629 { "extended_more", MOD_PATP, MOD_OPT, PCRE2_EXTENDED_MORE, PO(options) },
630 { "find_limits", MOD_DAT, MOD_CTL, CTL_FINDLIMITS, DO(control) },
631 { "firstline", MOD_PAT, MOD_OPT, PCRE2_FIRSTLINE, PO(options) },
632 { "framesize", MOD_PAT, MOD_CTL, CTL_FRAMESIZE, PO(control) },
633 { "fullbincode", MOD_PAT, MOD_CTL, CTL_FULLBINCODE, PO(control) },
634 { "get", MOD_DAT, MOD_NN, DO(get_numbers), DO(get_names) },
635 { "getall", MOD_DAT, MOD_CTL, CTL_GETALL, DO(control) },
636 { "global", MOD_PNDP, MOD_CTL, CTL_GLOBAL, PO(control) },
637 { "heap_limit", MOD_CTM, MOD_INT, 0, MO(heap_limit) },
638 { "hex", MOD_PAT, MOD_CTL, CTL_HEXPAT, PO(control) },
639 { "info", MOD_PAT, MOD_CTL, CTL_INFO, PO(control) },
640 { "jit", MOD_PAT, MOD_IND, 7, PO(jit) },
641 { "jitfast", MOD_PAT, MOD_CTL, CTL_JITFAST, PO(control) },
642 { "jitstack", MOD_PNDP, MOD_INT, 0, PO(jitstack) },
643 { "jitverify", MOD_PAT, MOD_CTL, CTL_JITVERIFY, PO(control) },
644 { "literal", MOD_PAT, MOD_OPT, PCRE2_LITERAL, PO(options) },
645 { "locale", MOD_PAT, MOD_STR, LOCALESIZE, PO(locale) },
646 { "mark", MOD_PNDP, MOD_CTL, CTL_MARK, PO(control) },
647 { "match_limit", MOD_CTM, MOD_INT, 0, MO(match_limit) },
648 { "match_line", MOD_CTC, MOD_OPT, PCRE2_EXTRA_MATCH_LINE, CO(extra_options) },
649 { "match_unset_backref", MOD_PAT, MOD_OPT, PCRE2_MATCH_UNSET_BACKREF, PO(options) },
650 { "match_word", MOD_CTC, MOD_OPT, PCRE2_EXTRA_MATCH_WORD, CO(extra_options) },
651 { "max_pattern_length", MOD_CTC, MOD_SIZ, 0, CO(max_pattern_length) },
652 { "memory", MOD_PD, MOD_CTL, CTL_MEMORY, PD(control) },
653 { "multiline", MOD_PATP, MOD_OPT, PCRE2_MULTILINE, PO(options) },
654 { "never_backslash_c", MOD_PAT, MOD_OPT, PCRE2_NEVER_BACKSLASH_C, PO(options) },
655 { "never_ucp", MOD_PAT, MOD_OPT, PCRE2_NEVER_UCP, PO(options) },
656 { "never_utf", MOD_PAT, MOD_OPT, PCRE2_NEVER_UTF, PO(options) },
657 { "newline", MOD_CTC, MOD_NL, 0, CO(newline_convention) },
658 { "no_auto_capture", MOD_PAT, MOD_OPT, PCRE2_NO_AUTO_CAPTURE, PO(options) },
659 { "no_auto_possess", MOD_PATP, MOD_OPT, PCRE2_NO_AUTO_POSSESS, PO(options) },
660 { "no_dotstar_anchor", MOD_PAT, MOD_OPT, PCRE2_NO_DOTSTAR_ANCHOR, PO(options) },
661 { "no_jit", MOD_DAT, MOD_OPT, PCRE2_NO_JIT, DO(options) },
662 { "no_start_optimize", MOD_PATP, MOD_OPT, PCRE2_NO_START_OPTIMIZE, PO(options) },
663 { "no_utf_check", MOD_PD, MOD_OPT, PCRE2_NO_UTF_CHECK, PD(options) },
664 { "notbol", MOD_DAT, MOD_OPT, PCRE2_NOTBOL, DO(options) },
665 { "notempty", MOD_DAT, MOD_OPT, PCRE2_NOTEMPTY, DO(options) },
666 { "notempty_atstart", MOD_DAT, MOD_OPT, PCRE2_NOTEMPTY_ATSTART, DO(options) },
667 { "noteol", MOD_DAT, MOD_OPT, PCRE2_NOTEOL, DO(options) },
668 { "null_context", MOD_PD, MOD_CTL, CTL_NULLCONTEXT, PO(control) },
669 { "offset", MOD_DAT, MOD_INT, 0, DO(offset) },
670 { "offset_limit", MOD_CTM, MOD_SIZ, 0, MO(offset_limit)},
671 { "ovector", MOD_DAT, MOD_INT, 0, DO(oveccount) },
672 { "parens_nest_limit", MOD_CTC, MOD_INT, 0, CO(parens_nest_limit) },
673 { "partial_hard", MOD_DAT, MOD_OPT, PCRE2_PARTIAL_HARD, DO(options) },
674 { "partial_soft", MOD_DAT, MOD_OPT, PCRE2_PARTIAL_SOFT, DO(options) },
675 { "ph", MOD_DAT, MOD_OPT, PCRE2_PARTIAL_HARD, DO(options) },
676 { "posix", MOD_PAT, MOD_CTL, CTL_POSIX, PO(control) },
677 { "posix_nosub", MOD_PAT, MOD_CTL, CTL_POSIX|CTL_POSIX_NOSUB, PO(control) },
678 { "posix_startend", MOD_DAT, MOD_IN2, 0, DO(startend) },
679 { "ps", MOD_DAT, MOD_OPT, PCRE2_PARTIAL_SOFT, DO(options) },
680 { "push", MOD_PAT, MOD_CTL, CTL_PUSH, PO(control) },
681 { "pushcopy", MOD_PAT, MOD_CTL, CTL_PUSHCOPY, PO(control) },
682 { "pushtablescopy", MOD_PAT, MOD_CTL, CTL_PUSHTABLESCOPY, PO(control) },
683 { "recursion_limit", MOD_CTM, MOD_INT, 0, MO(depth_limit) }, /* Obsolete synonym */
684 { "regerror_buffsize", MOD_PAT, MOD_INT, 0, PO(regerror_buffsize) },
685 { "replace", MOD_PND, MOD_STR, REPLACE_MODSIZE, PO(replacement) },
686 { "stackguard", MOD_PAT, MOD_INT, 0, PO(stackguard_test) },
687 { "startchar", MOD_PND, MOD_CTL, CTL_STARTCHAR, PO(control) },
688 { "startoffset", MOD_DAT, MOD_INT, 0, DO(offset) },
689 { "subject_literal", MOD_PATP, MOD_CTL, CTL2_SUBJECT_LITERAL, PO(control2) },
690 { "substitute_extended", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_EXTENDED, PO(control2) },
691 { "substitute_overflow_length", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_OVERFLOW_LENGTH, PO(control2) },
692 { "substitute_unknown_unset", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_UNKNOWN_UNSET, PO(control2) },
693 { "substitute_unset_empty", MOD_PND, MOD_CTL, CTL2_SUBSTITUTE_UNSET_EMPTY, PO(control2) },
694 { "tables", MOD_PAT, MOD_INT, 0, PO(tables_id) },
695 { "ucp", MOD_PATP, MOD_OPT, PCRE2_UCP, PO(options) },
696 { "ungreedy", MOD_PAT, MOD_OPT, PCRE2_UNGREEDY, PO(options) },
697 { "use_length", MOD_PAT, MOD_CTL, CTL_USE_LENGTH, PO(control) },
698 { "use_offset_limit", MOD_PAT, MOD_OPT, PCRE2_USE_OFFSET_LIMIT, PO(options) },
699 { "utf", MOD_PATP, MOD_OPT, PCRE2_UTF, PO(options) },
700 { "utf8_input", MOD_PAT, MOD_CTL, CTL_UTF8_INPUT, PO(control) },
701 { "zero_terminate", MOD_DAT, MOD_CTL, CTL_ZERO_TERMINATE, DO(control) }
704 #define MODLISTCOUNT sizeof(modlist)/sizeof(modstruct)
706 /* Controls and options that are supported for use with the POSIX interface. */
708 #define POSIX_SUPPORTED_COMPILE_OPTIONS ( \
709 PCRE2_CASELESS|PCRE2_DOTALL|PCRE2_LITERAL|PCRE2_MULTILINE|PCRE2_UCP| \
710 PCRE2_UTF|PCRE2_UNGREEDY)
712 #define POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS (0)
714 #define POSIX_SUPPORTED_COMPILE_CONTROLS ( \
715 CTL_AFTERTEXT|CTL_ALLAFTERTEXT|CTL_EXPAND|CTL_HEXPAT|CTL_POSIX| \
716 CTL_POSIX_NOSUB|CTL_USE_LENGTH)
718 #define POSIX_SUPPORTED_COMPILE_CONTROLS2 (0)
720 #define POSIX_SUPPORTED_MATCH_OPTIONS ( \
721 PCRE2_NOTBOL|PCRE2_NOTEMPTY|PCRE2_NOTEOL)
723 #define POSIX_SUPPORTED_MATCH_CONTROLS (CTL_AFTERTEXT|CTL_ALLAFTERTEXT)
724 #define POSIX_SUPPORTED_MATCH_CONTROLS2 (0)
726 /* Control bits that are not ignored with 'push'. */
728 #define PUSH_SUPPORTED_COMPILE_CONTROLS ( \
729 CTL_BINCODE|CTL_CALLOUT_INFO|CTL_FULLBINCODE|CTL_HEXPAT|CTL_INFO| \
730 CTL_JITVERIFY|CTL_MEMORY|CTL_FRAMESIZE|CTL_PUSH|CTL_PUSHCOPY| \
731 CTL_PUSHTABLESCOPY|CTL_USE_LENGTH)
733 #define PUSH_SUPPORTED_COMPILE_CONTROLS2 (CTL2_BSR_SET|CTL2_NL_SET)
735 /* Controls that apply only at compile time with 'push'. */
737 #define PUSH_COMPILE_ONLY_CONTROLS CTL_JITVERIFY
738 #define PUSH_COMPILE_ONLY_CONTROLS2 (0)
740 /* Controls that are forbidden with #pop or #popcopy. */
742 #define NOTPOP_CONTROLS (CTL_HEXPAT|CTL_POSIX|CTL_POSIX_NOSUB|CTL_PUSH| \
743 CTL_PUSHCOPY|CTL_PUSHTABLESCOPY|CTL_USE_LENGTH)
745 /* Pattern controls that are mutually exclusive. At present these are all in
746 the first control word. Note that CTL_POSIX_NOSUB is always accompanied by
747 CTL_POSIX, so it doesn't need its own entries. */
749 static uint32_t exclusive_pat_controls[] = {
750 CTL_POSIX | CTL_PUSH,
751 CTL_POSIX | CTL_PUSHCOPY,
752 CTL_POSIX | CTL_PUSHTABLESCOPY,
753 CTL_PUSH | CTL_PUSHCOPY,
754 CTL_PUSH | CTL_PUSHTABLESCOPY,
755 CTL_PUSHCOPY | CTL_PUSHTABLESCOPY,
756 CTL_EXPAND | CTL_HEXPAT };
758 /* Data controls that are mutually exclusive. At present these are all in the
759 first control word. */
761 static uint32_t exclusive_dat_controls[] = {
762 CTL_ALLUSEDTEXT | CTL_STARTCHAR,
763 CTL_FINDLIMITS | CTL_NULLCONTEXT };
765 /* Table of single-character abbreviated modifiers. The index field is
766 initialized to -1, but the first time the modifier is encountered, it is filled
767 in with the index of the full entry in modlist, to save repeated searching when
768 processing multiple test items. This short list is searched serially, so its
769 order does not matter. */
771 typedef struct c1modstruct {
772 const char *fullname;
777 static c1modstruct c1modlist[] = {
778 { "bincode", 'B', -1 },
780 { "global", 'g', -1 },
781 { "caseless", 'i', -1 },
782 { "multiline", 'm', -1 },
783 { "no_auto_capture", 'n', -1 },
784 { "dotall", 's', -1 },
785 { "extended", 'x', -1 }
788 #define C1MODLISTCOUNT sizeof(c1modlist)/sizeof(c1modstruct)
790 /* Table of arguments for the -C command line option. Use macros to make the
791 table itself easier to read. */
793 #if defined SUPPORT_PCRE2_8
796 #if defined SUPPORT_PCRE2_16
799 #if defined SUPPORT_PCRE2_32
814 #define SUPPORT_EBCDIC 1
815 #define EBCDIC_NL CHAR_LF
817 #define SUPPORT_EBCDIC 0
821 #ifdef NEVER_BACKSLASH_C
822 #define BACKSLASH_C 0
824 #define BACKSLASH_C 1
827 typedef struct coptstruct {
840 static coptstruct coptlist[] = {
841 { "backslash-C", CONF_FIX, BACKSLASH_C },
842 { "bsr", CONF_BSR, PCRE2_CONFIG_BSR },
843 { "ebcdic", CONF_FIX, SUPPORT_EBCDIC },
844 { "ebcdic-nl", CONF_FIZ, EBCDIC_NL },
845 { "jit", CONF_INT, PCRE2_CONFIG_JIT },
846 { "linksize", CONF_INT, PCRE2_CONFIG_LINKSIZE },
847 { "newline", CONF_NL, PCRE2_CONFIG_NEWLINE },
848 { "pcre2-16", CONF_FIX, SUPPORT_16 },
849 { "pcre2-32", CONF_FIX, SUPPORT_32 },
850 { "pcre2-8", CONF_FIX, SUPPORT_8 },
851 { "unicode", CONF_INT, PCRE2_CONFIG_UNICODE }
854 #define COPTLISTCOUNT sizeof(coptlist)/sizeof(coptstruct)
859 #undef SUPPORT_EBCDIC
862 /* ----------------------- Static variables ------------------------ */
865 static FILE *outfile;
867 static const void *last_callout_mark;
868 static PCRE2_JIT_STACK *jit_stack = NULL;
869 static size_t jit_stack_size = 0;
871 static BOOL first_callout;
872 static BOOL jit_was_used;
873 static BOOL restrict_for_perl_test = FALSE;
874 static BOOL show_memory = FALSE;
876 static int code_unit_size; /* Bytes */
877 static int jitrc; /* Return from JIT compile */
878 static int test_mode = DEFAULT_TEST_MODE;
879 static int timeit = 0;
880 static int timeitm = 0;
882 clock_t total_compile_time = 0;
883 clock_t total_jit_compile_time = 0;
884 clock_t total_match_time = 0;
886 static uint32_t dfa_matched;
887 static uint32_t forbid_utf = 0;
888 static uint32_t maxlookbehind;
889 static uint32_t max_oveccount;
890 static uint32_t callout_count;
892 static uint16_t local_newline_default = 0;
894 static VERSION_TYPE jittarget[VERSION_SIZE];
895 static VERSION_TYPE version[VERSION_SIZE];
896 static VERSION_TYPE uversion[VERSION_SIZE];
898 static patctl def_patctl;
899 static patctl pat_patctl;
900 static datctl def_datctl;
901 static datctl dat_datctl;
903 static void *patstack[PATSTACKSIZE];
904 static int patstacknext = 0;
906 static void *malloclist[MALLOCLISTSIZE];
907 static PCRE2_SIZE malloclistlength[MALLOCLISTSIZE];
908 static uint32_t malloclistptr = 0;
910 #ifdef SUPPORT_PCRE2_8
911 static regex_t preg = { NULL, NULL, 0, 0, 0, 0 };
914 static int *dfa_workspace = NULL;
915 static const uint8_t *locale_tables = NULL;
916 static const uint8_t *use_tables = NULL;
917 static uint8_t locale_name[32];
919 /* We need buffers for building 16/32-bit strings; 8-bit strings don't need
920 rebuilding, but set up the same naming scheme for use in macros. The "buffer"
921 buffer is where all input lines are read. Its size is the same as pbuffer8.
922 Pattern lines are always copied to pbuffer8 for use in callouts, even if they
923 are actually compiled from pbuffer16 or pbuffer32. */
925 static size_t pbuffer8_size = 50000; /* Initial size, bytes */
926 static uint8_t *pbuffer8 = NULL;
927 static uint8_t *buffer = NULL;
929 /* The dbuffer is where all processed data lines are put. In non-8-bit modes it
930 is cast as needed. For long data lines it grows as necessary. */
932 static size_t dbuffer_size = 1u << 14; /* Initial size, bytes */
933 static uint8_t *dbuffer = NULL;
936 /* ---------------- Mode-dependent variables -------------------*/
938 #ifdef SUPPORT_PCRE2_8
939 static pcre2_code_8 *compiled_code8;
940 static pcre2_general_context_8 *general_context8, *general_context_copy8;
941 static pcre2_compile_context_8 *pat_context8, *default_pat_context8;
942 static pcre2_convert_context_8 *con_context8, *default_con_context8;
943 static pcre2_match_context_8 *dat_context8, *default_dat_context8;
944 static pcre2_match_data_8 *match_data8;
947 #ifdef SUPPORT_PCRE2_16
948 static pcre2_code_16 *compiled_code16;
949 static pcre2_general_context_16 *general_context16, *general_context_copy16;
950 static pcre2_compile_context_16 *pat_context16, *default_pat_context16;
951 static pcre2_convert_context_16 *con_context16, *default_con_context16;
952 static pcre2_match_context_16 *dat_context16, *default_dat_context16;
953 static pcre2_match_data_16 *match_data16;
954 static PCRE2_SIZE pbuffer16_size = 0; /* Set only when needed */
955 static uint16_t *pbuffer16 = NULL;
958 #ifdef SUPPORT_PCRE2_32
959 static pcre2_code_32 *compiled_code32;
960 static pcre2_general_context_32 *general_context32, *general_context_copy32;
961 static pcre2_compile_context_32 *pat_context32, *default_pat_context32;
962 static pcre2_convert_context_32 *con_context32, *default_con_context32;
963 static pcre2_match_context_32 *dat_context32, *default_dat_context32;
964 static pcre2_match_data_32 *match_data32;
965 static PCRE2_SIZE pbuffer32_size = 0; /* Set only when needed */
966 static uint32_t *pbuffer32 = NULL;
970 /* ---------------- Macros that work in all modes ----------------- */
972 #define CAST8VAR(x) CASTVAR(uint8_t *, x)
973 #define SET(x,y) SETOP(x,y,=)
974 #define SETPLUS(x,y) SETOP(x,y,+=)
975 #define strlen8(x) strlen((char *)x)
978 /* ---------------- Mode-dependent, runtime-testing macros ------------------*/
980 /* Define macros for variables and functions that must be selected dynamically
981 depending on the mode setting (8, 16, 32). These are dependent on which modes
984 #if (defined (SUPPORT_PCRE2_8) + defined (SUPPORT_PCRE2_16) + \
985 defined (SUPPORT_PCRE2_32)) >= 2
987 /* ----- All three modes supported ----- */
989 #if defined(SUPPORT_PCRE2_8) && defined(SUPPORT_PCRE2_16) && defined(SUPPORT_PCRE2_32)
991 #define CASTFLD(t,a,b) ((test_mode == PCRE8_MODE)? (t)(G(a,8)->b) : \
992 (test_mode == PCRE16_MODE)? (t)(G(a,16)->b) : (t)(G(a,32)->b))
994 #define CASTVAR(t,x) ( \
995 (test_mode == PCRE8_MODE)? (t)G(x,8) : \
996 (test_mode == PCRE16_MODE)? (t)G(x,16) : (t)G(x,32))
998 #define CODE_UNIT(a,b) ( \
999 (test_mode == PCRE8_MODE)? (uint32_t)(((PCRE2_SPTR8)(a))[b]) : \
1000 (test_mode == PCRE16_MODE)? (uint32_t)(((PCRE2_SPTR16)(a))[b]) : \
1001 (uint32_t)(((PCRE2_SPTR32)(a))[b]))
1003 #define CONCTXCPY(a,b) \
1004 if (test_mode == PCRE8_MODE) \
1005 memcpy(G(a,8),G(b,8),sizeof(pcre2_convert_context_8)); \
1006 else if (test_mode == PCRE16_MODE) \
1007 memcpy(G(a,16),G(b,16),sizeof(pcre2_convert_context_16)); \
1008 else memcpy(G(a,32),G(b,32),sizeof(pcre2_convert_context_32))
1010 #define CONVERT_COPY(a,b,c) \
1011 if (test_mode == PCRE8_MODE) \
1012 memcpy(G(a,8),(char *)b,c); \
1013 else if (test_mode == PCRE16_MODE) \
1014 memcpy(G(a,16),(char *)b,(c)*2); \
1015 else if (test_mode == PCRE32_MODE) \
1016 memcpy(G(a,32),(char *)b,(c)*4)
1018 #define DATCTXCPY(a,b) \
1019 if (test_mode == PCRE8_MODE) \
1020 memcpy(G(a,8),G(b,8),sizeof(pcre2_match_context_8)); \
1021 else if (test_mode == PCRE16_MODE) \
1022 memcpy(G(a,16),G(b,16),sizeof(pcre2_match_context_16)); \
1023 else memcpy(G(a,32),G(b,32),sizeof(pcre2_match_context_32))
1025 #define FLD(a,b) ((test_mode == PCRE8_MODE)? G(a,8)->b : \
1026 (test_mode == PCRE16_MODE)? G(a,16)->b : G(a,32)->b)
1028 #define PATCTXCPY(a,b) \
1029 if (test_mode == PCRE8_MODE) \
1030 memcpy(G(a,8),G(b,8),sizeof(pcre2_compile_context_8)); \
1031 else if (test_mode == PCRE16_MODE) \
1032 memcpy(G(a,16),G(b,16),sizeof(pcre2_compile_context_16)); \
1033 else memcpy(G(a,32),G(b,32),sizeof(pcre2_compile_context_32))
1035 #define PCHARS(lv, p, offset, len, utf, f) \
1036 if (test_mode == PCRE32_MODE) \
1037 lv = pchars32((PCRE2_SPTR32)(p)+offset, len, utf, f); \
1038 else if (test_mode == PCRE16_MODE) \
1039 lv = pchars16((PCRE2_SPTR16)(p)+offset, len, utf, f); \
1041 lv = pchars8((PCRE2_SPTR8)(p)+offset, len, utf, f)
1043 #define PCHARSV(p, offset, len, utf, f) \
1044 if (test_mode == PCRE32_MODE) \
1045 (void)pchars32((PCRE2_SPTR32)(p)+offset, len, utf, f); \
1046 else if (test_mode == PCRE16_MODE) \
1047 (void)pchars16((PCRE2_SPTR16)(p)+offset, len, utf, f); \
1049 (void)pchars8((PCRE2_SPTR8)(p)+offset, len, utf, f)
1051 #define PCRE2_CALLOUT_ENUMERATE(a,b,c) \
1052 if (test_mode == PCRE8_MODE) \
1053 a = pcre2_callout_enumerate_8(compiled_code8, \
1054 (int (*)(struct pcre2_callout_enumerate_block_8 *, void *))b,c); \
1055 else if (test_mode == PCRE16_MODE) \
1056 a = pcre2_callout_enumerate_16(compiled_code16, \
1057 (int(*)(struct pcre2_callout_enumerate_block_16 *, void *))b,c); \
1059 a = pcre2_callout_enumerate_32(compiled_code32, \
1060 (int (*)(struct pcre2_callout_enumerate_block_32 *, void *))b,c)
1062 #define PCRE2_CODE_COPY_FROM_VOID(a,b) \
1063 if (test_mode == PCRE8_MODE) \
1064 G(a,8) = pcre2_code_copy_8(b); \
1065 else if (test_mode == PCRE16_MODE) \
1066 G(a,16) = pcre2_code_copy_16(b); \
1068 G(a,32) = pcre2_code_copy_32(b)
1070 #define PCRE2_CODE_COPY_TO_VOID(a,b) \
1071 if (test_mode == PCRE8_MODE) \
1072 a = (void *)pcre2_code_copy_8(G(b,8)); \
1073 else if (test_mode == PCRE16_MODE) \
1074 a = (void *)pcre2_code_copy_16(G(b,16)); \
1076 a = (void *)pcre2_code_copy_32(G(b,32))
1078 #define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) \
1079 if (test_mode == PCRE8_MODE) \
1080 a = (void *)pcre2_code_copy_with_tables_8(G(b,8)); \
1081 else if (test_mode == PCRE16_MODE) \
1082 a = (void *)pcre2_code_copy_with_tables_16(G(b,16)); \
1084 a = (void *)pcre2_code_copy_with_tables_32(G(b,32))
1086 #define PCRE2_COMPILE(a,b,c,d,e,f,g) \
1087 if (test_mode == PCRE8_MODE) \
1088 G(a,8) = pcre2_compile_8(G(b,8),c,d,e,f,g); \
1089 else if (test_mode == PCRE16_MODE) \
1090 G(a,16) = pcre2_compile_16(G(b,16),c,d,e,f,g); \
1092 G(a,32) = pcre2_compile_32(G(b,32),c,d,e,f,g)
1094 #define PCRE2_CONVERTED_PATTERN_FREE(a) \
1095 if (test_mode == PCRE8_MODE) pcre2_converted_pattern_free_8((PCRE2_UCHAR8 *)a); \
1096 else if (test_mode == PCRE16_MODE) pcre2_converted_pattern_free_16((PCRE2_UCHAR16 *)a); \
1097 else pcre2_converted_pattern_free_32((PCRE2_UCHAR32 *)a)
1099 #define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \
1100 if (test_mode == PCRE8_MODE) \
1101 a = pcre2_dfa_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h,i,j); \
1102 else if (test_mode == PCRE16_MODE) \
1103 a = pcre2_dfa_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h,i,j); \
1105 a = pcre2_dfa_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h,i,j)
1107 #define PCRE2_GET_ERROR_MESSAGE(r,a,b) \
1108 if (test_mode == PCRE8_MODE) \
1109 r = pcre2_get_error_message_8(a,G(b,8),G(G(b,8),_size)); \
1110 else if (test_mode == PCRE16_MODE) \
1111 r = pcre2_get_error_message_16(a,G(b,16),G(G(b,16),_size/2)); \
1113 r = pcre2_get_error_message_32(a,G(b,32),G(G(b,32),_size/4))
1115 #define PCRE2_GET_OVECTOR_COUNT(a,b) \
1116 if (test_mode == PCRE8_MODE) \
1117 a = pcre2_get_ovector_count_8(G(b,8)); \
1118 else if (test_mode == PCRE16_MODE) \
1119 a = pcre2_get_ovector_count_16(G(b,16)); \
1121 a = pcre2_get_ovector_count_32(G(b,32))
1123 #define PCRE2_GET_STARTCHAR(a,b) \
1124 if (test_mode == PCRE8_MODE) \
1125 a = pcre2_get_startchar_8(G(b,8)); \
1126 else if (test_mode == PCRE16_MODE) \
1127 a = pcre2_get_startchar_16(G(b,16)); \
1129 a = pcre2_get_startchar_32(G(b,32))
1131 #define PCRE2_JIT_COMPILE(r,a,b) \
1132 if (test_mode == PCRE8_MODE) r = pcre2_jit_compile_8(G(a,8),b); \
1133 else if (test_mode == PCRE16_MODE) r = pcre2_jit_compile_16(G(a,16),b); \
1134 else r = pcre2_jit_compile_32(G(a,32),b)
1136 #define PCRE2_JIT_FREE_UNUSED_MEMORY(a) \
1137 if (test_mode == PCRE8_MODE) pcre2_jit_free_unused_memory_8(G(a,8)); \
1138 else if (test_mode == PCRE16_MODE) pcre2_jit_free_unused_memory_16(G(a,16)); \
1139 else pcre2_jit_free_unused_memory_32(G(a,32))
1141 #define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \
1142 if (test_mode == PCRE8_MODE) \
1143 a = pcre2_jit_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h); \
1144 else if (test_mode == PCRE16_MODE) \
1145 a = pcre2_jit_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h); \
1147 a = pcre2_jit_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h)
1149 #define PCRE2_JIT_STACK_CREATE(a,b,c,d) \
1150 if (test_mode == PCRE8_MODE) \
1151 a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_8(b,c,d); \
1152 else if (test_mode == PCRE16_MODE) \
1153 a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_16(b,c,d); \
1155 a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_32(b,c,d);
1157 #define PCRE2_JIT_STACK_ASSIGN(a,b,c) \
1158 if (test_mode == PCRE8_MODE) \
1159 pcre2_jit_stack_assign_8(G(a,8),(pcre2_jit_callback_8)b,c); \
1160 else if (test_mode == PCRE16_MODE) \
1161 pcre2_jit_stack_assign_16(G(a,16),(pcre2_jit_callback_16)b,c); \
1163 pcre2_jit_stack_assign_32(G(a,32),(pcre2_jit_callback_32)b,c);
1165 #define PCRE2_JIT_STACK_FREE(a) \
1166 if (test_mode == PCRE8_MODE) \
1167 pcre2_jit_stack_free_8((pcre2_jit_stack_8 *)a); \
1168 else if (test_mode == PCRE16_MODE) \
1169 pcre2_jit_stack_free_16((pcre2_jit_stack_16 *)a); \
1171 pcre2_jit_stack_free_32((pcre2_jit_stack_32 *)a);
1173 #define PCRE2_MAKETABLES(a) \
1174 if (test_mode == PCRE8_MODE) a = pcre2_maketables_8(NULL); \
1175 else if (test_mode == PCRE16_MODE) a = pcre2_maketables_16(NULL); \
1176 else a = pcre2_maketables_32(NULL)
1178 #define PCRE2_MATCH(a,b,c,d,e,f,g,h) \
1179 if (test_mode == PCRE8_MODE) \
1180 a = pcre2_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h); \
1181 else if (test_mode == PCRE16_MODE) \
1182 a = pcre2_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h); \
1184 a = pcre2_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h)
1186 #define PCRE2_MATCH_DATA_CREATE(a,b,c) \
1187 if (test_mode == PCRE8_MODE) \
1188 G(a,8) = pcre2_match_data_create_8(b,c); \
1189 else if (test_mode == PCRE16_MODE) \
1190 G(a,16) = pcre2_match_data_create_16(b,c); \
1192 G(a,32) = pcre2_match_data_create_32(b,c)
1194 #define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
1195 if (test_mode == PCRE8_MODE) \
1196 G(a,8) = pcre2_match_data_create_from_pattern_8(G(b,8),c); \
1197 else if (test_mode == PCRE16_MODE) \
1198 G(a,16) = pcre2_match_data_create_from_pattern_16(G(b,16),c); \
1200 G(a,32) = pcre2_match_data_create_from_pattern_32(G(b,32),c)
1202 #define PCRE2_MATCH_DATA_FREE(a) \
1203 if (test_mode == PCRE8_MODE) \
1204 pcre2_match_data_free_8(G(a,8)); \
1205 else if (test_mode == PCRE16_MODE) \
1206 pcre2_match_data_free_16(G(a,16)); \
1208 pcre2_match_data_free_32(G(a,32))
1210 #define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) \
1211 if (test_mode == PCRE8_MODE) \
1212 a = pcre2_pattern_convert_8(G(b,8),c,d,(PCRE2_UCHAR8 **)e,f,G(g,8)); \
1213 else if (test_mode == PCRE16_MODE) \
1214 a = pcre2_pattern_convert_16(G(b,16),c,d,(PCRE2_UCHAR16 **)e,f,G(g,16)); \
1216 a = pcre2_pattern_convert_32(G(b,32),c,d,(PCRE2_UCHAR32 **)e,f,G(g,32))
1218 #define PCRE2_PATTERN_INFO(a,b,c,d) \
1219 if (test_mode == PCRE8_MODE) \
1220 a = pcre2_pattern_info_8(G(b,8),c,d); \
1221 else if (test_mode == PCRE16_MODE) \
1222 a = pcre2_pattern_info_16(G(b,16),c,d); \
1224 a = pcre2_pattern_info_32(G(b,32),c,d)
1226 #define PCRE2_PRINTINT(a) \
1227 if (test_mode == PCRE8_MODE) \
1228 pcre2_printint_8(compiled_code8,outfile,a); \
1229 else if (test_mode == PCRE16_MODE) \
1230 pcre2_printint_16(compiled_code16,outfile,a); \
1232 pcre2_printint_32(compiled_code32,outfile,a)
1234 #define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \
1235 if (test_mode == PCRE8_MODE) \
1236 r = pcre2_serialize_decode_8((pcre2_code_8 **)a,b,c,G(d,8)); \
1237 else if (test_mode == PCRE16_MODE) \
1238 r = pcre2_serialize_decode_16((pcre2_code_16 **)a,b,c,G(d,16)); \
1240 r = pcre2_serialize_decode_32((pcre2_code_32 **)a,b,c,G(d,32))
1242 #define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \
1243 if (test_mode == PCRE8_MODE) \
1244 r = pcre2_serialize_encode_8((const pcre2_code_8 **)a,b,c,d,G(e,8)); \
1245 else if (test_mode == PCRE16_MODE) \
1246 r = pcre2_serialize_encode_16((const pcre2_code_16 **)a,b,c,d,G(e,16)); \
1248 r = pcre2_serialize_encode_32((const pcre2_code_32 **)a,b,c,d,G(e,32))
1250 #define PCRE2_SERIALIZE_FREE(a) \
1251 if (test_mode == PCRE8_MODE) \
1252 pcre2_serialize_free_8(a); \
1253 else if (test_mode == PCRE16_MODE) \
1254 pcre2_serialize_free_16(a); \
1256 pcre2_serialize_free_32(a)
1258 #define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \
1259 if (test_mode == PCRE8_MODE) \
1260 r = pcre2_serialize_get_number_of_codes_8(a); \
1261 else if (test_mode == PCRE16_MODE) \
1262 r = pcre2_serialize_get_number_of_codes_16(a); \
1264 r = pcre2_serialize_get_number_of_codes_32(a); \
1266 #define PCRE2_SET_CALLOUT(a,b,c) \
1267 if (test_mode == PCRE8_MODE) \
1268 pcre2_set_callout_8(G(a,8),(int (*)(pcre2_callout_block_8 *, void *))b,c); \
1269 else if (test_mode == PCRE16_MODE) \
1270 pcre2_set_callout_16(G(a,16),(int (*)(pcre2_callout_block_16 *, void *))b,c); \
1272 pcre2_set_callout_32(G(a,32),(int (*)(pcre2_callout_block_32 *, void *))b,c);
1274 #define PCRE2_SET_CHARACTER_TABLES(a,b) \
1275 if (test_mode == PCRE8_MODE) \
1276 pcre2_set_character_tables_8(G(a,8),b); \
1277 else if (test_mode == PCRE16_MODE) \
1278 pcre2_set_character_tables_16(G(a,16),b); \
1280 pcre2_set_character_tables_32(G(a,32),b)
1282 #define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \
1283 if (test_mode == PCRE8_MODE) \
1284 pcre2_set_compile_recursion_guard_8(G(a,8),b,c); \
1285 else if (test_mode == PCRE16_MODE) \
1286 pcre2_set_compile_recursion_guard_16(G(a,16),b,c); \
1288 pcre2_set_compile_recursion_guard_32(G(a,32),b,c)
1290 #define PCRE2_SET_DEPTH_LIMIT(a,b) \
1291 if (test_mode == PCRE8_MODE) \
1292 pcre2_set_depth_limit_8(G(a,8),b); \
1293 else if (test_mode == PCRE16_MODE) \
1294 pcre2_set_depth_limit_16(G(a,16),b); \
1296 pcre2_set_depth_limit_32(G(a,32),b)
1298 #define PCRE2_SET_GLOB_SEPARATOR(r,a,b) \
1299 if (test_mode == PCRE8_MODE) \
1300 r = pcre2_set_glob_separator_8(G(a,8),b); \
1301 else if (test_mode == PCRE16_MODE) \
1302 r = pcre2_set_glob_separator_16(G(a,16),b); \
1304 r = pcre2_set_glob_separator_32(G(a,32),b)
1306 #define PCRE2_SET_GLOB_ESCAPE(r,a,b) \
1307 if (test_mode == PCRE8_MODE) \
1308 r = pcre2_set_glob_escape_8(G(a,8),b); \
1309 else if (test_mode == PCRE16_MODE) \
1310 r = pcre2_set_glob_escape_16(G(a,16),b); \
1312 r = pcre2_set_glob_escape_32(G(a,32),b)
1314 #define PCRE2_SET_HEAP_LIMIT(a,b) \
1315 if (test_mode == PCRE8_MODE) \
1316 pcre2_set_heap_limit_8(G(a,8),b); \
1317 else if (test_mode == PCRE16_MODE) \
1318 pcre2_set_heap_limit_16(G(a,16),b); \
1320 pcre2_set_heap_limit_32(G(a,32),b)
1322 #define PCRE2_SET_MATCH_LIMIT(a,b) \
1323 if (test_mode == PCRE8_MODE) \
1324 pcre2_set_match_limit_8(G(a,8),b); \
1325 else if (test_mode == PCRE16_MODE) \
1326 pcre2_set_match_limit_16(G(a,16),b); \
1328 pcre2_set_match_limit_32(G(a,32),b)
1330 #define PCRE2_SET_MAX_PATTERN_LENGTH(a,b) \
1331 if (test_mode == PCRE8_MODE) \
1332 pcre2_set_max_pattern_length_8(G(a,8),b); \
1333 else if (test_mode == PCRE16_MODE) \
1334 pcre2_set_max_pattern_length_16(G(a,16),b); \
1336 pcre2_set_max_pattern_length_32(G(a,32),b)
1338 #define PCRE2_SET_OFFSET_LIMIT(a,b) \
1339 if (test_mode == PCRE8_MODE) \
1340 pcre2_set_offset_limit_8(G(a,8),b); \
1341 else if (test_mode == PCRE16_MODE) \
1342 pcre2_set_offset_limit_16(G(a,16),b); \
1344 pcre2_set_offset_limit_32(G(a,32),b)
1346 #define PCRE2_SET_PARENS_NEST_LIMIT(a,b) \
1347 if (test_mode == PCRE8_MODE) \
1348 pcre2_set_parens_nest_limit_8(G(a,8),b); \
1349 else if (test_mode == PCRE16_MODE) \
1350 pcre2_set_parens_nest_limit_16(G(a,16),b); \
1352 pcre2_set_parens_nest_limit_32(G(a,32),b)
1354 #define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \
1355 if (test_mode == PCRE8_MODE) \
1356 a = pcre2_substitute_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),G(h,8), \
1357 (PCRE2_SPTR8)i,j,(PCRE2_UCHAR8 *)k,l); \
1358 else if (test_mode == PCRE16_MODE) \
1359 a = pcre2_substitute_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),G(h,16), \
1360 (PCRE2_SPTR16)i,j,(PCRE2_UCHAR16 *)k,l); \
1362 a = pcre2_substitute_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),G(h,32), \
1363 (PCRE2_SPTR32)i,j,(PCRE2_UCHAR32 *)k,l)
1365 #define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \
1366 if (test_mode == PCRE8_MODE) \
1367 a = pcre2_substring_copy_byname_8(G(b,8),G(c,8),(PCRE2_UCHAR8 *)d,e); \
1368 else if (test_mode == PCRE16_MODE) \
1369 a = pcre2_substring_copy_byname_16(G(b,16),G(c,16),(PCRE2_UCHAR16 *)d,e); \
1371 a = pcre2_substring_copy_byname_32(G(b,32),G(c,32),(PCRE2_UCHAR32 *)d,e)
1373 #define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \
1374 if (test_mode == PCRE8_MODE) \
1375 a = pcre2_substring_copy_bynumber_8(G(b,8),c,(PCRE2_UCHAR8 *)d,e); \
1376 else if (test_mode == PCRE16_MODE) \
1377 a = pcre2_substring_copy_bynumber_16(G(b,16),c,(PCRE2_UCHAR16 *)d,e); \
1379 a = pcre2_substring_copy_bynumber_32(G(b,32),c,(PCRE2_UCHAR32 *)d,e)
1381 #define PCRE2_SUBSTRING_FREE(a) \
1382 if (test_mode == PCRE8_MODE) pcre2_substring_free_8((PCRE2_UCHAR8 *)a); \
1383 else if (test_mode == PCRE16_MODE) \
1384 pcre2_substring_free_16((PCRE2_UCHAR16 *)a); \
1385 else pcre2_substring_free_32((PCRE2_UCHAR32 *)a)
1387 #define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \
1388 if (test_mode == PCRE8_MODE) \
1389 a = pcre2_substring_get_byname_8(G(b,8),G(c,8),(PCRE2_UCHAR8 **)d,e); \
1390 else if (test_mode == PCRE16_MODE) \
1391 a = pcre2_substring_get_byname_16(G(b,16),G(c,16),(PCRE2_UCHAR16 **)d,e); \
1393 a = pcre2_substring_get_byname_32(G(b,32),G(c,32),(PCRE2_UCHAR32 **)d,e)
1395 #define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \
1396 if (test_mode == PCRE8_MODE) \
1397 a = pcre2_substring_get_bynumber_8(G(b,8),c,(PCRE2_UCHAR8 **)d,e); \
1398 else if (test_mode == PCRE16_MODE) \
1399 a = pcre2_substring_get_bynumber_16(G(b,16),c,(PCRE2_UCHAR16 **)d,e); \
1401 a = pcre2_substring_get_bynumber_32(G(b,32),c,(PCRE2_UCHAR32 **)d,e)
1403 #define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \
1404 if (test_mode == PCRE8_MODE) \
1405 a = pcre2_substring_length_byname_8(G(b,8),G(c,8),d); \
1406 else if (test_mode == PCRE16_MODE) \
1407 a = pcre2_substring_length_byname_16(G(b,16),G(c,16),d); \
1409 a = pcre2_substring_length_byname_32(G(b,32),G(c,32),d)
1411 #define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \
1412 if (test_mode == PCRE8_MODE) \
1413 a = pcre2_substring_length_bynumber_8(G(b,8),c,d); \
1414 else if (test_mode == PCRE16_MODE) \
1415 a = pcre2_substring_length_bynumber_16(G(b,16),c,d); \
1417 a = pcre2_substring_length_bynumber_32(G(b,32),c,d)
1419 #define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \
1420 if (test_mode == PCRE8_MODE) \
1421 a = pcre2_substring_list_get_8(G(b,8),(PCRE2_UCHAR8 ***)c,d); \
1422 else if (test_mode == PCRE16_MODE) \
1423 a = pcre2_substring_list_get_16(G(b,16),(PCRE2_UCHAR16 ***)c,d); \
1425 a = pcre2_substring_list_get_32(G(b,32),(PCRE2_UCHAR32 ***)c,d)
1427 #define PCRE2_SUBSTRING_LIST_FREE(a) \
1428 if (test_mode == PCRE8_MODE) \
1429 pcre2_substring_list_free_8((PCRE2_SPTR8 *)a); \
1430 else if (test_mode == PCRE16_MODE) \
1431 pcre2_substring_list_free_16((PCRE2_SPTR16 *)a); \
1433 pcre2_substring_list_free_32((PCRE2_SPTR32 *)a)
1435 #define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \
1436 if (test_mode == PCRE8_MODE) \
1437 a = pcre2_substring_number_from_name_8(G(b,8),G(c,8)); \
1438 else if (test_mode == PCRE16_MODE) \
1439 a = pcre2_substring_number_from_name_16(G(b,16),G(c,16)); \
1441 a = pcre2_substring_number_from_name_32(G(b,32),G(c,32))
1444 (test_mode == PCRE8_MODE)? (void *)G(x,8) : \
1445 (test_mode == PCRE16_MODE)? (void *)G(x,16) : \
1448 #define SETFLD(x,y,z) \
1449 if (test_mode == PCRE8_MODE) G(x,8)->y = z; \
1450 else if (test_mode == PCRE16_MODE) G(x,16)->y = z; \
1453 #define SETFLDVEC(x,y,v,z) \
1454 if (test_mode == PCRE8_MODE) G(x,8)->y[v] = z; \
1455 else if (test_mode == PCRE16_MODE) G(x,16)->y[v] = z; \
1456 else G(x,32)->y[v] = z
1458 #define SETOP(x,y,z) \
1459 if (test_mode == PCRE8_MODE) G(x,8) z y; \
1460 else if (test_mode == PCRE16_MODE) G(x,16) z y; \
1463 #define SETCASTPTR(x,y) \
1464 if (test_mode == PCRE8_MODE) \
1465 G(x,8) = (uint8_t *)(y); \
1466 else if (test_mode == PCRE16_MODE) \
1467 G(x,16) = (uint16_t *)(y); \
1469 G(x,32) = (uint32_t *)(y)
1471 #define STRLEN(p) ((test_mode == PCRE8_MODE)? ((int)strlen((char *)p)) : \
1472 (test_mode == PCRE16_MODE)? ((int)strlen16((PCRE2_SPTR16)p)) : \
1473 ((int)strlen32((PCRE2_SPTR32)p)))
1476 if (test_mode == PCRE8_MODE) G(a,8)(G(b,8)); \
1477 else if (test_mode == PCRE16_MODE) G(a,16)(G(b,16)); \
1478 else G(a,32)(G(b,32))
1480 #define SUB2(a,b,c) \
1481 if (test_mode == PCRE8_MODE) G(a,8)(G(b,8),G(c,8)); \
1482 else if (test_mode == PCRE16_MODE) G(a,16)(G(b,16),G(c,16)); \
1483 else G(a,32)(G(b,32),G(c,32))
1485 #define TEST(x,r,y) ( \
1486 (test_mode == PCRE8_MODE && G(x,8) r (y)) || \
1487 (test_mode == PCRE16_MODE && G(x,16) r (y)) || \
1488 (test_mode == PCRE32_MODE && G(x,32) r (y)))
1490 #define TESTFLD(x,f,r,y) ( \
1491 (test_mode == PCRE8_MODE && G(x,8)->f r (y)) || \
1492 (test_mode == PCRE16_MODE && G(x,16)->f r (y)) || \
1493 (test_mode == PCRE32_MODE && G(x,32)->f r (y)))
1496 /* ----- Two out of three modes are supported ----- */
1500 /* We can use some macro trickery to make a single set of definitions work in
1501 the three different cases. */
1503 /* ----- 32-bit and 16-bit but not 8-bit supported ----- */
1505 #if defined(SUPPORT_PCRE2_32) && defined(SUPPORT_PCRE2_16)
1509 /* ----- 32-bit and 8-bit but not 16-bit supported ----- */
1511 #elif defined(SUPPORT_PCRE2_32) && defined(SUPPORT_PCRE2_8)
1515 /* ----- 16-bit and 8-bit but not 32-bit supported ----- */
1523 /* ----- Common macros for two-mode cases ----- */
1525 #define BYTEONE (BITONE/8)
1526 #define BYTETWO (BITTWO/8)
1528 #define CASTFLD(t,a,b) \
1529 ((test_mode == G(G(PCRE,BITONE),_MODE))? (t)(G(a,BITONE)->b) : \
1530 (t)(G(a,BITTWO)->b))
1532 #define CASTVAR(t,x) ( \
1533 (test_mode == G(G(PCRE,BITONE),_MODE))? \
1534 (t)G(x,BITONE) : (t)G(x,BITTWO))
1536 #define CODE_UNIT(a,b) ( \
1537 (test_mode == G(G(PCRE,BITONE),_MODE))? \
1538 (uint32_t)(((G(PCRE2_SPTR,BITONE))(a))[b]) : \
1539 (uint32_t)(((G(PCRE2_SPTR,BITTWO))(a))[b]))
1541 #define CONCTXCPY(a,b) \
1542 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1543 memcpy(G(a,BITONE),G(b,BITONE),sizeof(G(pcre2_convert_context_,BITONE))); \
1545 memcpy(G(a,BITTWO),G(b,BITTWO),sizeof(G(pcre2_convert_context_,BITTWO)))
1547 #define CONVERT_COPY(a,b,c) \
1548 (test_mode == G(G(PCRE,BITONE),_MODE))? \
1549 memcpy(G(a,BITONE),(char *)b,(c)*BYTEONE) : \
1550 memcpy(G(a,BITTWO),(char *)b,(c)*BYTETWO)
1552 #define DATCTXCPY(a,b) \
1553 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1554 memcpy(G(a,BITONE),G(b,BITONE),sizeof(G(pcre2_match_context_,BITONE))); \
1556 memcpy(G(a,BITTWO),G(b,BITTWO),sizeof(G(pcre2_match_context_,BITTWO)))
1559 ((test_mode == G(G(PCRE,BITONE),_MODE))? G(a,BITONE)->b : G(a,BITTWO)->b)
1561 #define PATCTXCPY(a,b) \
1562 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1563 memcpy(G(a,BITONE),G(b,BITONE),sizeof(G(pcre2_compile_context_,BITONE))); \
1565 memcpy(G(a,BITTWO),G(b,BITTWO),sizeof(G(pcre2_compile_context_,BITTWO)))
1567 #define PCHARS(lv, p, offset, len, utf, f) \
1568 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1569 lv = G(pchars,BITONE)((G(PCRE2_SPTR,BITONE))(p)+offset, len, utf, f); \
1571 lv = G(pchars,BITTWO)((G(PCRE2_SPTR,BITTWO))(p)+offset, len, utf, f)
1573 #define PCHARSV(p, offset, len, utf, f) \
1574 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1575 (void)G(pchars,BITONE)((G(PCRE2_SPTR,BITONE))(p)+offset, len, utf, f); \
1577 (void)G(pchars,BITTWO)((G(PCRE2_SPTR,BITTWO))(p)+offset, len, utf, f)
1579 #define PCRE2_CALLOUT_ENUMERATE(a,b,c) \
1580 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1581 a = G(pcre2_callout_enumerate,BITONE)(G(compiled_code,BITONE), \
1582 (int (*)(struct G(pcre2_callout_enumerate_block_,BITONE) *, void *))b,c); \
1584 a = G(pcre2_callout_enumerate,BITTWO)(G(compiled_code,BITTWO), \
1585 (int (*)(struct G(pcre2_callout_enumerate_block_,BITTWO) *, void *))b,c)
1587 #define PCRE2_CODE_COPY_FROM_VOID(a,b) \
1588 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1589 G(a,BITONE) = G(pcre2_code_copy_,BITONE)(b); \
1591 G(a,BITTWO) = G(pcre2_code_copy_,BITTWO)(b)
1593 #define PCRE2_CODE_COPY_TO_VOID(a,b) \
1594 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1595 a = (void *)G(pcre2_code_copy_,BITONE)(G(b,BITONE)); \
1597 a = (void *)G(pcre2_code_copy_,BITTWO)(G(b,BITTWO))
1599 #define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) \
1600 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1601 a = (void *)G(pcre2_code_copy_with_tables_,BITONE)(G(b,BITONE)); \
1603 a = (void *)G(pcre2_code_copy_with_tables_,BITTWO)(G(b,BITTWO))
1605 #define PCRE2_COMPILE(a,b,c,d,e,f,g) \
1606 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1607 G(a,BITONE) = G(pcre2_compile_,BITONE)(G(b,BITONE),c,d,e,f,g); \
1609 G(a,BITTWO) = G(pcre2_compile_,BITTWO)(G(b,BITTWO),c,d,e,f,g)
1611 #define PCRE2_CONVERTED_PATTERN_FREE(a) \
1612 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1613 G(pcre2_converted_pattern_free_,BITONE)((G(PCRE2_UCHAR,BITONE) *)a); \
1615 G(pcre2_converted_pattern_free_,BITTWO)((G(PCRE2_UCHAR,BITTWO) *)a)
1617 #define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \
1618 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1619 a = G(pcre2_dfa_match_,BITONE)(G(b,BITONE),(G(PCRE2_SPTR,BITONE))c,d,e,f, \
1620 G(g,BITONE),h,i,j); \
1622 a = G(pcre2_dfa_match_,BITTWO)(G(b,BITTWO),(G(PCRE2_SPTR,BITTWO))c,d,e,f, \
1625 #define PCRE2_GET_ERROR_MESSAGE(r,a,b) \
1626 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1627 r = G(pcre2_get_error_message_,BITONE)(a,G(b,BITONE),G(G(b,BITONE),_size/BYTEONE)); \
1629 r = G(pcre2_get_error_message_,BITTWO)(a,G(b,BITTWO),G(G(b,BITTWO),_size/BYTETWO))
1631 #define PCRE2_GET_OVECTOR_COUNT(a,b) \
1632 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1633 a = G(pcre2_get_ovector_count_,BITONE)(G(b,BITONE)); \
1635 a = G(pcre2_get_ovector_count_,BITTWO)(G(b,BITTWO))
1637 #define PCRE2_GET_STARTCHAR(a,b) \
1638 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1639 a = G(pcre2_get_startchar_,BITONE)(G(b,BITONE)); \
1641 a = G(pcre2_get_startchar_,BITTWO)(G(b,BITTWO))
1643 #define PCRE2_JIT_COMPILE(r,a,b) \
1644 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1645 r = G(pcre2_jit_compile_,BITONE)(G(a,BITONE),b); \
1647 r = G(pcre2_jit_compile_,BITTWO)(G(a,BITTWO),b)
1649 #define PCRE2_JIT_FREE_UNUSED_MEMORY(a) \
1650 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1651 G(pcre2_jit_free_unused_memory_,BITONE)(G(a,BITONE)); \
1653 G(pcre2_jit_free_unused_memory_,BITTWO)(G(a,BITTWO))
1655 #define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \
1656 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1657 a = G(pcre2_jit_match_,BITONE)(G(b,BITONE),(G(PCRE2_SPTR,BITONE))c,d,e,f, \
1660 a = G(pcre2_jit_match_,BITTWO)(G(b,BITTWO),(G(PCRE2_SPTR,BITTWO))c,d,e,f, \
1663 #define PCRE2_JIT_STACK_CREATE(a,b,c,d) \
1664 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1665 a = (PCRE2_JIT_STACK *)G(pcre2_jit_stack_create_,BITONE)(b,c,d); \
1667 a = (PCRE2_JIT_STACK *)G(pcre2_jit_stack_create_,BITTWO)(b,c,d); \
1669 #define PCRE2_JIT_STACK_ASSIGN(a,b,c) \
1670 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1671 G(pcre2_jit_stack_assign_,BITONE)(G(a,BITONE),(G(pcre2_jit_callback_,BITONE))b,c); \
1673 G(pcre2_jit_stack_assign_,BITTWO)(G(a,BITTWO),(G(pcre2_jit_callback_,BITTWO))b,c);
1675 #define PCRE2_JIT_STACK_FREE(a) \
1676 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1677 G(pcre2_jit_stack_free_,BITONE)((G(pcre2_jit_stack_,BITONE) *)a); \
1679 G(pcre2_jit_stack_free_,BITTWO)((G(pcre2_jit_stack_,BITTWO) *)a);
1681 #define PCRE2_MAKETABLES(a) \
1682 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1683 a = G(pcre2_maketables_,BITONE)(NULL); \
1685 a = G(pcre2_maketables_,BITTWO)(NULL)
1687 #define PCRE2_MATCH(a,b,c,d,e,f,g,h) \
1688 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1689 a = G(pcre2_match_,BITONE)(G(b,BITONE),(G(PCRE2_SPTR,BITONE))c,d,e,f, \
1692 a = G(pcre2_match_,BITTWO)(G(b,BITTWO),(G(PCRE2_SPTR,BITTWO))c,d,e,f, \
1695 #define PCRE2_MATCH_DATA_CREATE(a,b,c) \
1696 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1697 G(a,BITONE) = G(pcre2_match_data_create_,BITONE)(b,c); \
1699 G(a,BITTWO) = G(pcre2_match_data_create_,BITTWO)(b,c)
1701 #define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
1702 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1703 G(a,BITONE) = G(pcre2_match_data_create_from_pattern_,BITONE)(G(b,BITONE),c); \
1705 G(a,BITTWO) = G(pcre2_match_data_create_from_pattern_,BITTWO)(G(b,BITTWO),c)
1707 #define PCRE2_MATCH_DATA_FREE(a) \
1708 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1709 G(pcre2_match_data_free_,BITONE)(G(a,BITONE)); \
1711 G(pcre2_match_data_free_,BITTWO)(G(a,BITTWO))
1713 #define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) \
1714 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1715 a = G(pcre2_pattern_convert_,BITONE)(G(b,BITONE),c,d,(G(PCRE2_UCHAR,BITONE) **)e,f,G(g,BITONE)); \
1717 a = G(pcre2_pattern_convert_,BITTWO)(G(b,BITTWO),c,d,(G(PCRE2_UCHAR,BITTWO) **)e,f,G(g,BITTWO))
1719 #define PCRE2_PATTERN_INFO(a,b,c,d) \
1720 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1721 a = G(pcre2_pattern_info_,BITONE)(G(b,BITONE),c,d); \
1723 a = G(pcre2_pattern_info_,BITTWO)(G(b,BITTWO),c,d)
1725 #define PCRE2_PRINTINT(a) \
1726 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1727 G(pcre2_printint_,BITONE)(G(compiled_code,BITONE),outfile,a); \
1729 G(pcre2_printint_,BITTWO)(G(compiled_code,BITTWO),outfile,a)
1731 #define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \
1732 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1733 r = G(pcre2_serialize_decode_,BITONE)((G(pcre2_code_,BITONE) **)a,b,c,G(d,BITONE)); \
1735 r = G(pcre2_serialize_decode_,BITTWO)((G(pcre2_code_,BITTWO) **)a,b,c,G(d,BITTWO))
1737 #define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \
1738 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1739 r = G(pcre2_serialize_encode_,BITONE)((G(const pcre2_code_,BITONE) **)a,b,c,d,G(e,BITONE)); \
1741 r = G(pcre2_serialize_encode_,BITTWO)((G(const pcre2_code_,BITTWO) **)a,b,c,d,G(e,BITTWO))
1743 #define PCRE2_SERIALIZE_FREE(a) \
1744 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1745 G(pcre2_serialize_free_,BITONE)(a); \
1747 G(pcre2_serialize_free_,BITTWO)(a)
1749 #define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \
1750 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1751 r = G(pcre2_serialize_get_number_of_codes_,BITONE)(a); \
1753 r = G(pcre2_serialize_get_number_of_codes_,BITTWO)(a)
1755 #define PCRE2_SET_CALLOUT(a,b,c) \
1756 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1757 G(pcre2_set_callout_,BITONE)(G(a,BITONE), \
1758 (int (*)(G(pcre2_callout_block_,BITONE) *, void *))b,c); \
1760 G(pcre2_set_callout_,BITTWO)(G(a,BITTWO), \
1761 (int (*)(G(pcre2_callout_block_,BITTWO) *, void *))b,c);
1763 #define PCRE2_SET_CHARACTER_TABLES(a,b) \
1764 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1765 G(pcre2_set_character_tables_,BITONE)(G(a,BITONE),b); \
1767 G(pcre2_set_character_tables_,BITTWO)(G(a,BITTWO),b)
1769 #define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \
1770 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1771 G(pcre2_set_compile_recursion_guard_,BITONE)(G(a,BITONE),b,c); \
1773 G(pcre2_set_compile_recursion_guard_,BITTWO)(G(a,BITTWO),b,c)
1775 #define PCRE2_SET_DEPTH_LIMIT(a,b) \
1776 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1777 G(pcre2_set_depth_limit_,BITONE)(G(a,BITONE),b); \
1779 G(pcre2_set_depth_limit_,BITTWO)(G(a,BITTWO),b)
1781 #define PCRE2_SET_GLOB_ESCAPE(r,a,b) \
1782 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1783 r = G(pcre2_set_glob_escape_,BITONE)(G(a,BITONE),b); \
1785 r = G(pcre2_set_glob_escape_,BITTWO)(G(a,BITTWO),b)
1787 #define PCRE2_SET_GLOB_SEPARATOR(r,a,b) \
1788 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1789 r = G(pcre2_set_glob_separator_,BITONE)(G(a,BITONE),b); \
1791 r = G(pcre2_set_glob_separator_,BITTWO)(G(a,BITTWO),b)
1793 #define PCRE2_SET_HEAP_LIMIT(a,b) \
1794 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1795 G(pcre2_set_heap_limit_,BITONE)(G(a,BITONE),b); \
1797 G(pcre2_set_heap_limit_,BITTWO)(G(a,BITTWO),b)
1799 #define PCRE2_SET_MATCH_LIMIT(a,b) \
1800 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1801 G(pcre2_set_match_limit_,BITONE)(G(a,BITONE),b); \
1803 G(pcre2_set_match_limit_,BITTWO)(G(a,BITTWO),b)
1805 #define PCRE2_SET_MAX_PATTERN_LENGTH(a,b) \
1806 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1807 G(pcre2_set_max_pattern_length_,BITONE)(G(a,BITONE),b); \
1809 G(pcre2_set_max_pattern_length_,BITTWO)(G(a,BITTWO),b)
1811 #define PCRE2_SET_OFFSET_LIMIT(a,b) \
1812 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1813 G(pcre2_set_offset_limit_,BITONE)(G(a,BITONE),b); \
1815 G(pcre2_set_offset_limit_,BITTWO)(G(a,BITTWO),b)
1817 #define PCRE2_SET_PARENS_NEST_LIMIT(a,b) \
1818 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1819 G(pcre2_set_parens_nest_limit_,BITONE)(G(a,BITONE),b); \
1821 G(pcre2_set_parens_nest_limit_,BITTWO)(G(a,BITTWO),b)
1823 #define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \
1824 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1825 a = G(pcre2_substitute_,BITONE)(G(b,BITONE),(G(PCRE2_SPTR,BITONE))c,d,e,f, \
1826 G(g,BITONE),G(h,BITONE),(G(PCRE2_SPTR,BITONE))i,j, \
1827 (G(PCRE2_UCHAR,BITONE) *)k,l); \
1829 a = G(pcre2_substitute_,BITTWO)(G(b,BITTWO),(G(PCRE2_SPTR,BITTWO))c,d,e,f, \
1830 G(g,BITTWO),G(h,BITTWO),(G(PCRE2_SPTR,BITTWO))i,j, \
1831 (G(PCRE2_UCHAR,BITTWO) *)k,l)
1833 #define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \
1834 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1835 a = G(pcre2_substring_copy_byname_,BITONE)(G(b,BITONE),G(c,BITONE),\
1836 (G(PCRE2_UCHAR,BITONE) *)d,e); \
1838 a = G(pcre2_substring_copy_byname_,BITTWO)(G(b,BITTWO),G(c,BITTWO),\
1839 (G(PCRE2_UCHAR,BITTWO) *)d,e)
1841 #define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \
1842 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1843 a = G(pcre2_substring_copy_bynumber_,BITONE)(G(b,BITONE),c,\
1844 (G(PCRE2_UCHAR,BITONE) *)d,e); \
1846 a = G(pcre2_substring_copy_bynumber_,BITTWO)(G(b,BITTWO),c,\
1847 (G(PCRE2_UCHAR,BITTWO) *)d,e)
1849 #define PCRE2_SUBSTRING_FREE(a) \
1850 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1851 G(pcre2_substring_free_,BITONE)((G(PCRE2_UCHAR,BITONE) *)a); \
1852 else G(pcre2_substring_free_,BITTWO)((G(PCRE2_UCHAR,BITTWO) *)a)
1854 #define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \
1855 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1856 a = G(pcre2_substring_get_byname_,BITONE)(G(b,BITONE),G(c,BITONE),\
1857 (G(PCRE2_UCHAR,BITONE) **)d,e); \
1859 a = G(pcre2_substring_get_byname_,BITTWO)(G(b,BITTWO),G(c,BITTWO),\
1860 (G(PCRE2_UCHAR,BITTWO) **)d,e)
1862 #define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \
1863 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1864 a = G(pcre2_substring_get_bynumber_,BITONE)(G(b,BITONE),c,\
1865 (G(PCRE2_UCHAR,BITONE) **)d,e); \
1867 a = G(pcre2_substring_get_bynumber_,BITTWO)(G(b,BITTWO),c,\
1868 (G(PCRE2_UCHAR,BITTWO) **)d,e)
1870 #define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \
1871 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1872 a = G(pcre2_substring_length_byname_,BITONE)(G(b,BITONE),G(c,BITONE),d); \
1874 a = G(pcre2_substring_length_byname_,BITTWO)(G(b,BITTWO),G(c,BITTWO),d)
1876 #define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \
1877 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1878 a = G(pcre2_substring_length_bynumber_,BITONE)(G(b,BITONE),c,d); \
1880 a = G(pcre2_substring_length_bynumber_,BITTWO)(G(b,BITTWO),c,d)
1882 #define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \
1883 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1884 a = G(pcre2_substring_list_get_,BITONE)(G(b,BITONE), \
1885 (G(PCRE2_UCHAR,BITONE) ***)c,d); \
1887 a = G(pcre2_substring_list_get_,BITTWO)(G(b,BITTWO), \
1888 (G(PCRE2_UCHAR,BITTWO) ***)c,d)
1890 #define PCRE2_SUBSTRING_LIST_FREE(a) \
1891 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1892 G(pcre2_substring_list_free_,BITONE)((G(PCRE2_SPTR,BITONE) *)a); \
1894 G(pcre2_substring_list_free_,BITTWO)((G(PCRE2_SPTR,BITTWO) *)a)
1896 #define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \
1897 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1898 a = G(pcre2_substring_number_from_name_,BITONE)(G(b,BITONE),G(c,BITONE)); \
1900 a = G(pcre2_substring_number_from_name_,BITTWO)(G(b,BITTWO),G(c,BITTWO))
1903 (test_mode == G(G(PCRE,BITONE),_MODE))? (void *)G(x,BITONE) : \
1904 (void *)G(x,BITTWO))
1906 #define SETFLD(x,y,z) \
1907 if (test_mode == G(G(PCRE,BITONE),_MODE)) G(x,BITONE)->y = z; \
1908 else G(x,BITTWO)->y = z
1910 #define SETFLDVEC(x,y,v,z) \
1911 if (test_mode == G(G(PCRE,BITONE),_MODE)) G(x,BITONE)->y[v] = z; \
1912 else G(x,BITTWO)->y[v] = z
1914 #define SETOP(x,y,z) \
1915 if (test_mode == G(G(PCRE,BITONE),_MODE)) G(x,BITONE) z y; \
1916 else G(x,BITTWO) z y
1918 #define SETCASTPTR(x,y) \
1919 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1920 G(x,BITONE) = (G(G(uint,BITONE),_t) *)(y); \
1922 G(x,BITTWO) = (G(G(uint,BITTWO),_t) *)(y)
1924 #define STRLEN(p) ((test_mode == G(G(PCRE,BITONE),_MODE))? \
1925 G(strlen,BITONE)((G(PCRE2_SPTR,BITONE))p) : \
1926 G(strlen,BITTWO)((G(PCRE2_SPTR,BITTWO))p))
1929 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1930 G(a,BITONE)(G(b,BITONE)); \
1932 G(a,BITTWO)(G(b,BITTWO))
1934 #define SUB2(a,b,c) \
1935 if (test_mode == G(G(PCRE,BITONE),_MODE)) \
1936 G(a,BITONE))(G(b,BITONE),G(c,BITONE)); \
1938 G(a,BITTWO))(G(b,BITTWO),G(c,BITTWO))
1940 #define TEST(x,r,y) ( \
1941 (test_mode == G(G(PCRE,BITONE),_MODE) && G(x,BITONE) r (y)) || \
1942 (test_mode == G(G(PCRE,BITTWO),_MODE) && G(x,BITTWO) r (y)))
1944 #define TESTFLD(x,f,r,y) ( \
1945 (test_mode == G(G(PCRE,BITONE),_MODE) && G(x,BITONE)->f r (y)) || \
1946 (test_mode == G(G(PCRE,BITTWO),_MODE) && G(x,BITTWO)->f r (y)))
1949 #endif /* Two out of three modes */
1951 /* ----- End of cases where more than one mode is supported ----- */
1954 /* ----- Only 8-bit mode is supported ----- */
1956 #elif defined SUPPORT_PCRE2_8
1957 #define CASTFLD(t,a,b) (t)(G(a,8)->b)
1958 #define CASTVAR(t,x) (t)G(x,8)
1959 #define CODE_UNIT(a,b) (uint32_t)(((PCRE2_SPTR8)(a))[b])
1960 #define CONCTXCPY(a,b) memcpy(G(a,8),G(b,8),sizeof(pcre2_convert_context_8))
1961 #define CONVERT_COPY(a,b,c) memcpy(G(a,8),(char *)b, c)
1962 #define DATCTXCPY(a,b) memcpy(G(a,8),G(b,8),sizeof(pcre2_match_context_8))
1963 #define FLD(a,b) G(a,8)->b
1964 #define PATCTXCPY(a,b) memcpy(G(a,8),G(b,8),sizeof(pcre2_compile_context_8))
1965 #define PCHARS(lv, p, offset, len, utf, f) \
1966 lv = pchars8((PCRE2_SPTR8)(p)+offset, len, utf, f)
1967 #define PCHARSV(p, offset, len, utf, f) \
1968 (void)pchars8((PCRE2_SPTR8)(p)+offset, len, utf, f)
1969 #define PCRE2_CALLOUT_ENUMERATE(a,b,c) \
1970 a = pcre2_callout_enumerate_8(compiled_code8, \
1971 (int (*)(struct pcre2_callout_enumerate_block_8 *, void *))b,c)
1972 #define PCRE2_CODE_COPY_FROM_VOID(a,b) G(a,8) = pcre2_code_copy_8(b)
1973 #define PCRE2_CODE_COPY_TO_VOID(a,b) a = (void *)pcre2_code_copy_8(G(b,8))
1974 #define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) a = (void *)pcre2_code_copy_with_tables_8(G(b,8))
1975 #define PCRE2_COMPILE(a,b,c,d,e,f,g) \
1976 G(a,8) = pcre2_compile_8(G(b,8),c,d,e,f,g)
1977 #define PCRE2_CONVERTED_PATTERN_FREE(a) \
1978 pcre2_converted_pattern_free_8((PCRE2_UCHAR8 *)a)
1979 #define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \
1980 a = pcre2_dfa_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h,i,j)
1981 #define PCRE2_GET_ERROR_MESSAGE(r,a,b) \
1982 r = pcre2_get_error_message_8(a,G(b,8),G(G(b,8),_size))
1983 #define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_8(G(b,8))
1984 #define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_8(G(b,8))
1985 #define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_8(G(a,8),b)
1986 #define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_8(G(a,8))
1987 #define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \
1988 a = pcre2_jit_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h)
1989 #define PCRE2_JIT_STACK_CREATE(a,b,c,d) \
1990 a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_8(b,c,d);
1991 #define PCRE2_JIT_STACK_ASSIGN(a,b,c) \
1992 pcre2_jit_stack_assign_8(G(a,8),(pcre2_jit_callback_8)b,c);
1993 #define PCRE2_JIT_STACK_FREE(a) pcre2_jit_stack_free_8((pcre2_jit_stack_8 *)a);
1994 #define PCRE2_MAKETABLES(a) a = pcre2_maketables_8(NULL)
1995 #define PCRE2_MATCH(a,b,c,d,e,f,g,h) \
1996 a = pcre2_match_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),h)
1997 #define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,8) = pcre2_match_data_create_8(b,c)
1998 #define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
1999 G(a,8) = pcre2_match_data_create_from_pattern_8(G(b,8),c)
2000 #define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_8(G(a,8))
2001 #define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_8(G(b,8),c,d,(PCRE2_UCHAR8 **)e,f,G(g,8))
2002 #define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_8(G(b,8),c,d)
2003 #define PCRE2_PRINTINT(a) pcre2_printint_8(compiled_code8,outfile,a)
2004 #define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \
2005 r = pcre2_serialize_decode_8((pcre2_code_8 **)a,b,c,G(d,8))
2006 #define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \
2007 r = pcre2_serialize_encode_8((const pcre2_code_8 **)a,b,c,d,G(e,8))
2008 #define PCRE2_SERIALIZE_FREE(a) pcre2_serialize_free_8(a)
2009 #define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \
2010 r = pcre2_serialize_get_number_of_codes_8(a)
2011 #define PCRE2_SET_CALLOUT(a,b,c) \
2012 pcre2_set_callout_8(G(a,8),(int (*)(pcre2_callout_block_8 *, void *))b,c)
2013 #define PCRE2_SET_CHARACTER_TABLES(a,b) pcre2_set_character_tables_8(G(a,8),b)
2014 #define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \
2015 pcre2_set_compile_recursion_guard_8(G(a,8),b,c)
2016 #define PCRE2_SET_DEPTH_LIMIT(a,b) pcre2_set_depth_limit_8(G(a,8),b)
2017 #define PCRE2_SET_GLOB_ESCAPE(r,a,b) r = pcre2_set_glob_escape_8(G(a,8),b)
2018 #define PCRE2_SET_GLOB_SEPARATOR(r,a,b) r = pcre2_set_glob_separator_8(G(a,8),b)
2019 #define PCRE2_SET_HEAP_LIMIT(a,b) pcre2_set_heap_limit_8(G(a,8),b)
2020 #define PCRE2_SET_MATCH_LIMIT(a,b) pcre2_set_match_limit_8(G(a,8),b)
2021 #define PCRE2_SET_MAX_PATTERN_LENGTH(a,b) pcre2_set_max_pattern_length_8(G(a,8),b)
2022 #define PCRE2_SET_OFFSET_LIMIT(a,b) pcre2_set_offset_limit_8(G(a,8),b)
2023 #define PCRE2_SET_PARENS_NEST_LIMIT(a,b) pcre2_set_parens_nest_limit_8(G(a,8),b)
2024 #define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \
2025 a = pcre2_substitute_8(G(b,8),(PCRE2_SPTR8)c,d,e,f,G(g,8),G(h,8), \
2026 (PCRE2_SPTR8)i,j,(PCRE2_UCHAR8 *)k,l)
2027 #define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \
2028 a = pcre2_substring_copy_byname_8(G(b,8),G(c,8),(PCRE2_UCHAR8 *)d,e)
2029 #define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \
2030 a = pcre2_substring_copy_bynumber_8(G(b,8),c,(PCRE2_UCHAR8 *)d,e)
2031 #define PCRE2_SUBSTRING_FREE(a) pcre2_substring_free_8((PCRE2_UCHAR8 *)a)
2032 #define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \
2033 a = pcre2_substring_get_byname_8(G(b,8),G(c,8),(PCRE2_UCHAR8 **)d,e)
2034 #define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \
2035 a = pcre2_substring_get_bynumber_8(G(b,8),c,(PCRE2_UCHAR8 **)d,e)
2036 #define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \
2037 a = pcre2_substring_length_byname_8(G(b,8),G(c,8),d)
2038 #define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \
2039 a = pcre2_substring_length_bynumber_8(G(b,8),c,d)
2040 #define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \
2041 a = pcre2_substring_list_get_8(G(b,8),(PCRE2_UCHAR8 ***)c,d)
2042 #define PCRE2_SUBSTRING_LIST_FREE(a) \
2043 pcre2_substring_list_free_8((PCRE2_SPTR8 *)a)
2044 #define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \
2045 a = pcre2_substring_number_from_name_8(G(b,8),G(c,8));
2046 #define PTR(x) (void *)G(x,8)
2047 #define SETFLD(x,y,z) G(x,8)->y = z
2048 #define SETFLDVEC(x,y,v,z) G(x,8)->y[v] = z
2049 #define SETOP(x,y,z) G(x,8) z y
2050 #define SETCASTPTR(x,y) G(x,8) = (uint8_t *)(y)
2051 #define STRLEN(p) (int)strlen((char *)p)
2052 #define SUB1(a,b) G(a,8)(G(b,8))
2053 #define SUB2(a,b,c) G(a,8)(G(b,8),G(c,8))
2054 #define TEST(x,r,y) (G(x,8) r (y))
2055 #define TESTFLD(x,f,r,y) (G(x,8)->f r (y))
2058 /* ----- Only 16-bit mode is supported ----- */
2060 #elif defined SUPPORT_PCRE2_16
2061 #define CASTFLD(t,a,b) (t)(G(a,16)->b)
2062 #define CASTVAR(t,x) (t)G(x,16)
2063 #define CODE_UNIT(a,b) (uint32_t)(((PCRE2_SPTR16)(a))[b])
2064 #define CONCTXCPY(a,b) memcpy(G(a,16),G(b,16),sizeof(pcre2_convert_context_16))
2065 #define CONVERT_COPY(a,b,c) memcpy(G(a,16),(char *)b, (c)*2)
2066 #define DATCTXCPY(a,b) memcpy(G(a,16),G(b,16),sizeof(pcre2_match_context_16))
2067 #define FLD(a,b) G(a,16)->b
2068 #define PATCTXCPY(a,b) memcpy(G(a,16),G(b,16),sizeof(pcre2_compile_context_16))
2069 #define PCHARS(lv, p, offset, len, utf, f) \
2070 lv = pchars16((PCRE2_SPTR16)(p)+offset, len, utf, f)
2071 #define PCHARSV(p, offset, len, utf, f) \
2072 (void)pchars16((PCRE2_SPTR16)(p)+offset, len, utf, f)
2073 #define PCRE2_CALLOUT_ENUMERATE(a,b,c) \
2074 a = pcre2_callout_enumerate_16(compiled_code16, \
2075 (int (*)(struct pcre2_callout_enumerate_block_16 *, void *))b,c)
2076 #define PCRE2_CODE_COPY_FROM_VOID(a,b) G(a,16) = pcre2_code_copy_16(b)
2077 #define PCRE2_CODE_COPY_TO_VOID(a,b) a = (void *)pcre2_code_copy_16(G(b,16))
2078 #define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) a = (void *)pcre2_code_copy_with_tables_16(G(b,16))
2079 #define PCRE2_COMPILE(a,b,c,d,e,f,g) \
2080 G(a,16) = pcre2_compile_16(G(b,16),c,d,e,f,g)
2081 #define PCRE2_CONVERTED_PATTERN_FREE(a) \
2082 pcre2_converted_pattern_free_16((PCRE2_UCHAR16 *)a)
2083 #define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \
2084 a = pcre2_dfa_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h,i,j)
2085 #define PCRE2_GET_ERROR_MESSAGE(r,a,b) \
2086 r = pcre2_get_error_message_16(a,G(b,16),G(G(b,16),_size/2))
2087 #define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_16(G(b,16))
2088 #define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_16(G(b,16))
2089 #define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_16(G(a,16),b)
2090 #define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_16(G(a,16))
2091 #define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \
2092 a = pcre2_jit_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h)
2093 #define PCRE2_JIT_STACK_CREATE(a,b,c,d) \
2094 a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_16(b,c,d);
2095 #define PCRE2_JIT_STACK_ASSIGN(a,b,c) \
2096 pcre2_jit_stack_assign_16(G(a,16),(pcre2_jit_callback_16)b,c);
2097 #define PCRE2_JIT_STACK_FREE(a) pcre2_jit_stack_free_16((pcre2_jit_stack_16 *)a);
2098 #define PCRE2_MAKETABLES(a) a = pcre2_maketables_16(NULL)
2099 #define PCRE2_MATCH(a,b,c,d,e,f,g,h) \
2100 a = pcre2_match_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),h)
2101 #define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,16) = pcre2_match_data_create_16(b,c)
2102 #define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
2103 G(a,16) = pcre2_match_data_create_from_pattern_16(G(b,16),c)
2104 #define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_16(G(a,16))
2105 #define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_16(G(b,16),c,d,(PCRE2_UCHAR16 **)e,f,G(g,16))
2106 #define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_16(G(b,16),c,d)
2107 #define PCRE2_PRINTINT(a) pcre2_printint_16(compiled_code16,outfile,a)
2108 #define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \
2109 r = pcre2_serialize_decode_16((pcre2_code_16 **)a,b,c,G(d,16))
2110 #define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \
2111 r = pcre2_serialize_encode_16((const pcre2_code_16 **)a,b,c,d,G(e,16))
2112 #define PCRE2_SERIALIZE_FREE(a) pcre2_serialize_free_16(a)
2113 #define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \
2114 r = pcre2_serialize_get_number_of_codes_16(a)
2115 #define PCRE2_SET_CALLOUT(a,b,c) \
2116 pcre2_set_callout_16(G(a,16),(int (*)(pcre2_callout_block_16 *, void *))b,c);
2117 #define PCRE2_SET_CHARACTER_TABLES(a,b) pcre2_set_character_tables_16(G(a,16),b)
2118 #define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \
2119 pcre2_set_compile_recursion_guard_16(G(a,16),b,c)
2120 #define PCRE2_SET_DEPTH_LIMIT(a,b) pcre2_set_depth_limit_16(G(a,16),b)
2121 #define PCRE2_SET_GLOB_ESCAPE(r,a,b) r = pcre2_set_glob_escape_16(G(a,16),b)
2122 #define PCRE2_SET_GLOB_SEPARATOR(r,a,b) r = pcre2_set_glob_separator_16(G(a,16),b)
2123 #define PCRE2_SET_HEAP_LIMIT(a,b) pcre2_set_heap_limit_16(G(a,16),b)
2124 #define PCRE2_SET_MATCH_LIMIT(a,b) pcre2_set_match_limit_16(G(a,16),b)
2125 #define PCRE2_SET_MAX_PATTERN_LENGTH(a,b) pcre2_set_max_pattern_length_16(G(a,16),b)
2126 #define PCRE2_SET_OFFSET_LIMIT(a,b) pcre2_set_offset_limit_16(G(a,16),b)
2127 #define PCRE2_SET_PARENS_NEST_LIMIT(a,b) pcre2_set_parens_nest_limit_16(G(a,16),b)
2128 #define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \
2129 a = pcre2_substitute_16(G(b,16),(PCRE2_SPTR16)c,d,e,f,G(g,16),G(h,16), \
2130 (PCRE2_SPTR16)i,j,(PCRE2_UCHAR16 *)k,l)
2131 #define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \
2132 a = pcre2_substring_copy_byname_16(G(b,16),G(c,16),(PCRE2_UCHAR16 *)d,e)
2133 #define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \
2134 a = pcre2_substring_copy_bynumber_16(G(b,16),c,(PCRE2_UCHAR16 *)d,e)
2135 #define PCRE2_SUBSTRING_FREE(a) pcre2_substring_free_16((PCRE2_UCHAR16 *)a)
2136 #define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \
2137 a = pcre2_substring_get_byname_16(G(b,16),G(c,16),(PCRE2_UCHAR16 **)d,e)
2138 #define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \
2139 a = pcre2_substring_get_bynumber_16(G(b,16),c,(PCRE2_UCHAR16 **)d,e)
2140 #define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \
2141 a = pcre2_substring_length_byname_16(G(b,16),G(c,16),d)
2142 #define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \
2143 a = pcre2_substring_length_bynumber_16(G(b,16),c,d)
2144 #define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \
2145 a = pcre2_substring_list_get_16(G(b,16),(PCRE2_UCHAR16 ***)c,d)
2146 #define PCRE2_SUBSTRING_LIST_FREE(a) \
2147 pcre2_substring_list_free_16((PCRE2_SPTR16 *)a)
2148 #define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \
2149 a = pcre2_substring_number_from_name_16(G(b,16),G(c,16));
2150 #define PTR(x) (void *)G(x,16)
2151 #define SETFLD(x,y,z) G(x,16)->y = z
2152 #define SETFLDVEC(x,y,v,z) G(x,16)->y[v] = z
2153 #define SETOP(x,y,z) G(x,16) z y
2154 #define SETCASTPTR(x,y) G(x,16) = (uint16_t *)(y)
2155 #define STRLEN(p) (int)strlen16((PCRE2_SPTR16)p)
2156 #define SUB1(a,b) G(a,16)(G(b,16))
2157 #define SUB2(a,b,c) G(a,16)(G(b,16),G(c,16))
2158 #define TEST(x,r,y) (G(x,16) r (y))
2159 #define TESTFLD(x,f,r,y) (G(x,16)->f r (y))
2162 /* ----- Only 32-bit mode is supported ----- */
2164 #elif defined SUPPORT_PCRE2_32
2165 #define CASTFLD(t,a,b) (t)(G(a,32)->b)
2166 #define CASTVAR(t,x) (t)G(x,32)
2167 #define CODE_UNIT(a,b) (uint32_t)(((PCRE2_SPTR32)(a))[b])
2168 #define CONCTXCPY(a,b) memcpy(G(a,32),G(b,32),sizeof(pcre2_convert_context_32))
2169 #define CONVERT_COPY(a,b,c) memcpy(G(a,32),(char *)b, (c)*4)
2170 #define DATCTXCPY(a,b) memcpy(G(a,32),G(b,32),sizeof(pcre2_match_context_32))
2171 #define FLD(a,b) G(a,32)->b
2172 #define PATCTXCPY(a,b) memcpy(G(a,32),G(b,32),sizeof(pcre2_compile_context_32))
2173 #define PCHARS(lv, p, offset, len, utf, f) \
2174 lv = pchars32((PCRE2_SPTR32)(p)+offset, len, utf, f)
2175 #define PCHARSV(p, offset, len, utf, f) \
2176 (void)pchars32((PCRE2_SPTR32)(p)+offset, len, utf, f)
2177 #define PCRE2_CALLOUT_ENUMERATE(a,b,c) \
2178 a = pcre2_callout_enumerate_32(compiled_code32, \
2179 (int (*)(struct pcre2_callout_enumerate_block_32 *, void *))b,c)
2180 #define PCRE2_CODE_COPY_FROM_VOID(a,b) G(a,32) = pcre2_code_copy_32(b)
2181 #define PCRE2_CODE_COPY_TO_VOID(a,b) a = (void *)pcre2_code_copy_32(G(b,32))
2182 #define PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(a,b) a = (void *)pcre2_code_copy_with_tables_32(G(b,32))
2183 #define PCRE2_COMPILE(a,b,c,d,e,f,g) \
2184 G(a,32) = pcre2_compile_32(G(b,32),c,d,e,f,g)
2185 #define PCRE2_CONVERTED_PATTERN_FREE(a) \
2186 pcre2_converted_pattern_free_32((PCRE2_UCHAR32 *)a)
2187 #define PCRE2_DFA_MATCH(a,b,c,d,e,f,g,h,i,j) \
2188 a = pcre2_dfa_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h,i,j)
2189 #define PCRE2_GET_ERROR_MESSAGE(r,a,b) \
2190 r = pcre2_get_error_message_32(a,G(b,32),G(G(b,32),_size/4))
2191 #define PCRE2_GET_OVECTOR_COUNT(a,b) a = pcre2_get_ovector_count_32(G(b,32))
2192 #define PCRE2_GET_STARTCHAR(a,b) a = pcre2_get_startchar_32(G(b,32))
2193 #define PCRE2_JIT_COMPILE(r,a,b) r = pcre2_jit_compile_32(G(a,32),b)
2194 #define PCRE2_JIT_FREE_UNUSED_MEMORY(a) pcre2_jit_free_unused_memory_32(G(a,32))
2195 #define PCRE2_JIT_MATCH(a,b,c,d,e,f,g,h) \
2196 a = pcre2_jit_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h)
2197 #define PCRE2_JIT_STACK_CREATE(a,b,c,d) \
2198 a = (PCRE2_JIT_STACK *)pcre2_jit_stack_create_32(b,c,d);
2199 #define PCRE2_JIT_STACK_ASSIGN(a,b,c) \
2200 pcre2_jit_stack_assign_32(G(a,32),(pcre2_jit_callback_32)b,c);
2201 #define PCRE2_JIT_STACK_FREE(a) pcre2_jit_stack_free_32((pcre2_jit_stack_32 *)a);
2202 #define PCRE2_MAKETABLES(a) a = pcre2_maketables_32(NULL)
2203 #define PCRE2_MATCH(a,b,c,d,e,f,g,h) \
2204 a = pcre2_match_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),h)
2205 #define PCRE2_MATCH_DATA_CREATE(a,b,c) G(a,32) = pcre2_match_data_create_32(b,c)
2206 #define PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(a,b,c) \
2207 G(a,32) = pcre2_match_data_create_from_pattern_32(G(b,32),c)
2208 #define PCRE2_MATCH_DATA_FREE(a) pcre2_match_data_free_32(G(a,32))
2209 #define PCRE2_PATTERN_CONVERT(a,b,c,d,e,f,g) a = pcre2_pattern_convert_32(G(b,32),c,d,(PCRE2_UCHAR32 **)e,f,G(g,32))
2210 #define PCRE2_PATTERN_INFO(a,b,c,d) a = pcre2_pattern_info_32(G(b,32),c,d)
2211 #define PCRE2_PRINTINT(a) pcre2_printint_32(compiled_code32,outfile,a)
2212 #define PCRE2_SERIALIZE_DECODE(r,a,b,c,d) \
2213 r = pcre2_serialize_decode_32((pcre2_code_32 **)a,b,c,G(d,32))
2214 #define PCRE2_SERIALIZE_ENCODE(r,a,b,c,d,e) \
2215 r = pcre2_serialize_encode_32((const pcre2_code_32 **)a,b,c,d,G(e,32))
2216 #define PCRE2_SERIALIZE_FREE(a) pcre2_serialize_free_32(a)
2217 #define PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(r,a) \
2218 r = pcre2_serialize_get_number_of_codes_32(a)
2219 #define PCRE2_SET_CALLOUT(a,b,c) \
2220 pcre2_set_callout_32(G(a,32),(int (*)(pcre2_callout_block_32 *, void *))b,c);
2221 #define PCRE2_SET_CHARACTER_TABLES(a,b) pcre2_set_character_tables_32(G(a,32),b)
2222 #define PCRE2_SET_COMPILE_RECURSION_GUARD(a,b,c) \
2223 pcre2_set_compile_recursion_guard_32(G(a,32),b,c)
2224 #define PCRE2_SET_DEPTH_LIMIT(a,b) pcre2_set_depth_limit_32(G(a,32),b)
2225 #define PCRE2_SET_GLOB_ESCAPE(r,a,b) r = pcre2_set_glob_escape_32(G(a,32),b)
2226 #define PCRE2_SET_GLOB_SEPARATOR(r,a,b) r = pcre2_set_glob_separator_32(G(a,32),b)
2227 #define PCRE2_SET_HEAP_LIMIT(a,b) pcre2_set_heap_limit_32(G(a,32),b)
2228 #define PCRE2_SET_MATCH_LIMIT(a,b) pcre2_set_match_limit_32(G(a,32),b)
2229 #define PCRE2_SET_MAX_PATTERN_LENGTH(a,b) pcre2_set_max_pattern_length_32(G(a,32),b)
2230 #define PCRE2_SET_OFFSET_LIMIT(a,b) pcre2_set_offset_limit_32(G(a,32),b)
2231 #define PCRE2_SET_PARENS_NEST_LIMIT(a,b) pcre2_set_parens_nest_limit_32(G(a,32),b)
2232 #define PCRE2_SUBSTITUTE(a,b,c,d,e,f,g,h,i,j,k,l) \
2233 a = pcre2_substitute_32(G(b,32),(PCRE2_SPTR32)c,d,e,f,G(g,32),G(h,32), \
2234 (PCRE2_SPTR32)i,j,(PCRE2_UCHAR32 *)k,l)
2235 #define PCRE2_SUBSTRING_COPY_BYNAME(a,b,c,d,e) \
2236 a = pcre2_substring_copy_byname_32(G(b,32),G(c,32),(PCRE2_UCHAR32 *)d,e)
2237 #define PCRE2_SUBSTRING_COPY_BYNUMBER(a,b,c,d,e) \
2238 a = pcre2_substring_copy_bynumber_32(G(b,32),c,(PCRE2_UCHAR32 *)d,e);
2239 #define PCRE2_SUBSTRING_FREE(a) pcre2_substring_free_32((PCRE2_UCHAR32 *)a)
2240 #define PCRE2_SUBSTRING_GET_BYNAME(a,b,c,d,e) \
2241 a = pcre2_substring_get_byname_32(G(b,32),G(c,32),(PCRE2_UCHAR32 **)d,e)
2242 #define PCRE2_SUBSTRING_GET_BYNUMBER(a,b,c,d,e) \
2243 a = pcre2_substring_get_bynumber_32(G(b,32),c,(PCRE2_UCHAR32 **)d,e)
2244 #define PCRE2_SUBSTRING_LENGTH_BYNAME(a,b,c,d) \
2245 a = pcre2_substring_length_byname_32(G(b,32),G(c,32),d)
2246 #define PCRE2_SUBSTRING_LENGTH_BYNUMBER(a,b,c,d) \
2247 a = pcre2_substring_length_bynumber_32(G(b,32),c,d)
2248 #define PCRE2_SUBSTRING_LIST_GET(a,b,c,d) \
2249 a = pcre2_substring_list_get_32(G(b,32),(PCRE2_UCHAR32 ***)c,d)
2250 #define PCRE2_SUBSTRING_LIST_FREE(a) \
2251 pcre2_substring_list_free_32((PCRE2_SPTR32 *)a)
2252 #define PCRE2_SUBSTRING_NUMBER_FROM_NAME(a,b,c) \
2253 a = pcre2_substring_number_from_name_32(G(b,32),G(c,32));
2254 #define PTR(x) (void *)G(x,32)
2255 #define SETFLD(x,y,z) G(x,32)->y = z
2256 #define SETFLDVEC(x,y,v,z) G(x,32)->y[v] = z
2257 #define SETOP(x,y,z) G(x,32) z y
2258 #define SETCASTPTR(x,y) G(x,32) = (uint32_t *)(y)
2259 #define STRLEN(p) (int)strlen32((PCRE2_SPTR32)p)
2260 #define SUB1(a,b) G(a,32)(G(b,32))
2261 #define SUB2(a,b,c) G(a,32)(G(b,32),G(c,32))
2262 #define TEST(x,r,y) (G(x,32) r (y))
2263 #define TESTFLD(x,f,r,y) (G(x,32)->f r (y))
2267 /* ----- End of mode-specific function call macros ----- */
2272 /*************************************************
2273 * Alternate character tables *
2274 *************************************************/
2276 /* By default, the "tables" pointer in the compile context when calling
2277 pcre2_compile() is not set (= NULL), thereby using the default tables of the
2278 library. However, the tables modifier can be used to select alternate sets of
2279 tables, for different kinds of testing. Note that the locale modifier also
2280 adjusts the tables. */
2282 /* This is the set of tables distributed as default with PCRE2. It recognizes
2283 only ASCII characters. */
2285 static const uint8_t tables1[] = {
2287 /* This table is a lower casing table. */
2289 0, 1, 2, 3, 4, 5, 6, 7,
2290 8, 9, 10, 11, 12, 13, 14, 15,
2291 16, 17, 18, 19, 20, 21, 22, 23,
2292 24, 25, 26, 27, 28, 29, 30, 31,
2293 32, 33, 34, 35, 36, 37, 38, 39,
2294 40, 41, 42, 43, 44, 45, 46, 47,
2295 48, 49, 50, 51, 52, 53, 54, 55,
2296 56, 57, 58, 59, 60, 61, 62, 63,
2297 64, 97, 98, 99,100,101,102,103,
2298 104,105,106,107,108,109,110,111,
2299 112,113,114,115,116,117,118,119,
2300 120,121,122, 91, 92, 93, 94, 95,
2301 96, 97, 98, 99,100,101,102,103,
2302 104,105,106,107,108,109,110,111,
2303 112,113,114,115,116,117,118,119,
2304 120,121,122,123,124,125,126,127,
2305 128,129,130,131,132,133,134,135,
2306 136,137,138,139,140,141,142,143,
2307 144,145,146,147,148,149,150,151,
2308 152,153,154,155,156,157,158,159,
2309 160,161,162,163,164,165,166,167,
2310 168,169,170,171,172,173,174,175,
2311 176,177,178,179,180,181,182,183,
2312 184,185,186,187,188,189,190,191,
2313 192,193,194,195,196,197,198,199,
2314 200,201,202,203,204,205,206,207,
2315 208,209,210,211,212,213,214,215,
2316 216,217,218,219,220,221,222,223,
2317 224,225,226,227,228,229,230,231,
2318 232,233,234,235,236,237,238,239,
2319 240,241,242,243,244,245,246,247,
2320 248,249,250,251,252,253,254,255,
2322 /* This table is a case flipping table. */
2324 0, 1, 2, 3, 4, 5, 6, 7,
2325 8, 9, 10, 11, 12, 13, 14, 15,
2326 16, 17, 18, 19, 20, 21, 22, 23,
2327 24, 25, 26, 27, 28, 29, 30, 31,
2328 32, 33, 34, 35, 36, 37, 38, 39,
2329 40, 41, 42, 43, 44, 45, 46, 47,
2330 48, 49, 50, 51, 52, 53, 54, 55,
2331 56, 57, 58, 59, 60, 61, 62, 63,
2332 64, 97, 98, 99,100,101,102,103,
2333 104,105,106,107,108,109,110,111,
2334 112,113,114,115,116,117,118,119,
2335 120,121,122, 91, 92, 93, 94, 95,
2336 96, 65, 66, 67, 68, 69, 70, 71,
2337 72, 73, 74, 75, 76, 77, 78, 79,
2338 80, 81, 82, 83, 84, 85, 86, 87,
2339 88, 89, 90,123,124,125,126,127,
2340 128,129,130,131,132,133,134,135,
2341 136,137,138,139,140,141,142,143,
2342 144,145,146,147,148,149,150,151,
2343 152,153,154,155,156,157,158,159,
2344 160,161,162,163,164,165,166,167,
2345 168,169,170,171,172,173,174,175,
2346 176,177,178,179,180,181,182,183,
2347 184,185,186,187,188,189,190,191,
2348 192,193,194,195,196,197,198,199,
2349 200,201,202,203,204,205,206,207,
2350 208,209,210,211,212,213,214,215,
2351 216,217,218,219,220,221,222,223,
2352 224,225,226,227,228,229,230,231,
2353 232,233,234,235,236,237,238,239,
2354 240,241,242,243,244,245,246,247,
2355 248,249,250,251,252,253,254,255,
2357 /* This table contains bit maps for various character classes. Each map is 32
2358 bytes long and the bits run from the least significant end of each byte. The
2359 classes that have their own maps are: space, xdigit, digit, upper, lower, word,
2360 graph, print, punct, and cntrl. Other classes are built from combinations. */
2362 0x00,0x3e,0x00,0x00,0x01,0x00,0x00,0x00,
2363 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2364 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2365 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2367 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
2368 0x7e,0x00,0x00,0x00,0x7e,0x00,0x00,0x00,
2369 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2370 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2372 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
2373 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2374 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2375 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2377 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2378 0xfe,0xff,0xff,0x07,0x00,0x00,0x00,0x00,
2379 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2380 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2382 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2383 0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0x07,
2384 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2385 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2387 0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x03,
2388 0xfe,0xff,0xff,0x87,0xfe,0xff,0xff,0x07,
2389 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2390 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2392 0x00,0x00,0x00,0x00,0xfe,0xff,0xff,0xff,
2393 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
2394 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2395 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2397 0x00,0x00,0x00,0x00,0xff,0xff,0xff,0xff,
2398 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,
2399 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2400 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2402 0x00,0x00,0x00,0x00,0xfe,0xff,0x00,0xfc,
2403 0x01,0x00,0x00,0xf8,0x01,0x00,0x00,0x78,
2404 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2405 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2407 0xff,0xff,0xff,0xff,0x00,0x00,0x00,0x00,
2408 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
2409 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2410 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
2412 /* This table identifies various classes of character by individual bits:
2413 0x01 white space character
2416 0x08 hexadecimal digit
2417 0x10 alphanumeric or '_'
2418 0x80 regular expression metacharacter or binary zero
2421 0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 0- 7 */
2422 0x00,0x01,0x01,0x01,0x01,0x01,0x00,0x00, /* 8- 15 */
2423 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 16- 23 */
2424 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 24- 31 */
2425 0x01,0x00,0x00,0x00,0x80,0x00,0x00,0x00, /* - ' */
2426 0x80,0x80,0x80,0x80,0x00,0x00,0x80,0x00, /* ( - / */
2427 0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c, /* 0 - 7 */
2428 0x1c,0x1c,0x00,0x00,0x00,0x00,0x00,0x80, /* 8 - ? */
2429 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* @ - G */
2430 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* H - O */
2431 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* P - W */
2432 0x12,0x12,0x12,0x80,0x80,0x00,0x80,0x10, /* X - _ */
2433 0x00,0x1a,0x1a,0x1a,0x1a,0x1a,0x1a,0x12, /* ` - g */
2434 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* h - o */
2435 0x12,0x12,0x12,0x12,0x12,0x12,0x12,0x12, /* p - w */
2436 0x12,0x12,0x12,0x80,0x80,0x00,0x00,0x00, /* x -127 */
2437 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 128-135 */
2438 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 136-143 */
2439 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 144-151 */
2440 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 152-159 */
2441 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 160-167 */
2442 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 168-175 */
2443 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 176-183 */
2444 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 184-191 */
2445 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 192-199 */
2446 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 200-207 */
2447 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 208-215 */
2448 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 216-223 */
2449 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 224-231 */
2450 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 232-239 */
2451 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, /* 240-247 */
2452 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};/* 248-255 */
2454 /* This is a set of tables that came originally from a Windows user. It seems
2455 to be at least an approximation of ISO 8859. In particular, there are
2456 characters greater than 128 that are marked as spaces, letters, etc. */
2458 static const uint8_t tables2[] = {
2460 8,9,10,11,12,13,14,15,
2461 16,17,18,19,20,21,22,23,
2462 24,25,26,27,28,29,30,31,
2463 32,33,34,35,36,37,38,39,
2464 40,41,42,43,44,45,46,47,
2465 48,49,50,51,52,53,54,55,
2466 56,57,58,59,60,61,62,63,
2467 64,97,98,99,100,101,102,103,
2468 104,105,106,107,108,109,110,111,
2469 112,113,114,115,116,117,118,119,
2470 120,121,122,91,92,93,94,95,
2471 96,97,98,99,100,101,102,103,
2472 104,105,106,107,108,109,110,111,
2473 112,113,114,115,116,117,118,119,
2474 120,121,122,123,124,125,126,127,
2475 128,129,130,131,132,133,134,135,
2476 136,137,138,139,140,141,142,143,
2477 144,145,146,147,148,149,150,151,
2478 152,153,154,155,156,157,158,159,
2479 160,161,162,163,164,165,166,167,
2480 168,169,170,171,172,173,174,175,
2481 176,177,178,179,180,181,182,183,
2482 184,185,186,187,188,189,190,191,
2483 224,225,226,227,228,229,230,231,
2484 232,233,234,235,236,237,238,239,
2485 240,241,242,243,244,245,246,215,
2486 248,249,250,251,252,253,254,223,
2487 224,225,226,227,228,229,230,231,
2488 232,233,234,235,236,237,238,239,
2489 240,241,242,243,244,245,246,247,
2490 248,249,250,251,252,253,254,255,
2492 8,9,10,11,12,13,14,15,
2493 16,17,18,19,20,21,22,23,
2494 24,25,26,27,28,29,30,31,
2495 32,33,34,35,36,37,38,39,
2496 40,41,42,43,44,45,46,47,
2497 48,49,50,51,52,53,54,55,
2498 56,57,58,59,60,61,62,63,
2499 64,97,98,99,100,101,102,103,
2500 104,105,106,107,108,109,110,111,
2501 112,113,114,115,116,117,118,119,
2502 120,121,122,91,92,93,94,95,
2503 96,65,66,67,68,69,70,71,
2504 72,73,74,75,76,77,78,79,
2505 80,81,82,83,84,85,86,87,
2506 88,89,90,123,124,125,126,127,
2507 128,129,130,131,132,133,134,135,
2508 136,137,138,139,140,141,142,143,
2509 144,145,146,147,148,149,150,151,
2510 152,153,154,155,156,157,158,159,
2511 160,161,162,163,164,165,166,167,
2512 168,169,170,171,172,173,174,175,
2513 176,177,178,179,180,181,182,183,
2514 184,185,186,187,188,189,190,191,
2515 224,225,226,227,228,229,230,231,
2516 232,233,234,235,236,237,238,239,
2517 240,241,242,243,244,245,246,215,
2518 248,249,250,251,252,253,254,223,
2519 192,193,194,195,196,197,198,199,
2520 200,201,202,203,204,205,206,207,
2521 208,209,210,211,212,213,214,247,
2522 216,217,218,219,220,221,222,255,
2528 126,0,0,0,126,0,0,0,
2536 254,255,255,7,0,0,0,0,
2538 255,255,127,127,0,0,0,0,
2540 0,0,0,0,254,255,255,7,
2542 0,0,0,128,255,255,127,255,
2544 254,255,255,135,254,255,255,7,
2546 255,255,127,255,255,255,127,255,
2547 0,0,0,0,254,255,255,255,
2548 255,255,255,255,255,255,255,127,
2549 0,0,0,0,254,255,255,255,
2550 255,255,255,255,255,255,255,255,
2551 0,2,0,0,255,255,255,255,
2552 255,255,255,255,255,255,255,127,
2553 0,0,0,0,255,255,255,255,
2554 255,255,255,255,255,255,255,255,
2555 0,0,0,0,254,255,0,252,
2556 1,0,0,248,1,0,0,120,
2557 0,0,0,0,254,255,255,255,
2558 0,0,128,0,0,0,128,0,
2559 255,255,255,255,0,0,0,0,
2561 255,255,255,255,0,0,0,0,
2568 128,128,128,128,0,0,128,0,
2569 28,28,28,28,28,28,28,28,
2570 28,28,0,0,0,0,0,128,
2571 0,26,26,26,26,26,26,18,
2572 18,18,18,18,18,18,18,18,
2573 18,18,18,18,18,18,18,18,
2574 18,18,18,128,128,0,128,16,
2575 0,26,26,26,26,26,26,18,
2576 18,18,18,18,18,18,18,18,
2577 18,18,18,18,18,18,18,18,
2578 18,18,18,128,128,0,0,0,
2587 18,18,18,18,18,18,18,18,
2588 18,18,18,18,18,18,18,18,
2589 18,18,18,18,18,18,18,0,
2590 18,18,18,18,18,18,18,18,
2591 18,18,18,18,18,18,18,18,
2592 18,18,18,18,18,18,18,18,
2593 18,18,18,18,18,18,18,0,
2594 18,18,18,18,18,18,18,18
2599 #if !defined(VPCOMPAT) && !defined(HAVE_MEMMOVE)
2600 /*************************************************
2601 * Emulated memmove() for systems without it *
2602 *************************************************/
2604 /* This function can make use of bcopy() if it is available. Otherwise do it by
2605 steam, as there are some non-Unix environments that lack both memmove() and
2609 emulated_memmove(void *d, const void *s, size_t n)
2616 unsigned char *dest = (unsigned char *)d;
2617 const unsigned char *src = (const unsigned char *)s;
2622 for (i = 0; i < n; ++i) *(--dest) = *(--src);
2623 return (void *)dest;
2627 for (i = 0; i < n; ++i) *dest++ = *src++;
2628 return (void *)(dest - n);
2630 #endif /* not HAVE_BCOPY */
2633 #define memmove(d,s,n) emulated_memmove(d,s,n)
2634 #endif /* not VPCOMPAT && not HAVE_MEMMOVE */
2638 #ifndef HAVE_STRERROR
2639 /*************************************************
2640 * Provide strerror() for non-ANSI libraries *
2641 *************************************************/
2643 /* Some old-fashioned systems (e.g. SunOS4) didn't have strerror() in their
2644 libraries. They may no longer be around, but just in case, we can try to
2645 provide the same facility by this simple alternative function. */
2647 extern int sys_nerr;
2648 extern char *sys_errlist[];
2653 if (n < 0 || n >= sys_nerr) return "unknown error number";
2654 return sys_errlist[n];
2656 #endif /* HAVE_STRERROR */
2660 /*************************************************
2661 * Local memory functions *
2662 *************************************************/
2664 /* Alternative memory functions, to test functionality. */
2666 static void *my_malloc(PCRE2_SIZE size, void *data)
2668 void *block = malloc(size);
2674 fprintf(outfile, "** malloc() failed for %" SIZ_FORM "\n", SIZ_CAST size);
2678 fprintf(outfile, "malloc %5" SIZ_FORM, SIZ_CAST size);
2679 #ifdef DEBUG_SHOW_MALLOC_ADDRESSES
2680 fprintf(outfile, " %p", block); /* Not portable */
2682 if (malloclistptr < MALLOCLISTSIZE)
2684 malloclist[malloclistptr] = block;
2685 malloclistlength[malloclistptr++] = size;
2688 fprintf(outfile, " (not remembered)");
2689 fprintf(outfile, "\n");
2695 static void my_free(void *block, void *data)
2703 fprintf(outfile, "free");
2704 for (i = 0; i < malloclistptr; i++)
2706 if (block == malloclist[i])
2708 fprintf(outfile, " %5" SIZ_FORM, SIZ_CAST malloclistlength[i]);
2710 for (j = i; j < malloclistptr; j++)
2712 malloclist[j] = malloclist[j+1];
2713 malloclistlength[j] = malloclistlength[j+1];
2719 if (!found) fprintf(outfile, " unremembered block");
2720 #ifdef DEBUG_SHOW_MALLOC_ADDRESSES
2721 fprintf(outfile, " %p", block); /* Not portable */
2723 fprintf(outfile, "\n");
2730 /*************************************************
2731 * Callback function for stack guard *
2732 *************************************************/
2734 /* This is set up to be called from pcre2_compile() when the stackguard=n
2735 modifier sets a value greater than zero. The test we do is whether the
2736 parenthesis nesting depth is greater than the value set by the modifier.
2738 Argument: the current parenthesis nesting depth
2739 Returns: non-zero to kill the compilation
2743 stack_guard(uint32_t depth, void *user_data)
2746 return depth > pat_patctl.stackguard_test;
2750 /*************************************************
2751 * JIT memory callback *
2752 *************************************************/
2754 static PCRE2_JIT_STACK*
2755 jit_callback(void *arg)
2757 jit_was_used = TRUE;
2758 return (PCRE2_JIT_STACK *)arg;
2762 /*************************************************
2763 * Convert UTF-8 character to code point *
2764 *************************************************/
2766 /* This function reads one or more bytes that represent a UTF-8 character,
2767 and returns the codepoint of that character. Note that the function supports
2768 the original UTF-8 definition of RFC 2279, allowing for values in the range 0
2769 to 0x7fffffff, up to 6 bytes long. This makes it possible to generate
2770 codepoints greater than 0x10ffff which are useful for testing PCRE2's error
2771 checking, and also for generating 32-bit non-UTF data values above the UTF
2775 utf8bytes a pointer to the byte vector
2776 vptr a pointer to an int to receive the value
2778 Returns: > 0 => the number of bytes consumed
2779 -6 to 0 => malformed UTF-8 character at offset = (-return)
2783 utf82ord(PCRE2_SPTR8 utf8bytes, uint32_t *vptr)
2785 uint32_t c = *utf8bytes++;
2789 for (i = -1; i < 6; i++) /* i is number of additional bytes */
2791 if ((d & 0x80) == 0) break;
2795 if (i == -1) { *vptr = c; return 1; } /* ascii character */
2796 if (i == 0 || i == 6) return 0; /* invalid UTF-8 */
2798 /* i now has a value in the range 1-5 */
2801 d = (c & utf8_table3[i]) << s;
2803 for (j = 0; j < i; j++)
2806 if ((c & 0xc0) != 0x80) return -(j+1);
2808 d |= (c & 0x3f) << s;
2811 /* Check that encoding was the correct unique one */
2813 for (j = 0; j < utf8_table1_size; j++)
2814 if (d <= (uint32_t)utf8_table1[j]) break;
2815 if (j != i) return -(i+1);
2825 /*************************************************
2826 * Print one character *
2827 *************************************************/
2829 /* Print a single character either literally, or as a hex escape, and count how
2830 many printed characters are used.
2834 utf TRUE in UTF mode
2835 f the FILE to print to, or NULL just to count characters
2837 Returns: number of characters written
2841 pchar(uint32_t c, BOOL utf, FILE *f)
2844 char tempbuffer[16];
2848 if (f != NULL) fprintf(f, "%c", c);
2856 if (f != NULL) fprintf(f, "\\x{%02x}", c);
2861 if (f != NULL) fprintf(f, "\\x%02x", c);
2866 if (f != NULL) n = fprintf(f, "\\x{%02x}", c);
2867 else n = sprintf(tempbuffer, "\\x{%02x}", c);
2869 return n >= 0 ? n : 0;
2874 #ifdef SUPPORT_PCRE2_16
2875 /*************************************************
2876 * Find length of 0-terminated 16-bit string *
2877 *************************************************/
2879 static size_t strlen16(PCRE2_SPTR16 p)
2881 PCRE2_SPTR16 pp = p;
2882 while (*pp != 0) pp++;
2883 return (int)(pp - p);
2885 #endif /* SUPPORT_PCRE2_16 */
2889 #ifdef SUPPORT_PCRE2_32
2890 /*************************************************
2891 * Find length of 0-terminated 32-bit string *
2892 *************************************************/
2894 static size_t strlen32(PCRE2_SPTR32 p)
2896 PCRE2_SPTR32 pp = p;
2897 while (*pp != 0) pp++;
2898 return (int)(pp - p);
2900 #endif /* SUPPORT_PCRE2_32 */
2903 #ifdef SUPPORT_PCRE2_8
2904 /*************************************************
2905 * Print 8-bit character string *
2906 *************************************************/
2908 /* Must handle UTF-8 strings in utf8 mode. Yields number of characters printed.
2909 For printing *MARK strings, a negative length is given. If handed a NULL file,
2910 just counts chars without printing (because pchar() does that). */
2912 static int pchars8(PCRE2_SPTR8 p, int length, BOOL utf, FILE *f)
2917 if (length < 0) length = p[-1];
2918 while (length-- > 0)
2922 int rc = utf82ord(p, &c);
2923 if (rc > 0 && rc <= length + 1) /* Mustn't run over the end */
2927 yield += pchar(c, utf, f);
2932 yield += pchar(c, utf, f);
2940 #ifdef SUPPORT_PCRE2_16
2941 /*************************************************
2942 * Print 16-bit character string *
2943 *************************************************/
2945 /* Must handle UTF-16 strings in utf mode. Yields number of characters printed.
2946 For printing *MARK strings, a negative length is given. If handed a NULL file,
2947 just counts chars without printing. */
2949 static int pchars16(PCRE2_SPTR16 p, int length, BOOL utf, FILE *f)
2952 if (length < 0) length = p[-1];
2953 while (length-- > 0)
2955 uint32_t c = *p++ & 0xffff;
2956 if (utf && c >= 0xD800 && c < 0xDC00 && length > 0)
2958 int d = *p & 0xffff;
2959 if (d >= 0xDC00 && d <= 0xDFFF)
2961 c = ((c & 0x3ff) << 10) + (d & 0x3ff) + 0x10000;
2966 yield += pchar(c, utf, f);
2970 #endif /* SUPPORT_PCRE2_16 */
2974 #ifdef SUPPORT_PCRE2_32
2975 /*************************************************
2976 * Print 32-bit character string *
2977 *************************************************/
2979 /* Must handle UTF-32 strings in utf mode. Yields number of characters printed.
2980 For printing *MARK strings, a negative length is given. If handed a NULL file,
2981 just counts chars without printing. */
2983 static int pchars32(PCRE2_SPTR32 p, int length, BOOL utf, FILE *f)
2986 (void)(utf); /* Avoid compiler warning */
2988 if (length < 0) length = p[-1];
2989 while (length-- > 0)
2992 yield += pchar(c, utf, f);
2996 #endif /* SUPPORT_PCRE2_32 */
3001 #ifdef SUPPORT_PCRE2_8
3002 /*************************************************
3003 * Convert character value to UTF-8 *
3004 *************************************************/
3006 /* This function takes an integer value in the range 0 - 0x7fffffff
3007 and encodes it as a UTF-8 character in 0 to 6 bytes.
3010 cvalue the character value
3011 utf8bytes pointer to buffer for result - at least 6 bytes long
3013 Returns: number of characters placed in the buffer
3017 ord2utf8(uint32_t cvalue, uint8_t *utf8bytes)
3020 if (cvalue > 0x7fffffffu)
3022 for (i = 0; i < utf8_table1_size; i++)
3023 if (cvalue <= (uint32_t)utf8_table1[i]) break;
3025 for (j = i; j > 0; j--)
3027 *utf8bytes-- = 0x80 | (cvalue & 0x3f);
3030 *utf8bytes = utf8_table2[i] | cvalue;
3033 #endif /* SUPPORT_PCRE2_8 */
3037 #ifdef SUPPORT_PCRE2_16
3038 /*************************************************
3039 * Convert string to 16-bit *
3040 *************************************************/
3042 /* In UTF mode the input is always interpreted as a string of UTF-8 bytes using
3043 the original UTF-8 definition of RFC 2279, which allows for up to 6 bytes, and
3044 code values from 0 to 0x7fffffff. However, values greater than the later UTF
3045 limit of 0x10ffff cause an error. In non-UTF mode the input is interpreted as
3046 UTF-8 if the utf8_input modifier is set, but an error is generated for values
3047 greater than 0xffff.
3049 If all the input bytes are ASCII, the space needed for a 16-bit string is
3050 exactly double the 8-bit size. Otherwise, the size needed for a 16-bit string
3051 is no more than double, because up to 0xffff uses no more than 3 bytes in UTF-8
3052 but possibly 4 in UTF-16. Higher values use 4 bytes in UTF-8 and up to 4 bytes
3053 in UTF-16. The result is always left in pbuffer16. Impose a minimum size to
3054 save repeated re-sizing.
3056 Note that this function does not object to surrogate values. This is
3057 deliberate; it makes it possible to construct UTF-16 strings that are invalid,
3058 for the purpose of testing that they are correctly faulted.
3061 p points to a byte string
3062 utf true in UTF mode
3063 lenptr points to number of bytes in the string (excluding trailing zero)
3065 Returns: 0 on success, with the length updated to the number of 16-bit
3066 data items used (excluding the trailing zero)
3067 OR -1 if a UTF-8 string is malformed
3068 OR -2 if a value > 0x10ffff is encountered in UTF mode
3069 OR -3 if a value > 0xffff is encountered when not in UTF mode
3073 to16(uint8_t *p, int utf, PCRE2_SIZE *lenptr)
3076 PCRE2_SIZE len = *lenptr;
3078 if (pbuffer16_size < 2*len + 2)
3080 if (pbuffer16 != NULL) free(pbuffer16);
3081 pbuffer16_size = 2*len + 2;
3082 if (pbuffer16_size < 4096) pbuffer16_size = 4096;
3083 pbuffer16 = (uint16_t *)malloc(pbuffer16_size);
3084 if (pbuffer16 == NULL)
3086 fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n",
3087 SIZ_CAST pbuffer16_size);
3093 if (!utf && (pat_patctl.control & CTL_UTF8_INPUT) == 0)
3095 for (; len > 0; len--) *pp++ = *p++;
3097 else while (len > 0)
3100 int chlen = utf82ord(p, &c);
3101 if (chlen <= 0) return -1;
3102 if (!utf && c > 0xffff) return -3;
3103 if (c > 0x10ffff) return -2;
3106 if (c < 0x10000) *pp++ = c; else
3109 *pp++ = 0xD800 | (c >> 10);
3110 *pp++ = 0xDC00 | (c & 0x3ff);
3115 *lenptr = pp - pbuffer16;
3122 #ifdef SUPPORT_PCRE2_32
3123 /*************************************************
3124 * Convert string to 32-bit *
3125 *************************************************/
3127 /* In UTF mode the input is always interpreted as a string of UTF-8 bytes using
3128 the original UTF-8 definition of RFC 2279, which allows for up to 6 bytes, and
3129 code values from 0 to 0x7fffffff. However, values greater than the later UTF
3130 limit of 0x10ffff cause an error.
3132 In non-UTF mode the input is interpreted as UTF-8 if the utf8_input modifier
3133 is set, and no limit is imposed. There is special interpretation of the 0xff
3134 byte (which is illegal in UTF-8) in this case: it causes the top bit of the
3135 next character to be set. This provides a way of generating 32-bit characters
3136 greater than 0x7fffffff.
3138 If all the input bytes are ASCII, the space needed for a 32-bit string is
3139 exactly four times the 8-bit size. Otherwise, the size needed for a 32-bit
3140 string is no more than four times, because the number of characters must be
3141 less than the number of bytes. The result is always left in pbuffer32. Impose a
3142 minimum size to save repeated re-sizing.
3144 Note that this function does not object to surrogate values. This is
3145 deliberate; it makes it possible to construct UTF-32 strings that are invalid,
3146 for the purpose of testing that they are correctly faulted.
3149 p points to a byte string
3150 utf true in UTF mode
3151 lenptr points to number of bytes in the string (excluding trailing zero)
3153 Returns: 0 on success, with the length updated to the number of 32-bit
3154 data items used (excluding the trailing zero)
3155 OR -1 if a UTF-8 string is malformed
3156 OR -2 if a value > 0x10ffff is encountered in UTF mode
3160 to32(uint8_t *p, int utf, PCRE2_SIZE *lenptr)
3163 PCRE2_SIZE len = *lenptr;
3165 if (pbuffer32_size < 4*len + 4)
3167 if (pbuffer32 != NULL) free(pbuffer32);
3168 pbuffer32_size = 4*len + 4;
3169 if (pbuffer32_size < 8192) pbuffer32_size = 8192;
3170 pbuffer32 = (uint32_t *)malloc(pbuffer32_size);
3171 if (pbuffer32 == NULL)
3173 fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n",
3174 SIZ_CAST pbuffer32_size);
3181 if (!utf && (pat_patctl.control & CTL_UTF8_INPUT) == 0)
3183 for (; len > 0; len--) *pp++ = *p++;
3186 else while (len > 0)
3190 uint32_t topbit = 0;
3191 if (!utf && *p == 0xff && len > 1)
3193 topbit = 0x80000000u;
3197 chlen = utf82ord(p, &c);
3198 if (chlen <= 0) return -1;
3199 if (utf && c > 0x10ffff) return -2;
3206 *lenptr = pp - pbuffer32;
3209 #endif /* SUPPORT_PCRE2_32 */
3213 /*************************************************
3214 * Move back by so many characters *
3215 *************************************************/
3217 /* Given a code unit offset in a subject string, move backwards by a number of
3218 characters, and return the resulting offset.
3221 subject pointer to the string
3223 count count to move back by
3224 utf TRUE if in UTF mode
3226 Returns: a possibly changed offset
3230 backchars(uint8_t *subject, PCRE2_SIZE offset, uint32_t count, BOOL utf)
3232 if (!utf || test_mode == PCRE32_MODE)
3233 return (count >= offset)? 0 : (offset - count);
3235 else if (test_mode == PCRE8_MODE)
3237 PCRE2_SPTR8 pp = (PCRE2_SPTR8)subject + offset;
3238 for (; count > 0 && pp > (PCRE2_SPTR8)subject; count--)
3241 while ((*pp & 0xc0) == 0x80) pp--;
3243 return pp - (PCRE2_SPTR8)subject;
3246 else /* 16-bit mode */
3248 PCRE2_SPTR16 pp = (PCRE2_SPTR16)subject + offset;
3249 for (; count > 0 && pp > (PCRE2_SPTR16)subject; count--)
3252 if ((*pp & 0xfc00) == 0xdc00) pp--;
3254 return pp - (PCRE2_SPTR16)subject;
3260 /*************************************************
3261 * Expand input buffers *
3262 *************************************************/
3264 /* This function doubles the size of the input buffer and the buffer for
3265 keeping an 8-bit copy of patterns (pbuffer8), and copies the current buffers to
3269 Returns: nothing (aborts if malloc() fails)
3273 expand_input_buffers(void)
3275 int new_pbuffer8_size = 2*pbuffer8_size;
3276 uint8_t *new_buffer = (uint8_t *)malloc(new_pbuffer8_size);
3277 uint8_t *new_pbuffer8 = (uint8_t *)malloc(new_pbuffer8_size);
3279 if (new_buffer == NULL || new_pbuffer8 == NULL)
3281 fprintf(stderr, "pcre2test: malloc(%d) failed\n", new_pbuffer8_size);
3285 memcpy(new_buffer, buffer, pbuffer8_size);
3286 memcpy(new_pbuffer8, pbuffer8, pbuffer8_size);
3288 pbuffer8_size = new_pbuffer8_size;
3293 buffer = new_buffer;
3294 pbuffer8 = new_pbuffer8;
3299 /*************************************************
3300 * Read or extend an input line *
3301 *************************************************/
3303 /* Input lines are read into buffer, but both patterns and data lines can be
3304 continued over multiple input lines. In addition, if the buffer fills up, we
3305 want to automatically expand it so as to be able to handle extremely large
3306 lines that are needed for certain stress tests, although this is less likely
3307 now that there are repetition features for both patterns and data. When the
3308 input buffer is expanded, the other two buffers must also be expanded likewise,
3309 and the contents of pbuffer, which are a copy of the input for callouts, must
3310 be preserved (for when expansion happens for a data line). This is not the most
3311 optimal way of handling this, but hey, this is just a test program!
3315 start where in buffer to start (this *must* be within buffer)
3316 prompt for stdin or readline()
3318 Returns: pointer to the start of new data
3319 could be a copy of start, or could be moved
3320 NULL if no data read and EOF reached
3324 extend_inputline(FILE *f, uint8_t *start, const char *prompt)
3326 uint8_t *here = start;
3330 size_t rlen = (size_t)(pbuffer8_size - (here - buffer));
3336 /* If libreadline or libedit support is required, use readline() to read a
3337 line if the input is a terminal. Note that readline() removes the trailing
3338 newline, so we must put it back again, to be compatible with fgets(). */
3340 #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
3344 char *s = readline(prompt);
3345 if (s == NULL) return (here == start)? NULL : start;
3347 if (len > 0) add_history(s);
3348 if (len > rlen - 1) len = rlen - 1;
3349 memcpy(here, s, len);
3357 /* Read the next line by normal means, prompting if the file is a tty. */
3360 if (INTERACTIVE(f)) printf("%s", prompt);
3361 if (fgets((char *)here, rlen, f) == NULL)
3362 return (here == start)? NULL : start;
3365 dlen = strlen((char *)here);
3368 /* Check for end of line reached. Take care not to read data from before
3369 start (dlen will be zero for a file starting with a binary zero). */
3371 if (here > start && here[-1] == '\n') return start;
3373 /* If we have not read a newline when reading a file, we have either filled
3374 the buffer or reached the end of the file. We can detect the former by
3375 checking that the string fills the buffer, and the latter by feof(). If
3376 neither of these is true, it means we read a binary zero which has caused
3377 strlen() to give a short length. This is a hard error because pcre2test
3378 expects to work with C strings. */
3380 if (!INTERACTIVE(f) && dlen < rlen - 1 && !feof(f))
3382 fprintf(outfile, "** Binary zero encountered in input\n");
3383 fprintf(outfile, "** pcre2test run abandoned\n");
3390 size_t start_offset = start - buffer;
3391 size_t here_offset = here - buffer;
3392 expand_input_buffers();
3393 start = buffer + start_offset;
3394 here = buffer + here_offset;
3398 /* Control never gets here */
3403 /*************************************************
3404 * Case-independent strncmp() function *
3405 *************************************************/
3411 n number of characters to compare
3413 Returns: < 0, = 0, or > 0, according to the comparison
3417 strncmpic(const uint8_t *s, const uint8_t *t, int n)
3421 int c = tolower(*s++) - tolower(*t++);
3422 if (c != 0) return c;
3429 /*************************************************
3430 * Scan the main modifier list *
3431 *************************************************/
3433 /* This function searches the modifier list for a long modifier name.
3437 lenp length of the name
3439 Returns: an index in the modifier list, or -1 on failure
3443 scan_modifiers(const uint8_t *p, unsigned int len)
3446 int top = MODLISTCOUNT;
3450 int mid = (bot + top)/2;
3451 unsigned int mlen = strlen(modlist[mid].name);
3452 int c = strncmp((char *)p, modlist[mid].name, (len < mlen)? len : mlen);
3455 if (len == mlen) return mid;
3456 c = (int)len - (int)mlen;
3458 if (c > 0) bot = mid + 1; else top = mid;
3467 /*************************************************
3468 * Check a modifer and find its field *
3469 *************************************************/
3471 /* This function is called when a modifier has been identified. We check that
3472 it is allowed here and find the field that is to be changed.
3475 m the modifier list entry
3476 ctx CTX_PAT => pattern context
3477 CTX_POPPAT => pattern context for popped pattern
3478 CTX_DEFPAT => default pattern context
3479 CTX_DAT => data context
3480 CTX_DEFDAT => default data context
3481 pctl point to pattern control block
3482 dctl point to data control block
3483 c a single character or 0
3485 Returns: a field pointer or NULL
3489 check_modifier(modstruct *m, int ctx, patctl *pctl, datctl *dctl, uint32_t c)
3492 PCRE2_SIZE offset = m->offset;
3494 if (restrict_for_perl_test) switch(m->which)
3502 fprintf(outfile, "** '%s' is not allowed in a Perl-compatible test\n",
3509 case MOD_CTC: /* Compile context modifier */
3510 if (ctx == CTX_DEFPAT) field = PTR(default_pat_context);
3511 else if (ctx == CTX_PAT) field = PTR(pat_context);
3514 case MOD_CTM: /* Match context modifier */
3515 if (ctx == CTX_DEFDAT) field = PTR(default_dat_context);
3516 else if (ctx == CTX_DAT) field = PTR(dat_context);
3519 case MOD_DAT: /* Data line modifier */
3520 if (dctl != NULL) field = dctl;
3523 case MOD_PAT: /* Pattern modifier */
3524 case MOD_PATP: /* Allowed for Perl test */
3525 if (pctl != NULL) field = pctl;
3528 case MOD_PD: /* Pattern or data line modifier */
3529 case MOD_PDP: /* Ditto, allowed for Perl test */
3530 case MOD_PND: /* Ditto, but not default pattern */
3531 case MOD_PNDP: /* Ditto, allowed for Perl test */
3532 if (dctl != NULL) field = dctl;
3533 else if (pctl != NULL && (m->which == MOD_PD || m->which == MOD_PDP ||
3542 fprintf(outfile, "** '%s' is not valid here\n", m->name);
3544 fprintf(outfile, "** /%c is not valid here\n", c);
3548 return (char *)field + offset;
3553 /*************************************************
3554 * Decode a modifier list *
3555 *************************************************/
3557 /* A pointer to a control block is NULL when called in cases when that block is
3558 not relevant. They are never all relevant in one call. At least one of patctl
3559 and datctl is NULL. The second argument specifies which context to use for
3560 modifiers that apply to contexts.
3563 p point to modifier string
3564 ctx CTX_PAT => pattern context
3565 CTX_POPPAT => pattern context for popped pattern
3566 CTX_DEFPAT => default pattern context
3567 CTX_DAT => data context
3568 CTX_DEFDAT => default data context
3569 pctl point to pattern control block
3570 dctl point to data control block
3572 Returns: TRUE if successful decode, FALSE otherwise
3576 decode_modifiers(uint8_t *p, int ctx, patctl *pctl, datctl *dctl)
3588 unsigned int i, len;
3592 /* Skip white space and commas. */
3594 while (isspace(*p) || *p == ',') p++;
3597 /* Find the end of the item; lose trailing whitespace at end of line. */
3599 for (ep = p; *ep != 0 && *ep != ','; ep++);
3602 while (ep > p && isspace(ep[-1])) ep--;
3606 /* Remember if the first character is '-'. */
3614 /* Find the length of a full-length modifier name, and scan for it. */
3617 while (pp < ep && *pp != '=') pp++;
3618 index = scan_modifiers(p, pp - p);
3620 /* If the first modifier is unrecognized, try to interpret it as a sequence
3621 of single-character abbreviated modifiers. None of these modifiers have any
3622 associated data. They just set options or control bits. */
3631 fprintf(outfile, "** Unrecognized modifier '%.*s'\n", (int)(ep-p), p);
3633 fprintf(outfile, "** Single-character modifiers must come first\n");
3637 for (cc = *p; cc != ',' && cc != '\n' && cc != 0; cc = *(++p))
3639 for (i = 0; i < C1MODLISTCOUNT; i++)
3640 if (cc == c1modlist[i].onechar) break;
3642 if (i >= C1MODLISTCOUNT)
3644 fprintf(outfile, "** Unrecognized modifier '%c' in '%.*s'\n",
3645 *p, (int)(ep-mp), mp);
3649 if (c1modlist[i].index >= 0)
3651 index = c1modlist[i].index;
3656 index = scan_modifiers((uint8_t *)(c1modlist[i].fullname),
3657 strlen(c1modlist[i].fullname));
3660 fprintf(outfile, "** Internal error: single-character equivalent "
3661 "modifier '%s' not found\n", c1modlist[i].fullname);
3664 c1modlist[i].index = index; /* Cache for next time */
3667 field = check_modifier(modlist + index, ctx, pctl, dctl, *p);
3668 if (field == NULL) return FALSE;
3670 /* /x is a special case; a second appearance changes PCRE2_EXTENDED to
3671 PCRE2_EXTENDED_MORE. */
3673 if (cc == 'x' && (*((uint32_t *)field) & PCRE2_EXTENDED) != 0)
3675 *((uint32_t *)field) &= ~PCRE2_EXTENDED;
3676 *((uint32_t *)field) |= PCRE2_EXTENDED_MORE;
3679 *((uint32_t *)field) |= modlist[index].value;
3682 continue; /* With tne next (fullname) modifier */
3685 /* We have a match on a full-name modifier. Check for the existence of data
3688 m = modlist + index; /* Save typing */
3689 if (m->type != MOD_CTL && m->type != MOD_OPT &&
3690 (m->type != MOD_IND || *pp == '='))
3694 fprintf(outfile, "** '=' expected after '%s'\n", m->name);
3699 fprintf(outfile, "** '-' is not valid for '%s'\n", m->name);
3704 /* These on/off types have no data. */
3706 else if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0)
3708 fprintf(outfile, "** Unrecognized modifier '%.*s'\n", (int)(ep-p), p);
3712 /* Set the data length for those types that have data. Then find the field
3713 that is to be set. If check_modifier() returns NULL, it has already output an
3717 field = check_modifier(m, ctx, pctl, dctl, 0);
3718 if (field == NULL) return FALSE;
3720 /* Process according to data type. */
3726 if (off) *((uint32_t *)field) &= ~m->value;
3727 else *((uint32_t *)field) |= m->value;
3731 if (len == 7 && strncmpic(pp, (const uint8_t *)"default", 7) == 0)
3734 *((uint16_t *)field) = PCRE2_BSR_ANYCRLF;
3736 *((uint16_t *)field) = PCRE2_BSR_UNICODE;
3738 if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 &= ~CTL2_BSR_SET;
3739 else dctl->control2 &= ~CTL2_BSR_SET;
3743 if (len == 7 && strncmpic(pp, (const uint8_t *)"anycrlf", 7) == 0)
3744 *((uint16_t *)field) = PCRE2_BSR_ANYCRLF;
3745 else if (len == 7 && strncmpic(pp, (const uint8_t *)"unicode", 7) == 0)
3746 *((uint16_t *)field) = PCRE2_BSR_UNICODE;
3747 else goto INVALID_VALUE;
3748 if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 |= CTL2_BSR_SET;
3749 else dctl->control2 |= CTL2_BSR_SET;
3754 case MOD_CHR: /* A single character */
3755 *((uint32_t *)field) = *pp++;
3758 case MOD_CON: /* A convert type/options list */
3761 uint8_t *colon = (uint8_t *)strchr((const char *)pp, ':');
3762 len = ((colon != NULL && colon < ep)? colon:ep) - pp;
3763 for (i = 0; i < convertlistcount; i++)
3765 if (strncmpic(pp, (const uint8_t *)convertlist[i].name, len) == 0)
3767 if (*((uint32_t *)field) == CONVERT_UNSET)
3768 *((uint32_t *)field) = convertlist[i].option;
3770 *((uint32_t *)field) |= convertlist[i].option;
3774 if (i >= convertlistcount) goto INVALID_VALUE;
3776 if (*pp != ':') break;
3780 case MOD_IN2: /* One or two unsigned integers */
3781 if (!isdigit(*pp)) goto INVALID_VALUE;
3782 uli = strtoul((const char *)pp, &endptr, 10);
3783 if (U32OVERFLOW(uli)) goto INVALID_VALUE;
3784 ((uint32_t *)field)[0] = (uint32_t)uli;
3787 uli = strtoul((const char *)endptr+1, &endptr, 10);
3788 if (U32OVERFLOW(uli)) goto INVALID_VALUE;
3789 ((uint32_t *)field)[1] = (uint32_t)uli;
3791 else ((uint32_t *)field)[1] = 0;
3792 pp = (uint8_t *)endptr;
3795 /* PCRE2_SIZE_MAX is usually SIZE_MAX, which may be greater, equal to, or
3796 less than ULONG_MAX. So first test for overflowing the long int, and then
3797 test for overflowing PCRE2_SIZE_MAX if it is smaller than ULONG_MAX. */
3799 case MOD_SIZ: /* PCRE2_SIZE value */
3800 if (!isdigit(*pp)) goto INVALID_VALUE;
3801 uli = strtoul((const char *)pp, &endptr, 10);
3802 if (uli == ULONG_MAX) goto INVALID_VALUE;
3803 #if ULONG_MAX > PCRE2_SIZE_MAX
3804 if (uli > PCRE2_SIZE_MAX) goto INVALID_VALUE;
3806 *((PCRE2_SIZE *)field) = (PCRE2_SIZE)uli;
3807 pp = (uint8_t *)endptr;
3810 case MOD_IND: /* Unsigned integer with default */
3813 *((uint32_t *)field) = (uint32_t)(m->value);
3818 case MOD_INT: /* Unsigned integer */
3819 if (!isdigit(*pp)) goto INVALID_VALUE;
3820 uli = strtoul((const char *)pp, &endptr, 10);
3821 if (U32OVERFLOW(uli)) goto INVALID_VALUE;
3822 *((uint32_t *)field) = (uint32_t)uli;
3823 pp = (uint8_t *)endptr;
3826 case MOD_INS: /* Signed integer */
3827 if (!isdigit(*pp) && *pp != '-') goto INVALID_VALUE;
3828 li = strtol((const char *)pp, &endptr, 10);
3829 if (S32OVERFLOW(li)) goto INVALID_VALUE;
3830 *((int32_t *)field) = (int32_t)li;
3831 pp = (uint8_t *)endptr;
3835 for (i = 0; i < sizeof(newlines)/sizeof(char *); i++)
3836 if (len == strlen(newlines[i]) &&
3837 strncmpic(pp, (const uint8_t *)newlines[i], len) == 0) break;
3838 if (i >= sizeof(newlines)/sizeof(char *)) goto INVALID_VALUE;
3841 *((uint16_t *)field) = NEWLINE_DEFAULT;
3842 if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 &= ~CTL2_NL_SET;
3843 else dctl->control2 &= ~CTL2_NL_SET;
3847 *((uint16_t *)field) = i;
3848 if (ctx == CTX_PAT || ctx == CTX_DEFPAT) pctl->control2 |= CTL2_NL_SET;
3849 else dctl->control2 |= CTL2_NL_SET;
3854 case MOD_NN: /* Name or (signed) number; may be several */
3855 if (isdigit(*pp) || *pp == '-')
3857 int ct = MAXCPYGET - 1;
3859 li = strtol((const char *)pp, &endptr, 10);
3860 if (S32OVERFLOW(li)) goto INVALID_VALUE;
3861 value = (int32_t)li;
3862 field = (char *)field - m->offset + m->value; /* Adjust field ptr */
3863 if (value >= 0) /* Add new number */
3865 while (*((int32_t *)field) >= 0 && ct-- > 0) /* Skip previous */
3866 field = (char *)field + sizeof(int32_t);
3869 fprintf(outfile, "** Too many numeric '%s' modifiers\n", m->name);
3873 *((int32_t *)field) = value;
3874 if (ct > 0) ((int32_t *)field)[1] = -1;
3875 pp = (uint8_t *)endptr;
3878 /* Multiple strings are put end to end. */
3882 char *nn = (char *)field;
3883 if (len > 0) /* Add new name */
3885 if (len > MAX_NAME_SIZE)
3887 fprintf(outfile, "** Group name in '%s' is too long\n", m->name);
3890 while (*nn != 0) nn += strlen(nn) + 1;
3891 if (nn + len + 2 - (char *)field > LENCPYGET)
3893 fprintf(outfile, "** Too many characters in named '%s' modifiers\n",
3897 memcpy(nn, pp, len);
3906 if (len + 1 > m->value)
3908 fprintf(outfile, "** Overlong value for '%s' (max %d code units)\n",
3909 m->name, m->value - 1);
3912 memcpy(field, pp, len);
3913 ((uint8_t *)field)[len] = 0;
3918 if (*pp != ',' && *pp != '\n' && *pp != ' ' && *pp != 0)
3920 fprintf(outfile, "** Comma expected after modifier item '%s'\n", m->name);
3927 if (ctx == CTX_POPPAT &&
3928 (pctl->options != 0 ||
3929 pctl->tables_id != 0 ||
3930 pctl->locale[0] != 0 ||
3931 (pctl->control & NOTPOP_CONTROLS) != 0))
3933 fprintf(outfile, "** '%s' is not valid here\n", m->name);
3941 fprintf(outfile, "** Invalid value in '%.*s'\n", (int)(ep-p), p);
3946 /*************************************************
3947 * Get info from a pattern *
3948 *************************************************/
3950 /* A wrapped call to pcre2_pattern_info(), applied to the current compiled
3954 what code for the required information
3955 where where to put the answer
3956 unsetok PCRE2_ERROR_UNSET is an "expected" result
3958 Returns: the return from pcre2_pattern_info()
3962 pattern_info(int what, void *where, BOOL unsetok)
3965 PCRE2_PATTERN_INFO(rc, compiled_code, what, NULL); /* Exercise the code */
3966 PCRE2_PATTERN_INFO(rc, compiled_code, what, where);
3967 if (rc >= 0) return 0;
3968 if (rc != PCRE2_ERROR_UNSET || !unsetok)
3970 fprintf(outfile, "Error %d from pcre2_pattern_info_%d(%d)\n", rc, test_mode,
3972 if (rc == PCRE2_ERROR_BADMODE)
3973 fprintf(outfile, "Running in %d-bit mode but pattern was compiled in "
3974 "%d-bit mode\n", test_mode,
3975 8 * (FLD(compiled_code, flags) & PCRE2_MODE_MASK));
3982 #ifdef SUPPORT_PCRE2_8
3983 /*************************************************
3984 * Show something in a list *
3985 *************************************************/
3987 /* This function just helps to keep the code that uses it tidier. It's used for
3988 various lists of things where there needs to be introductory text before the
3989 first item. As these calls are all in the POSIX-support code, they happen only
3990 when 8-bit mode is supported. */
3993 prmsg(const char **msg, const char *s)
3995 fprintf(outfile, "%s %s", *msg, s);
3998 #endif /* SUPPORT_PCRE2_8 */
4002 /*************************************************
4003 * Show control bits *
4004 *************************************************/
4006 /* Called for mutually exclusive controls and for unsupported POSIX controls.
4007 Because the bits are unique, this can be used for both pattern and data control
4011 controls control bits
4012 controls2 more control bits
4013 before text to print before
4019 show_controls(uint32_t controls, uint32_t controls2, const char *before)
4021 fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
4023 ((controls & CTL_AFTERTEXT) != 0)? " aftertext" : "",
4024 ((controls & CTL_ALLAFTERTEXT) != 0)? " allaftertext" : "",
4025 ((controls & CTL_ALLCAPTURES) != 0)? " allcaptures" : "",
4026 ((controls & CTL_ALLUSEDTEXT) != 0)? " allusedtext" : "",
4027 ((controls & CTL_ALTGLOBAL) != 0)? " altglobal" : "",
4028 ((controls & CTL_BINCODE) != 0)? " bincode" : "",
4029 ((controls2 & CTL2_BSR_SET) != 0)? " bsr" : "",
4030 ((controls & CTL_CALLOUT_CAPTURE) != 0)? " callout_capture" : "",
4031 ((controls2 & CTL2_CALLOUT_EXTRA) != 0)? " callout_extra" : "",
4032 ((controls & CTL_CALLOUT_INFO) != 0)? " callout_info" : "",
4033 ((controls & CTL_CALLOUT_NONE) != 0)? " callout_none" : "",
4034 ((controls2 & CTL2_CALLOUT_NO_WHERE) != 0)? " callout_no_where" : "",
4035 ((controls & CTL_DFA) != 0)? " dfa" : "",
4036 ((controls & CTL_EXPAND) != 0)? " expand" : "",
4037 ((controls & CTL_FINDLIMITS) != 0)? " find_limits" : "",
4038 ((controls & CTL_FRAMESIZE) != 0)? " framesize" : "",
4039 ((controls & CTL_FULLBINCODE) != 0)? " fullbincode" : "",
4040 ((controls & CTL_GETALL) != 0)? " getall" : "",
4041 ((controls & CTL_GLOBAL) != 0)? " global" : "",
4042 ((controls & CTL_HEXPAT) != 0)? " hex" : "",
4043 ((controls & CTL_INFO) != 0)? " info" : "",
4044 ((controls & CTL_JITFAST) != 0)? " jitfast" : "",
4045 ((controls & CTL_JITVERIFY) != 0)? " jitverify" : "",
4046 ((controls & CTL_MARK) != 0)? " mark" : "",
4047 ((controls & CTL_MEMORY) != 0)? " memory" : "",
4048 ((controls2 & CTL2_NL_SET) != 0)? " newline" : "",
4049 ((controls & CTL_NULLCONTEXT) != 0)? " null_context" : "",
4050 ((controls & CTL_POSIX) != 0)? " posix" : "",
4051 ((controls & CTL_POSIX_NOSUB) != 0)? " posix_nosub" : "",
4052 ((controls & CTL_PUSH) != 0)? " push" : "",
4053 ((controls & CTL_PUSHCOPY) != 0)? " pushcopy" : "",
4054 ((controls & CTL_PUSHTABLESCOPY) != 0)? " pushtablescopy" : "",
4055 ((controls & CTL_STARTCHAR) != 0)? " startchar" : "",
4056 ((controls2 & CTL2_SUBSTITUTE_EXTENDED) != 0)? " substitute_extended" : "",
4057 ((controls2 & CTL2_SUBSTITUTE_OVERFLOW_LENGTH) != 0)? " substitute_overflow_length" : "",
4058 ((controls2 & CTL2_SUBSTITUTE_UNKNOWN_UNSET) != 0)? " substitute_unknown_unset" : "",
4059 ((controls2 & CTL2_SUBSTITUTE_UNSET_EMPTY) != 0)? " substitute_unset_empty" : "",
4060 ((controls & CTL_USE_LENGTH) != 0)? " use_length" : "",
4061 ((controls & CTL_UTF8_INPUT) != 0)? " utf8_input" : "",
4062 ((controls & CTL_ZERO_TERMINATE) != 0)? " zero_terminate" : "");
4067 /*************************************************
4068 * Show compile options *
4069 *************************************************/
4071 /* Called from show_pattern_info() and for unsupported POSIX options.
4074 options an options word
4075 before text to print before
4076 after text to print after
4082 show_compile_options(uint32_t options, const char *before, const char *after)
4084 if (options == 0) fprintf(outfile, "%s <none>%s", before, after);
4085 else fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
4087 ((options & PCRE2_ALT_BSUX) != 0)? " alt_bsux" : "",
4088 ((options & PCRE2_ALT_CIRCUMFLEX) != 0)? " alt_circumflex" : "",
4089 ((options & PCRE2_ALT_VERBNAMES) != 0)? " alt_verbnames" : "",
4090 ((options & PCRE2_ALLOW_EMPTY_CLASS) != 0)? " allow_empty_class" : "",
4091 ((options & PCRE2_ANCHORED) != 0)? " anchored" : "",
4092 ((options & PCRE2_AUTO_CALLOUT) != 0)? " auto_callout" : "",
4093 ((options & PCRE2_CASELESS) != 0)? " caseless" : "",
4094 ((options & PCRE2_DOLLAR_ENDONLY) != 0)? " dollar_endonly" : "",
4095 ((options & PCRE2_DOTALL) != 0)? " dotall" : "",
4096 ((options & PCRE2_DUPNAMES) != 0)? " dupnames" : "",
4097 ((options & PCRE2_ENDANCHORED) != 0)? " endanchored" : "",
4098 ((options & PCRE2_EXTENDED) != 0)? " extended" : "",
4099 ((options & PCRE2_EXTENDED_MORE) != 0)? " extended_more" : "",
4100 ((options & PCRE2_FIRSTLINE) != 0)? " firstline" : "",
4101 ((options & PCRE2_LITERAL) != 0)? " literal" : "",
4102 ((options & PCRE2_MATCH_UNSET_BACKREF) != 0)? " match_unset_backref" : "",
4103 ((options & PCRE2_MULTILINE) != 0)? " multiline" : "",
4104 ((options & PCRE2_NEVER_BACKSLASH_C) != 0)? " never_backslash_c" : "",
4105 ((options & PCRE2_NEVER_UCP) != 0)? " never_ucp" : "",
4106 ((options & PCRE2_NEVER_UTF) != 0)? " never_utf" : "",
4107 ((options & PCRE2_NO_AUTO_CAPTURE) != 0)? " no_auto_capture" : "",
4108 ((options & PCRE2_NO_AUTO_POSSESS) != 0)? " no_auto_possess" : "",
4109 ((options & PCRE2_NO_DOTSTAR_ANCHOR) != 0)? " no_dotstar_anchor" : "",
4110 ((options & PCRE2_NO_UTF_CHECK) != 0)? " no_utf_check" : "",
4111 ((options & PCRE2_NO_START_OPTIMIZE) != 0)? " no_start_optimize" : "",
4112 ((options & PCRE2_UCP) != 0)? " ucp" : "",
4113 ((options & PCRE2_UNGREEDY) != 0)? " ungreedy" : "",
4114 ((options & PCRE2_USE_OFFSET_LIMIT) != 0)? " use_offset_limit" : "",
4115 ((options & PCRE2_UTF) != 0)? " utf" : "",
4120 /*************************************************
4121 * Show compile extra options *
4122 *************************************************/
4124 /* Called from show_pattern_info() and for unsupported POSIX options.
4127 options an options word
4128 before text to print before
4129 after text to print after
4135 show_compile_extra_options(uint32_t options, const char *before,
4138 if (options == 0) fprintf(outfile, "%s <none>%s", before, after);
4139 else fprintf(outfile, "%s%s%s%s%s%s",
4141 ((options & PCRE2_EXTRA_ALLOW_SURROGATE_ESCAPES) != 0)? " allow_surrogate_escapes" : "",
4142 ((options & PCRE2_EXTRA_BAD_ESCAPE_IS_LITERAL) != 0)? " bad_escape_is_literal" : "",
4143 ((options & PCRE2_EXTRA_MATCH_WORD) != 0)? " match_word" : "",
4144 ((options & PCRE2_EXTRA_MATCH_LINE) != 0)? " match_line" : "",
4150 #ifdef SUPPORT_PCRE2_8
4151 /*************************************************
4152 * Show match options *
4153 *************************************************/
4155 /* Called for unsupported POSIX options. */
4158 show_match_options(uint32_t options)
4160 fprintf(outfile, "%s%s%s%s%s%s%s%s%s%s%s",
4161 ((options & PCRE2_ANCHORED) != 0)? " anchored" : "",
4162 ((options & PCRE2_DFA_RESTART) != 0)? " dfa_restart" : "",
4163 ((options & PCRE2_DFA_SHORTEST) != 0)? " dfa_shortest" : "",
4164 ((options & PCRE2_ENDANCHORED) != 0)? " endanchored" : "",
4165 ((options & PCRE2_NO_UTF_CHECK) != 0)? " no_utf_check" : "",
4166 ((options & PCRE2_NOTBOL) != 0)? " notbol" : "",
4167 ((options & PCRE2_NOTEMPTY) != 0)? " notempty" : "",
4168 ((options & PCRE2_NOTEMPTY_ATSTART) != 0)? " notempty_atstart" : "",
4169 ((options & PCRE2_NOTEOL) != 0)? " noteol" : "",
4170 ((options & PCRE2_PARTIAL_HARD) != 0)? " partial_hard" : "",
4171 ((options & PCRE2_PARTIAL_SOFT) != 0)? " partial_soft" : "");
4173 #endif /* SUPPORT_PCRE2_8 */
4177 /*************************************************
4178 * Show memory usage info for a pattern *
4179 *************************************************/
4182 show_memory_info(void)
4184 uint32_t name_count, name_entry_size;
4185 size_t size, cblock_size;
4187 /* One of the test_mode values will always be true, but to stop a compiler
4188 warning we must initialize cblock_size. */
4191 #ifdef SUPPORT_PCRE2_8
4192 if (test_mode == PCRE8_MODE) cblock_size = sizeof(pcre2_real_code_8);
4194 #ifdef SUPPORT_PCRE2_16
4195 if (test_mode == PCRE16_MODE) cblock_size = sizeof(pcre2_real_code_16);
4197 #ifdef SUPPORT_PCRE2_32
4198 if (test_mode == PCRE32_MODE) cblock_size = sizeof(pcre2_real_code_32);
4201 (void)pattern_info(PCRE2_INFO_SIZE, &size, FALSE);
4202 (void)pattern_info(PCRE2_INFO_NAMECOUNT, &name_count, FALSE);
4203 (void)pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &name_entry_size, FALSE);
4204 fprintf(outfile, "Memory allocation (code space): %d\n",
4205 (int)(size - name_count*name_entry_size*code_unit_size - cblock_size));
4206 if (pat_patctl.jit != 0)
4208 (void)pattern_info(PCRE2_INFO_JITSIZE, &size, FALSE);
4209 fprintf(outfile, "Memory allocation (JIT code): %d\n", (int)size);
4215 /*************************************************
4216 * Show frame size info for a pattern *
4217 *************************************************/
4220 show_framesize(void)
4223 (void)pattern_info(PCRE2_INFO_FRAMESIZE, &frame_size, FALSE);
4224 fprintf(outfile, "Frame size for pcre2_match(): %d\n", (int)frame_size);
4229 /*************************************************
4230 * Get and output an error message *
4231 *************************************************/
4234 print_error_message(int errorcode, const char *before, const char *after)
4237 PCRE2_GET_ERROR_MESSAGE(len, errorcode, pbuffer);
4240 fprintf(outfile, "\n** pcre2test internal error: cannot interpret error "
4241 "number\n** Unexpected return (%d) from pcre2_get_error_message()\n", len);
4245 fprintf(outfile, "%s", before);
4246 PCHARSV(CASTVAR(void *, pbuffer), 0, len, FALSE, outfile);
4247 fprintf(outfile, "%s", after);
4253 /*************************************************
4254 * Callback function for callout enumeration *
4255 *************************************************/
4257 /* The only differences in the callout emumeration block for different code
4258 unit widths are that the pointers to the subject, the most recent MARK, and a
4259 callout argument string point to strings of the appropriate width. Casts can be
4260 used to deal with this.
4263 cb pointer to enumerate block
4264 callout_data user data
4269 static int callout_callback(pcre2_callout_enumerate_block_8 *cb,
4273 BOOL utf = (FLD(compiled_code, overall_options) & PCRE2_UTF) != 0;
4275 (void)callout_data; /* Not currently displayed */
4277 fprintf(outfile, "Callout ");
4278 if (cb->callout_string != NULL)
4280 uint32_t delimiter = CODE_UNIT(cb->callout_string, -1);
4281 fprintf(outfile, "%c", delimiter);
4282 PCHARSV(cb->callout_string, 0,
4283 cb->callout_string_length, utf, outfile);
4284 for (i = 0; callout_start_delims[i] != 0; i++)
4285 if (delimiter == callout_start_delims[i])
4287 delimiter = callout_end_delims[i];
4290 fprintf(outfile, "%c ", delimiter);
4292 else fprintf(outfile, "%d ", cb->callout_number);
4294 fprintf(outfile, "%.*s\n",
4295 (int)((cb->next_item_length == 0)? 1 : cb->next_item_length),
4296 pbuffer8 + cb->pattern_position);
4303 /*************************************************
4304 * Show information about a pattern *
4305 *************************************************/
4307 /* This function is called after a pattern has been compiled if any of the
4308 information-requesting controls have been set.
4312 Returns: PR_OK continue processing next line
4313 PR_SKIP skip to a blank line
4314 PR_ABEND abort the pcre2test run
4318 show_pattern_info(void)
4320 uint32_t compile_options, overall_options, extra_options;
4322 if ((pat_patctl.control & (CTL_BINCODE|CTL_FULLBINCODE)) != 0)
4324 fprintf(outfile, "------------------------------------------------------------------\n");
4325 PCRE2_PRINTINT((pat_patctl.control & CTL_FULLBINCODE) != 0);
4328 if ((pat_patctl.control & CTL_INFO) != 0)
4332 uint8_t *start_bits;
4333 BOOL heap_limit_set, match_limit_set, depth_limit_set;
4334 uint32_t backrefmax, bsr_convention, capture_count, first_ctype, first_cunit,
4335 hasbackslashc, hascrorlf, jchanged, last_ctype, last_cunit, match_empty,
4336 depth_limit, heap_limit, match_limit, minlength, nameentrysize, namecount,
4339 /* Exercise the error route. */
4341 PCRE2_PATTERN_INFO(rc, compiled_code, 999, NULL);
4344 /* These info requests may return PCRE2_ERROR_UNSET. */
4346 switch(pattern_info(PCRE2_INFO_HEAPLIMIT, &heap_limit, TRUE))
4349 heap_limit_set = TRUE;
4352 case PCRE2_ERROR_UNSET:
4353 heap_limit_set = FALSE;
4360 switch(pattern_info(PCRE2_INFO_MATCHLIMIT, &match_limit, TRUE))
4363 match_limit_set = TRUE;
4366 case PCRE2_ERROR_UNSET:
4367 match_limit_set = FALSE;
4374 switch(pattern_info(PCRE2_INFO_DEPTHLIMIT, &depth_limit, TRUE))
4377 depth_limit_set = TRUE;
4380 case PCRE2_ERROR_UNSET:
4381 depth_limit_set = FALSE;
4388 /* These info requests should always succeed. */
4390 if (pattern_info(PCRE2_INFO_BACKREFMAX, &backrefmax, FALSE) +
4391 pattern_info(PCRE2_INFO_BSR, &bsr_convention, FALSE) +
4392 pattern_info(PCRE2_INFO_CAPTURECOUNT, &capture_count, FALSE) +
4393 pattern_info(PCRE2_INFO_FIRSTBITMAP, &start_bits, FALSE) +
4394 pattern_info(PCRE2_INFO_FIRSTCODEUNIT, &first_cunit, FALSE) +
4395 pattern_info(PCRE2_INFO_FIRSTCODETYPE, &first_ctype, FALSE) +
4396 pattern_info(PCRE2_INFO_HASBACKSLASHC, &hasbackslashc, FALSE) +
4397 pattern_info(PCRE2_INFO_HASCRORLF, &hascrorlf, FALSE) +
4398 pattern_info(PCRE2_INFO_JCHANGED, &jchanged, FALSE) +
4399 pattern_info(PCRE2_INFO_LASTCODEUNIT, &last_cunit, FALSE) +
4400 pattern_info(PCRE2_INFO_LASTCODETYPE, &last_ctype, FALSE) +
4401 pattern_info(PCRE2_INFO_MATCHEMPTY, &match_empty, FALSE) +
4402 pattern_info(PCRE2_INFO_MINLENGTH, &minlength, FALSE) +
4403 pattern_info(PCRE2_INFO_NAMECOUNT, &namecount, FALSE) +
4404 pattern_info(PCRE2_INFO_NAMEENTRYSIZE, &nameentrysize, FALSE) +
4405 pattern_info(PCRE2_INFO_NAMETABLE, &nametable, FALSE) +
4406 pattern_info(PCRE2_INFO_NEWLINE, &newline_convention, FALSE)
4410 fprintf(outfile, "Capturing subpattern count = %d\n", capture_count);
4413 fprintf(outfile, "Max back reference = %d\n", backrefmax);
4415 if (maxlookbehind > 0)
4416 fprintf(outfile, "Max lookbehind = %d\n", maxlookbehind);
4419 fprintf(outfile, "Heap limit = %u\n", heap_limit);
4421 if (match_limit_set)
4422 fprintf(outfile, "Match limit = %u\n", match_limit);
4424 if (depth_limit_set)
4425 fprintf(outfile, "Depth limit = %u\n", depth_limit);
4429 fprintf(outfile, "Named capturing subpatterns:\n");
4430 for (; namecount > 0; namecount--)
4432 int imm2_size = test_mode == PCRE8_MODE ? 2 : 1;
4433 uint32_t length = (uint32_t)STRLEN(nametable + imm2_size);
4434 fprintf(outfile, " ");
4435 PCHARSV(nametable, imm2_size, length, FALSE, outfile);
4436 while (length++ < nameentrysize - imm2_size) putc(' ', outfile);
4437 #ifdef SUPPORT_PCRE2_32
4438 if (test_mode == PCRE32_MODE)
4439 fprintf(outfile, "%3d\n", (int)(((PCRE2_SPTR32)nametable)[0]));
4441 #ifdef SUPPORT_PCRE2_16
4442 if (test_mode == PCRE16_MODE)
4443 fprintf(outfile, "%3d\n", (int)(((PCRE2_SPTR16)nametable)[0]));
4445 #ifdef SUPPORT_PCRE2_8
4446 if (test_mode == PCRE8_MODE)
4447 fprintf(outfile, "%3d\n", (int)(
4448 ((((PCRE2_SPTR8)nametable)[0]) << 8) | ((PCRE2_SPTR8)nametable)[1]));
4450 nametable = (void*)((PCRE2_SPTR8)nametable + nameentrysize * code_unit_size);
4454 if (hascrorlf) fprintf(outfile, "Contains explicit CR or LF match\n");
4455 if (hasbackslashc) fprintf(outfile, "Contains \\C\n");
4456 if (match_empty) fprintf(outfile, "May match empty string\n");
4458 pattern_info(PCRE2_INFO_ARGOPTIONS, &compile_options, FALSE);
4459 pattern_info(PCRE2_INFO_ALLOPTIONS, &overall_options, FALSE);
4460 pattern_info(PCRE2_INFO_EXTRAOPTIONS, &extra_options, FALSE);
4462 /* Remove UTF/UCP if they were there only because of forbid_utf. This saves
4463 cluttering up the verification output of non-UTF test files. */
4465 if ((pat_patctl.options & PCRE2_NEVER_UTF) == 0)
4467 compile_options &= ~PCRE2_NEVER_UTF;
4468 overall_options &= ~PCRE2_NEVER_UTF;
4471 if ((pat_patctl.options & PCRE2_NEVER_UCP) == 0)
4473 compile_options &= ~PCRE2_NEVER_UCP;
4474 overall_options &= ~PCRE2_NEVER_UCP;
4477 if ((compile_options|overall_options) != 0)
4479 if (compile_options == overall_options)
4480 show_compile_options(compile_options, "Options:", "\n");
4483 show_compile_options(compile_options, "Compile options:", "\n");
4484 show_compile_options(overall_options, "Overall options:", "\n");
4488 if (extra_options != 0)
4489 show_compile_extra_options(extra_options, "Extra options:", "\n");
4491 if (jchanged) fprintf(outfile, "Duplicate name status changes\n");
4493 if ((pat_patctl.control2 & CTL2_BSR_SET) != 0 ||
4494 (FLD(compiled_code, flags) & PCRE2_BSR_SET) != 0)
4495 fprintf(outfile, "\\R matches %s\n", (bsr_convention == PCRE2_BSR_UNICODE)?
4496 "any Unicode newline" : "CR, LF, or CRLF");
4498 if ((FLD(compiled_code, flags) & PCRE2_NL_SET) != 0)
4500 switch (newline_convention)
4502 case PCRE2_NEWLINE_CR:
4503 fprintf(outfile, "Forced newline is CR\n");
4506 case PCRE2_NEWLINE_LF:
4507 fprintf(outfile, "Forced newline is LF\n");
4510 case PCRE2_NEWLINE_CRLF:
4511 fprintf(outfile, "Forced newline is CRLF\n");
4514 case PCRE2_NEWLINE_ANYCRLF:
4515 fprintf(outfile, "Forced newline is CR, LF, or CRLF\n");
4518 case PCRE2_NEWLINE_ANY:
4519 fprintf(outfile, "Forced newline is any Unicode newline\n");
4522 case PCRE2_NEWLINE_NUL:
4523 fprintf(outfile, "Forced newline is NUL\n");
4531 if (first_ctype == 2)
4533 fprintf(outfile, "First code unit at start or follows newline\n");
4535 else if (first_ctype == 1)
4537 const char *caseless =
4538 ((FLD(compiled_code, flags) & PCRE2_FIRSTCASELESS) == 0)?
4540 if (PRINTOK(first_cunit))
4541 fprintf(outfile, "First code unit = \'%c\'%s\n", first_cunit, caseless);
4544 fprintf(outfile, "First code unit = ");
4545 pchar(first_cunit, FALSE, outfile);
4546 fprintf(outfile, "%s\n", caseless);
4549 else if (start_bits != NULL)
4553 fprintf(outfile, "Starting code units: ");
4554 for (i = 0; i < 256; i++)
4556 if ((start_bits[i/8] & (1<<(i&7))) != 0)
4560 fprintf(outfile, "\n ");
4563 if (PRINTOK(i) && i != ' ')
4565 fprintf(outfile, "%c ", i);
4570 fprintf(outfile, "\\x%02x ", i);
4575 fprintf(outfile, "\n");
4578 if (last_ctype != 0)
4580 const char *caseless =
4581 ((FLD(compiled_code, flags) & PCRE2_LASTCASELESS) == 0)?
4583 if (PRINTOK(last_cunit))
4584 fprintf(outfile, "Last code unit = \'%c\'%s\n", last_cunit, caseless);
4587 fprintf(outfile, "Last code unit = ");
4588 pchar(last_cunit, FALSE, outfile);
4589 fprintf(outfile, "%s\n", caseless);
4593 fprintf(outfile, "Subject length lower bound = %d\n", minlength);
4595 if (pat_patctl.jit != 0 && (pat_patctl.control & CTL_JITVERIFY) != 0)
4597 if (FLD(compiled_code, executable_jit) != NULL)
4598 fprintf(outfile, "JIT compilation was successful\n");
4602 fprintf(outfile, "JIT compilation was not successful");
4603 if (jitrc != 0 && !print_error_message(jitrc, " (", ")"))
4605 fprintf(outfile, "\n");
4607 fprintf(outfile, "JIT support is not available in this version of PCRE2\n");
4613 if ((pat_patctl.control & CTL_CALLOUT_INFO) != 0)
4616 PCRE2_CALLOUT_ENUMERATE(errorcode, callout_callback, 0);
4619 fprintf(outfile, "Callout enumerate failed: error %d: ", errorcode);
4620 if (errorcode < 0 && !print_error_message(errorcode, "", "\n"))
4631 /*************************************************
4632 * Handle serialization error *
4633 *************************************************/
4635 /* Print an error message after a serialization failure.
4639 msg an initial message for what failed
4641 Returns: FALSE if print_error_message() fails
4645 serial_error(int rc, const char *msg)
4647 fprintf(outfile, "%s failed: error %d: ", msg, rc);
4648 return print_error_message(rc, "", "\n");
4653 /*************************************************
4654 * Open file for save/load commands *
4655 *************************************************/
4657 /* This function decodes the file name and opens the file.
4660 buffptr point after the #command
4662 fptr points to the FILE variable
4664 Returns: PR_OK or PR_ABEND
4668 open_file(uint8_t *buffptr, const char *mode, FILE **fptr)
4671 char *filename = (char *)buffptr;
4672 while (isspace(*filename)) filename++;
4673 endf = filename + strlen8(filename);
4674 while (endf > filename && isspace(endf[-1])) endf--;
4676 if (endf == filename)
4678 fprintf(outfile, "** File name expected after #save\n");
4683 *fptr = fopen((const char *)filename, mode);
4686 fprintf(outfile, "** Failed to open '%s': %s\n", filename, strerror(errno));
4695 /*************************************************
4696 * Process command line *
4697 *************************************************/
4699 /* This function is called for lines beginning with # and a character that is
4700 not ! or whitespace, when encountered between tests, which means that there is
4701 no compiled pattern (compiled_code is NULL). The line is in buffer.
4705 Returns: PR_OK continue processing next line
4706 PR_SKIP skip to a blank line
4707 PR_ABEND abort the pcre2test run
4711 process_command(void)
4714 PCRE2_SIZE serial_size;
4716 int rc, cmd, cmdlen, yield;
4717 uint16_t first_listed_newline;
4718 const char *cmdname;
4719 uint8_t *argptr, *serial;
4725 for (i = 0; i < cmdlistcount; i++)
4727 cmdname = cmdlist[i].name;
4728 cmdlen = strlen(cmdname);
4729 if (strncmp((char *)(buffer+1), cmdname, cmdlen) == 0 &&
4730 isspace(buffer[cmdlen+1]))
4732 cmd = cmdlist[i].value;
4737 argptr = buffer + cmdlen + 1;
4739 if (restrict_for_perl_test && cmd != CMD_PATTERN && cmd != CMD_SUBJECT)
4741 fprintf(outfile, "** #%s is not allowed after #perltest\n", cmdname);
4748 fprintf(outfile, "** Unknown command: %s", buffer);
4751 case CMD_FORBID_UTF:
4752 forbid_utf = PCRE2_NEVER_UTF|PCRE2_NEVER_UCP;
4756 restrict_for_perl_test = TRUE;
4759 /* Set default pattern modifiers */
4762 (void)decode_modifiers(argptr, CTX_DEFPAT, &def_patctl, NULL);
4763 if (def_patctl.jit == 0 && (def_patctl.control & CTL_JITVERIFY) != 0)
4767 /* Set default subject modifiers */
4770 (void)decode_modifiers(argptr, CTX_DEFDAT, NULL, &def_datctl);
4773 /* Check the default newline, and if not one of those listed, set up the
4774 first one to be forced. An empty list unsets. */
4776 case CMD_NEWLINE_DEFAULT:
4777 local_newline_default = 0; /* Unset */
4778 first_listed_newline = 0;
4781 while (isspace(*argptr)) argptr++;
4782 if (*argptr == 0) break;
4783 for (i = 1; i < sizeof(newlines)/sizeof(char *); i++)
4785 size_t nlen = strlen(newlines[i]);
4786 if (strncmpic(argptr, (const uint8_t *)newlines[i], nlen) == 0 &&
4787 isspace(argptr[nlen]))
4789 if (i == NEWLINE_DEFAULT) return PR_OK; /* Default is valid */
4790 if (first_listed_newline == 0) first_listed_newline = i;
4793 while (*argptr != 0 && !isspace(*argptr)) argptr++;
4795 local_newline_default = first_listed_newline;
4798 /* Pop or copy a compiled pattern off the stack. Modifiers that do not affect
4799 the compiled pattern (e.g. to give information) are permitted. The default
4800 pattern modifiers are ignored. */
4804 if (patstacknext <= 0)
4806 fprintf(outfile, "** Can't pop off an empty stack\n");
4809 memset(&pat_patctl, 0, sizeof(patctl)); /* Completely unset */
4810 if (!decode_modifiers(argptr, CTX_POPPAT, &pat_patctl, NULL))
4815 SET(compiled_code, patstack[--patstacknext]);
4819 PCRE2_CODE_COPY_FROM_VOID(compiled_code, patstack[patstacknext - 1]);
4822 if (pat_patctl.jit != 0)
4824 PCRE2_JIT_COMPILE(jitrc, compiled_code, pat_patctl.jit);
4826 if ((pat_patctl.control & CTL_MEMORY) != 0) show_memory_info();
4827 if ((pat_patctl.control & CTL_FRAMESIZE) != 0) show_framesize();
4828 if ((pat_patctl.control & CTL_ANYINFO) != 0)
4830 rc = show_pattern_info();
4831 if (rc != PR_OK) return rc;
4835 /* Save the stack of compiled patterns to a file, then empty the stack. */
4838 if (patstacknext <= 0)
4840 fprintf(outfile, "** No stacked patterns to save\n");
4844 rc = open_file(argptr+1, BINARY_OUTPUT_MODE, &f);
4845 if (rc != PR_OK) return rc;
4847 PCRE2_SERIALIZE_ENCODE(rc, patstack, patstacknext, &serial, &serial_size,
4852 if (!serial_error(rc, "Serialization")) return PR_ABEND;
4856 /* Write the length at the start of the file to make it straightforward to
4857 get the right memory when re-loading. This saves having to read the file size
4858 in different operating systems. To allow for different endianness (even
4859 though reloading with the opposite endianness does not work), write the
4860 length byte-by-byte. */
4862 for (i = 0; i < 4; i++) fputc((serial_size >> (i*8)) & 255, f);
4863 if (fwrite(serial, 1, serial_size, f) != serial_size)
4865 fprintf(outfile, "** Wrong return from fwrite()\n");
4871 PCRE2_SERIALIZE_FREE(serial);
4872 while(patstacknext > 0)
4874 SET(compiled_code, patstack[--patstacknext]);
4875 SUB1(pcre2_code_free, compiled_code);
4877 SET(compiled_code, NULL);
4880 /* Load a set of compiled patterns from a file onto the stack */
4883 rc = open_file(argptr+1, BINARY_INPUT_MODE, &f);
4884 if (rc != PR_OK) return rc;
4887 for (i = 0; i < 4; i++) serial_size |= fgetc(f) << (i*8);
4889 serial = malloc(serial_size);
4892 fprintf(outfile, "** Failed to get memory (size %" SIZ_FORM ") for #load\n",
4893 SIZ_CAST serial_size);
4898 i = fread(serial, 1, serial_size, f);
4901 if (i != serial_size)
4903 fprintf(outfile, "** Wrong return from fread()\n");
4908 PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(rc, serial);
4911 if (!serial_error(rc, "Get number of codes")) yield = PR_ABEND;
4915 if (rc + patstacknext > PATSTACKSIZE)
4917 fprintf(outfile, "** Not enough space on pattern stack for %d pattern%s\n",
4918 rc, (rc == 1)? "" : "s");
4919 rc = PATSTACKSIZE - patstacknext;
4920 fprintf(outfile, "** Decoding %d pattern%s\n", rc,
4921 (rc == 1)? "" : "s");
4923 PCRE2_SERIALIZE_DECODE(rc, patstack + patstacknext, rc, serial,
4927 if (!serial_error(rc, "Deserialization")) yield = PR_ABEND;
4929 else patstacknext += rc;
4942 /*************************************************
4943 * Process pattern line *
4944 *************************************************/
4946 /* This function is called when the input buffer contains the start of a
4947 pattern. The first character is known to be a valid delimiter. The pattern is
4948 read, modifiers are interpreted, and a suitable local context is set up for
4949 this test. The pattern is then compiled.
4953 Returns: PR_OK continue processing next line
4954 PR_SKIP skip to a blank line
4955 PR_ABEND abort the pcre2test run
4959 process_pattern(void)
4963 uint8_t *p = buffer;
4964 unsigned int delimiter = *p++;
4966 void *use_pat_context;
4967 uint32_t use_forbid_utf = forbid_utf;
4969 PCRE2_SIZE valgrind_access_length;
4970 PCRE2_SIZE erroroffset;
4972 /* Initialize the context and pattern/data controls for this test from the
4975 PATCTXCPY(pat_context, default_pat_context);
4976 memcpy(&pat_patctl, &def_patctl, sizeof(patctl));
4978 /* Find the end of the pattern, reading more lines if necessary. */
4984 if (*p == '\\' && p[1] != 0) p++;
4985 else if (*p == delimiter) break;
4989 if ((p = extend_inputline(infile, p, " > ")) == NULL)
4991 fprintf(outfile, "** Unexpected EOF\n");
4994 if (!INTERACTIVE(infile)) fprintf(outfile, "%s", (char *)p);
4997 /* If the first character after the delimiter is backslash, make the pattern
4998 end with backslash. This is purely to provide a way of testing for the error
4999 message when a pattern ends with backslash. */
5001 if (p[1] == '\\') *p++ = '\\';
5003 /* Terminate the pattern at the delimiter, and compute the length. */
5006 patlen = p - buffer - 2;
5008 /* Look for modifiers and options after the final delimiter. */
5010 if (!decode_modifiers(p, CTX_PAT, &pat_patctl, NULL)) return PR_SKIP;
5011 utf = (pat_patctl.options & PCRE2_UTF) != 0;
5013 /* The utf8_input modifier is not allowed in 8-bit mode, and is mutually
5014 exclusive with the utf modifier. */
5016 if ((pat_patctl.control & CTL_UTF8_INPUT) != 0)
5018 if (test_mode == PCRE8_MODE)
5020 fprintf(outfile, "** The utf8_input modifier is not allowed in 8-bit mode\n");
5025 fprintf(outfile, "** The utf and utf8_input modifiers are mutually exclusive\n");
5030 /* The convert and posix modifiers are mutually exclusive. */
5032 if (pat_patctl.convert_type != CONVERT_UNSET &&
5033 (pat_patctl.control & CTL_POSIX) != 0)
5035 fprintf(outfile, "** The convert and posix modifiers are mutually exclusive\n");
5039 /* Check for mutually exclusive control modifiers. At present, these are all in
5040 the first control word. */
5042 for (k = 0; k < sizeof(exclusive_pat_controls)/sizeof(uint32_t); k++)
5044 uint32_t c = pat_patctl.control & exclusive_pat_controls[k];
5045 if (c != 0 && c != (c & (~c+1)))
5047 show_controls(c, 0, "** Not allowed together:");
5048 fprintf(outfile, "\n");
5053 /* Assume full JIT compile for jitverify and/or jitfast if nothing else was
5056 if (pat_patctl.jit == 0 &&
5057 (pat_patctl.control & (CTL_JITVERIFY|CTL_JITFAST)) != 0)
5060 /* Now copy the pattern to pbuffer8 for use in 8-bit testing and for reflecting
5061 in callouts. Convert from hex if requested (literal strings in quotes may be
5062 present within the hexadecimal pairs). The result must necessarily be fewer
5063 characters so will always fit in pbuffer8. */
5065 if ((pat_patctl.control & CTL_HEXPAT) != 0)
5071 for (pp = buffer + 1; *pp != 0; pp++)
5073 if (isspace(*pp)) continue;
5076 /* Handle a literal substring */
5078 if (c == '\'' || c == '"')
5086 fprintf(outfile, "** Missing closing quote in hex pattern: "
5087 "opening quote is at offset %" PTR_FORM ".\n", pq - buffer - 2);
5095 /* Expect a hex pair */
5101 fprintf(outfile, "** Unexpected non-hex-digit '%c' at offset %"
5102 PTR_FORM " in hex pattern: quote missing?\n", c, pp - buffer - 2);
5107 fprintf(outfile, "** Odd number of digits in hex pattern\n");
5113 fprintf(outfile, "** Unexpected non-hex-digit '%c' at offset %"
5114 PTR_FORM " in hex pattern: quote missing?\n", d, pp - buffer - 1);
5119 *pt++ = ((isdigit(c)? (c - '0') : (c - 'A' + 10)) << 4) +
5120 (isdigit(d)? (d - '0') : (d - 'A' + 10));
5124 patlen = pt - pbuffer8;
5127 /* If not a hex string, process for repetition expansion if requested. */
5129 else if ((pat_patctl.control & CTL_EXPAND) != 0)
5134 for (pp = buffer + 1; *pp != 0; pp++)
5140 /* Check for replication syntax; if not found, the defaults just set will
5141 prevail and one character will be copied. */
5143 if (pp[0] == '\\' && pp[1] == '[')
5146 for (pe = pp + 2; *pe != 0; pe++)
5148 if (pe[0] == ']' && pe[1] == '{')
5150 uint32_t clen = pe - pc - 2;
5156 uli = strtoul((const char *)pe, &endptr, 10);
5157 if (U32OVERFLOW(uli))
5159 fprintf(outfile, "** Pattern repeat count too large\n");
5164 pe = (uint8_t *)endptr;
5169 fprintf(outfile, "** Zero repeat not allowed\n");
5182 /* Add to output. If the buffer is too small expand it. The function for
5183 expanding buffers always keeps buffer and pbuffer8 in step as far as their
5186 while (pt + count * length > pbuffer8 + pbuffer8_size)
5188 size_t pc_offset = pc - buffer;
5189 size_t pp_offset = pp - buffer;
5190 size_t pt_offset = pt - pbuffer8;
5191 expand_input_buffers();
5192 pc = buffer + pc_offset;
5193 pp = buffer + pp_offset;
5194 pt = pbuffer8 + pt_offset;
5197 for (; count > 0; count--)
5199 memcpy(pt, pc, length);
5205 patlen = pt - pbuffer8;
5207 if ((pat_patctl.control & CTL_INFO) != 0)
5208 fprintf(outfile, "Expanded: %s\n", pbuffer8);
5211 /* Neither hex nor expanded, just copy the input verbatim. */
5215 strncpy((char *)pbuffer8, (char *)(buffer+1), patlen + 1);
5218 /* Sort out character tables */
5220 if (pat_patctl.locale[0] != 0)
5222 if (pat_patctl.tables_id != 0)
5224 fprintf(outfile, "** 'Locale' and 'tables' must not both be set\n");
5227 if (setlocale(LC_CTYPE, (const char *)pat_patctl.locale) == NULL)
5229 fprintf(outfile, "** Failed to set locale '%s'\n", pat_patctl.locale);
5232 if (strcmp((const char *)pat_patctl.locale, (const char *)locale_name) != 0)
5234 strcpy((char *)locale_name, (char *)pat_patctl.locale);
5235 if (locale_tables != NULL) free((void *)locale_tables);
5236 PCRE2_MAKETABLES(locale_tables);
5238 use_tables = locale_tables;
5241 else switch (pat_patctl.tables_id)
5243 case 0: use_tables = NULL; break;
5244 case 1: use_tables = tables1; break;
5245 case 2: use_tables = tables2; break;
5247 fprintf(outfile, "** 'Tables' must specify 0, 1, or 2.\n");
5251 PCRE2_SET_CHARACTER_TABLES(pat_context, use_tables);
5253 /* Set up for the stackguard test. */
5255 if (pat_patctl.stackguard_test != 0)
5257 PCRE2_SET_COMPILE_RECURSION_GUARD(pat_context, stack_guard, NULL);
5260 /* Handle compiling via the POSIX interface, which doesn't support the
5261 timing, showing, or debugging options, nor the ability to pass over
5262 local character tables. Neither does it have 16-bit or 32-bit support. */
5264 if ((pat_patctl.control & CTL_POSIX) != 0)
5266 #ifdef SUPPORT_PCRE2_8
5269 const char *msg = "** Ignored with POSIX interface:";
5272 if (test_mode != PCRE8_MODE)
5274 fprintf(outfile, "** The POSIX interface is available only in 8-bit mode\n");
5278 #ifdef SUPPORT_PCRE2_8
5279 /* Check for features that the POSIX interface does not support. */
5281 if (pat_patctl.locale[0] != 0) prmsg(&msg, "locale");
5282 if (pat_patctl.replacement[0] != 0) prmsg(&msg, "replace");
5283 if (pat_patctl.tables_id != 0) prmsg(&msg, "tables");
5284 if (pat_patctl.stackguard_test != 0) prmsg(&msg, "stackguard");
5285 if (timeit > 0) prmsg(&msg, "timing");
5286 if (pat_patctl.jit != 0) prmsg(&msg, "JIT");
5288 if ((pat_patctl.options & ~POSIX_SUPPORTED_COMPILE_OPTIONS) != 0)
5290 show_compile_options(
5291 pat_patctl.options & ~POSIX_SUPPORTED_COMPILE_OPTIONS, msg, "");
5295 if ((FLD(pat_context, extra_options) &
5296 ~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS) != 0)
5298 show_compile_extra_options(
5299 FLD(pat_context, extra_options) & ~POSIX_SUPPORTED_COMPILE_EXTRA_OPTIONS,
5304 if ((pat_patctl.control & ~POSIX_SUPPORTED_COMPILE_CONTROLS) != 0 ||
5305 (pat_patctl.control2 & ~POSIX_SUPPORTED_COMPILE_CONTROLS2) != 0)
5307 show_controls(pat_patctl.control & ~POSIX_SUPPORTED_COMPILE_CONTROLS,
5308 pat_patctl.control2 & ~POSIX_SUPPORTED_COMPILE_CONTROLS2, msg);
5312 if (local_newline_default != 0) prmsg(&msg, "#newline_default");
5313 if (FLD(pat_context, max_pattern_length) != PCRE2_UNSET)
5314 prmsg(&msg, "max_pattern_length");
5315 if (FLD(pat_context, parens_nest_limit) != PARENS_NEST_DEFAULT)
5316 prmsg(&msg, "parens_nest_limit");
5318 if (msg[0] == 0) fprintf(outfile, "\n");
5320 /* Translate PCRE2 options to POSIX options and then compile. */
5322 if (utf) cflags |= REG_UTF;
5323 if ((pat_patctl.control & CTL_POSIX_NOSUB) != 0) cflags |= REG_NOSUB;
5324 if ((pat_patctl.options & PCRE2_UCP) != 0) cflags |= REG_UCP;
5325 if ((pat_patctl.options & PCRE2_CASELESS) != 0) cflags |= REG_ICASE;
5326 if ((pat_patctl.options & PCRE2_LITERAL) != 0) cflags |= REG_NOSPEC;
5327 if ((pat_patctl.options & PCRE2_MULTILINE) != 0) cflags |= REG_NEWLINE;
5328 if ((pat_patctl.options & PCRE2_DOTALL) != 0) cflags |= REG_DOTALL;
5329 if ((pat_patctl.options & PCRE2_UNGREEDY) != 0) cflags |= REG_UNGREEDY;
5331 if ((pat_patctl.control & (CTL_HEXPAT|CTL_USE_LENGTH)) != 0)
5333 preg.re_endp = (char *)pbuffer8 + patlen;
5337 rc = regcomp(&preg, (char *)pbuffer8, cflags);
5339 /* Compiling failed */
5343 size_t bsize, usize;
5346 preg.re_pcre2_code = NULL; /* In case something was left in there */
5347 preg.re_match_data = NULL;
5349 bsize = (pat_patctl.regerror_buffsize != 0)?
5350 pat_patctl.regerror_buffsize : pbuffer8_size;
5351 if (bsize + 8 < pbuffer8_size)
5352 memcpy(pbuffer8 + bsize, "DEADBEEF", 8);
5353 usize = regerror(rc, &preg, (char *)pbuffer8, bsize);
5355 /* Inside regerror(), snprintf() is used. If the buffer is too small, some
5356 versions of snprintf() put a zero byte at the end, but others do not.
5357 Therefore, we print a maximum of one less than the size of the buffer. */
5359 psize = (int)bsize - 1;
5360 fprintf(outfile, "Failed: POSIX code %d: %.*s\n", rc, psize, pbuffer8);
5363 fprintf(outfile, "** regerror() message truncated\n");
5364 if (memcmp(pbuffer8 + bsize, "DEADBEEF", 8) != 0)
5365 fprintf(outfile, "** regerror() buffer overflow\n");
5370 /* Compiling succeeded. Check that the values in the preg block are sensible.
5371 It can happen that pcre2test is accidentally linked with a different POSIX
5372 library which succeeds, but of course puts different things into preg. In
5373 this situation, calling regfree() may cause a segfault (or invalid free() in
5374 valgrind), so ensure that preg.re_pcre2_code is NULL, which suppresses the
5375 calling of regfree() on exit. */
5377 if (preg.re_pcre2_code == NULL ||
5378 ((pcre2_real_code_8 *)preg.re_pcre2_code)->magic_number != MAGIC_NUMBER ||
5379 ((pcre2_real_code_8 *)preg.re_pcre2_code)->top_bracket != preg.re_nsub ||
5380 preg.re_match_data == NULL ||
5381 preg.re_cflags != cflags)
5384 "** The regcomp() function returned zero (success), but the values set\n"
5385 "** in the preg block are not valid for PCRE2. Check that pcre2test is\n"
5386 "** linked with PCRE2's pcre2posix module (-lpcre2-posix) and not with\n"
5387 "** some other POSIX regex library.\n**\n");
5388 preg.re_pcre2_code = NULL;
5393 #endif /* SUPPORT_PCRE2_8 */
5396 /* Handle compiling via the native interface. Controls that act later are
5397 ignored with "push". Replacements are locked out. */
5399 if ((pat_patctl.control & (CTL_PUSH|CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0)
5401 if (pat_patctl.replacement[0] != 0)
5403 fprintf(outfile, "** Replacement text is not supported with 'push'.\n");
5406 if ((pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS) != 0 ||
5407 (pat_patctl.control2 & ~PUSH_SUPPORTED_COMPILE_CONTROLS2) != 0)
5409 show_controls(pat_patctl.control & ~PUSH_SUPPORTED_COMPILE_CONTROLS,
5410 pat_patctl.control2 & ~PUSH_SUPPORTED_COMPILE_CONTROLS2,
5411 "** Ignored when compiled pattern is stacked with 'push':");
5412 fprintf(outfile, "\n");
5414 if ((pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS) != 0 ||
5415 (pat_patctl.control2 & PUSH_COMPILE_ONLY_CONTROLS2) != 0)
5417 show_controls(pat_patctl.control & PUSH_COMPILE_ONLY_CONTROLS,
5418 pat_patctl.control2 & PUSH_COMPILE_ONLY_CONTROLS2,
5419 "** Applies only to compile when pattern is stacked with 'push':");
5420 fprintf(outfile, "\n");
5424 /* Convert the input in non-8-bit modes. */
5428 #ifdef SUPPORT_PCRE2_16
5429 if (test_mode == PCRE16_MODE) errorcode = to16(pbuffer8, utf, &patlen);
5432 #ifdef SUPPORT_PCRE2_32
5433 if (test_mode == PCRE32_MODE) errorcode = to32(pbuffer8, utf, &patlen);
5439 fprintf(outfile, "** Failed: invalid UTF-8 string cannot be "
5440 "converted to %d-bit string\n", (test_mode == PCRE16_MODE)? 16:32);
5444 fprintf(outfile, "** Failed: character value greater than 0x10ffff "
5445 "cannot be converted to UTF\n");
5449 fprintf(outfile, "** Failed: character value greater than 0xffff "
5450 "cannot be converted to 16-bit in non-UTF mode\n");
5457 /* The pattern is now in pbuffer[8|16|32], with the length in code units in
5458 patlen. If it is to be converted, copy the result back afterwards so that it
5459 ends up back in the usual place. */
5461 if (pat_patctl.convert_type != CONVERT_UNSET)
5464 int convert_return = PR_OK;
5465 uint32_t convert_options = pat_patctl.convert_type;
5466 void *converted_pattern;
5467 PCRE2_SIZE converted_length;
5469 if (pat_patctl.convert_length != 0)
5471 converted_length = pat_patctl.convert_length;
5472 converted_pattern = malloc(converted_length * code_unit_size);
5473 if (converted_pattern == NULL)
5475 fprintf(outfile, "** Failed: malloc failed for converted pattern\n");
5479 else converted_pattern = NULL; /* Let the library allocate */
5481 if (utf) convert_options |= PCRE2_CONVERT_UTF;
5482 if ((pat_patctl.options & PCRE2_NO_UTF_CHECK) != 0)
5483 convert_options |= PCRE2_CONVERT_NO_UTF_CHECK;
5485 CONCTXCPY(con_context, default_con_context);
5487 if (pat_patctl.convert_glob_escape != 0)
5489 uint32_t escape = (pat_patctl.convert_glob_escape == '0')? 0 :
5490 pat_patctl.convert_glob_escape;
5491 PCRE2_SET_GLOB_ESCAPE(rc, con_context, escape);
5494 fprintf(outfile, "** Invalid glob escape '%c'\n",
5495 pat_patctl.convert_glob_escape);
5496 convert_return = PR_SKIP;
5497 goto CONVERT_FINISH;
5501 if (pat_patctl.convert_glob_separator != 0)
5503 PCRE2_SET_GLOB_SEPARATOR(rc, con_context, pat_patctl.convert_glob_separator);
5506 fprintf(outfile, "** Invalid glob separator '%c'\n",
5507 pat_patctl.convert_glob_separator);
5508 convert_return = PR_SKIP;
5509 goto CONVERT_FINISH;
5513 PCRE2_PATTERN_CONVERT(rc, pbuffer, patlen, convert_options,
5514 &converted_pattern, &converted_length, con_context);
5518 fprintf(outfile, "** Pattern conversion error at offset %" SIZ_FORM ": ",
5519 SIZ_CAST converted_length);
5520 convert_return = print_error_message(rc, "", "\n")? PR_SKIP:PR_ABEND;
5523 /* Output the converted pattern, then copy it. */
5527 PCHARSV(converted_pattern, 0, converted_length, utf, outfile);
5528 fprintf(outfile, "\n");
5529 patlen = converted_length;
5530 CONVERT_COPY(pbuffer, converted_pattern, converted_length + 1);
5533 /* Free the converted pattern. */
5536 if (pat_patctl.convert_length != 0)
5537 free(converted_pattern);
5539 PCRE2_CONVERTED_PATTERN_FREE(converted_pattern);
5541 /* Return if conversion was unsuccessful. */
5543 if (convert_return != PR_OK) return convert_return;
5546 /* By default we pass a zero-terminated pattern, but a length is passed if
5547 "use_length" was specified or this is a hex pattern (which might contain binary
5548 zeros). When valgrind is supported, arrange for the unused part of the buffer
5549 to be marked as no access. */
5551 valgrind_access_length = patlen;
5552 if ((pat_patctl.control & (CTL_HEXPAT|CTL_USE_LENGTH)) == 0)
5554 patlen = PCRE2_ZERO_TERMINATED;
5555 valgrind_access_length += 1; /* For the terminating zero */
5558 #ifdef SUPPORT_VALGRIND
5559 #ifdef SUPPORT_PCRE2_8
5560 if (test_mode == PCRE8_MODE && pbuffer8 != NULL)
5562 VALGRIND_MAKE_MEM_NOACCESS(pbuffer8 + valgrind_access_length,
5563 pbuffer8_size - valgrind_access_length);
5566 #ifdef SUPPORT_PCRE2_16
5567 if (test_mode == PCRE16_MODE && pbuffer16 != NULL)
5569 VALGRIND_MAKE_MEM_NOACCESS(pbuffer16 + valgrind_access_length,
5570 pbuffer16_size - valgrind_access_length*sizeof(uint16_t));
5573 #ifdef SUPPORT_PCRE2_32
5574 if (test_mode == PCRE32_MODE && pbuffer32 != NULL)
5576 VALGRIND_MAKE_MEM_NOACCESS(pbuffer32 + valgrind_access_length,
5577 pbuffer32_size - valgrind_access_length*sizeof(uint32_t));
5580 #else /* Valgrind not supported */
5581 (void)valgrind_access_length; /* Avoid compiler warning */
5584 /* If #newline_default has been used and the library was not compiled with an
5585 appropriate default newline setting, local_newline_default will be non-zero. We
5586 use this if there is no explicit newline modifier. */
5588 if ((pat_patctl.control2 & CTL2_NL_SET) == 0 && local_newline_default != 0)
5590 SETFLD(pat_context, newline_convention, local_newline_default);
5593 /* The null_context modifier is used to test calling pcre2_compile() with a
5596 use_pat_context = ((pat_patctl.control & CTL_NULLCONTEXT) != 0)?
5597 NULL : PTR(pat_context);
5599 /* If PCRE2_LITERAL is set, set use_forbid_utf zero because PCRE2_NEVER_UTF
5600 and PCRE2_NEVER_UCP are invalid with it. */
5602 if ((pat_patctl.options & PCRE2_LITERAL) != 0) use_forbid_utf = 0;
5604 /* Compile many times when timing. */
5609 clock_t time_taken = 0;
5610 for (i = 0; i < timeit; i++)
5612 clock_t start_time = clock();
5613 PCRE2_COMPILE(compiled_code, pbuffer, patlen,
5614 pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset,
5616 time_taken += clock() - start_time;
5617 if (TEST(compiled_code, !=, NULL))
5618 { SUB1(pcre2_code_free, compiled_code); }
5620 total_compile_time += time_taken;
5621 fprintf(outfile, "Compile time %.4f milliseconds\n",
5622 (((double)time_taken * 1000.0) / (double)timeit) /
5623 (double)CLOCKS_PER_SEC);
5626 /* A final compile that is used "for real". */
5628 PCRE2_COMPILE(compiled_code, pbuffer, patlen, pat_patctl.options|use_forbid_utf,
5629 &errorcode, &erroroffset, use_pat_context);
5631 /* Call the JIT compiler if requested. When timing, we must free and recompile
5632 the pattern each time because that is the only way to free the JIT compiled
5633 code. We know that compilation will always succeed. */
5635 if (TEST(compiled_code, !=, NULL) && pat_patctl.jit != 0)
5640 clock_t time_taken = 0;
5641 for (i = 0; i < timeit; i++)
5644 SUB1(pcre2_code_free, compiled_code);
5645 PCRE2_COMPILE(compiled_code, pbuffer, patlen,
5646 pat_patctl.options|use_forbid_utf, &errorcode, &erroroffset,
5648 start_time = clock();
5649 PCRE2_JIT_COMPILE(jitrc,compiled_code, pat_patctl.jit);
5650 time_taken += clock() - start_time;
5652 total_jit_compile_time += time_taken;
5653 fprintf(outfile, "JIT compile %.4f milliseconds\n",
5654 (((double)time_taken * 1000.0) / (double)timeit) /
5655 (double)CLOCKS_PER_SEC);
5659 PCRE2_JIT_COMPILE(jitrc, compiled_code, pat_patctl.jit);
5663 /* If valgrind is supported, mark the pbuffer as accessible again. The 16-bit
5664 and 32-bit buffers can be marked completely undefined, but we must leave the
5665 pattern in the 8-bit buffer defined because it may be read from a callout
5668 #ifdef SUPPORT_VALGRIND
5669 #ifdef SUPPORT_PCRE2_8
5670 if (test_mode == PCRE8_MODE)
5672 VALGRIND_MAKE_MEM_UNDEFINED(pbuffer8 + valgrind_access_length,
5673 pbuffer8_size - valgrind_access_length);
5676 #ifdef SUPPORT_PCRE2_16
5677 if (test_mode == PCRE16_MODE)
5679 VALGRIND_MAKE_MEM_UNDEFINED(pbuffer16, pbuffer16_size);
5682 #ifdef SUPPORT_PCRE2_32
5683 if (test_mode == PCRE32_MODE)
5685 VALGRIND_MAKE_MEM_UNDEFINED(pbuffer32, pbuffer32_size);
5690 /* Compilation failed; go back for another re, skipping to blank line
5691 if non-interactive. */
5693 if (TEST(compiled_code, ==, NULL))
5695 fprintf(outfile, "Failed: error %d at offset %d: ", errorcode,
5697 if (!print_error_message(errorcode, "", "\n")) return PR_ABEND;
5701 /* If forbid_utf is non-zero, we are running a non-UTF test. UTF and UCP are
5702 locked out at compile time, but we must also check for occurrences of \P, \p,
5703 and \X, which are only supported when Unicode is supported. */
5705 if (forbid_utf != 0)
5707 if ((FLD(compiled_code, flags) & PCRE2_HASBKPORX) != 0)
5709 fprintf(outfile, "** \\P, \\p, and \\X are not allowed after the "
5710 "#forbid_utf command\n");
5715 /* Remember the maximum lookbehind, for partial matching. */
5717 if (pattern_info(PCRE2_INFO_MAXLOOKBEHIND, &maxlookbehind, FALSE) != 0)
5720 /* If an explicit newline modifier was given, set the information flag in the
5721 pattern so that it is preserved over push/pop. */
5723 if ((pat_patctl.control2 & CTL2_NL_SET) != 0)
5725 SETFLD(compiled_code, flags, FLD(compiled_code, flags) | PCRE2_NL_SET);
5728 /* Output code size and other information if requested. */
5730 if ((pat_patctl.control & CTL_MEMORY) != 0) show_memory_info();
5731 if ((pat_patctl.control & CTL_FRAMESIZE) != 0) show_framesize();
5732 if ((pat_patctl.control & CTL_ANYINFO) != 0)
5734 int rc = show_pattern_info();
5735 if (rc != PR_OK) return rc;
5738 /* The "push" control requests that the compiled pattern be remembered on a
5739 stack. This is mainly for testing the serialization functionality. */
5741 if ((pat_patctl.control & CTL_PUSH) != 0)
5743 if (patstacknext >= PATSTACKSIZE)
5745 fprintf(outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
5748 patstack[patstacknext++] = PTR(compiled_code);
5749 SET(compiled_code, NULL);
5752 /* The "pushcopy" and "pushtablescopy" controls are similar, but push a
5753 copy of the pattern, the latter with a copy of its character tables. This tests
5754 the pcre2_code_copy() and pcre2_code_copy_with_tables() functions. */
5756 if ((pat_patctl.control & (CTL_PUSHCOPY|CTL_PUSHTABLESCOPY)) != 0)
5758 if (patstacknext >= PATSTACKSIZE)
5760 fprintf(outfile, "** Too many pushed patterns (max %d)\n", PATSTACKSIZE);
5763 if ((pat_patctl.control & CTL_PUSHCOPY) != 0)
5765 PCRE2_CODE_COPY_TO_VOID(patstack[patstacknext++], compiled_code);
5769 PCRE2_CODE_COPY_WITH_TABLES_TO_VOID(patstack[patstacknext++],
5778 /*************************************************
5779 * Check heap, match or depth limit *
5780 *************************************************/
5782 /* This is used for DFA, normal, and JIT fast matching. For DFA matching it
5783 should only be called with the third argument set to PCRE2_ERROR_DEPTHLIMIT.
5786 pp the subject string
5787 ulen length of subject or PCRE2_ZERO_TERMINATED
5788 errnumber defines which limit to test
5789 msg string to include in final message
5791 Returns: the return from the final match function call
5795 check_match_limit(uint8_t *pp, PCRE2_SIZE ulen, int errnumber, const char *msg)
5800 uint32_t max = UINT32_MAX;
5802 PCRE2_SET_MATCH_LIMIT(dat_context, max);
5803 PCRE2_SET_DEPTH_LIMIT(dat_context, max);
5804 PCRE2_SET_HEAP_LIMIT(dat_context, max);
5808 uint32_t stack_start = 0;
5810 if (errnumber == PCRE2_ERROR_HEAPLIMIT)
5812 PCRE2_SET_HEAP_LIMIT(dat_context, mid);
5814 else if (errnumber == PCRE2_ERROR_MATCHLIMIT)
5816 PCRE2_SET_MATCH_LIMIT(dat_context, mid);
5820 PCRE2_SET_DEPTH_LIMIT(dat_context, mid);
5823 if ((dat_datctl.control & CTL_DFA) != 0)
5825 stack_start = DFA_START_RWS_SIZE/1024;
5826 if (dfa_workspace == NULL)
5827 dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
5828 if (dfa_matched++ == 0)
5829 dfa_workspace[0] = -1; /* To catch bad restart */
5830 PCRE2_DFA_MATCH(capcount, compiled_code, pp, ulen, dat_datctl.offset,
5831 dat_datctl.options, match_data,
5832 PTR(dat_context), dfa_workspace, DFA_WS_DIMENSION);
5835 else if ((pat_patctl.control & CTL_JITFAST) != 0)
5836 PCRE2_JIT_MATCH(capcount, compiled_code, pp, ulen, dat_datctl.offset,
5837 dat_datctl.options, match_data, PTR(dat_context));
5841 stack_start = START_FRAMES_SIZE/1024;
5842 PCRE2_MATCH(capcount, compiled_code, pp, ulen, dat_datctl.offset,
5843 dat_datctl.options, match_data, PTR(dat_context));
5846 if (capcount == errnumber)
5848 if ((mid & 0x80000000u) != 0)
5850 fprintf(outfile, "Can't find minimum %s limit: check pattern for "
5851 "restriction\n", msg);
5856 mid = (mid == max - 1)? max : (max != UINT32_MAX)? (min + max)/2 : mid*2;
5858 else if (capcount >= 0 ||
5859 capcount == PCRE2_ERROR_NOMATCH ||
5860 capcount == PCRE2_ERROR_PARTIAL)
5862 /* If we've not hit the error with a heap limit less than the size of the
5863 initial stack frame vector (for pcre2_match()) or the initial stack
5864 workspace vector (for pcre2_dfa_match()), the heap is not being used, so
5865 the minimum limit is zero; there's no need to go on. The other limits are
5866 always greater than zero. */
5868 if (errnumber == PCRE2_ERROR_HEAPLIMIT && mid < stack_start)
5870 fprintf(outfile, "Minimum %s limit = 0\n", msg);
5875 fprintf(outfile, "Minimum %s limit = %d\n", msg, mid);
5879 mid = (min + max)/2;
5881 else break; /* Some other error */
5889 /*************************************************
5890 * Callout function *
5891 *************************************************/
5893 /* Called from a PCRE2 library as a result of the (?C) item. We print out where
5894 we are in the match (unless suppressed). Yield zero unless more callouts than
5895 the fail count, or the callout data is not zero. The only differences in the
5896 callout block for different code unit widths are that the pointers to the
5897 subject, the most recent MARK, and a callout argument string point to strings
5898 of the appropriate width. Casts can be used to deal with this.
5900 Argument: a pointer to a callout block
5905 callout_function(pcre2_callout_block_8 *cb, void *callout_data_ptr)
5908 uint32_t i, pre_start, post_start, subject_length;
5909 PCRE2_SIZE current_position;
5910 BOOL utf = (FLD(compiled_code, overall_options) & PCRE2_UTF) != 0;
5911 BOOL callout_capture = (dat_datctl.control & CTL_CALLOUT_CAPTURE) != 0;
5912 BOOL callout_where = (dat_datctl.control2 & CTL2_CALLOUT_NO_WHERE) == 0;
5914 /* The FILE f is used for echoing the subject string if it is non-NULL. This
5915 happens only once in simple cases, but we want to repeat after any additional
5916 output caused by CALLOUT_EXTRA. */
5918 fdefault = (!first_callout && !callout_capture && cb->callout_string == NULL)?
5921 if ((dat_datctl.control2 & CTL2_CALLOUT_EXTRA) != 0)
5924 switch (cb->callout_flags)
5926 case PCRE2_CALLOUT_BACKTRACK:
5927 fprintf(f, "Backtrack\n");
5930 case PCRE2_CALLOUT_STARTMATCH|PCRE2_CALLOUT_BACKTRACK:
5931 fprintf(f, "Backtrack\nNo other matching paths\n");
5934 case PCRE2_CALLOUT_STARTMATCH:
5935 fprintf(f, "New match attempt\n");
5945 /* For a callout with a string argument, show the string first because there
5946 isn't a tidy way to fit it in the rest of the data. */
5948 if (cb->callout_string != NULL)
5950 uint32_t delimiter = CODE_UNIT(cb->callout_string, -1);
5951 fprintf(outfile, "Callout (%" SIZ_FORM "): %c",
5952 SIZ_CAST cb->callout_string_offset, delimiter);
5953 PCHARSV(cb->callout_string, 0,
5954 cb->callout_string_length, utf, outfile);
5955 for (i = 0; callout_start_delims[i] != 0; i++)
5956 if (delimiter == callout_start_delims[i])
5958 delimiter = callout_end_delims[i];
5961 fprintf(outfile, "%c", delimiter);
5962 if (!callout_capture) fprintf(outfile, "\n");
5965 /* Show captured strings if required */
5967 if (callout_capture)
5969 if (cb->callout_string == NULL)
5970 fprintf(outfile, "Callout %d:", cb->callout_number);
5971 fprintf(outfile, " last capture = %d\n", cb->capture_last);
5972 for (i = 2; i < cb->capture_top * 2; i += 2)
5974 fprintf(outfile, "%2d: ", i/2);
5975 if (cb->offset_vector[i] == PCRE2_UNSET)
5976 fprintf(outfile, "<unset>");
5979 PCHARSV(cb->subject, cb->offset_vector[i],
5980 cb->offset_vector[i+1] - cb->offset_vector[i], utf, f);
5982 fprintf(outfile, "\n");
5986 /* Unless suppressed, re-print the subject in canonical form (with escapes for
5987 non-printing characters), the first time, or if giving full details. On
5988 subsequent calls in the same match, we use PCHARS() just to find the printed
5989 lengths of the substrings. */
5993 if (f != NULL) fprintf(f, "--->");
5995 /* The subject before the match start. */
5997 PCHARS(pre_start, cb->subject, 0, cb->start_match, utf, f);
5999 /* If a lookbehind is involved, the current position may be earlier than the
6000 match start. If so, use the match start instead. */
6002 current_position = (cb->current_position >= cb->start_match)?
6003 cb->current_position : cb->start_match;
6005 /* The subject between the match start and the current position. */
6007 PCHARS(post_start, cb->subject, cb->start_match,
6008 current_position - cb->start_match, utf, f);
6010 /* Print from the current position to the end. */
6012 PCHARSV(cb->subject, current_position, cb->subject_length - current_position,
6015 /* Calculate the total subject printed length (no print). */
6017 PCHARS(subject_length, cb->subject, 0, cb->subject_length, utf, NULL);
6019 if (f != NULL) fprintf(f, "\n");
6021 /* For automatic callouts, show the pattern offset. Otherwise, for a
6022 numerical callout whose number has not already been shown with captured
6023 strings, show the number here. A callout with a string argument has been
6026 if (cb->callout_number == 255)
6028 fprintf(outfile, "%+3d ", (int)cb->pattern_position);
6029 if (cb->pattern_position > 99) fprintf(outfile, "\n ");
6033 if (callout_capture || cb->callout_string != NULL) fprintf(outfile, " ");
6034 else fprintf(outfile, "%3d ", cb->callout_number);
6037 /* Now show position indicators */
6039 for (i = 0; i < pre_start; i++) fprintf(outfile, " ");
6040 fprintf(outfile, "^");
6044 for (i = 0; i < post_start - 1; i++) fprintf(outfile, " ");
6045 fprintf(outfile, "^");
6048 for (i = 0; i < subject_length - pre_start - post_start + 4; i++)
6049 fprintf(outfile, " ");
6051 if (cb->next_item_length != 0)
6052 fprintf(outfile, "%.*s", (int)(cb->next_item_length),
6053 pbuffer8 + cb->pattern_position);
6055 fprintf(outfile, "End of pattern");
6057 fprintf(outfile, "\n");
6060 first_callout = FALSE;
6062 /* Show any mark info */
6064 if (cb->mark != last_callout_mark)
6066 if (cb->mark == NULL)
6067 fprintf(outfile, "Latest Mark: <unset>\n");
6070 fprintf(outfile, "Latest Mark: ");
6071 PCHARSV(cb->mark, 0, -1, utf, outfile);
6072 putc('\n', outfile);
6074 last_callout_mark = cb->mark;
6077 /* Show callout data */
6079 if (callout_data_ptr != NULL)
6081 int callout_data = *((int32_t *)callout_data_ptr);
6082 if (callout_data != 0)
6084 fprintf(outfile, "Callout data = %d\n", callout_data);
6085 return callout_data;
6089 /* Keep count and give the appropriate return code */
6093 if (cb->callout_number == dat_datctl.cerror[0] &&
6094 callout_count >= dat_datctl.cerror[1])
6095 return PCRE2_ERROR_CALLOUT;
6097 if (cb->callout_number == dat_datctl.cfail[0] &&
6098 callout_count >= dat_datctl.cfail[1])
6106 /*************************************************
6107 * Handle *MARK and copy/get tests *
6108 *************************************************/
6110 /* This function is called after complete and partial matches. It runs the
6111 tests for substring extraction.
6115 capcount return from pcre2_match()
6117 Returns: FALSE if print_error_message() fails
6121 copy_and_get(BOOL utf, int capcount)
6126 /* Test copy strings by number */
6128 for (i = 0; i < MAXCPYGET && dat_datctl.copy_numbers[i] >= 0; i++)
6131 PCRE2_SIZE length, length2;
6132 uint32_t copybuffer[256];
6133 uint32_t n = (uint32_t)(dat_datctl.copy_numbers[i]);
6134 length = sizeof(copybuffer)/code_unit_size;
6135 PCRE2_SUBSTRING_COPY_BYNUMBER(rc, match_data, n, copybuffer, &length);
6138 fprintf(outfile, "Copy substring %d failed (%d): ", n, rc);
6139 if (!print_error_message(rc, "", "\n")) return FALSE;
6143 PCRE2_SUBSTRING_LENGTH_BYNUMBER(rc, match_data, n, &length2);
6146 fprintf(outfile, "Get substring %d length failed (%d): ", n, rc);
6147 if (!print_error_message(rc, "", "\n")) return FALSE;
6149 else if (length2 != length)
6151 fprintf(outfile, "Mismatched substring lengths: %"
6152 SIZ_FORM " %" SIZ_FORM "\n", SIZ_CAST length, SIZ_CAST length2);
6154 fprintf(outfile, "%2dC ", n);
6155 PCHARSV(copybuffer, 0, length, utf, outfile);
6156 fprintf(outfile, " (%" SIZ_FORM ")\n", SIZ_CAST length);
6160 /* Test copy strings by name */
6162 nptr = dat_datctl.copy_names;
6167 PCRE2_SIZE length, length2;
6168 uint32_t copybuffer[256];
6169 int namelen = strlen((const char *)nptr);
6170 #if defined SUPPORT_PCRE2_16 || defined SUPPORT_PCRE2_32
6171 PCRE2_SIZE cnl = namelen;
6173 if (namelen == 0) break;
6175 #ifdef SUPPORT_PCRE2_8
6176 if (test_mode == PCRE8_MODE) strcpy((char *)pbuffer8, (char *)nptr);
6178 #ifdef SUPPORT_PCRE2_16
6179 if (test_mode == PCRE16_MODE)(void)to16(nptr, utf, &cnl);
6181 #ifdef SUPPORT_PCRE2_32
6182 if (test_mode == PCRE32_MODE)(void)to32(nptr, utf, &cnl);
6185 PCRE2_SUBSTRING_NUMBER_FROM_NAME(groupnumber, compiled_code, pbuffer);
6186 if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING)
6187 fprintf(outfile, "Number not found for group '%s'\n", nptr);
6189 length = sizeof(copybuffer)/code_unit_size;
6190 PCRE2_SUBSTRING_COPY_BYNAME(rc, match_data, pbuffer, copybuffer, &length);
6193 fprintf(outfile, "Copy substring '%s' failed (%d): ", nptr, rc);
6194 if (!print_error_message(rc, "", "\n")) return FALSE;
6198 PCRE2_SUBSTRING_LENGTH_BYNAME(rc, match_data, pbuffer, &length2);
6201 fprintf(outfile, "Get substring '%s' length failed (%d): ", nptr, rc);
6202 if (!print_error_message(rc, "", "\n")) return FALSE;
6204 else if (length2 != length)
6206 fprintf(outfile, "Mismatched substring lengths: %"
6207 SIZ_FORM " %" SIZ_FORM "\n", SIZ_CAST length, SIZ_CAST length2);
6209 fprintf(outfile, " C ");
6210 PCHARSV(copybuffer, 0, length, utf, outfile);
6211 fprintf(outfile, " (%" SIZ_FORM ") %s", SIZ_CAST length, nptr);
6212 if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber);
6213 else fprintf(outfile, " (non-unique)\n");
6215 nptr += namelen + 1;
6218 /* Test get strings by number */
6220 for (i = 0; i < MAXCPYGET && dat_datctl.get_numbers[i] >= 0; i++)
6225 uint32_t n = (uint32_t)(dat_datctl.get_numbers[i]);
6226 PCRE2_SUBSTRING_GET_BYNUMBER(rc, match_data, n, &gotbuffer, &length);
6229 fprintf(outfile, "Get substring %d failed (%d): ", n, rc);
6230 if (!print_error_message(rc, "", "\n")) return FALSE;
6234 fprintf(outfile, "%2dG ", n);
6235 PCHARSV(gotbuffer, 0, length, utf, outfile);
6236 fprintf(outfile, " (%" SIZ_FORM ")\n", SIZ_CAST length);
6237 PCRE2_SUBSTRING_FREE(gotbuffer);
6241 /* Test get strings by name */
6243 nptr = dat_datctl.get_names;
6250 int namelen = strlen((const char *)nptr);
6251 #if defined SUPPORT_PCRE2_16 || defined SUPPORT_PCRE2_32
6252 PCRE2_SIZE cnl = namelen;
6254 if (namelen == 0) break;
6256 #ifdef SUPPORT_PCRE2_8
6257 if (test_mode == PCRE8_MODE) strcpy((char *)pbuffer8, (char *)nptr);
6259 #ifdef SUPPORT_PCRE2_16
6260 if (test_mode == PCRE16_MODE)(void)to16(nptr, utf, &cnl);
6262 #ifdef SUPPORT_PCRE2_32
6263 if (test_mode == PCRE32_MODE)(void)to32(nptr, utf, &cnl);
6266 PCRE2_SUBSTRING_NUMBER_FROM_NAME(groupnumber, compiled_code, pbuffer);
6267 if (groupnumber < 0 && groupnumber != PCRE2_ERROR_NOUNIQUESUBSTRING)
6268 fprintf(outfile, "Number not found for group '%s'\n", nptr);
6270 PCRE2_SUBSTRING_GET_BYNAME(rc, match_data, pbuffer, &gotbuffer, &length);
6273 fprintf(outfile, "Get substring '%s' failed (%d): ", nptr, rc);
6274 if (!print_error_message(rc, "", "\n")) return FALSE;
6278 fprintf(outfile, " G ");
6279 PCHARSV(gotbuffer, 0, length, utf, outfile);
6280 fprintf(outfile, " (%" SIZ_FORM ") %s", SIZ_CAST length, nptr);
6281 if (groupnumber >= 0) fprintf(outfile, " (group %d)\n", groupnumber);
6282 else fprintf(outfile, " (non-unique)\n");
6283 PCRE2_SUBSTRING_FREE(gotbuffer);
6285 nptr += namelen + 1;
6288 /* Test getting the complete list of captured strings. */
6290 if ((dat_datctl.control & CTL_GETALL) != 0)
6294 PCRE2_SIZE *lengths;
6295 PCRE2_SUBSTRING_LIST_GET(rc, match_data, &stringlist, &lengths);
6298 fprintf(outfile, "get substring list failed (%d): ", rc);
6299 if (!print_error_message(rc, "", "\n")) return FALSE;
6303 for (i = 0; i < capcount; i++)
6305 fprintf(outfile, "%2dL ", i);
6306 PCHARSV(stringlist[i], 0, lengths[i], utf, outfile);
6307 putc('\n', outfile);
6309 if (stringlist[i] != NULL)
6310 fprintf(outfile, "string list not terminated by NULL\n");
6311 PCRE2_SUBSTRING_LIST_FREE(stringlist);
6320 /*************************************************
6321 * Process a data line *
6322 *************************************************/
6324 /* The line is in buffer; it will not be empty.
6328 Returns: PR_OK continue processing next line
6329 PR_SKIP skip to a blank line
6330 PR_ABEND abort the pcre2test run
6336 PCRE2_SIZE len, ulen, arg_ulen;
6339 uint32_t g_notempty = 0;
6340 uint8_t *p, *pp, *start_rep;
6342 void *use_dat_context;
6344 BOOL subject_literal;
6345 PCRE2_SIZE ovecsave[3];
6347 #ifdef SUPPORT_PCRE2_8
6350 #ifdef SUPPORT_PCRE2_16
6351 uint16_t *q16 = NULL;
6353 #ifdef SUPPORT_PCRE2_32
6354 uint32_t *q32 = NULL;
6357 subject_literal = (pat_patctl.control2 & CTL2_SUBJECT_LITERAL) != 0;
6359 /* Copy the default context and data control blocks to the active ones. Then
6360 copy from the pattern the controls that can be set in either the pattern or the
6361 data. This allows them to be overridden in the data line. We do not do this for
6362 options because those that are common apply separately to compiling and
6365 DATCTXCPY(dat_context, default_dat_context);
6366 memcpy(&dat_datctl, &def_datctl, sizeof(datctl));
6367 dat_datctl.control |= (pat_patctl.control & CTL_ALLPD);
6368 dat_datctl.control2 |= (pat_patctl.control2 & CTL2_ALLPD);
6369 strcpy((char *)dat_datctl.replacement, (char *)pat_patctl.replacement);
6370 if (dat_datctl.jitstack == 0) dat_datctl.jitstack = pat_patctl.jitstack;
6372 /* Initialize for scanning the data line. */
6374 #ifdef SUPPORT_PCRE2_8
6375 utf = ((((pat_patctl.control & CTL_POSIX) != 0)?
6376 ((pcre2_real_code_8 *)preg.re_pcre2_code)->overall_options :
6377 FLD(compiled_code, overall_options)) & PCRE2_UTF) != 0;
6379 utf = (FLD(compiled_code, overall_options) & PCRE2_UTF) != 0;
6383 len = strlen((const char *)buffer);
6384 while (len > 0 && isspace(buffer[len-1])) len--;
6387 while (isspace(*p)) p++;
6389 /* Check that the data is well-formed UTF-8 if we're in UTF mode. To create
6390 invalid input to pcre2_match(), you must use \x?? or \x{} sequences. */
6397 for (q = p; n > 0 && *q; q += n) n = utf82ord(q, &cc);
6400 fprintf(outfile, "** Failed: invalid UTF-8 string cannot be used as input "
6406 #ifdef SUPPORT_VALGRIND
6407 /* Mark the dbuffer as addressable but undefined again. */
6408 if (dbuffer != NULL)
6410 VALGRIND_MAKE_MEM_UNDEFINED(dbuffer, dbuffer_size);
6414 /* Allocate a buffer to hold the data line; len+1 is an upper bound on
6415 the number of code units that will be needed (though the buffer may have to be
6416 extended if replication is involved). */
6418 needlen = (size_t)((len+1) * code_unit_size);
6419 if (dbuffer == NULL || needlen >= dbuffer_size)
6421 while (needlen >= dbuffer_size) dbuffer_size *= 2;
6422 dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size);
6423 if (dbuffer == NULL)
6425 fprintf(stderr, "pcre2test: realloc(%d) failed\n", (int)dbuffer_size);
6429 SETCASTPTR(q, dbuffer); /* Sets q8, q16, or q32, as appropriate. */
6431 /* Scan the data line, interpreting data escapes, and put the result into a
6432 buffer of the appropriate width. In UTF mode, input is always UTF-8; otherwise,
6433 in 16- and 32-bit modes, it can be forced to UTF-8 by the utf8_input modifier.
6436 while ((c = *p++) != 0)
6441 /* ] may mark the end of a replicated sequence */
6443 if (c == ']' && start_rep != NULL)
6447 size_t qoffset = CAST8VAR(q) - dbuffer;
6448 size_t rep_offset = start_rep - dbuffer;
6452 fprintf(outfile, "** Expected '{' after \\[....]\n");
6456 li = strtol((const char *)p, &endptr, 10);
6457 if (S32OVERFLOW(li))
6459 fprintf(outfile, "** Repeat count too large\n");
6463 p = (uint8_t *)endptr;
6466 fprintf(outfile, "** Expected '}' after \\[...]{...\n");
6473 fprintf(outfile, "** Zero repeat not allowed\n");
6477 replen = CAST8VAR(q) - start_rep;
6478 needlen += replen * i;
6480 if (needlen >= dbuffer_size)
6482 while (needlen >= dbuffer_size) dbuffer_size *= 2;
6483 dbuffer = (uint8_t *)realloc(dbuffer, dbuffer_size);
6484 if (dbuffer == NULL)
6486 fprintf(stderr, "pcre2test: realloc(%d) failed\n", (int)dbuffer_size);
6489 SETCASTPTR(q, dbuffer + qoffset);
6490 start_rep = dbuffer + rep_offset;
6495 memcpy(CAST8VAR(q), start_rep, replen);
6496 SETPLUS(q, replen/code_unit_size);
6503 /* Handle a non-escaped character. In non-UTF 32-bit mode with utf8_input
6504 set, do the fudge for setting the top bit. */
6506 if (c != '\\' || subject_literal)
6508 uint32_t topbit = 0;
6509 if (test_mode == PCRE32_MODE && c == 0xff && *p != 0)
6511 topbit = 0x80000000;
6514 if ((utf || (pat_patctl.control & CTL_UTF8_INPUT) != 0) &&
6515 HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
6519 /* Handle backslash escapes */
6521 else switch ((c = *p++))
6524 case 'a': c = CHAR_BEL; break;
6525 case 'b': c = '\b'; break;
6526 case 'e': c = CHAR_ESC; break;
6527 case 'f': c = '\f'; break;
6528 case 'n': c = '\n'; break;
6529 case 'r': c = '\r'; break;
6530 case 't': c = '\t'; break;
6531 case 'v': c = '\v'; break;
6533 case '0': case '1': case '2': case '3':
6534 case '4': case '5': case '6': case '7':
6536 while (i++ < 2 && isdigit(*p) && *p != '8' && *p != '9')
6537 c = c * 8 + *p++ - '0';
6545 for (pt++; isdigit(*pt) && *pt != '8' && *pt != '9'; pt++)
6548 fprintf(outfile, "** Too many octal digits in \\o{...} item; "
6549 "using only the first twelve.\n");
6550 else c = c * 8 + *pt - '0';
6552 if (*pt == '}') p = pt + 1;
6553 else fprintf(outfile, "** Missing } after \\o{ (assumed)\n");
6563 /* We used to have "while (isxdigit(*(++pt)))" here, but it fails
6564 when isxdigit() is a macro that refers to its argument more than
6565 once. This is banned by the C Standard, but apparently happens in at
6566 least one MacOS environment. */
6568 for (pt++; isxdigit(*pt); pt++)
6571 fprintf(outfile, "** Too many hex digits in \\x{...} item; "
6572 "using only the first eight.\n");
6573 else c = c * 16 + tolower(*pt) - ((isdigit(*pt))? '0' : 'a' - 10);
6580 /* Not correct form for \x{...}; fall through */
6583 /* \x without {} always defines just one byte in 8-bit mode. This
6584 allows UTF-8 characters to be constructed byte by byte, and also allows
6585 invalid UTF-8 sequences to be made. Just copy the byte in UTF-8 mode.
6586 Otherwise, pass it down as data. */
6589 while (i++ < 2 && isxdigit(*p))
6591 c = c * 16 + tolower(*p) - ((isdigit(*p))? '0' : 'a' - 10);
6594 #if defined SUPPORT_PCRE2_8
6595 if (utf && (test_mode == PCRE8_MODE))
6603 case 0: /* \ followed by EOF allows for an empty line */
6607 case '=': /* \= terminates the data, starts modifiers */
6610 case '[': /* \[ introduces a replicated character sequence */
6611 if (start_rep != NULL)
6613 fprintf(outfile, "** Nested replication is not supported\n");
6616 start_rep = CAST8VAR(q);
6622 fprintf(outfile, "** Unrecognized escape sequence \"\\%c\"\n", c);
6627 /* We now have a character value in c that may be greater than 255.
6628 In 8-bit mode we convert to UTF-8 if we are in UTF mode. Values greater
6629 than 127 in UTF mode must have come from \x{...} or octal constructs
6630 because values from \x.. get this far only in non-UTF mode. */
6632 #ifdef SUPPORT_PCRE2_8
6633 if (test_mode == PCRE8_MODE)
6639 fprintf(outfile, "** Character \\x{%x} is greater than 0x7fffffff "
6640 "and so cannot be converted to UTF-8\n", c);
6643 q8 += ord2utf8(c, q8);
6649 fprintf(outfile, "** Character \\x{%x} is greater than 255 "
6650 "and UTF-8 mode is not enabled.\n", c);
6651 fprintf(outfile, "** Truncation will probably give the wrong "
6658 #ifdef SUPPORT_PCRE2_16
6659 if (test_mode == PCRE16_MODE)
6665 fprintf(outfile, "** Failed: character \\x{%x} is greater than "
6666 "0x10ffff and so cannot be converted to UTF-16\n", c);
6669 else if (c >= 0x10000u)
6672 *q16++ = 0xD800 | (c >> 10);
6673 *q16++ = 0xDC00 | (c & 0x3ff);
6682 fprintf(outfile, "** Character \\x{%x} is greater than 0xffff "
6683 "and UTF-16 mode is not enabled.\n", c);
6684 fprintf(outfile, "** Truncation will probably give the wrong "
6692 #ifdef SUPPORT_PCRE2_32
6693 if (test_mode == PCRE32_MODE)
6702 len = CASTVAR(uint8_t *, q) - dbuffer; /* Length in bytes */
6703 ulen = len/code_unit_size; /* Length in code units */
6704 arg_ulen = ulen; /* Value to use in match arg */
6706 /* If the string was terminated by \= we must now interpret modifiers. */
6708 if (p[-1] != 0 && !decode_modifiers(p, CTX_DAT, NULL, &dat_datctl))
6711 /* Check for mutually exclusive modifiers. At present, these are all in the
6712 first control word. */
6714 for (k = 0; k < sizeof(exclusive_dat_controls)/sizeof(uint32_t); k++)
6716 c = dat_datctl.control & exclusive_dat_controls[k];
6717 if (c != 0 && c != (c & (~c+1)))
6719 show_controls(c, 0, "** Not allowed together:");
6720 fprintf(outfile, "\n");
6725 if (pat_patctl.replacement[0] != 0 &&
6726 (dat_datctl.control & CTL_NULLCONTEXT) != 0)
6728 fprintf(outfile, "** Replacement text is not supported with null_context.\n");
6732 /* We now have the subject in dbuffer, with len containing the byte length, and
6733 ulen containing the code unit length, with a copy in arg_ulen for use in match
6734 function arguments (this gets changed to PCRE2_ZERO_TERMINATED when the
6735 zero_terminate modifier is present).
6737 Move the data to the end of the buffer so that a read over the end can be
6738 caught by valgrind or other means. If we have explicit valgrind support, mark
6739 the unused start of the buffer unaddressable. If we are using the POSIX
6740 interface, or testing zero-termination, we must include the terminating zero in
6743 c = code_unit_size * (((pat_patctl.control & CTL_POSIX) +
6744 (dat_datctl.control & CTL_ZERO_TERMINATE) != 0)? 1:0);
6745 pp = memmove(dbuffer + dbuffer_size - len - c, dbuffer, len + c);
6746 #ifdef SUPPORT_VALGRIND
6747 VALGRIND_MAKE_MEM_NOACCESS(dbuffer, dbuffer_size - (len + c));
6750 /* Now pp points to the subject string. POSIX matching is only possible in
6751 8-bit mode, and it does not support timing or other fancy features. Some were
6752 checked at compile time, but we need to check the match-time settings here. */
6754 #ifdef SUPPORT_PCRE2_8
6755 if ((pat_patctl.control & CTL_POSIX) != 0)
6759 regmatch_t *pmatch = NULL;
6760 const char *msg = "** Ignored with POSIX interface:";
6762 if (dat_datctl.cerror[0] != CFORE_UNSET || dat_datctl.cerror[1] != CFORE_UNSET)
6763 prmsg(&msg, "callout_error");
6764 if (dat_datctl.cfail[0] != CFORE_UNSET || dat_datctl.cfail[1] != CFORE_UNSET)
6765 prmsg(&msg, "callout_fail");
6766 if (dat_datctl.copy_numbers[0] >= 0 || dat_datctl.copy_names[0] != 0)
6767 prmsg(&msg, "copy");
6768 if (dat_datctl.get_numbers[0] >= 0 || dat_datctl.get_names[0] != 0)
6770 if (dat_datctl.jitstack != 0) prmsg(&msg, "jitstack");
6771 if (dat_datctl.offset != 0) prmsg(&msg, "offset");
6773 if ((dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS) != 0)
6775 fprintf(outfile, "%s", msg);
6776 show_match_options(dat_datctl.options & ~POSIX_SUPPORTED_MATCH_OPTIONS);
6779 if ((dat_datctl.control & ~POSIX_SUPPORTED_MATCH_CONTROLS) != 0 ||
6780 (dat_datctl.control2 & ~POSIX_SUPPORTED_MATCH_CONTROLS2) != 0)
6782 show_controls(dat_datctl.control & ~POSIX_SUPPORTED_MATCH_CONTROLS,
6783 dat_datctl.control2 & ~POSIX_SUPPORTED_MATCH_CONTROLS2, msg);
6787 if (msg[0] == 0) fprintf(outfile, "\n");
6789 if (dat_datctl.oveccount > 0)
6791 pmatch = (regmatch_t *)malloc(sizeof(regmatch_t) * dat_datctl.oveccount);
6794 fprintf(outfile, "** Failed to get memory for recording matching "
6795 "information (size set = %du)\n", dat_datctl.oveccount);
6800 if (dat_datctl.startend[0] != CFORE_UNSET)
6802 pmatch[0].rm_so = dat_datctl.startend[0];
6803 pmatch[0].rm_eo = (dat_datctl.startend[1] != 0)?
6804 dat_datctl.startend[1] : len;
6805 eflags |= REG_STARTEND;
6808 if ((dat_datctl.options & PCRE2_NOTBOL) != 0) eflags |= REG_NOTBOL;
6809 if ((dat_datctl.options & PCRE2_NOTEOL) != 0) eflags |= REG_NOTEOL;
6810 if ((dat_datctl.options & PCRE2_NOTEMPTY) != 0) eflags |= REG_NOTEMPTY;
6812 rc = regexec(&preg, (const char *)pp, dat_datctl.oveccount, pmatch, eflags);
6815 (void)regerror(rc, &preg, (char *)pbuffer8, pbuffer8_size);
6816 fprintf(outfile, "No match: POSIX code %d: %s\n", rc, pbuffer8);
6818 else if ((pat_patctl.control & CTL_POSIX_NOSUB) != 0)
6819 fprintf(outfile, "Matched with REG_NOSUB\n");
6820 else if (dat_datctl.oveccount == 0)
6821 fprintf(outfile, "Matched without capture\n");
6825 size_t last_printed = (size_t)dat_datctl.oveccount;
6826 for (i = 0; i < (size_t)dat_datctl.oveccount; i++)
6828 if (pmatch[i].rm_so >= 0)
6830 PCRE2_SIZE start = pmatch[i].rm_so;
6831 PCRE2_SIZE end = pmatch[i].rm_eo;
6832 for (j = last_printed + 1; j < i; j++)
6833 fprintf(outfile, "%2d: <unset>\n", (int)j);
6837 start = pmatch[i].rm_eo;
6838 end = pmatch[i].rm_so;
6839 fprintf(outfile, "Start of matched string is beyond its end - "
6840 "displaying from end to start.\n");
6842 fprintf(outfile, "%2d: ", (int)i);
6843 PCHARSV(pp, start, end - start, utf, outfile);
6844 fprintf(outfile, "\n");
6846 if ((i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0) ||
6847 (dat_datctl.control & CTL_ALLAFTERTEXT) != 0)
6849 fprintf(outfile, "%2d+ ", (int)i);
6850 /* Note: don't use the start/end variables here because we want to
6851 show the text from what is reported as the end. */
6852 PCHARSV(pp, pmatch[i].rm_eo, len - pmatch[i].rm_eo, utf, outfile);
6853 fprintf(outfile, "\n"); }
6860 #endif /* SUPPORT_PCRE2_8 */
6862 /* Handle matching via the native interface. Check for consistency of
6865 if (dat_datctl.startend[0] != CFORE_UNSET)
6866 fprintf(outfile, "** \\=posix_startend ignored for non-POSIX matching\n");
6868 /* ALLUSEDTEXT is not supported with JIT, but JIT is not used with DFA
6869 matching, even if the JIT compiler was used. */
6871 if ((dat_datctl.control & (CTL_ALLUSEDTEXT|CTL_DFA)) == CTL_ALLUSEDTEXT &&
6872 FLD(compiled_code, executable_jit) != NULL)
6874 fprintf(outfile, "** Showing all consulted text is not supported by JIT: ignored\n");
6875 dat_datctl.control &= ~CTL_ALLUSEDTEXT;
6878 /* Handle passing the subject as zero-terminated. */
6880 if ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0)
6881 arg_ulen = PCRE2_ZERO_TERMINATED;
6883 /* The nullcontext modifier is used to test calling pcre2_[jit_]match() with a
6886 use_dat_context = ((dat_datctl.control & CTL_NULLCONTEXT) != 0)?
6887 NULL : PTR(dat_context);
6889 /* Enable display of malloc/free if wanted. We can do this only if either the
6890 pattern or the subject is processed with a context. */
6892 show_memory = (dat_datctl.control & CTL_MEMORY) != 0;
6895 (pat_patctl.control & dat_datctl.control & CTL_NULLCONTEXT) != 0)
6896 fprintf(outfile, "** \\=memory requires either a pattern or a subject "
6897 "context: ignored\n");
6899 /* Create and assign a JIT stack if requested. */
6901 if (dat_datctl.jitstack != 0)
6903 if (dat_datctl.jitstack != jit_stack_size)
6905 PCRE2_JIT_STACK_FREE(jit_stack);
6906 PCRE2_JIT_STACK_CREATE(jit_stack, 1, dat_datctl.jitstack * 1024, NULL);
6907 jit_stack_size = dat_datctl.jitstack;
6909 PCRE2_JIT_STACK_ASSIGN(dat_context, jit_callback, jit_stack);
6914 else if (jit_stack != NULL)
6916 PCRE2_JIT_STACK_ASSIGN(dat_context, NULL, NULL);
6917 PCRE2_JIT_STACK_FREE(jit_stack);
6922 /* When no JIT stack is assigned, we must ensure that there is a JIT callback
6923 if we want to verify that JIT was actually used. */
6925 if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_stack == NULL)
6927 PCRE2_JIT_STACK_ASSIGN(dat_context, jit_callback, NULL);
6930 /* Adjust match_data according to size of offsets required. A size of zero
6931 causes a new match data block to be obtained that exactly fits the pattern. */
6933 if (dat_datctl.oveccount == 0)
6935 PCRE2_MATCH_DATA_FREE(match_data);
6936 PCRE2_MATCH_DATA_CREATE_FROM_PATTERN(match_data, compiled_code, NULL);
6937 PCRE2_GET_OVECTOR_COUNT(max_oveccount, match_data);
6939 else if (dat_datctl.oveccount <= max_oveccount)
6941 SETFLD(match_data, oveccount, dat_datctl.oveccount);
6945 max_oveccount = dat_datctl.oveccount;
6946 PCRE2_MATCH_DATA_FREE(match_data);
6947 PCRE2_MATCH_DATA_CREATE(match_data, max_oveccount, NULL);
6950 if (CASTVAR(void *, match_data) == NULL)
6952 fprintf(outfile, "** Failed to get memory for recording matching "
6953 "information (size requested: %d)\n", dat_datctl.oveccount);
6958 /* Replacement processing is ignored for DFA matching. */
6960 if (dat_datctl.replacement[0] != 0 && (dat_datctl.control & CTL_DFA) != 0)
6962 fprintf(outfile, "** Ignored for DFA matching: replace\n");
6963 dat_datctl.replacement[0] = 0;
6966 /* If a replacement string is provided, call pcre2_substitute() instead of one
6967 of the matching functions. First we have to convert the replacement string to
6968 the appropriate width. */
6970 if (dat_datctl.replacement[0] != 0)
6974 uint8_t rbuffer[REPLACE_BUFFSIZE];
6975 uint8_t nbuffer[REPLACE_BUFFSIZE];
6977 PCRE2_SIZE rlen, nsize, erroroffset;
6978 BOOL badutf = FALSE;
6980 #ifdef SUPPORT_PCRE2_8
6983 #ifdef SUPPORT_PCRE2_16
6984 uint16_t *r16 = NULL;
6986 #ifdef SUPPORT_PCRE2_32
6987 uint32_t *r32 = NULL;
6991 fprintf(outfile, "** Timing is not supported with replace: ignored\n");
6993 if ((dat_datctl.control & CTL_ALTGLOBAL) != 0)
6994 fprintf(outfile, "** Altglobal is not supported with replace: ignored\n");
6996 xoptions = (((dat_datctl.control & CTL_GLOBAL) == 0)? 0 :
6997 PCRE2_SUBSTITUTE_GLOBAL) |
6998 (((dat_datctl.control2 & CTL2_SUBSTITUTE_EXTENDED) == 0)? 0 :
6999 PCRE2_SUBSTITUTE_EXTENDED) |
7000 (((dat_datctl.control2 & CTL2_SUBSTITUTE_OVERFLOW_LENGTH) == 0)? 0 :
7001 PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) |
7002 (((dat_datctl.control2 & CTL2_SUBSTITUTE_UNKNOWN_UNSET) == 0)? 0 :
7003 PCRE2_SUBSTITUTE_UNKNOWN_UNSET) |
7004 (((dat_datctl.control2 & CTL2_SUBSTITUTE_UNSET_EMPTY) == 0)? 0 :
7005 PCRE2_SUBSTITUTE_UNSET_EMPTY);
7007 SETCASTPTR(r, rbuffer); /* Sets r8, r16, or r32, as appropriate. */
7008 pr = dat_datctl.replacement;
7010 /* If the replacement starts with '[<number>]' we interpret that as length
7011 value for the replacement buffer. */
7013 nsize = REPLACE_BUFFSIZE/code_unit_size;
7017 while ((c = *(++pr)) >= CHAR_0 && c <= CHAR_9) n = n * 10 + c - CHAR_0;
7020 fprintf(outfile, "Bad buffer size in replacement string\n");
7025 fprintf(outfile, "Replacement buffer setting (%" SIZ_FORM ") is too "
7026 "large (max %" SIZ_FORM ")\n", SIZ_CAST n, SIZ_CAST nsize);
7032 /* Now copy the replacement string to a buffer of the appropriate width. No
7033 escape processing is done for replacements. In UTF mode, check for an invalid
7034 UTF-8 input string, and if it is invalid, just copy its code units without
7035 UTF interpretation. This provides a means of checking that an invalid string
7036 is detected. Otherwise, UTF-8 can be used to include wide characters in a
7039 if (utf) badutf = valid_utf(pr, strlen((const char *)pr), &erroroffset);
7041 /* Not UTF or invalid UTF-8: just copy the code units. */
7045 while ((c = *pr++) != 0)
7047 #ifdef SUPPORT_PCRE2_8
7048 if (test_mode == PCRE8_MODE) *r8++ = c;
7050 #ifdef SUPPORT_PCRE2_16
7051 if (test_mode == PCRE16_MODE) *r16++ = c;
7053 #ifdef SUPPORT_PCRE2_32
7054 if (test_mode == PCRE32_MODE) *r32++ = c;
7059 /* Valid UTF-8 replacement string */
7061 else while ((c = *pr++) != 0)
7063 if (HASUTF8EXTRALEN(c)) { GETUTF8INC(c, pr); }
7065 #ifdef SUPPORT_PCRE2_8
7066 if (test_mode == PCRE8_MODE) r8 += ord2utf8(c, r8);
7069 #ifdef SUPPORT_PCRE2_16
7070 if (test_mode == PCRE16_MODE)
7075 *r16++ = 0xD800 | (c >> 10);
7076 *r16++ = 0xDC00 | (c & 0x3ff);
7082 #ifdef SUPPORT_PCRE2_32
7083 if (test_mode == PCRE32_MODE) *r32++ = c;
7088 if ((dat_datctl.control & CTL_ZERO_TERMINATE) != 0)
7089 rlen = PCRE2_ZERO_TERMINATED;
7091 rlen = (CASTVAR(uint8_t *, r) - rbuffer)/code_unit_size;
7092 PCRE2_SUBSTITUTE(rc, compiled_code, pp, arg_ulen, dat_datctl.offset,
7093 dat_datctl.options|xoptions, match_data, dat_context,
7094 rbuffer, rlen, nbuffer, &nsize);
7098 fprintf(outfile, "Failed: error %d", rc);
7099 if (rc != PCRE2_ERROR_NOMEMORY && nsize != PCRE2_UNSET)
7100 fprintf(outfile, " at offset %ld in replacement", (long int)nsize);
7101 fprintf(outfile, ": ");
7102 if (!print_error_message(rc, "", "")) return PR_ABEND;
7103 if (rc == PCRE2_ERROR_NOMEMORY &&
7104 (xoptions & PCRE2_SUBSTITUTE_OVERFLOW_LENGTH) != 0)
7105 fprintf(outfile, ": %ld code units are needed", (long int)nsize);
7109 fprintf(outfile, "%2d: ", rc);
7110 PCHARSV(nbuffer, 0, nsize, utf, outfile);
7113 fprintf(outfile, "\n");
7114 show_memory = FALSE;
7116 } /* End of substitution handling */
7118 /* When a replacement string is not provided, run a loop for global matching
7119 with one of the basic matching functions. For altglobal (or first time round
7120 the loop), set an "unset" value for the previous match info. */
7122 ovecsave[0] = ovecsave[1] = ovecsave[2] = PCRE2_UNSET;
7124 for (gmatched = 0;; gmatched++)
7128 PCRE2_SIZE *ovector;
7130 ovector = FLD(match_data, ovector);
7132 /* Fill the ovector with junk to detect elements that do not get set
7133 when they should be. */
7135 for (j = 0; j < 2*dat_datctl.oveccount; j++) ovector[j] = JUNK_OFFSET;
7137 /* When matching is via pcre2_match(), we will detect the use of JIT via the
7138 stack callback function. */
7140 jit_was_used = (pat_patctl.control & CTL_JITFAST) != 0;
7142 /* Do timing if required. */
7147 clock_t start_time, time_taken;
7149 if ((dat_datctl.control & CTL_DFA) != 0)
7151 if ((dat_datctl.options & PCRE2_DFA_RESTART) != 0)
7153 fprintf(outfile, "Timing DFA restarts is not supported\n");
7156 if (dfa_workspace == NULL)
7157 dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
7158 start_time = clock();
7159 for (i = 0; i < timeitm; i++)
7161 PCRE2_DFA_MATCH(capcount, compiled_code, pp, arg_ulen,
7162 dat_datctl.offset, dat_datctl.options | g_notempty, match_data,
7163 use_dat_context, dfa_workspace, DFA_WS_DIMENSION);
7167 else if ((pat_patctl.control & CTL_JITFAST) != 0)
7169 start_time = clock();
7170 for (i = 0; i < timeitm; i++)
7172 PCRE2_JIT_MATCH(capcount, compiled_code, pp, arg_ulen,
7173 dat_datctl.offset, dat_datctl.options | g_notempty, match_data,
7180 start_time = clock();
7181 for (i = 0; i < timeitm; i++)
7183 PCRE2_MATCH(capcount, compiled_code, pp, arg_ulen,
7184 dat_datctl.offset, dat_datctl.options | g_notempty, match_data,
7188 total_match_time += (time_taken = clock() - start_time);
7189 fprintf(outfile, "Match time %.4f milliseconds\n",
7190 (((double)time_taken * 1000.0) / (double)timeitm) /
7191 (double)CLOCKS_PER_SEC);
7194 /* Find the heap, match and depth limits if requested. The depth and heap
7195 limits are not relevant for JIT. The return from check_match_limit() is the
7196 return from the final call to pcre2_match() or pcre2_dfa_match(). */
7198 if ((dat_datctl.control & CTL_FINDLIMITS) != 0)
7200 capcount = 0; /* This stops compiler warnings */
7202 if (FLD(compiled_code, executable_jit) == NULL ||
7203 (dat_datctl.options & PCRE2_NO_JIT) != 0)
7205 (void)check_match_limit(pp, arg_ulen, PCRE2_ERROR_HEAPLIMIT, "heap");
7208 capcount = check_match_limit(pp, arg_ulen, PCRE2_ERROR_MATCHLIMIT,
7211 if (FLD(compiled_code, executable_jit) == NULL ||
7212 (dat_datctl.options & PCRE2_NO_JIT) != 0 ||
7213 (dat_datctl.control & CTL_DFA) != 0)
7215 capcount = check_match_limit(pp, arg_ulen, PCRE2_ERROR_DEPTHLIMIT,
7221 fprintf(outfile, "Matched, but offsets vector is too small to show all matches\n");
7222 capcount = dat_datctl.oveccount;
7226 /* Otherwise just run a single match, setting up a callout if required (the
7227 default). There is a copy of the pattern in pbuffer8 for use by callouts. */
7231 if ((dat_datctl.control & CTL_CALLOUT_NONE) == 0)
7233 PCRE2_SET_CALLOUT(dat_context, callout_function,
7234 (void *)(&dat_datctl.callout_data));
7235 first_callout = TRUE;
7236 last_callout_mark = NULL;
7241 PCRE2_SET_CALLOUT(dat_context, NULL, NULL); /* No callout */
7244 /* Run a single DFA or NFA match. */
7246 if ((dat_datctl.control & CTL_DFA) != 0)
7248 if (dfa_workspace == NULL)
7249 dfa_workspace = (int *)malloc(DFA_WS_DIMENSION*sizeof(int));
7250 if (dfa_matched++ == 0)
7251 dfa_workspace[0] = -1; /* To catch bad restart */
7252 PCRE2_DFA_MATCH(capcount, compiled_code, pp, arg_ulen,
7253 dat_datctl.offset, dat_datctl.options | g_notempty, match_data,
7254 use_dat_context, dfa_workspace, DFA_WS_DIMENSION);
7257 fprintf(outfile, "Matched, but offsets vector is too small to show all matches\n");
7258 capcount = dat_datctl.oveccount;
7263 if ((pat_patctl.control & CTL_JITFAST) != 0)
7264 PCRE2_JIT_MATCH(capcount, compiled_code, pp, arg_ulen, dat_datctl.offset,
7265 dat_datctl.options | g_notempty, match_data, use_dat_context);
7267 PCRE2_MATCH(capcount, compiled_code, pp, arg_ulen, dat_datctl.offset,
7268 dat_datctl.options | g_notempty, match_data, use_dat_context);
7271 fprintf(outfile, "Matched, but too many substrings\n");
7272 capcount = dat_datctl.oveccount;
7277 /* The result of the match is now in capcount. First handle a successful
7285 /* This is a check against a lunatic return value. */
7287 PCRE2_GET_OVECTOR_COUNT(oveccount, match_data);
7288 if (capcount > (int)oveccount)
7291 "** PCRE2 error: returned count %d is too big for ovector count %d\n",
7292 capcount, oveccount);
7293 capcount = oveccount;
7294 if ((dat_datctl.control & CTL_ANYGLOB) != 0)
7296 fprintf(outfile, "** Global loop abandoned\n");
7297 dat_datctl.control &= ~CTL_ANYGLOB; /* Break g/G loop */
7301 /* If this is not the first time round a global loop, check that the
7302 returned string has changed. If it has not, check for an empty string match
7303 at different starting offset from the previous match. This is a failed test
7304 retry for null-matching patterns that don't match at their starting offset,
7305 for example /(?<=\G.)/. A repeated match at the same point is not such a
7306 pattern, and must be discarded, and we then proceed to seek a non-null
7307 match at the current point. For any other repeated match, there is a bug
7308 somewhere and we must break the loop because it will go on for ever. We
7309 know that there are always at least two elements in the ovector. */
7311 if (gmatched > 0 && ovecsave[0] == ovector[0] && ovecsave[1] == ovector[1])
7313 if (ovector[0] == ovector[1] && ovecsave[2] != dat_datctl.offset)
7315 g_notempty = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED;
7316 ovecsave[2] = dat_datctl.offset;
7317 continue; /* Back to the top of the loop */
7320 "** PCRE2 error: global repeat returned the same string as previous\n");
7321 fprintf(outfile, "** Global loop abandoned\n");
7322 dat_datctl.control &= ~CTL_ANYGLOB; /* Break g/G loop */
7325 /* "allcaptures" requests showing of all captures in the pattern, to check
7326 unset ones at the end. It may be set on the pattern or the data. Implement
7327 by setting capcount to the maximum. This is not relevant for DFA matching,
7330 if ((dat_datctl.control & CTL_ALLCAPTURES) != 0)
7332 uint32_t maxcapcount;
7333 if ((dat_datctl.control & CTL_DFA) != 0)
7335 fprintf(outfile, "** Ignored after DFA matching: allcaptures\n");
7339 if (pattern_info(PCRE2_INFO_CAPTURECOUNT, &maxcapcount, FALSE) < 0)
7341 capcount = maxcapcount + 1; /* Allow for full match */
7342 if (capcount > (int)oveccount) capcount = oveccount;
7346 /* Output the captured substrings. Note that, for the matched string,
7347 the use of \K in an assertion can make the start later than the end. */
7349 for (i = 0; i < 2*capcount; i += 2)
7351 PCRE2_SIZE lleft, lmiddle, lright;
7352 PCRE2_SIZE start = ovector[i];
7353 PCRE2_SIZE end = ovector[i+1];
7357 start = ovector[i+1];
7359 fprintf(outfile, "Start of matched string is beyond its end - "
7360 "displaying from end to start.\n");
7363 fprintf(outfile, "%2d: ", i/2);
7365 /* Check for an unset group */
7367 if (start == PCRE2_UNSET)
7369 fprintf(outfile, "<unset>\n");
7373 /* Check for silly offsets, in particular, values that have not been
7374 set when they should have been. */
7376 if (start > ulen || end > ulen)
7378 fprintf(outfile, "ERROR: bad value(s) for offset(s): 0x%lx 0x%lx\n",
7379 (unsigned long int)start, (unsigned long int)end);
7383 /* When JIT is not being used, ALLUSEDTEXT may be set. (It if is set with
7384 JIT, it is disabled above, with a comment.) When the match is done by the
7385 interpreter, leftchar and rightchar are available, and if ALLUSEDTEXT is
7386 set, and if the leftmost consulted character is before the start of the
7387 match or the rightmost consulted character is past the end of the match,
7388 we want to show all consulted characters for the main matched string, and
7389 indicate which were lookarounds. */
7394 PCRE2_SIZE leftchar, rightchar;
7396 if ((dat_datctl.control & CTL_ALLUSEDTEXT) != 0)
7398 leftchar = FLD(match_data, leftchar);
7399 rightchar = FLD(match_data, rightchar);
7400 showallused = i == 0 && (leftchar < start || rightchar > end);
7402 else showallused = FALSE;
7406 PCHARS(lleft, pp, leftchar, start - leftchar, utf, outfile);
7407 PCHARS(lmiddle, pp, start, end - start, utf, outfile);
7408 PCHARS(lright, pp, end, rightchar - end, utf, outfile);
7409 if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
7410 fprintf(outfile, " (JIT)");
7411 fprintf(outfile, "\n ");
7412 for (j = 0; j < lleft; j++) fprintf(outfile, "<");
7413 for (j = 0; j < lmiddle; j++) fprintf(outfile, " ");
7414 for (j = 0; j < lright; j++) fprintf(outfile, ">");
7417 /* When a pattern contains \K, the start of match position may be
7418 different to the start of the matched string. When this is the case,
7419 show it when requested. */
7421 else if ((dat_datctl.control & CTL_STARTCHAR) != 0)
7423 PCRE2_SIZE startchar;
7424 PCRE2_GET_STARTCHAR(startchar, match_data);
7425 PCHARS(lleft, pp, startchar, start - startchar, utf, outfile);
7426 PCHARSV(pp, start, end - start, utf, outfile);
7427 if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
7428 fprintf(outfile, " (JIT)");
7429 if (startchar != start)
7431 fprintf(outfile, "\n ");
7432 for (j = 0; j < lleft; j++) fprintf(outfile, "^");
7436 /* Otherwise, just show the matched string. */
7440 PCHARSV(pp, start, end - start, utf, outfile);
7441 if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
7442 fprintf(outfile, " (JIT)");
7446 /* Not the main matched string. Just show it unadorned. */
7450 PCHARSV(pp, start, end - start, utf, outfile);
7453 fprintf(outfile, "\n");
7455 /* Note: don't use the start/end variables here because we want to
7456 show the text from what is reported as the end. */
7458 if ((dat_datctl.control & CTL_ALLAFTERTEXT) != 0 ||
7459 (i == 0 && (dat_datctl.control & CTL_AFTERTEXT) != 0))
7461 fprintf(outfile, "%2d+ ", i/2);
7462 PCHARSV(pp, ovector[i+1], ulen - ovector[i+1], utf, outfile);
7463 fprintf(outfile, "\n");
7467 /* Output (*MARK) data if requested */
7469 if ((dat_datctl.control & CTL_MARK) != 0 &&
7470 TESTFLD(match_data, mark, !=, NULL))
7472 fprintf(outfile, "MK: ");
7473 PCHARSV(CASTFLD(void *, match_data, mark), 0, -1, utf, outfile);
7474 fprintf(outfile, "\n");
7477 /* Process copy/get strings */
7479 if (!copy_and_get(utf, capcount)) return PR_ABEND;
7481 } /* End of handling a successful match */
7483 /* There was a partial match. The value of ovector[0] is the bumpalong point,
7484 that is, startchar, not any \K point that might have been passed. */
7486 else if (capcount == PCRE2_ERROR_PARTIAL)
7490 int rubriclength = 0;
7492 fprintf(outfile, "Partial match");
7493 if ((dat_datctl.control & CTL_MARK) != 0 &&
7494 TESTFLD(match_data, mark, !=, NULL))
7496 fprintf(outfile, ", mark=");
7497 PCHARS(rubriclength, CASTFLD(void *, match_data, mark), 0, -1, utf,
7501 fprintf(outfile, ": ");
7504 poffset = backchars(pp, ovector[0], maxlookbehind, utf);
7505 PCHARS(backlength, pp, poffset, ovector[0] - poffset, utf, outfile);
7506 PCHARSV(pp, ovector[0], ulen - ovector[0], utf, outfile);
7508 if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
7509 fprintf(outfile, " (JIT)");
7510 fprintf(outfile, "\n");
7512 if (backlength != 0)
7515 for (i = 0; i < rubriclength; i++) fprintf(outfile, " ");
7516 for (i = 0; i < backlength; i++) fprintf(outfile, "<");
7517 fprintf(outfile, "\n");
7520 /* Process copy/get strings */
7522 if (!copy_and_get(utf, 1)) return PR_ABEND;
7524 break; /* Out of the /g loop */
7525 } /* End of handling partial match */
7527 /* Failed to match. If this is a /g or /G loop, we might previously have
7528 set g_notempty (to PCRE2_NOTEMPTY_ATSTART|PCRE2_ANCHORED) after a null match.
7529 If that is the case, this is not necessarily the end. We want to advance the
7530 start offset, and continue. We won't be at the end of the string - that was
7531 checked before setting g_notempty. We achieve the effect by pretending that a
7532 single character was matched.
7534 Complication arises in the case when the newline convention is "any", "crlf",
7535 or "anycrlf". If the previous match was at the end of a line terminated by
7536 CRLF, an advance of one character just passes the CR, whereas we should
7537 prefer the longer newline sequence, as does the code in pcre2_match().
7539 Otherwise, in the case of UTF-8 or UTF-16 matching, the advance must be one
7540 character, not one byte. */
7542 else if (g_notempty != 0) /* There was a previous null match */
7544 uint16_t nl = FLD(compiled_code, newline_convention);
7545 PCRE2_SIZE start_offset = dat_datctl.offset; /* Where the match was */
7546 PCRE2_SIZE end_offset = start_offset + 1;
7548 if ((nl == PCRE2_NEWLINE_CRLF || nl == PCRE2_NEWLINE_ANY ||
7549 nl == PCRE2_NEWLINE_ANYCRLF) &&
7550 start_offset < ulen - 1 &&
7551 CODE_UNIT(pp, start_offset) == '\r' &&
7552 CODE_UNIT(pp, end_offset) == '\n')
7555 else if (utf && test_mode != PCRE32_MODE)
7557 if (test_mode == PCRE8_MODE)
7559 for (; end_offset < ulen; end_offset++)
7560 if ((((PCRE2_SPTR8)pp)[end_offset] & 0xc0) != 0x80) break;
7562 else /* 16-bit mode */
7564 for (; end_offset < ulen; end_offset++)
7565 if ((((PCRE2_SPTR16)pp)[end_offset] & 0xfc00) != 0xdc00) break;
7569 SETFLDVEC(match_data, ovector, 0, start_offset);
7570 SETFLDVEC(match_data, ovector, 1, end_offset);
7571 } /* End of handling null match in a global loop */
7573 /* A "normal" match failure. There will be a negative error number in
7580 case PCRE2_ERROR_NOMATCH:
7583 fprintf(outfile, "No match");
7584 if ((dat_datctl.control & CTL_MARK) != 0 &&
7585 TESTFLD(match_data, mark, !=, NULL))
7587 fprintf(outfile, ", mark = ");
7588 PCHARSV(CASTFLD(void *, match_data, mark), 0, -1, utf, outfile);
7590 if ((pat_patctl.control & CTL_JITVERIFY) != 0 && jit_was_used)
7591 fprintf(outfile, " (JIT)");
7592 fprintf(outfile, "\n");
7596 case PCRE2_ERROR_BADUTFOFFSET:
7597 fprintf(outfile, "Error %d (bad UTF-%d offset)\n", capcount, test_mode);
7601 fprintf(outfile, "Failed: error %d: ", capcount);
7602 if (!print_error_message(capcount, "", "")) return PR_ABEND;
7603 if (capcount <= PCRE2_ERROR_UTF8_ERR1 &&
7604 capcount >= PCRE2_ERROR_UTF32_ERR2)
7606 PCRE2_SIZE startchar;
7607 PCRE2_GET_STARTCHAR(startchar, match_data);
7608 fprintf(outfile, " at offset %" SIZ_FORM, SIZ_CAST startchar);
7610 fprintf(outfile, "\n");
7614 break; /* Out of the /g loop */
7615 } /* End of failed match handling */
7617 /* Control reaches here in two circumstances: (a) after a match, and (b)
7618 after a non-match that immediately followed a match on an empty string when
7619 doing a global search. Such a match is done with PCRE2_NOTEMPTY_ATSTART and
7620 PCRE2_ANCHORED set in g_notempty. The code above turns it into a fake match
7621 of one character. So effectively we get here only after a match. If we
7622 are not doing a global search, we are done. */
7624 if ((dat_datctl.control & CTL_ANYGLOB) == 0) break; else
7626 PCRE2_SIZE match_offset = FLD(match_data, ovector)[0];
7627 PCRE2_SIZE end_offset = FLD(match_data, ovector)[1];
7629 /* We must now set up for the next iteration of a global search. If we have
7630 matched an empty string, first check to see if we are at the end of the
7631 subject. If so, the loop is over. Otherwise, mimic what Perl's /g option
7632 does. Set PCRE2_NOTEMPTY_ATSTART and PCRE2_ANCHORED and try the match again
7633 at the same point. If this fails it will be picked up above, where a fake
7634 match is set up so that at this point we advance to the next character.
7636 However, in order to cope with patterns that never match at their starting
7637 offset (e.g. /(?<=\G.)/) we don't do this when the match offset is greater
7638 than the starting offset. This means there will be a retry with the
7639 starting offset at the match offset. If this returns the same match again,
7640 it is picked up above and ignored, and the special action is then taken. */
7642 if (match_offset == end_offset)
7644 if (end_offset == ulen) break; /* End of subject */
7645 if (match_offset <= dat_datctl.offset)
7646 g_notempty = PCRE2_NOTEMPTY_ATSTART | PCRE2_ANCHORED;
7649 /* However, even after matching a non-empty string, there is still one
7650 tricky case. If a pattern contains \K within a lookbehind assertion at the
7651 start, the end of the matched string can be at the offset where the match
7652 started. In the case of a normal /g iteration without special action, this
7653 leads to a loop that keeps on returning the same substring. The loop would
7654 be caught above, but we really want to move on to the next match. */
7658 g_notempty = 0; /* Set for a "normal" repeat */
7659 if ((dat_datctl.control & CTL_GLOBAL) != 0)
7661 PCRE2_SIZE startchar;
7662 PCRE2_GET_STARTCHAR(startchar, match_data);
7663 if (end_offset <= startchar)
7665 if (startchar >= ulen) break; /* End of subject */
7666 end_offset = startchar + 1;
7667 if (utf && test_mode != PCRE32_MODE)
7669 if (test_mode == PCRE8_MODE)
7671 for (; end_offset < ulen; end_offset++)
7672 if ((((PCRE2_SPTR8)pp)[end_offset] & 0xc0) != 0x80) break;
7674 else /* 16-bit mode */
7676 for (; end_offset < ulen; end_offset++)
7677 if ((((PCRE2_SPTR16)pp)[end_offset] & 0xfc00) != 0xdc00) break;
7684 /* For a normal global (/g) iteration, save the current ovector[0,1] and
7685 the starting offset so that we can check that they do change each time.
7686 Otherwise a matching bug that returns the same string causes an infinite
7687 loop. It has happened! Then update the start offset, leaving other
7688 parameters alone. */
7690 if ((dat_datctl.control & CTL_GLOBAL) != 0)
7692 ovecsave[0] = ovector[0];
7693 ovecsave[1] = ovector[1];
7694 ovecsave[2] = dat_datctl.offset;
7695 dat_datctl.offset = end_offset;
7698 /* For altglobal, just update the pointer and length. */
7702 pp += end_offset * code_unit_size;
7703 len -= end_offset * code_unit_size;
7705 if (arg_ulen != PCRE2_ZERO_TERMINATED) arg_ulen -= end_offset;
7708 } /* End of global loop */
7710 show_memory = FALSE;
7717 /*************************************************
7718 * Print PCRE2 version *
7719 *************************************************/
7722 print_version(FILE *f)
7725 fprintf(f, "PCRE2 version ");
7726 for (vp = version; *vp != 0; vp++) fprintf(f, "%c", *vp);
7732 /*************************************************
7733 * Print Unicode version *
7734 *************************************************/
7737 print_unicode_version(FILE *f)
7740 fprintf(f, "Unicode version ");
7741 for (vp = uversion; *vp != 0; vp++) fprintf(f, "%c", *vp);
7746 /*************************************************
7747 * Print JIT target *
7748 *************************************************/
7751 print_jit_target(FILE *f)
7754 for (vp = jittarget; *vp != 0; vp++) fprintf(f, "%c", *vp);
7759 /*************************************************
7760 * Print newline configuration *
7761 *************************************************/
7763 /* Output is always to stdout.
7766 rc the return code from PCRE2_CONFIG_NEWLINE
7767 isc TRUE if called from "-C newline"
7772 print_newline_config(uint32_t optval, BOOL isc)
7774 if (!isc) printf(" Newline sequence is ");
7775 if (optval < sizeof(newlines)/sizeof(char *))
7776 printf("%s\n", newlines[optval]);
7778 printf("a non-standard value: %d\n", optval);
7783 /*************************************************
7785 *************************************************/
7790 printf("Usage: pcre2test [options] [<input file> [<output file>]]\n\n");
7791 printf("Input and output default to stdin and stdout.\n");
7792 #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
7793 printf("If input is a terminal, readline() is used to read from it.\n");
7795 printf("This version of pcre2test is not linked with readline().\n");
7797 printf("\nOptions:\n");
7798 #ifdef SUPPORT_PCRE2_8
7799 printf(" -8 use the 8-bit library\n");
7801 #ifdef SUPPORT_PCRE2_16
7802 printf(" -16 use the 16-bit library\n");
7804 #ifdef SUPPORT_PCRE2_32
7805 printf(" -32 use the 32-bit library\n");
7807 printf(" -ac set default pattern modifier PCRE2_AUTO_CALLOUT\n");
7808 printf(" -AC as -ac, but also set subject 'callout_extra' modifier\n");
7809 printf(" -b set default pattern modifier 'fullbincode'\n");
7810 printf(" -C show PCRE2 compile-time options and exit\n");
7811 printf(" -C arg show a specific compile-time option and exit with its\n");
7812 printf(" value if numeric (else 0). The arg can be:\n");
7813 printf(" backslash-C use of \\C is enabled [0, 1]\n");
7814 printf(" bsr \\R type [ANYCRLF, ANY]\n");
7815 printf(" ebcdic compiled for EBCDIC character code [0,1]\n");
7816 printf(" ebcdic-nl NL code if compiled for EBCDIC\n");
7817 printf(" jit just-in-time compiler supported [0, 1]\n");
7818 printf(" linksize internal link size [2, 3, 4]\n");
7819 printf(" newline newline type [CR, LF, CRLF, ANYCRLF, ANY, NUL]\n");
7820 printf(" pcre2-8 8 bit library support enabled [0, 1]\n");
7821 printf(" pcre2-16 16 bit library support enabled [0, 1]\n");
7822 printf(" pcre2-32 32 bit library support enabled [0, 1]\n");
7823 printf(" unicode Unicode and UTF support enabled [0, 1]\n");
7824 printf(" -d set default pattern modifier 'debug'\n");
7825 printf(" -dfa set default subject modifier 'dfa'\n");
7826 printf(" -error <n,m,..> show messages for error numbers, then exit\n");
7827 printf(" -help show usage information\n");
7828 printf(" -i set default pattern modifier 'info'\n");
7829 printf(" -jit set default pattern modifier 'jit'\n");
7830 printf(" -jitverify set default pattern modifier 'jitverify'\n");
7831 printf(" -LM list pattern and subject modifiers, then exit\n");
7832 printf(" -q quiet: do not output PCRE2 version number at start\n");
7833 printf(" -pattern <s> set default pattern modifier fields\n");
7834 printf(" -subject <s> set default subject modifier fields\n");
7835 printf(" -S <n> set stack size to <n> mebibytes\n");
7836 printf(" -t [<n>] time compilation and execution, repeating <n> times\n");
7837 printf(" -tm [<n>] time execution (matching) only, repeating <n> times\n");
7838 printf(" -T same as -t, but show total times at the end\n");
7839 printf(" -TM same as -tm, but show total time at the end\n");
7840 printf(" -version show PCRE2 version and exit\n");
7845 /*************************************************
7846 * Handle -C option *
7847 *************************************************/
7849 /* This option outputs configuration options and sets an appropriate return
7850 code when asked for a single option. The code is abstracted into a separate
7851 function because of its size. Use whichever pcre2_config() function is
7854 Argument: an option name or NULL
7855 Returns: the return code
7859 c_option(const char *arg)
7862 unsigned int i = COPTLISTCOUNT;
7865 if (arg != NULL && arg[0] != CHAR_MINUS)
7867 for (i = 0; i < COPTLISTCOUNT; i++)
7868 if (strcmp(arg, coptlist[i].name) == 0) break;
7870 if (i >= COPTLISTCOUNT)
7872 fprintf(stderr, "** Unknown -C option '%s'\n", arg);
7876 switch (coptlist[i].type)
7879 (void)PCRE2_CONFIG(coptlist[i].value, &optval);
7880 printf("%s\n", (optval == PCRE2_BSR_ANYCRLF)? "ANYCRLF" : "ANY");
7884 yield = coptlist[i].value;
7885 printf("%d\n", yield);
7889 optval = coptlist[i].value;
7890 printf("%d\n", optval);
7894 (void)PCRE2_CONFIG(coptlist[i].value, &yield);
7895 printf("%d\n", yield);
7899 (void)PCRE2_CONFIG(coptlist[i].value, &optval);
7900 print_newline_config(optval, TRUE);
7904 /* For VMS, return the value by setting a symbol, for certain values only. */
7907 if (copytlist[i].type == CONF_FIX || coptlist[i].type == CONF_INT)
7910 strcpy(ucname, coptlist[i].name);
7911 for (i = 0; ucname[i] != 0; i++) ucname[i] = toupper[ucname[i]];
7912 vms_setsymbol(ucname, 0, optval);
7919 /* No argument for -C: output all configuration information. */
7921 print_version(stdout);
7922 printf("Compiled with\n");
7925 printf(" EBCDIC code support: LF is 0x%02x\n", CHAR_LF);
7926 #if defined NATIVE_ZOS
7927 printf(" EBCDIC code page %s or similar\n", pcrz_cpversion());
7931 (void)PCRE2_CONFIG(PCRE2_CONFIG_COMPILED_WIDTHS, &optval);
7932 if (optval & 1) printf(" 8-bit support\n");
7933 if (optval & 2) printf(" 16-bit support\n");
7934 if (optval & 4) printf(" 32-bit support\n");
7936 #ifdef SUPPORT_VALGRIND
7937 printf(" Valgrind support\n");
7940 (void)PCRE2_CONFIG(PCRE2_CONFIG_UNICODE, &optval);
7943 printf(" UTF and UCP support (");
7944 print_unicode_version(stdout);
7947 else printf(" No Unicode support\n");
7949 (void)PCRE2_CONFIG(PCRE2_CONFIG_JIT, &optval);
7952 printf(" Just-in-time compiler support: ");
7953 print_jit_target(stdout);
7958 printf(" No just-in-time compiler support\n");
7961 (void)PCRE2_CONFIG(PCRE2_CONFIG_NEWLINE, &optval);
7962 print_newline_config(optval, FALSE);
7963 (void)PCRE2_CONFIG(PCRE2_CONFIG_BSR, &optval);
7964 printf(" \\R matches %s\n",
7965 (optval == PCRE2_BSR_ANYCRLF)? "CR, LF, or CRLF only" :
7966 "all Unicode newlines");
7967 (void)PCRE2_CONFIG(PCRE2_CONFIG_NEVER_BACKSLASH_C, &optval);
7968 printf(" \\C is %ssupported\n", optval? "not ":"");
7969 (void)PCRE2_CONFIG(PCRE2_CONFIG_LINKSIZE, &optval);
7970 printf(" Internal link size = %d\n", optval);
7971 (void)PCRE2_CONFIG(PCRE2_CONFIG_PARENSLIMIT, &optval);
7972 printf(" Parentheses nest limit = %d\n", optval);
7973 (void)PCRE2_CONFIG(PCRE2_CONFIG_HEAPLIMIT, &optval);
7974 printf(" Default heap limit = %d\n", optval);
7975 (void)PCRE2_CONFIG(PCRE2_CONFIG_MATCHLIMIT, &optval);
7976 printf(" Default match limit = %d\n", optval);
7977 (void)PCRE2_CONFIG(PCRE2_CONFIG_DEPTHLIMIT, &optval);
7978 printf(" Default depth limit = %d\n", optval);
7984 /*************************************************
7985 * Display one modifier *
7986 *************************************************/
7989 display_one_modifier(modstruct *m, BOOL for_pattern)
7991 uint32_t c = (!for_pattern && (m->which == MOD_PND || m->which == MOD_PNDP))?
7993 printf("%c%s", c, m->name);
7998 /*************************************************
7999 * Display pattern or subject modifiers *
8000 *************************************************/
8002 /* In order to print in two columns, first scan without printing to get a list
8003 of the modifiers that are required.
8006 for_pattern TRUE for pattern modifiers, FALSE for subject modifiers
8007 title string to be used in title
8013 display_selected_modifiers(BOOL for_pattern, const char *title)
8017 uint32_t list[MODLISTCOUNT];
8019 for (i = 0; i < MODLISTCOUNT; i++)
8021 BOOL is_pattern = TRUE;
8022 modstruct *m = modlist + i;
8026 case MOD_CTC: /* Compile context */
8027 case MOD_PAT: /* Pattern */
8028 case MOD_PATP: /* Pattern, OK for Perl-compatible test */
8031 /* The MOD_PND and MOD_PNDP modifiers are precisely those that affect
8032 subjects, but can be given with a pattern. We list them as subject
8033 modifiers, but marked with an asterisk.*/
8035 case MOD_CTM: /* Match context */
8036 case MOD_DAT: /* Subject line */
8037 case MOD_PND: /* As PD, but not default pattern */
8038 case MOD_PNDP: /* As PND, OK for Perl-compatible test */
8042 default: printf("** Unknown type for modifier '%s'\n", m->name);
8044 case MOD_PD: /* Pattern or subject */
8045 case MOD_PDP: /* As PD, OK for Perl-compatible test */
8046 is_pattern = for_pattern;
8050 if (for_pattern == is_pattern) list[n++] = i;
8053 /* Now print from the list in two columns. */
8055 printf("-------------- %s MODIFIERS --------------\n", title);
8057 for (i = 0, j = (n+1)/2; i < (n+1)/2; i++, j++)
8059 modstruct *m = modlist + list[i];
8060 display_one_modifier(m, for_pattern);
8063 uint32_t k = 27 - strlen(m->name);
8064 while (k-- > 0) printf(" ");
8065 display_one_modifier(modlist + list[j], for_pattern);
8073 /*************************************************
8074 * Display the list of modifiers *
8075 *************************************************/
8078 display_modifiers(void)
8081 "An asterisk on a subject modifier means that it may be given on a pattern\n"
8082 "line, in order to apply to all subjects matched by that pattern. Modifiers\n"
8083 "that are listed for both patterns and subjects have different effects in\n"
8085 display_selected_modifiers(TRUE, "PATTERN");
8087 display_selected_modifiers(FALSE, "SUBJECT");
8092 /*************************************************
8094 *************************************************/
8097 main(int argc, char **argv)
8102 BOOL notdone = TRUE;
8104 BOOL showtotaltimes = FALSE;
8105 BOOL skipping = FALSE;
8106 char *arg_subject = NULL;
8107 char *arg_pattern = NULL;
8108 char *arg_error = NULL;
8110 /* The offsets to the options and control bits fields of the pattern and data
8111 control blocks must be the same so that common options and controls such as
8112 "anchored" or "memory" can work for either of them from a single table entry.
8113 We cannot test this till runtime because "offsetof" does not work in the
8116 if (PO(options) != DO(options) || PO(control) != DO(control) ||
8117 PO(control2) != DO(control2))
8119 fprintf(stderr, "** Coding error: "
8120 "options and control offsets for pattern and data must be the same.\n");
8124 /* Get the PCRE2 and Unicode version number and JIT target information, at the
8125 same time checking that a request for the length gives the same answer. Also
8126 check lengths for non-string items. */
8128 if (PCRE2_CONFIG(PCRE2_CONFIG_VERSION, NULL) !=
8129 PCRE2_CONFIG(PCRE2_CONFIG_VERSION, version) ||
8131 PCRE2_CONFIG(PCRE2_CONFIG_UNICODE_VERSION, NULL) !=
8132 PCRE2_CONFIG(PCRE2_CONFIG_UNICODE_VERSION, uversion) ||
8134 PCRE2_CONFIG(PCRE2_CONFIG_JITTARGET, NULL) !=
8135 PCRE2_CONFIG(PCRE2_CONFIG_JITTARGET, jittarget) ||
8137 PCRE2_CONFIG(PCRE2_CONFIG_UNICODE, NULL) != sizeof(uint32_t) ||
8138 PCRE2_CONFIG(PCRE2_CONFIG_MATCHLIMIT, NULL) != sizeof(uint32_t))
8140 fprintf(stderr, "** Error in pcre2_config(): bad length\n");
8144 /* Check that bad options are diagnosed. */
8146 if (PCRE2_CONFIG(999, NULL) != PCRE2_ERROR_BADOPTION ||
8147 PCRE2_CONFIG(999, &temp) != PCRE2_ERROR_BADOPTION)
8149 fprintf(stderr, "** Error in pcre2_config(): bad option not diagnosed\n");
8153 /* This configuration option is now obsolete, but running a quick check ensures
8154 that its code is covered. */
8156 (void)PCRE2_CONFIG(PCRE2_CONFIG_STACKRECURSE, &temp);
8158 /* Get buffers from malloc() so that valgrind will check their misuse when
8159 debugging. They grow automatically when very long lines are read. The 16-
8160 and 32-bit buffers (pbuffer16, pbuffer32) are obtained only if needed. */
8162 buffer = (uint8_t *)malloc(pbuffer8_size);
8163 pbuffer8 = (uint8_t *)malloc(pbuffer8_size);
8165 /* The following _setmode() stuff is some Windows magic that tells its runtime
8166 library to translate CRLF into a single LF character. At least, that's what
8167 I've been told: never having used Windows I take this all on trust. Originally
8168 it set 0x8000, but then I was advised that _O_BINARY was better. */
8170 #if defined(_WIN32) || defined(WIN32)
8171 _setmode( _fileno( stdout ), _O_BINARY );
8174 /* Initialization that does not depend on the running mode. */
8178 memset(&def_patctl, 0, sizeof(patctl));
8179 def_patctl.convert_type = CONVERT_UNSET;
8181 memset(&def_datctl, 0, sizeof(datctl));
8182 def_datctl.oveccount = DEFAULT_OVECCOUNT;
8183 def_datctl.copy_numbers[0] = -1;
8184 def_datctl.get_numbers[0] = -1;
8185 def_datctl.startend[0] = def_datctl.startend[1] = CFORE_UNSET;
8186 def_datctl.cerror[0] = def_datctl.cerror[1] = CFORE_UNSET;
8187 def_datctl.cfail[0] = def_datctl.cfail[1] = CFORE_UNSET;
8189 /* Scan command line options. */
8191 while (argc > 1 && argv[op][0] == '-' && argv[op][1] != 0)
8194 char *arg = argv[op];
8197 /* List modifiers and exit. */
8199 if (strcmp(arg, "-LM") == 0)
8201 display_modifiers();
8205 /* Display and/or set return code for configuration options. */
8207 if (strcmp(arg, "-C") == 0)
8209 yield = c_option(argv[op + 1]);
8213 /* Select operating mode. Ensure that pcre2_config() is called in 16-bit
8214 and 32-bit modes because that won't happen naturally when 8-bit is also
8215 configured. Also call some other functions that are not otherwise used. This
8216 means that a coverage report won't claim there are uncalled functions. */
8218 if (strcmp(arg, "-8") == 0)
8220 #ifdef SUPPORT_PCRE2_8
8221 test_mode = PCRE8_MODE;
8222 (void)pcre2_set_bsr_8(pat_context8, 999);
8223 (void)pcre2_set_newline_8(pat_context8, 999);
8226 "** This version of PCRE2 was built without 8-bit support\n");
8231 else if (strcmp(arg, "-16") == 0)
8233 #ifdef SUPPORT_PCRE2_16
8234 test_mode = PCRE16_MODE;
8235 (void)pcre2_config_16(PCRE2_CONFIG_VERSION, NULL);
8236 (void)pcre2_set_bsr_16(pat_context16, 999);
8237 (void)pcre2_set_newline_16(pat_context16, 999);
8240 "** This version of PCRE2 was built without 16-bit support\n");
8245 else if (strcmp(arg, "-32") == 0)
8247 #ifdef SUPPORT_PCRE2_32
8248 test_mode = PCRE32_MODE;
8249 (void)pcre2_config_32(PCRE2_CONFIG_VERSION, NULL);
8250 (void)pcre2_set_bsr_32(pat_context32, 999);
8251 (void)pcre2_set_newline_32(pat_context32, 999);
8254 "** This version of PCRE2 was built without 32-bit support\n");
8259 /* Set quiet (no version verification) */
8261 else if (strcmp(arg, "-q") == 0) quiet = TRUE;
8263 /* Set system stack size */
8265 else if (strcmp(arg, "-S") == 0 && argc > 2 &&
8266 ((uli = strtoul(argv[op+1], &endptr, 10)), *endptr == 0))
8268 #if defined(_WIN32) || defined(WIN32) || defined(__minix) || defined(NATIVE_ZOS) || defined(__VMS)
8269 fprintf(stderr, "pcre2test: -S is not supported on this OS\n");
8273 uint32_t stack_size;
8275 if (U32OVERFLOW(uli))
8277 fprintf(stderr, "** Argument for -S is too big\n");
8280 stack_size = (uint32_t)uli;
8281 getrlimit(RLIMIT_STACK, &rlim);
8282 rlim.rlim_cur = stack_size * 1024 * 1024;
8283 if (rlim.rlim_cur > rlim.rlim_max)
8286 "pcre2test: requested stack size %luMiB is greater than hard limit "
8287 "%luMiB\n", (unsigned long int)stack_size,
8288 (unsigned long int)(rlim.rlim_max));
8291 rc = setrlimit(RLIMIT_STACK, &rlim);
8294 fprintf(stderr, "pcre2test: setting stack size %luMiB failed: %s\n",
8295 (unsigned long int)stack_size, strerror(errno));
8303 /* Set some common pattern and subject controls */
8305 else if (strcmp(arg, "-AC") == 0)
8307 def_patctl.options |= PCRE2_AUTO_CALLOUT;
8308 def_datctl.control2 |= CTL2_CALLOUT_EXTRA;
8310 else if (strcmp(arg, "-ac") == 0) def_patctl.options |= PCRE2_AUTO_CALLOUT;
8311 else if (strcmp(arg, "-b") == 0) def_patctl.control |= CTL_FULLBINCODE;
8312 else if (strcmp(arg, "-d") == 0) def_patctl.control |= CTL_DEBUG;
8313 else if (strcmp(arg, "-dfa") == 0) def_datctl.control |= CTL_DFA;
8314 else if (strcmp(arg, "-i") == 0) def_patctl.control |= CTL_INFO;
8315 else if (strcmp(arg, "-jit") == 0 || strcmp(arg, "-jitverify") == 0)
8317 if (arg[4] != 0) def_patctl.control |= CTL_JITVERIFY;
8318 def_patctl.jit = 7; /* full & partial */
8320 fprintf(stderr, "** Warning: JIT support is not available: "
8321 "-jit[verify] calls functions that do nothing.\n");
8325 /* Set timing parameters */
8327 else if (strcmp(arg, "-t") == 0 || strcmp(arg, "-tm") == 0 ||
8328 strcmp(arg, "-T") == 0 || strcmp(arg, "-TM") == 0)
8330 int both = arg[2] == 0;
8331 showtotaltimes = arg[1] == 'T';
8332 if (argc > 2 && (uli = strtoul(argv[op+1], &endptr, 10), *endptr == 0))
8334 if (U32OVERFLOW(uli))
8336 fprintf(stderr, "** Argument for %s is too big\n", arg);
8343 else timeitm = LOOPREPEAT;
8344 if (both) timeit = timeitm;
8349 else if (strcmp(arg, "-help") == 0 ||
8350 strcmp(arg, "--help") == 0)
8358 else if (strcmp(arg, "-version") == 0 ||
8359 strcmp(arg, "--version") == 0)
8361 print_version(stdout);
8365 /* The following options save their data for processing once we know what
8366 the running mode is. */
8368 else if (strcmp(arg, "-error") == 0)
8370 arg_error = argv[op+1];
8371 goto CHECK_VALUE_EXISTS;
8374 else if (strcmp(arg, "-subject") == 0)
8376 arg_subject = argv[op+1];
8377 goto CHECK_VALUE_EXISTS;
8380 else if (strcmp(arg, "-pattern") == 0)
8382 arg_pattern = argv[op+1];
8386 fprintf(stderr, "** Missing value for %s\n", arg);
8394 /* Unrecognized option */
8398 fprintf(stderr, "** Unknown or malformed option '%s'\n", arg);
8407 /* If -error was present, get the error numbers, show the messages, and exit.
8408 We wait to do this until we know which mode we are in. */
8410 if (arg_error != NULL)
8416 /* Ensure the relevant non-8-bit buffer is available. Ensure that it is at
8417 least 128 code units, because it is used for retrieving error messages. */
8419 #ifdef SUPPORT_PCRE2_16
8420 if (test_mode == PCRE16_MODE)
8422 pbuffer16_size = 256;
8423 pbuffer16 = (uint16_t *)malloc(pbuffer16_size);
8424 if (pbuffer16 == NULL)
8426 fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer16\n",
8427 SIZ_CAST pbuffer16_size);
8434 #ifdef SUPPORT_PCRE2_32
8435 if (test_mode == PCRE32_MODE)
8437 pbuffer32_size = 512;
8438 pbuffer32 = (uint32_t *)malloc(pbuffer32_size);
8439 if (pbuffer32 == NULL)
8441 fprintf(stderr, "pcre2test: malloc(%" SIZ_FORM ") failed for pbuffer32\n",
8442 SIZ_CAST pbuffer32_size);
8449 /* Loop along a list of error numbers. */
8453 errcode = strtol(arg_error, &endptr, 10);
8454 if (*endptr != 0 && *endptr != CHAR_COMMA)
8456 fprintf(stderr, "** '%s' is not a valid error number list\n", arg_error);
8460 printf("Error %d: ", errcode);
8461 PCRE2_GET_ERROR_MESSAGE(len, errcode, pbuffer);
8466 case PCRE2_ERROR_BADDATA:
8467 printf("PCRE2_ERROR_BADDATA (unknown error number)");
8470 case PCRE2_ERROR_NOMEMORY:
8471 printf("PCRE2_ERROR_NOMEMORY (buffer too small)");
8475 printf("Unexpected return (%d) from pcre2_get_error_message()", len);
8481 PCHARSV(CASTVAR(void *, pbuffer), 0, len, FALSE, stdout);
8484 if (*endptr == 0) goto EXIT;
8485 arg_error = endptr + 1;
8487 /* Control never reaches here */
8488 } /* End of -error handling */
8490 /* Initialize things that cannot be done until we know which test mode we are
8491 running in. Exercise the general context copying function, which is not
8494 code_unit_size = test_mode/8;
8495 max_oveccount = DEFAULT_OVECCOUNT;
8497 /* Use macros to save a lot of duplication. */
8499 #define CREATECONTEXTS \
8500 G(general_context,BITS) = G(pcre2_general_context_create_,BITS)(&my_malloc, &my_free, NULL); \
8501 G(general_context_copy,BITS) = G(pcre2_general_context_copy_,BITS)(G(general_context,BITS)); \
8502 G(default_pat_context,BITS) = G(pcre2_compile_context_create_,BITS)(G(general_context,BITS)); \
8503 G(pat_context,BITS) = G(pcre2_compile_context_copy_,BITS)(G(default_pat_context,BITS)); \
8504 G(default_dat_context,BITS) = G(pcre2_match_context_create_,BITS)(G(general_context,BITS)); \
8505 G(dat_context,BITS) = G(pcre2_match_context_copy_,BITS)(G(default_dat_context,BITS)); \
8506 G(default_con_context,BITS) = G(pcre2_convert_context_create_,BITS)(G(general_context,BITS)); \
8507 G(con_context,BITS) = G(pcre2_convert_context_copy_,BITS)(G(default_con_context,BITS)); \
8508 G(match_data,BITS) = G(pcre2_match_data_create_,BITS)(max_oveccount, G(general_context,BITS))
8510 #define CONTEXTTESTS \
8511 (void)G(pcre2_set_compile_extra_options_,BITS)(G(pat_context,BITS), 0); \
8512 (void)G(pcre2_set_max_pattern_length_,BITS)(G(pat_context,BITS), 0); \
8513 (void)G(pcre2_set_offset_limit_,BITS)(G(dat_context,BITS), 0); \
8514 (void)G(pcre2_set_recursion_memory_management_,BITS)(G(dat_context,BITS), my_malloc, my_free, NULL)
8516 /* Call the appropriate functions for the current mode, and exercise some
8517 functions that are not otherwise called. */
8519 #ifdef SUPPORT_PCRE2_8
8522 if (test_mode == PCRE8_MODE)
8529 #ifdef SUPPORT_PCRE2_16
8532 if (test_mode == PCRE16_MODE)
8539 #ifdef SUPPORT_PCRE2_32
8542 if (test_mode == PCRE32_MODE)
8549 /* Set a default parentheses nest limit that is large enough to run the
8550 standard tests (this also exercises the function). */
8552 PCRE2_SET_PARENS_NEST_LIMIT(default_pat_context, PARENS_NEST_DEFAULT);
8554 /* Handle command line modifier settings, sending any error messages to
8555 stderr. We need to know the mode before modifying the context, and it is tidier
8556 to do them all in the same way. */
8559 if ((arg_pattern != NULL &&
8560 !decode_modifiers((uint8_t *)arg_pattern, CTX_DEFPAT, &def_patctl, NULL)) ||
8561 (arg_subject != NULL &&
8562 !decode_modifiers((uint8_t *)arg_subject, CTX_DEFDAT, NULL, &def_datctl)))
8568 /* Sort out the input and output files, defaulting to stdin/stdout. */
8573 if (argc > 1 && strcmp(argv[op], "-") != 0)
8575 infile = fopen(argv[op], INPUT_MODE);
8578 printf("** Failed to open '%s': %s\n", argv[op], strerror(errno));
8584 #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
8585 if (INTERACTIVE(infile)) using_history();
8590 outfile = fopen(argv[op+1], OUTPUT_MODE);
8591 if (outfile == NULL)
8593 printf("** Failed to open '%s': %s\n", argv[op+1], strerror(errno));
8599 /* Output a heading line unless quiet, then process input lines. */
8601 if (!quiet) print_version(outfile);
8603 SET(compiled_code, NULL);
8605 #ifdef SUPPORT_PCRE2_8
8606 preg.re_pcre2_code = NULL;
8607 preg.re_match_data = NULL;
8614 BOOL expectdata = TEST(compiled_code, !=, NULL);
8615 #ifdef SUPPORT_PCRE2_8
8616 expectdata |= preg.re_pcre2_code != NULL;
8619 if (extend_inputline(infile, buffer, expectdata? "data> " : " re> ") == NULL)
8621 if (!INTERACTIVE(infile)) fprintf(outfile, "%s", (char *)buffer);
8625 /* If we have a pattern set up for testing, or we are skipping after a
8626 compile failure, a blank line terminates this test. */
8628 if (expectdata || skipping)
8630 while (isspace(*p)) p++;
8633 #ifdef SUPPORT_PCRE2_8
8634 if (preg.re_pcre2_code != NULL)
8637 preg.re_pcre2_code = NULL;
8638 preg.re_match_data = NULL;
8640 #endif /* SUPPORT_PCRE2_8 */
8641 if (TEST(compiled_code, !=, NULL))
8643 SUB1(pcre2_code_free, compiled_code);
8644 SET(compiled_code, NULL);
8647 setlocale(LC_CTYPE, "C");
8650 /* Otherwise, if we are not skipping, and the line is not a data comment
8651 line starting with "\=", process a data line. */
8653 else if (!skipping && !(p[0] == '\\' && p[1] == '=' && isspace(p[2])))
8655 rc = process_data();
8659 /* We do not have a pattern set up for testing. Lines starting with # are
8660 either comments or special commands. Blank lines are ignored. Otherwise, the
8661 line must start with a valid delimiter. It is then processed as a pattern
8662 line. A copy of the pattern is left in pbuffer8 for use by callouts. Under
8663 valgrind, make the unused part of the buffer undefined, to catch overruns. */
8667 if (isspace(p[1]) || p[1] == '!' || p[1] == 0) continue;
8668 rc = process_command();
8671 else if (strchr("/!\"'`%&-=_:;,@~", *p) != NULL)
8673 rc = process_pattern();
8679 while (isspace(*p)) p++;
8682 fprintf(outfile, "** Invalid pattern delimiter '%c' (x%x).\n", *buffer,
8688 if (rc == PR_SKIP && !INTERACTIVE(infile)) skipping = TRUE;
8689 else if (rc == PR_ABEND)
8691 fprintf(outfile, "** pcre2test run abandoned\n");
8697 /* Finish off a normal run. */
8699 if (INTERACTIVE(infile)) fprintf(outfile, "\n");
8703 const char *pad = "";
8704 fprintf(outfile, "--------------------------------------\n");
8707 fprintf(outfile, "Total compile time %.4f milliseconds\n",
8708 (((double)total_compile_time * 1000.0) / (double)timeit) /
8709 (double)CLOCKS_PER_SEC);
8710 if (total_jit_compile_time > 0)
8711 fprintf(outfile, "Total JIT compile %.4f milliseconds\n",
8712 (((double)total_jit_compile_time * 1000.0) / (double)timeit) /
8713 (double)CLOCKS_PER_SEC);
8716 fprintf(outfile, "Total match time %s%.4f milliseconds\n", pad,
8717 (((double)total_match_time * 1000.0) / (double)timeitm) /
8718 (double)CLOCKS_PER_SEC);
8724 #if defined(SUPPORT_LIBREADLINE) || defined(SUPPORT_LIBEDIT)
8725 if (infile != NULL && INTERACTIVE(infile)) clear_history();
8728 if (infile != NULL && infile != stdin) fclose(infile);
8729 if (outfile != NULL && outfile != stdout) fclose(outfile);
8734 free(dfa_workspace);
8735 free((void *)locale_tables);
8736 PCRE2_MATCH_DATA_FREE(match_data);
8737 SUB1(pcre2_code_free, compiled_code);
8739 while(patstacknext-- > 0)
8741 SET(compiled_code, patstack[patstacknext]);
8742 SUB1(pcre2_code_free, compiled_code);
8745 PCRE2_JIT_FREE_UNUSED_MEMORY(general_context);
8746 if (jit_stack != NULL)
8748 PCRE2_JIT_STACK_FREE(jit_stack);
8751 #define FREECONTEXTS \
8752 G(pcre2_general_context_free_,BITS)(G(general_context,BITS)); \
8753 G(pcre2_general_context_free_,BITS)(G(general_context_copy,BITS)); \
8754 G(pcre2_compile_context_free_,BITS)(G(pat_context,BITS)); \
8755 G(pcre2_compile_context_free_,BITS)(G(default_pat_context,BITS)); \
8756 G(pcre2_match_context_free_,BITS)(G(dat_context,BITS)); \
8757 G(pcre2_match_context_free_,BITS)(G(default_dat_context,BITS)); \
8758 G(pcre2_convert_context_free_,BITS)(G(default_con_context,BITS)); \
8759 G(pcre2_convert_context_free_,BITS)(G(con_context,BITS));
8761 #ifdef SUPPORT_PCRE2_8
8764 if (preg.re_pcre2_code != NULL) regfree(&preg);
8768 #ifdef SUPPORT_PCRE2_16
8775 #ifdef SUPPORT_PCRE2_32
8783 yield = SS$_NORMAL; /* Return values via DCL symbols */
8789 /* End of pcre2test.c */