Skip to content

Commit 4981fca

Browse files
committed
maint: build fix for ucptest and related code tyding up
Since 9a868b0 (Tidy up config.h management (task from README) (#658), 2025-01-11), it fails to build with an "#error" because "config.h" is no longer included directly. Move the check and change some types in the utf8 tables it uses through pcre2_ord2utf() so it better matches its current use.
1 parent 5281d67 commit 4981fca

File tree

5 files changed

+29
-18
lines changed

5 files changed

+29
-18
lines changed

maint/ucptest.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ characters, the list ends with ...
8282
The command "list" must be followed by one of property names script, bool,
8383
type, gbreak or bidi. The defined values for that property are listed. */
8484

85-
#ifndef SUPPORT_UNICODE
86-
#error "Unicode support not enabled"
87-
#endif
88-
8985
#include <ctype.h>
9086
#include <stdio.h>
9187
#include <stdlib.h>
9288
#include <string.h>
9389
#include "../src/pcre2_internal.h"
9490
#include "../src/pcre2_ucp.h"
9591

92+
#ifndef SUPPORT_UNICODE
93+
#error "Unicode support not enabled"
94+
#endif
95+
9696
#ifdef HAVE_UNISTD_H
9797
#include <unistd.h>
9898
#endif

src/pcre2_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ tables are needed only when compiling the 8-bit library. */
22332233

22342234
#if PCRE2_CODE_UNIT_WIDTH == 8
22352235
extern const int PRIV(utf8_table1)[];
2236-
extern const int PRIV(utf8_table1_size);
2236+
extern const unsigned PRIV(utf8_table1_size);
22372237
extern const int PRIV(utf8_table2)[];
22382238
extern const int PRIV(utf8_table3)[];
22392239
extern const uint8_t PRIV(utf8_table4)[];

src/pcre2_ord2utf.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,17 @@ PRIV(ord2utf)(uint32_t cvalue, PCRE2_UCHAR *buffer)
8080
/* Convert to UTF-8 */
8181

8282
#if PCRE2_CODE_UNIT_WIDTH == 8
83-
int i, j;
83+
unsigned int i;
84+
8485
for (i = 0; i < PRIV(utf8_table1_size); i++)
8586
if ((int)cvalue <= PRIV(utf8_table1)[i]) break;
8687
buffer += i;
87-
for (j = i; j > 0; j--)
88+
for (unsigned int j = i; j != 0; j--)
8889
{
8990
*buffer-- = 0x80 | (cvalue & 0x3f);
9091
cvalue >>= 6;
9192
}
92-
*buffer = PRIV(utf8_table2)[i] | cvalue;
93+
*buffer = (PCRE2_UCHAR)(PRIV(utf8_table2)[i] | (int)cvalue);
9394
return i + 1;
9495

9596
/* Convert to UTF-16 */

src/pcre2_tables.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ defined. */
5151
#endif
5252

5353

54+
/* Utility macros */
55+
#define ARR_SIZE(x) sizeof(x)/sizeof(x[0])
5456

5557
/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that
5658
the definition is next to the definition of the opcodes in pcre2_internal.h.
@@ -100,15 +102,15 @@ handling wide characters. */
100102
character. */
101103

102104
const int PRIV(utf8_table1)[] =
103-
{ 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff};
105+
{ 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff };
104106

105-
const int PRIV(utf8_table1_size) = sizeof(PRIV(utf8_table1)) / sizeof(int);
107+
const unsigned PRIV(utf8_table1_size) = ARR_SIZE(PRIV(utf8_table1));
106108

107109
/* These are the indicator bits and the mask for the data bits to set in the
108110
first byte of a character, indexed by the number of additional bytes. */
109111

110-
const int PRIV(utf8_table2)[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc};
111-
const int PRIV(utf8_table3)[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01};
112+
const int PRIV(utf8_table2)[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc };
113+
const int PRIV(utf8_table3)[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
112114

113115
/* Table of the number of extra bytes, indexed by the first byte masked with
114116
0x3f. The highest number for a valid UTF-8 first byte is in fact 0x3d. */

src/pcre2test.c

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3236,7 +3236,8 @@ utf8_to_ord(PCRE2_SPTR8 utf8bytes, PCRE2_SPTR8 end, uint32_t *vptr)
32363236
{
32373237
uint32_t c = *utf8bytes++;
32383238
uint32_t d = c;
3239-
int i, j, s;
3239+
unsigned j;
3240+
int i, s;
32403241

32413242
for (i = -1; i < 6; i++) /* i is number of additional bytes */
32423243
{
@@ -3252,7 +3253,7 @@ if (i == 0 || i == 6) return 0; /* invalid UTF-8 */
32523253
s = 6*i;
32533254
d = (c & utf8_table3[i]) << s;
32543255

3255-
for (j = 0; j < i; j++)
3256+
for (j = 0; (int)j < i; j++)
32563257
{
32573258
if (utf8bytes >= end) return 0;
32583259

@@ -3266,7 +3267,7 @@ for (j = 0; j < i; j++)
32663267

32673268
for (j = 0; j < utf8_table1_size; j++)
32683269
if (d <= (uint32_t)utf8_table1[j]) break;
3269-
if (j != i) return -(i+1);
3270+
if ((int)j != i) return -(i+1);
32703271

32713272
/* Valid value */
32723273

@@ -3340,7 +3341,7 @@ ord_to_utf8(uint32_t cvalue, uint8_t *utf8bytes)
33403341
int i, j;
33413342
if (cvalue > 0x7fffffffu)
33423343
return -1;
3343-
for (i = 0; i < utf8_table1_size; i++)
3344+
for (i = 0; i < (int)utf8_table1_size; i++)
33443345
if (cvalue <= (uint32_t)utf8_table1[i]) break;
33453346
utf8bytes += i;
33463347
for (j = i; j > 0; j--)
@@ -3746,6 +3747,7 @@ if (!utf && (pat_patctl.control & CTL_UTF8_INPUT) == 0)
37463747
{
37473748
for (; len > 0; len--) *pp++ = *p++;
37483749
}
3750+
37493751
else while (len > 0)
37503752
{
37513753
uint32_t c;
@@ -3830,7 +3832,6 @@ if (pbuffer32_size < 4*len + 4)
38303832
}
38313833

38323834
pp = pbuffer32;
3833-
38343835
if (!utf && (pat_patctl.control & CTL_UTF8_INPUT) == 0)
38353836
{
38363837
for (; len > 0; len--) *pp++ = *p++;
@@ -8189,15 +8190,22 @@ while ((c = *p++) != 0)
81898190

81908191
if (c != '\\' || subject_literal)
81918192
{
8193+
#ifdef SUPPORT_PCRE2_32
81928194
uint32_t topbit = 0;
81938195
if (test_mode == PCRE32_MODE && c == 0xff && *p != 0)
81948196
{
81958197
topbit = 0x80000000;
81968198
c = *p++;
81978199
}
8200+
#endif
81988201
if ((utf || (pat_patctl.control & CTL_UTF8_INPUT) != 0) &&
8199-
HASUTF8EXTRALEN(c)) { GETUTF8INC(c, p); }
8202+
HASUTF8EXTRALEN(c))
8203+
{
8204+
GETUTF8INC(c, p);
8205+
}
8206+
#ifdef SUPPORT_PCRE2_32
82008207
c |= topbit;
8208+
#endif
82018209
}
82028210

82038211
/* Handle backslash escapes */

0 commit comments

Comments
 (0)