Przeglądaj źródła

better to use 'long' to represent UTF-8 code points

Roberto Ierusalimschy 10 lat temu
rodzic
commit
34b6664dcb
4 zmienionych plików z 13 dodań i 12 usunięć
  1. 3 3
      llex.c
  2. 4 3
      lobject.c
  3. 2 2
      lobject.h
  4. 4 4
      lutf8lib.c

+ 3 - 3
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 '{'");

+ 4 - 3
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;
       }

+ 2 - 2
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);

+ 4 - 4
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,