@@ -14,8 +14,11 @@ Written by Philip Hazel, October 2016
1414#include <stdlib.h>
1515#include <string.h>
1616
17- #include "config.h"
17+ #ifndef PCRE2_CODE_UNIT_WIDTH
1818#define PCRE2_CODE_UNIT_WIDTH 8
19+ #endif
20+
21+ #include "config.h"
1922#include "pcre2.h"
2023
2124#define MAX_MATCH_SIZE 1000
@@ -86,7 +89,9 @@ fprintf(stream, "%s%s%s%s%s%s%s%s%s\n",
8689
8790static void dump_matches (FILE * stream , int count , pcre2_match_data * match_data , pcre2_match_context * match_context )
8891{
92+ #if PCRE2_CODE_UNIT_WIDTH == 8
8993PCRE2_UCHAR error_buf [256 ];
94+ #endif
9095int errorcode ;
9196
9297for (uint32_t index = 0 ; index < count ; index ++ )
@@ -107,8 +112,12 @@ for (uint32_t index = 0; index < count; index++)
107112 }
108113 else
109114 {
115+ #if PCRE2_CODE_UNIT_WIDTH == 8
110116 pcre2_get_error_message (errorcode , error_buf , 256 );
111117 fprintf (stream , "Match %d failed: %s\n" , index , error_buf );
118+ #else
119+ fprintf (stream , "Match %d failed: %d\n" , index , errorcode );
120+ #endif
112121 }
113122 }
114123}
@@ -130,7 +139,9 @@ static void describe_failure(
130139 pcre2_match_data * match_data_jit ,
131140 pcre2_match_context * match_context
132141) {
142+ #if PCRE2_CODE_UNIT_WIDTH == 8
133143PCRE2_UCHAR buffer [256 ];
144+ #endif
134145
135146fprintf (stderr , "Encountered failure while performing %s; context:\n" , task );
136147
@@ -146,8 +157,12 @@ print_match_options(stderr, match_options);
146157
147158if (errorcode < 0 )
148159 {
160+ #if PCRE2_CODE_UNIT_WIDTH == 8
149161 pcre2_get_error_message (errorcode , buffer , 256 );
150162 fprintf (stderr , "Non-JIT'd operation emitted an error: %s (%d)\n" , buffer , errorcode );
163+ #else
164+ fprintf (stderr , "Non-JIT'd operation emitted an error: %d\n" , errorcode );
165+ #endif
151166 }
152167if (matches >= 0 )
153168 {
@@ -162,8 +177,12 @@ if (matches >= 0)
162177
163178if (errorcode_jit < 0 )
164179 {
180+ #if PCRE2_CODE_UNIT_WIDTH == 8
165181 pcre2_get_error_message (errorcode_jit , buffer , 256 );
166182 fprintf (stderr , "JIT'd operation emitted an error: %s (%d)\n" , buffer , errorcode_jit );
183+ #else
184+ fprintf (stderr , "JIT'd operation emitted an error: %d\n" , errorcode );
185+ #endif
167186 }
168187if (matches_jit >= 0 )
169188 {
@@ -220,6 +239,7 @@ in large trees taking too much time. */
220239random_options = * (uint64_t * )(data );
221240data += sizeof (random_options );
222241size -= sizeof (random_options );
242+ size /= PCRE2_CODE_UNIT_WIDTH / 8 ;
223243
224244match_size = (size > MAX_MATCH_SIZE )? MAX_MATCH_SIZE : size ;
225245
@@ -323,9 +343,13 @@ for (i = 0; i < 2; i++)
323343#ifdef STANDALONE
324344 if (errorcode >= 0 ) printf ("Match returned %d\n" , errorcode ); else
325345 {
346+ #if PCRE2_CODE_UNIT_WIDTH == 8
326347 unsigned char buffer [256 ];
327348 pcre2_get_error_message (errorcode , buffer , 256 );
328349 printf ("Match failed: error %d: %s\n" , errorcode , buffer );
350+ #else
351+ printf ("Match failed: error %d\n" , errorcode );
352+ #endif
329353 }
330354#endif
331355
@@ -417,9 +441,13 @@ for (i = 0; i < 2; i++)
417441#ifdef STANDALONE
418442 if (errorcode >= 0 ) printf ("Match returned %d\n" , errorcode ); else
419443 {
444+ #if PCRE2_CODE_UNIT_WIDTH == 8
420445 unsigned char buffer [256 ];
421446 pcre2_get_error_message (errorcode , buffer , 256 );
422447 printf ("Match failed: error %d: %s\n" , errorcode , buffer );
448+ #else
449+ printf ("Match failed: error %d\n" , errorcode );
450+ #endif
423451 }
424452#endif
425453
@@ -434,12 +462,17 @@ for (i = 0; i < 2; i++)
434462
435463 else
436464 {
465+ #ifdef STANDALONE
466+ #if PCRE2_CODE_UNIT_WIDTH == 8
437467 unsigned char buffer [256 ];
438468 pcre2_get_error_message (errorcode , buffer , 256 );
439- #ifdef STANDALONE
440469 printf ("Error %d at offset %lu: %s\n" , errorcode , erroroffset , buffer );
441470#else
442- if (strstr ((const char * )buffer , "internal error" ) != NULL ) abort ();
471+ printf ("Error %d at offset %lu\n" , errorcode , erroroffset );
472+ #endif
473+
474+ #else
475+ if (errorcode == PCRE2_ERROR_INTERNAL ) abort ();
443476#endif
444477 }
445478
0 commit comments