Skip to content

Commit ec9fdc8

Browse files
committed
Some further fixes
1 parent aea53cd commit ec9fdc8

File tree

8 files changed

+71
-54
lines changed

8 files changed

+71
-54
lines changed

.github/workflows/dev.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ jobs:
440440
run: bazelisk test //... --enable_runfiles --incompatible_strict_action_env --test_output=all
441441

442442
# XXX Maybe this should just go in the ManyConfig tests, actually??
443+
# XXX JIT IS TURNED OFF - apparently it needs some fixes (not surprising)
443444
ebcdic:
444445
# Tests the full support for EBCDIC on a non-EBCDIC platform, using a
445446
# hardcoded EBCDIC-1047 codepage.

Makefile.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ EXTRA_DIST += \
781781
testdata/testinput25 \
782782
testdata/testinput26 \
783783
testdata/testinput27 \
784-
testdata/testinputEBC \
784+
testdata/testinput28 \
785785
testdata/testinputheap \
786786
testdata/testoutput1 \
787787
testdata/testoutput2 \
@@ -823,7 +823,7 @@ EXTRA_DIST += \
823823
testdata/testoutput25 \
824824
testdata/testoutput26 \
825825
testdata/testoutput27 \
826-
testdata/testoutputEBC \
826+
testdata/testoutput28 \
827827
testdata/testoutputheap-16 \
828828
testdata/testoutputheap-32 \
829829
testdata/testoutputheap-8 \

RunTest

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ fi
130130
# have a diff that lacks a -u option. Try to deal with this.
131131

132132
cf="diff"
133-
diff -u /dev/null /dev/null 2>/dev/null && cf="diff -U15 --color=always" # XXX TEST HACK
133+
diff -u /dev/null /dev/null 2>/dev/null && cf="diff -u"
134134

135135
# Find the test data
136136

@@ -374,8 +374,14 @@ if [ $ebcdic -eq 1 ]; then
374374
# modified input file. That's it.
375375
filterebcdic()
376376
{
377-
filter_cmd="$1"
378377
filter_args=
378+
while [ "$1" != "$pcre2test" ] ; do
379+
# Shift off any Valgrind args
380+
filter_args="$filter_args $1"
381+
shift
382+
done
383+
# Shift off the $pcre2test arg
384+
filter_args="$filter_args $1"
379385
shift
380386
while [ $# -gt 0 ] ; do
381387
case "$1" in
@@ -393,9 +399,9 @@ if [ $ebcdic -eq 1 ]; then
393399
if [ $# -gt 0 ] ; then
394400
input="$1"
395401
shift
396-
sed '/^# if !EBCDIC/,/^# endif/d' "$input" | "$filter_cmd" $filter_args "/dev/stdin" "$@"
402+
sed '/^# if !EBCDIC/,/^# endif/d' "$input" | $filter_args "/dev/stdin" "$@"
397403
else
398-
"$filter_cmd" $filter_args "$@"
404+
$filter_args "$@"
399405
fi
400406
}
401407
sim="filterebcdic $sim"

maint/ManyConfigTests

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
# -nomainvalgrind skip the main (non-JIT) valgrind tests
2121
# -notmp skip the tests in a temporary directory
2222
# -notmpjit skip the JIT test in a temporary directory
23+
# -noebcdic skip the EBCDIC tests
2324
# -novalgrind skip all the valgrind tests
2425

2526
# Alternatively, if any of those names are given with '+' instead of '-no',
@@ -38,6 +39,7 @@ usemain=1
3839
usemainvalgrind=1
3940
usetmp=1
4041
usetmpjit=1
42+
useebcdic=0 # XXX Set to 1 after fixed on all plats
4143
usevalgrind=1
4244

4345
dummy=0
@@ -55,8 +57,9 @@ while [ $# -gt 0 ] ; do
5557
usemain=0
5658
usemainvalgrind=0
5759
usetmp=0
58-
usetmpjit=0
59-
usevalgrind=0
60+
usetmpjit=0
61+
useebcdic=0
62+
usevalgrind=0
6063
seenplus=1
6164
fi;;
6265
esac
@@ -74,6 +77,7 @@ while [ $# -gt 0 ] ; do
7477
-nomainvalgrind) usemainvalgrind=0;;
7578
-notmp) usetmp=0; usetmpjit=0;;
7679
-notmpjit) usetmpjit=0;;
80+
-noebcdic) useebcdic=0;;
7781
-novalgrind) usevalgrind=0;;
7882
+asan) useasan=1;;
7983
+usan) useusan=1;;
@@ -85,6 +89,7 @@ while [ $# -gt 0 ] ; do
8589
+mainvalgrind) usemainvalgrind=1;;
8690
+tmp) usetmp=1;;
8791
+tmpjit) usetmpjit=1;;
92+
+ebcdic) useebcdic=1;;
8893
+valgrind) usevalgrind=1; usejitvalgrind=1; usemainvalgrind=1;;
8994
*) echo "Unknown option '$1'"; exit 1;;
9095
esac
@@ -221,7 +226,11 @@ runtest()
221226
exit 1
222227
fi
223228

