Skip to content

Commit 424d89c

Browse files
committed
WANT_UTF8 = 0 is now fixed
1 parent 0e5d172 commit 424d89c

2 files changed

Lines changed: 24 additions & 3 deletions

File tree

src/runtime/bfile.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,13 @@ add_bwt_compressor(BFILE *file)
11711171

11721172
/***************** BFILE with UTF8 encode/decode *******************/
11731173

1174-
#if WANT_UTF8
1174+
/*
1175+
* This transducer is always compiled in: mk_std() and mkStringU() in eval.c
1176+
* use it unconditionally for stdio and ByteString-to-String decoding, so it
1177+
* must exist regardless of WANT_UTF8. The flag instead selects the decode
1178+
* policy below: real UTF-8 when set, one Char per raw byte when not, so
1179+
* every byte<->Char boundary in the runtime agrees on what "no UTF-8" means.
1180+
*/
11751181
struct BFILE_utf8 {
11761182
BFILE mets;
11771183
BFILE *bfile;
@@ -1184,7 +1190,7 @@ getb_utf8(BFILE *bp)
11841190
{
11851191
struct BFILE_utf8 *p = (struct BFILE_utf8*)bp;
11861192
CHECKBFILE(bp, getb_utf8);
1187-
int c1, c2, c3, c4;
1193+
int c1;
11881194

11891195
/* Do we have an ungetb character? */
11901196
if (p->unget >= 0) {
@@ -1193,6 +1199,10 @@ getb_utf8(BFILE *bp)
11931199
return c1;
11941200
}
11951201
c1 = getb(p->bfile);
1202+
#if !WANT_UTF8
1203+
return c1; /* one Char per raw byte, no decoding */
1204+
#else
1205+
int c2, c3, c4;
11961206
if (c1 < 0)
11971207
return -1;
11981208
if ((c1 & 0x80) == 0)
@@ -1224,6 +1234,7 @@ getb_utf8(BFILE *bp)
12241234
}
12251235
ERR("getb_utf8");
12261236
NOTREACHED;
1237+
#endif /* WANT_UTF8 */
12271238
}
12281239

12291240
void
@@ -1243,6 +1254,10 @@ putb_utf8(int c, BFILE *bp)
12431254
CHECKBFILE(bp, getb_utf8);
12441255
if (c < 0)
12451256
ERR("putb_utf8: < 0");
1257+
#if !WANT_UTF8
1258+
putb(c, p->bfile); /* one raw byte per Char, no encoding */
1259+
return;
1260+
#else
12461261
if (0 < c && c < 0x80) { /* modified UTF-8 avoids 0 */
12471262
putb(c, p->bfile);
12481263
return;
@@ -1266,6 +1281,7 @@ putb_utf8(int c, BFILE *bp)
12661281
return;
12671282
}
12681283
ERR("putb_utf8");
1284+
#endif /* WANT_UTF8 */
12691285
}
12701286

12711287
void
@@ -1306,7 +1322,6 @@ add_utf8(BFILE *file)
13061322

13071323
return (BFILE*)p;
13081324
}
1309-
#endif /* WANT_UTF8 */
13101325

13111326
/***************** BFILE that just buffers *******************/
13121327

src/runtime/eval.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4698,6 +4698,11 @@ headutf8(struct bytestring bs, void **ret)
46984698
uint8_t *p = bs.bs_array;
46994699
if (bs.bs_size == 0)
47004700
ERR("headUTF8 0");
4701+
#if !WANT_UTF8
4702+
if (ret)
4703+
*ret = p + 1;
4704+
return *p;
4705+
#else
47014706
int c1 = *p++;
47024707
if ((c1 & 0x80) == 0) {
47034708
if (ret)
@@ -4730,6 +4735,7 @@ headutf8(struct bytestring bs, void **ret)
47304735
}
47314736
ERR("headUTF8 4");
47324737
NOTREACHED;
4738+
#endif /* WANT_UTF8 */
47334739
}
47344740

47354741
/* Evaluate to an INT */

0 commit comments

Comments
 (0)