浏览代码

avoid conversion from 'const char*' to 'void *' (warning about 'const')

Roberto Ierusalimschy 14 年之前
父节点
当前提交
22e1c5ebad
共有 1 个文件被更改,包括 15 次插入6 次删除
  1. 15 6
      lbaselib.c

+ 15 - 6
lbaselib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lbaselib.c,v 1.260 2011/02/28 17:32:10 roberto Exp roberto $
+** $Id: lbaselib.c,v 1.261 2011/05/26 16:09:40 roberto Exp roberto $
 ** Basic library
 ** Basic library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -268,6 +268,13 @@ static int luaB_loadfile (lua_State *L) {
 ** =======================================================
 ** =======================================================
 */
 */
 
 
+
+typedef struct {
+char c;
+  const char *mode;
+} loaddata;
+
+
 /*
 /*
 ** check whether a chunk (prefix in 's') satisfies given 'mode'
 ** check whether a chunk (prefix in 's') satisfies given 'mode'
 ** ('t' for text, 'b' for binary). Returns error message (also
 ** ('t' for text, 'b' for binary). Returns error message (also
@@ -298,7 +305,7 @@ static const char *checkrights (lua_State *L, const char *mode, const char *s) {
 */
 */
 static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
 static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
   const char *s;
   const char *s;
-  const char **mode = (const char **)ud;
+  loaddata *ld = (loaddata *)ud;
   luaL_checkstack(L, 2, "too many nested functions");
   luaL_checkstack(L, 2, "too many nested functions");
   lua_pushvalue(L, 1);  /* get function */
   lua_pushvalue(L, 1);  /* get function */
   lua_call(L, 0, 1);  /* call it */
   lua_call(L, 0, 1);  /* call it */
@@ -307,9 +314,9 @@ static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
     return NULL;
     return NULL;
   }
   }
   else if ((s = lua_tostring(L, -1)) != NULL) {
   else if ((s = lua_tostring(L, -1)) != NULL) {
-    if (*mode != NULL) {  /* first time? */
-      s = checkrights(L, *mode, s);  /* check mode */
-      *mode = NULL;  /* to avoid further checks */
+    if (ld->mode != NULL) {  /* first time? */
+      s = checkrights(L, ld->mode, s);  /* check mode */
+      ld->mode = NULL;  /* to avoid further checks */
       if (s) luaL_error(L, s);
       if (s) luaL_error(L, s);
     }
     }
     lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */
     lua_replace(L, RESERVEDSLOT);  /* save string in reserved slot */
@@ -335,9 +342,11 @@ static int luaB_load (lua_State *L) {
   }
   }
   else {  /* loading from a reader function */
   else {  /* loading from a reader function */
     const char *chunkname = luaL_optstring(L, 2, "=(load)");
     const char *chunkname = luaL_optstring(L, 2, "=(load)");
+    loaddata ld;
+    ld.mode = mode;
     luaL_checktype(L, 1, LUA_TFUNCTION);
     luaL_checktype(L, 1, LUA_TFUNCTION);
     lua_settop(L, RESERVEDSLOT);  /* create reserved slot */
     lua_settop(L, RESERVEDSLOT);  /* create reserved slot */
-    status = lua_load(L, generic_reader, &mode, chunkname);
+    status = lua_load(L, generic_reader, &ld, chunkname);
   }
   }
   if (status == LUA_OK && top >= 4) {  /* is there an 'env' argument */
   if (status == LUA_OK && top >= 4) {  /* is there an 'env' argument */
     lua_pushvalue(L, 4);  /* environment for loaded function */
     lua_pushvalue(L, 4);  /* environment for loaded function */