224-
if [ $pcre2_8 -gt 0 ]; then
229+
if [ "x$withebcdic" != x ]; then
230+
echo "Skipping pcre2grep and pcre2posix tests: not supported on EBCDIC"
231+
elif [ $pcre2_8 -eq 0 ]; then
232+
echo "Skipping pcre2grep and pcre2posix tests: 8-bit library not compiled"
233+
else
225234
echo "Running pcre2grep tests $withvalgrind"
226235
$srcdir/RunGrepTest $valgrind >teststdoutM 2>teststderrM
227236
if [ $? -ne 0 -o -s teststderrM ]; then
@@ -239,8 +248,6 @@ runtest()
239248
echo "**** Test failed ****"
240249
exit 1
241250
fi
242-
else
243-
echo "Skipping pcre2grep and pcre2posix tests: 8-bit library not compiled"
244251
fi
245252

246253
if [ "$jit" -gt 0 ]; then
@@ -268,6 +275,7 @@ testtotal=`expr 17 \* $usemain + \
268275
1 \* $ISGCC \* $usemain \* $useasan + \
269276
1 \* $ISGCC \* $usemain \* $useusan + \
270277
13 \* $usejit + \
278+
2 \* $useebcdic + \
271279
2 \* $usemainvalgrind + \
272280
2 \* $usejitvalgrind`
273281

@@ -388,6 +396,22 @@ if [ $usejit -ne 0 ]; then
388396
done
389397
fi
390398

399+
# Now run some tests with EBCDIC enabled
400+
401+
if [ $useebcdic -ne 0 ]; then
402+
echo "---------- EBCDIC tests in the current directory ----------"
403+
withebcdic="with EBCDIC"
404+
405+
for opts in \
406+
"--disable-unicode --enable-ebcdic --enable-ebcdic-ignoring-compiler" \
407+
"--disable-unicode --enable-ebcdic --enable-ebcdic-ignoring-compiler --enable-ebcdic-nl25"
408+
do
409+
runtest
410+
done
411+
fi
412+
413+
withebcdic=
414+
391415
# Now re-run some of the tests under valgrind.
392416

393417
if [ $usevalgrind -ne 0 ]; then
@@ -464,8 +488,8 @@ if [ $usetmp -ne 0 -o $usetmpjit -ne 0 ]; then
464488
do
465489
runtest
466490
done
467-
fi
468-
491+
fi
492+
469493
if [ $usetmpjit -ne 0 ]; then
470494
echo "---------- JIT tests in the $tmp directory ----------"
471495
for opts in \

