diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-08 12:49:39 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-05-08 12:49:39 -0300 |
commit | d827e96f33056bcc0daca0c04b3273604f9d5986 (patch) | |
tree | ec3d9fb723319edc0105d7bea652c8d07c064770 | |
parent | 3f0ea90aa8b8493485637f6e8d2a070a1ac0d5cb (diff) | |
download | lua-d827e96f33056bcc0daca0c04b3273604f9d5986.tar.gz lua-d827e96f33056bcc0daca0c04b3273604f9d5986.tar.bz2 lua-d827e96f33056bcc0daca0c04b3273604f9d5986.zip |
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.
-rw-r--r-- | llex.c | 6 | ||||
-rw-r--r-- | llimits.h | 1 | ||||
-rw-r--r-- | lobject.c | 5 | ||||
-rw-r--r-- | lobject.h | 2 |
4 files changed, 7 insertions, 7 deletions
@@ -359,12 +359,12 @@ static int readhexaesc (LexState *ls) { | |||
359 | ** for error reporting in case of errors; 'i' counts the number of | 359 | ** for error reporting in case of errors; 'i' counts the number of |
360 | ** saved characters, so that they can be removed if case of success. | 360 | ** saved characters, so that they can be removed if case of success. |
361 | */ | 361 | */ |
362 | static unsigned long readutf8esc (LexState *ls) { | 362 | static l_uint32 readutf8esc (LexState *ls) { |
363 | unsigned long r; | 363 | l_uint32 r; |
364 | int i = 4; /* number of chars to be removed: start with #"\u{X" */ | 364 | int i = 4; /* number of chars to be removed: start with #"\u{X" */ |
365 | save_and_next(ls); /* skip 'u' */ | 365 | save_and_next(ls); /* skip 'u' */ |
366 | esccheck(ls, ls->current == '{', "missing '{'"); | 366 | esccheck(ls, ls->current == '{', "missing '{'"); |
367 | r = cast_ulong(gethexa(ls)); /* must have at least one digit */ | 367 | r = cast_uint(gethexa(ls)); /* must have at least one digit */ |
368 | while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { | 368 | while (cast_void(save_and_next(ls)), lisxdigit(ls->current)) { |
369 | i++; | 369 | i++; |
370 | esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); | 370 | esccheck(ls, r <= (0x7FFFFFFFu >> 4), "UTF-8 value too large"); |
@@ -138,7 +138,6 @@ typedef LUAI_UACINT l_uacInt; | |||
138 | #define cast_num(i) cast(lua_Number, (i)) | 138 | #define cast_num(i) cast(lua_Number, (i)) |
139 | #define cast_int(i) cast(int, (i)) | 139 | #define cast_int(i) cast(int, (i)) |
140 | #define cast_uint(i) cast(unsigned int, (i)) | 140 | #define cast_uint(i) cast(unsigned int, (i)) |
141 | #define cast_ulong(i) cast(unsigned long, (i)) | ||
142 | #define cast_byte(i) cast(lu_byte, (i)) | 141 | #define cast_byte(i) cast(lu_byte, (i)) |
143 | #define cast_uchar(i) cast(unsigned char, (i)) | 142 | #define cast_uchar(i) cast(unsigned char, (i)) |
144 | #define cast_char(i) cast(char, (i)) | 143 | #define cast_char(i) cast(char, (i)) |
@@ -382,7 +382,7 @@ size_t luaO_str2num (const char *s, TValue *o) { | |||
382 | } | 382 | } |
383 | 383 | ||
384 | 384 | ||
385 | int luaO_utf8esc (char *buff, unsigned long x) { | 385 | int luaO_utf8esc (char *buff, l_uint32 x) { |
386 | int n = 1; /* number of bytes put in buffer (backwards) */ | 386 | int n = 1; /* number of bytes put in buffer (backwards) */ |
387 | lua_assert(x <= 0x7FFFFFFFu); | 387 | lua_assert(x <= 0x7FFFFFFFu); |
388 | if (x < 0x80) /* ascii? */ | 388 | if (x < 0x80) /* ascii? */ |
@@ -637,7 +637,8 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { | |||
637 | } | 637 | } |
638 | case 'U': { /* an 'unsigned long' as a UTF-8 sequence */ | 638 | case 'U': { /* an 'unsigned long' as a UTF-8 sequence */ |
639 | char bf[UTF8BUFFSZ]; | 639 | char bf[UTF8BUFFSZ]; |
640 | int len = luaO_utf8esc(bf, va_arg(argp, unsigned long)); | 640 | unsigned long arg = va_arg(argp, unsigned long); |
641 | int len = luaO_utf8esc(bf, cast(l_uint32, arg)); | ||
641 | addstr2buff(&buff, bf + UTF8BUFFSZ - len, cast_uint(len)); | 642 | addstr2buff(&buff, bf + UTF8BUFFSZ - len, cast_uint(len)); |
642 | break; | 643 | break; |
643 | } | 644 | } |
@@ -831,7 +831,7 @@ typedef struct Table { | |||
831 | if (msg == NULL) luaD_throw(L, LUA_ERRMEM); /* only after 'va_end' */ } | 831 | if (msg == NULL) luaD_throw(L, LUA_ERRMEM); /* only after 'va_end' */ } |
832 | 832 | ||
833 | 833 | ||
834 | LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); | 834 | LUAI_FUNC int luaO_utf8esc (char *buff, l_uint32 x); |
835 | LUAI_FUNC lu_byte luaO_ceillog2 (unsigned int x); | 835 | LUAI_FUNC lu_byte luaO_ceillog2 (unsigned int x); |
836 | LUAI_FUNC lu_byte luaO_codeparam (unsigned int p); | 836 | LUAI_FUNC lu_byte luaO_codeparam (unsigned int p); |
837 | LUAI_FUNC l_mem luaO_applyparam (lu_byte p, l_mem x); | 837 | LUAI_FUNC l_mem luaO_applyparam (lu_byte p, l_mem x); |