@@ -14,8 +14,11 @@ Written by Philip Hazel, October 2016
14
14
#include <stdlib.h>
15
15
#include <string.h>
16
16
17
- #include "config.h"
17
+ #ifndef PCRE2_CODE_UNIT_WIDTH
18
18
#define PCRE2_CODE_UNIT_WIDTH 8
19
+ #endif
20
+
21
+ #include "config.h"
19
22
#include "pcre2.h"
20
23
21
24
#define MAX_MATCH_SIZE 1000
@@ -86,7 +89,9 @@ fprintf(stream, "%s%s%s%s%s%s%s%s%s\n",
86
89
87
90
static void dump_matches (FILE * stream , int count , pcre2_match_data * match_data , pcre2_match_context * match_context )
88
91
{
92
+ #if PCRE2_CODE_UNIT_WIDTH == 8
89
93
PCRE2_UCHAR error_buf [256 ];
94
+ #endif
90
95
int errorcode ;
91
96
92
97
for (uint32_t index = 0 ; index < count ; index ++ )
@@ -107,8 +112,12 @@ for (uint32_t index = 0; index < count; index++)
107
112
}
108
113
else
109
114
{
115
+ #if PCRE2_CODE_UNIT_WIDTH == 8
110
116
pcre2_get_error_message (errorcode , error_buf , 256 );
111
117
fprintf (stream , "Match %d failed: %s\n" , index , error_buf );
118
+ #else
119
+ fprintf (stream , "Match %d failed: %d\n" , index , errorcode );
120
+ #endif
112
121
}
113
122
}
114
123
}
@@ -130,7 +139,9 @@ static void describe_failure(
130
139
pcre2_match_data * match_data_jit ,
131
140
pcre2_match_context * match_context
132
141
) {
142
+ #if PCRE2_CODE_UNIT_WIDTH == 8
133
143
PCRE2_UCHAR buffer [256 ];
144
+ #endif
134
145
135
146
fprintf (stderr , "Encountered failure while performing %s; context:\n" , task );
136
147
@@ -146,8 +157,12 @@ print_match_options(stderr, match_options);
146
157
147
158
if (errorcode < 0 )
148
159
{
160
+ #if PCRE2_CODE_UNIT_WIDTH == 8
149
161
pcre2_get_error_message (errorcode , buffer , 256 );
150
162
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
151
166
}
152
167
if (matches >= 0 )
153
168
{
@@ -162,8 +177,12 @@ if (matches >= 0)
162
177
163
178
if (errorcode_jit < 0 )
164
179
{
180
+ #if PCRE2_CODE_UNIT_WIDTH == 8
165
181
pcre2_get_error_message (errorcode_jit , buffer , 256 );
166
182
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
167
186
}
168
187
if (matches_jit >= 0 )
169
188
{
@@ -220,6 +239,7 @@ in large trees taking too much time. */
220
239
random_options = * (uint64_t * )(data );
221
240
data += sizeof (random_options );
222
241
size -= sizeof (random_options );
242
+ size /= PCRE2_CODE_UNIT_WIDTH / 8 ;
223
243
224
244
match_size = (size > MAX_MATCH_SIZE )? MAX_MATCH_SIZE : size ;
225
245
@@ -323,9 +343,13 @@ for (i = 0; i < 2; i++)
323
343
#ifdef STANDALONE
324
344
if (errorcode >= 0 ) printf ("Match returned %d\n" , errorcode ); else
325
345
{
346
+ #if PCRE2_CODE_UNIT_WIDTH == 8
326
347
unsigned char buffer [256 ];
327
348
pcre2_get_error_message (errorcode , buffer , 256 );
328
349
printf ("Match failed: error %d: %s\n" , errorcode , buffer );
350
+ #else
351
+ printf ("Match failed: error %d\n" , errorcode );
352
+ #endif
329
353
}
330
354
#endif
331
355
@@ -417,9 +441,13 @@ for (i = 0; i < 2; i++)
417
441
#ifdef STANDALONE
418
442
if (errorcode >= 0 ) printf ("Match returned %d\n" , errorcode ); else
419
443
{
444
+ #if PCRE2_CODE_UNIT_WIDTH == 8
420
445
unsigned char buffer [256 ];
421
446
pcre2_get_error_message (errorcode , buffer , 256 );
422
447
printf ("Match failed: error %d: %s\n" , errorcode , buffer );
448
+ #else
449
+ printf ("Match failed: error %d\n" , errorcode );
450
+ #endif
423
451
}
424
452
#endif
425
453
@@ -434,12 +462,17 @@ for (i = 0; i < 2; i++)
434
462
435
463
else
436
464
{
465
+ #ifdef STANDALONE
466
+ #if PCRE2_CODE_UNIT_WIDTH == 8
437
467
unsigned char buffer [256 ];
438
468
pcre2_get_error_message (errorcode , buffer , 256 );
439
- #ifdef STANDALONE
440
469
printf ("Error %d at offset %lu: %s\n" , errorcode , erroroffset , buffer );
441
470
#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 ();
443
476
#endif
444
477
}
445
478
0 commit comments