src/pcre2_error.c

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,7 @@ performance issue because these strings are used only when there is an error.
5858
5959
Each substring ends with \0 to insert a null character. This includes the final
6060
substring, so that the whole string ends with \0\0, which can be detected when
61-
counting through.
62-
63-
In the rare configuration of EBCDIC-with-ASCII-compiler, we currently output
64-
ASCII strings for the error messages, which is unlikely to cause complaints if
65-
some client does want to use PCRE2 on Linux or Windows to process their EBCDIC
66-
files.
67-
68-
XXX No! Let's just make it 100% EBCDIC.
69-
*/
61+
counting through. */
7062

7163
static const unsigned char compile_error_texts[] =
7264
"no error\0"
@@ -330,7 +322,7 @@ pcre2_get_error_message(int enumber, PCRE2_UCHAR *buffer, PCRE2_SIZE size)
330322
{
331323
const unsigned char *message;
332324
PCRE2_SIZE i;
333-
int n;
325+
int n, rc = 0;
334326

335327
if (size == 0) return PCRE2_ERROR_NOMEMORY;
336328

@@ -360,14 +352,23 @@ for (i = 0; *message != 0; i++)
360352
{
361353
if (i >= size - 1)
362354
{
363-
buffer[i] = 0; /* Terminate partial message */
364-
return PCRE2_ERROR_NOMEMORY;
355+
rc = PCRE2_ERROR_NOMEMORY;
356+
break;
365357
}
366358
buffer[i] = *message++;
367359
}
368360

369-
buffer[i] = 0;
370-
return (int)i;
361+
#if defined EBCDIC && 'a' != 0x81
362+
/* If compiling for EBCDIC, but the compiler's string literals are not EBCDIC,
363+
then we are in the "force EBCDIC 1047" mode. I have chosen to add a few lines
364+
here to translate the error strings on the fly, rather than require the string
365+
literals above to be written out arduously using the "STR_XYZ" macros. */
366+
for (PCRE2_SIZE j = 0; j < i; ++j)
367+
buffer[j] = PRIV(ascii_to_ebcdic_1047)[buffer[j]];
368+
#endif
369+
370+
buffer[i] = 0; /* Terminate message, even if truncated. */
371+
return rc? rc : (int)i;
371372
}
372373

373374
/* End of pcre2_error.c */

src/pcre2_internal.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,6 +2268,8 @@ extern const uint8_t PRIV(utf8_table4)[];
22682268
#define _pcre2_utt PCRE2_SUFFIX(_pcre2_utt_)
22692269
#define _pcre2_utt_names PCRE2_SUFFIX(_pcre2_utt_names_)
22702270
#define _pcre2_utt_size PCRE2_SUFFIX(_pcre2_utt_size_)
2271+
#define _pcre2_ebcdic_1047_to_ascii PCRE2_SUFFIX(_pcre2_ebcdic_1047_to_ascii_)
2272+
#define _pcre2_ascii_to_ebcdic_1047 PCRE2_SUFFIX(_pcre2_ascii_to_ebcdic_1047_)
22712273

22722274
extern const uint8_t PRIV(OP_lengths)[];
22732275
extern const uint32_t PRIV(callout_end_delims)[];
@@ -2300,6 +2302,8 @@ extern const char *PRIV(unicode_version);
23002302
extern const ucp_type_table PRIV(utt)[];
23012303
extern const char PRIV(utt_names)[];
23022304
extern const size_t PRIV(utt_size);
2305+
extern const uint8_t PRIV(ebcdic_1047_to_ascii)[];
2306+
extern const uint8_t PRIV(ascii_to_ebcdic_1047)[];
23032307

23042308
/* Mode-dependent macros and hidden and private structures are defined in a
23052309
separate file so that pcre2test can include them at all supported widths. When

src/pcre2_tables.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,10 @@ files. */
238238
* Tables for EBCDIC support *
239239
*************************************************/
240240

241-
#if defined(EBCDIC) && (defined(PCRE2_PCRE2TEST) || defined(PCRE2_DFTABLES))
241+
#if defined(EBCDIC) && \
242+
(defined(PCRE2_PCRE2TEST) || defined(PCRE2_DFTABLES) || 'a' != 0x81)
242243

