aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-05-08 12:49:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2025-05-08 12:49:39 -0300
commitd827e96f33056bcc0daca0c04b3273604f9d5986 (patch)
treeec3d9fb723319edc0105d7bea652c8d07c064770
parent3f0ea90aa8b8493485637f6e8d2a070a1ac0d5cb (diff)
downloadlua-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.c6
-rw-r--r--llimits.h1
-rw-r--r--lobject.c5
-rw-r--r--lobject.h2
4 files changed, 7 insertions, 7 deletions
diff --git a/llex.c b/llex.c
index 9d93224f..edeb48fe 100644
--- a/llex.c
+++ b/llex.c
@@ -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*/
362static unsigned long readutf8esc (LexState *ls) { 362static 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");
diff --git a/llimits.h b/llimits.h
index 710dc1b4..b1fc384b 100644
--- a/llimits.h
+++ b/llimits.h
@@ -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))
diff --git a/lobject.c b/lobject.c
index 68566a2b..57fc6a91 100644
--- a/lobject.c
+++ b/lobject.c
@@ -382,7 +382,7 @@ size_t luaO_str2num (const char *s, TValue *o) {
382} 382}
383 383
384 384
385int luaO_utf8esc (char *buff, unsigned long x) { 385int 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 }
diff --git a/lobject.h b/lobject.h
index b5ca3668..bc2f69ab 100644
--- a/lobject.h
+++ b/lobject.h
@@ -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
834LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); 834LUAI_FUNC int luaO_utf8esc (char *buff, l_uint32 x);
835LUAI_FUNC lu_byte luaO_ceillog2 (unsigned int x); 835LUAI_FUNC lu_byte luaO_ceillog2 (unsigned int x);
836LUAI_FUNC lu_byte luaO_codeparam (unsigned int p); 836LUAI_FUNC lu_byte luaO_codeparam (unsigned int p);
837LUAI_FUNC l_mem luaO_applyparam (lu_byte p, l_mem x); 837LUAI_FUNC l_mem luaO_applyparam (lu_byte p, l_mem x);