Using 'l_uint32' for unicode codepoints in scanner

'l_uint32' is enough for unicode codepoints (versus unsigned long),
and the utf-8 library already uses that type.
This commit is contained in:
Roberto Ierusalimschy 2025-05-08 12:49:39 -03:00
parent 3f0ea90aa8
commit d827e96f33
4 changed files with 7 additions and 7 deletions

6
llex.c
View file

@ -359,12 +359,12 @@ static int readhexaesc (LexState *ls) {
** for error reporting in case of errors; 'i' counts the number of ** for error reporting in case of errors; 'i' counts the number of
** saved characters, so that they can be removed if case of success. ** saved characters, so that they can be removed if case of success.
*/ */
static unsigned long readutf8esc (LexState *ls) { static l_uint32 readutf8esc (LexState *ls) {
unsigned long r; l_uint32 r;
int i = 4; /* number of chars to be removed: start with #"\u{X" */ int i = 4; /* number of chars to be removed: start with #"\u{X" */
save_and_next(ls); /* skip 'u' */ save_and_next(ls); /* skip 'u' */
esccheck(ls, ls->current == '{', "missing '{'"); esccheck(ls, ls->current == '{', "missing '{'");
r = cast_ulong(gethexa(ls)); /* must have at least one digit */ r = cast_uint(gethexa(ls)); /* must have at least one digit */
while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) {
i++; i++;
esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large");

View file

@ -138,7 +138,6 @@ typedef LUAI_UACINT l_uacInt;
#define cast_num(i) cast(lua_Number, (i)) #define cast_num(i) cast(lua_Number, (i))
#define cast_int(i) cast(int, (i)) #define cast_int(i) cast(int, (i))
#define cast_uint(i) cast(unsigned int, (i)) #define cast_uint(i) cast(unsigned int, (i))
#define cast_ulong(i) cast(unsigned long, (i))
#define cast_byte(i) cast(lu_byte, (i)) #define cast_byte(i) cast(lu_byte, (i))
#define cast_uchar(i) cast(unsigned char, (i)) #define cast_uchar(i) cast(unsigned char, (i))
#define cast_char(i) cast(char, (i)) #define cast_char(i) cast(char, (i))

View file

@ -382,7 +382,7 @@ size_t luaO_str2num (const char *s, TValue *o) {
} }
int luaO_utf8esc (char *buff, unsigned long x) { int luaO_utf8esc (char *buff, l_uint32 x) {
int n = 1; /* number of bytes put in buffer (backwards) */ int n = 1; /* number of bytes put in buffer (backwards) */
lua_assert(x <= 0x7FFFFFFFu); lua_assert(x <= 0x7FFFFFFFu);
if (x < 0x80) /* ascii? */ if (x < 0x80) /* ascii? */
@ -637,7 +637,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
} }
case 'U': { /* an 'unsigned long' as a UTF-8 sequence */ case 'U': { /* an 'unsigned long' as a UTF-8 sequence */
char bf[UTF8BUFFSZ]; char bf[UTF8BUFFSZ];
int len = luaO_utf8esc(bf, va_arg(argp, unsigned long)); unsigned long arg = va_arg(argp, unsigned long);
int len = luaO_utf8esc(bf, cast(l_uint32, arg));
addstr2buff(&buff, bf + UTF8BUFFSZ - len, cast_uint(len)); addstr2buff(&buff, bf + UTF8BUFFSZ - len, cast_uint(len));
break; break;
} }

View file

@ -831,7 +831,7 @@ typedef struct Table {
if (msg == NULL) luaD_throw(L, LUA_ERRMEM); /* only after 'va_end' */ } if (msg == NULL) luaD_throw(L, LUA_ERRMEM); /* only after 'va_end' */ }
LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); LUAI_FUNC int luaO_utf8esc (char *buff, l_uint32 x);
LUAI_FUNC lu_byte luaO_ceillog2 (unsigned int x); LUAI_FUNC lu_byte luaO_ceillog2 (unsigned int x);
LUAI_FUNC lu_byte luaO_codeparam (unsigned int p); LUAI_FUNC lu_byte luaO_codeparam (unsigned int p);
LUAI_FUNC l_mem luaO_applyparam (lu_byte p, l_mem x); LUAI_FUNC l_mem luaO_applyparam (lu_byte p, l_mem x);