243-
const uint8_t ebcdic_1047_to_ascii[256] = {
244+
const uint8_t PRIV(ebcdic_1047_to_ascii)[256] = {
244245
0x00,0x01,0x02,0x03,0x9c,0x09,0x86,0x7f,0x97,0x8d,0x8e,0x0b,0x0c,0x0d,0x0e,0x0f,
245246
#ifdef EBCDIC_NL25
246247
0x10,0x11,0x12,0x13,0x9d,0x85,0x08,0x87,0x18,0x19,0x92,0x8f,0x1c,0x1d,0x1e,0x1f,
@@ -264,7 +265,7 @@ const uint8_t ebcdic_1047_to_ascii[256] = {
264265
0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0xb3,0xdb,0xdc,0xd9,0xda,0x9f,
265266
};
266267

267-
const uint8_t ascii_to_ebcdic_1047[256] = {
268+
const uint8_t PRIV(ascii_to_ebcdic_1047)[256] = {
268269
#ifdef EBCDIC_NL25
269270
0x00,0x01,0x02,0x03,0x37,0x2d,0x2e,0x2f,0x16,0x05,0x25,0x0b,0x0c,0x0d,0x0e,0x0f,
270271
#else

src/pcre2test.c

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,11 @@ previous definition of PRIV avoids name clashes. */
315315

316316
/* Forward-declarations for PRINTABLE(). */
317317

318+
#if defined(EBCDIC) && !EBCDIC_IO
318319
static void ascii_to_ebcdic_str(uint8_t *buf, size_t len);
319320
static uint32_t ascii_to_ebcdic(uint32_t c);
320321
static uint32_t ebcdic_to_ascii(uint32_t c);
322+
#endif
321323

322324
/* 32-bit integer values in the input are read by strtoul() or strtol(). The
323325
check needed for overflow depends on whether long ints are in fact longer than
@@ -4610,21 +4612,7 @@ if (len < 0)
46104612
else
46114613
{
46124614
fprintf(outfile, "%s", before);
4613-
4614-
/* In the rare configuration of EBCDIC-with-ASCII-compiler, we currently
4615-
output ASCII strings for the error messages, so we do special filtering for
4616-
that here. */
4617-
4618-
#ifdef SUPPORT_PCRE2_16
4619-
if (test_mode == PCRE16_MODE)
4620-
for (int i = 0; i <= len; i++) pbuffer8[i] = (uint8_t)pbuffer16[i];
4621-
#endif
4622-
#ifdef SUPPORT_PCRE2_32
4623-
if (test_mode == PCRE32_MODE)
4624-
for (int i = 0; i <= len; i++) pbuffer8[i] = (uint8_t)pbuffer32[i];
4625-
#endif
4626-
fprintf(outfile, "%s", pbuffer8);
4627-
4615+
PCHARSV(CASTVAR(void *, pbuffer), 0, len, FALSE, outfile);
46284616
fprintf(outfile, "%s", after);
46294617
}
46304618
return len >= 0;
@@ -9921,15 +9909,7 @@ least 128 code units, because it is used for retrieving error messages. */
99219909
}
99229910
else
99239911
{
9924-
#ifdef SUPPORT_PCRE2_16
9925-
if (test_mode == PCRE16_MODE)
9926-
for (int i = 0; i <= len; i++) pbuffer8[i] = (uint8_t)pbuffer16[i];
9927-
#endif
9928-
#ifdef SUPPORT_PCRE2_32
9929-
if (test_mode == PCRE32_MODE)
9930-
for (int i = 0; i <= len; i++) pbuffer8[i] = (uint8_t)pbuffer32[i];
9931-
#endif
9932-
printf("%s", pbuffer8);
9912+
PCHARSV(CASTVAR(void *, pbuffer), 0, len, FALSE, stdout);
99339913
}
99349914
printf("\n");
99359915
if (*endptr == 0) goto EXIT;

0 commit comments

Comments
 (0)