From 22e1c5ebadc63f4b6aa1b2db82067151041e75c7 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 16 Jun 2011 11:12:24 -0300 Subject: avoid conversion from 'const char*' to 'void *' (warning about 'const') --- lbaselib.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lbaselib.c b/lbaselib.c index eb06df4e..d5dc913b 100644 --- a/lbaselib.c +++ b/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 ** 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' ** ('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) { const char *s; - const char **mode = (const char **)ud; + loaddata *ld = (loaddata *)ud; luaL_checkstack(L, 2, "too many nested functions"); lua_pushvalue(L, 1); /* get function */ 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; } 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); } 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 */ const char *chunkname = luaL_optstring(L, 2, "=(load)"); + loaddata ld; + ld.mode = mode; luaL_checktype(L, 1, LUA_TFUNCTION); 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 */ lua_pushvalue(L, 4); /* environment for loaded function */ -- cgit v1.2.3-55-g6feb