From 34b6664dcb28b18ca3f08ed5e36da094b007eb7b Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 1 Oct 2014 08:52:33 -0300 Subject: better to use 'long' to represent UTF-8 code points --- llex.c | 6 +++--- lobject.c | 7 ++++--- lobject.h | 4 ++-- lutf8lib.c | 8 ++++---- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/llex.c b/llex.c index 4f8756a6..66a3e3c4 100644 --- a/llex.c +++ b/llex.c @@ -1,5 +1,5 @@ /* -** $Id: llex.c,v 2.79 2014/07/18 12:17:54 roberto Exp roberto $ +** $Id: llex.c,v 2.80 2014/07/18 13:36:14 roberto Exp roberto $ ** Lexical Analyzer ** See Copyright Notice in lua.h */ @@ -360,8 +360,8 @@ static int readhexaesc (LexState *ls) { } -static unsigned int readutf8esc (LexState *ls) { - unsigned int r; +static unsigned long readutf8esc (LexState *ls) { + unsigned long r; int i = 4; /* chars to be removed: '\', 'u', '{', and first digit */ save_and_next(ls); /* skip 'u' */ esccheck(ls, ls->current == '{', "missing '{'"); diff --git a/lobject.c b/lobject.c index e7ce0141..0d59d344 100644 --- a/lobject.c +++ b/lobject.c @@ -1,5 +1,5 @@ /* -** $Id: lobject.c,v 2.88 2014/07/30 14:00:14 roberto Exp roberto $ +** $Id: lobject.c,v 2.89 2014/08/01 17:24:02 roberto Exp roberto $ ** Some generic functions over Lua objects ** See Copyright Notice in lua.h */ @@ -310,8 +310,9 @@ size_t luaO_str2num (const char *s, TValue *o) { } -int luaO_utf8esc (char *buff, unsigned int x) { +int luaO_utf8esc (char *buff, unsigned long x) { int n = 1; /* number of bytes put in buffer (backwards) */ + lua_assert(x <= 0x10FFFF); if (x < 0x80) /* ascii? */ buff[UTF8BUFFSZ - 1] = x; else { /* need continuation bytes */ @@ -402,7 +403,7 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) { } case 'U': { char buff[UTF8BUFFSZ]; - int l = luaO_utf8esc(buff, va_arg(argp, int)); + int l = luaO_utf8esc(buff, cast(long, va_arg(argp, long))); pushstr(L, buff + UTF8BUFFSZ - l, l); break; } diff --git a/lobject.h b/lobject.h index 13fe3423..c721d3e8 100644 --- a/lobject.h +++ b/lobject.h @@ -1,5 +1,5 @@ /* -** $Id: lobject.h,v 2.101 2014/07/30 14:00:14 roberto Exp roberto $ +** $Id: lobject.h,v 2.102 2014/09/04 18:15:29 roberto Exp roberto $ ** Type definitions for Lua objects ** See Copyright Notice in lua.h */ @@ -521,7 +521,7 @@ LUAI_DDEC const TValue luaO_nilobject_; LUAI_FUNC int luaO_int2fb (unsigned int x); LUAI_FUNC int luaO_fb2int (int x); -LUAI_FUNC int luaO_utf8esc (char *buff, unsigned int x); +LUAI_FUNC int luaO_utf8esc (char *buff, unsigned long x); LUAI_FUNC int luaO_ceillog2 (unsigned int x); LUAI_FUNC void luaO_arith (lua_State *L, int op, const TValue *p1, const TValue *p2, TValue *res); diff --git a/lutf8lib.c b/lutf8lib.c index e9557d61..3cf2f1cf 100644 --- a/lutf8lib.c +++ b/lutf8lib.c @@ -1,5 +1,5 @@ /* -** $Id: lutf8lib.c,v 1.9 2014/05/14 18:33:37 roberto Exp roberto $ +** $Id: lutf8lib.c,v 1.10 2014/07/16 13:56:14 roberto Exp roberto $ ** Standard library for UTF-8 manipulation ** See Copyright Notice in lua.h */ @@ -123,9 +123,9 @@ static int codepoint (lua_State *L) { static void pushutfchar (lua_State *L, int arg) { - int code = luaL_checkint(L, arg); + lua_Integer code = luaL_checkinteger(L, arg); luaL_argcheck(L, 0 <= code && code <= MAXUNICODE, arg, "value out of range"); - lua_pushfstring(L, "%U", code); + lua_pushfstring(L, "%U", (long)code); } @@ -157,7 +157,7 @@ static int utfchar (lua_State *L) { static int byteoffset (lua_State *L) { size_t len; const char *s = luaL_checklstring(L, 1, &len); - int n = luaL_checkint(L, 2); + lua_Integer n = luaL_checkinteger(L, 2); lua_Integer posi = (n >= 0) ? 1 : len + 1; posi = u_posrelat(luaL_optinteger(L, 3, posi), len); luaL_argcheck(L, 1 <= posi && --posi <= (lua_Integer)len, 3, -- cgit v1.2.3-55-g6feb