[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [ANN] Lua 5.4.0 (rc2) now available
- From: François Perrad <francois.perrad@...>
- Date: Fri, 1 May 2020 13:42:26 +0200
avoid the unusual use of '&' in argument to sizeof
diff --git a/src/ldump.c b/src/ldump.c
index fbadbcc..986f97a 100644
--- a/src/ldump.c
+++ b/src/ldump.c
@@ -36,6 +36,8 @@
#define dumpLiteral(D, s) dumpBlock(D,s,sizeof(s) - sizeof(char))
+#define dumpVar(D,x) dumpBlock(D,&x,sizeof(x))
+
static void dumpBlock (DumpState *D, const void *b, size_t size) {
if (D->status == 0 && size > 0) {
@@ -46,9 +48,6 @@
}
-#define dumpVar(D,x) dumpVector(D,&x,1)
-
-
static void dumpByte (DumpState *D, int y) {
lu_byte x = (lu_byte)y;
dumpVar(D, x);
diff --git a/src/lundump.c b/src/lundump.c
index 1736499..44aa898 100644
--- a/src/lundump.c
+++ b/src/lundump.c
@@ -49,15 +49,14 @@
*/
#define loadVector(S,b,n) loadBlock(S,b,(n)*sizeof((b)[0]))
+#define loadVar(S,x) loadBlock(S,&x,sizeof(x))
+
static void loadBlock (LoadState *S, void *b, size_t size) {
if (luaZ_read(S->Z, b, size) != 0)
error(S, "truncated chunk");
}
-#define loadVar(S,x) loadVector(S,&x,1)
-
-
static lu_byte loadByte (LoadState *S) {
int b = zgetc(S->Z);
if (b == EOZ)
--
the name of a function gives the address of this function,
so the & before the name is useless
diff --git a/src/lauxlib.c b/src/lauxlib.c
index 7235909..77b9f8e 100644
--- a/src/lauxlib.c
+++ b/src/lauxlib.c
@@ -1034,7 +1034,7 @@ LUALIB_API lua_State *luaL_newstate (void) {
lua_State *L = lua_newstate(l_alloc, NULL);
if (L) {
int *warnstate; /* space for warning state */
- lua_atpanic(L, &panic);
+ lua_atpanic(L, panic);
warnstate = (int *)lua_newuserdatauv(L, sizeof(int), 0);
luaL_ref(L, LUA_REGISTRYINDEX); /* make sure it won't be collected */
*warnstate = 0; /* default is warnings off */
diff --git a/src/liolib.c b/src/liolib.c
index 08d1839..57591a7 100644
--- a/src/liolib.c
+++ b/src/liolib.c
@@ -241,7 +241,7 @@ static int io_fclose (lua_State *L) {
static LStream *newfile (lua_State *L) {
LStream *p = newprefile(L);
p->f = NULL;
- p->closef = &io_fclose;
+ p->closef = io_fclose;
return p;
}
@@ -279,7 +279,7 @@ static int io_popen (lua_State *L) {
const char *mode = luaL_optstring(L, 2, "r");
LStream *p = newprefile(L);
p->f = l_popen(L, filename, mode);
- p->closef = &io_pclose;
+ p->closef = io_pclose;
return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
}
@@ -781,7 +781,7 @@ static void createmeta (lua_State *L) {
*/
static int io_noclose (lua_State *L) {
LStream *p = tolstream(L);
- p->closef = &io_noclose; /* keep file opened */
+ p->closef = io_noclose; /* keep file opened */
luaL_pushfail(L);
lua_pushliteral(L, "cannot close standard file");
return 2;
@@ -792,7 +792,7 @@ static void createstdfile (lua_State *L, FILE *f, const char *k,
const char *fname) {
LStream *p = newprefile(L);
p->f = f;
- p->closef = &io_noclose;
+ p->closef = io_noclose;
if (k != NULL) {
lua_pushvalue(L, -1);
lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */
diff --git a/src/lstate.c b/src/lstate.c
index 8fba70d..484e39d 100644
--- a/src/lstate.c
+++ b/src/lstate.c
@@ -74,7 +74,7 @@ static unsigned int luai_makeseed (lua_State *L) {
int p = 0;
addbuff(buff, p, L); /* heap variable */
addbuff(buff, p, &h); /* local variable */
- addbuff(buff, p, &lua_newstate); /* public function */
+ addbuff(buff, p, lua_newstate); /* public function */
lua_assert(p == sizeof(buff));
return luaS_hash(buff, p, h, 1);
}
diff --git a/src/lua.c b/src/lua.c
index 18f53c3..b69369b 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -622,7 +622,7 @@ int main (int argc, char **argv) {
l_message(argv[0], "cannot create state: not enough memory");
return EXIT_FAILURE;
}
- lua_pushcfunction(L, &pmain); /* to call 'pmain' in protected mode */
+ lua_pushcfunction(L, pmain); /* to call 'pmain' in protected mode */
lua_pushinteger(L, argc); /* 1st argument */
lua_pushlightuserdata(L, argv); /* 2nd argument */
status = lua_pcall(L, 2, 1, 0); /* do the call */
diff --git a/src/luac.c b/src/luac.c
index 56ddc41..00264f2 100644
--- a/src/luac.c
+++ b/src/luac.c
@@ -202,7 +202,7 @@ int main(int argc, char* argv[])
if (argc<=0) usage("no input files given");
L=luaL_newstate();
if (L==NULL) fatal("cannot create state: not enough memory");
- lua_pushcfunction(L,&pmain);
+ lua_pushcfunction(L,pmain);
lua_pushinteger(L,argc);
lua_pushlightuserdata(L,argv);
if (lua_pcall(L,2,0,0)!=LUA_OK) fatal(lua_tostring(L,-1));
--
this typedef is only used in the LUA_DL_DLL part
diff --git a/src/loadlib.c b/src/loadlib.c
index ddfecca..c79db80 100644
--- a/src/loadlib.c
+++ b/src/loadlib.c
@@ -68,13 +68,6 @@ static const char *const CLIBS = "_CLIBS";
/*
-** Special type equivalent to '(void*)' for functions in gcc
-** (to supress warnings when converting function pointers)
-*/
-typedef void (*voidf)(void);
-
-
-/*
** system-dependent functions
*/
@@ -156,6 +149,13 @@ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {
#include <windows.h>
+/*
+** Special type equivalent to '(void*)' for functions in gcc
+** (to supress warnings when converting function pointers)
+*/
+typedef void (*voidf)(void);
+
+
/*
** optional flags for LoadLibraryEx
--
_______________________________________________
lua-l mailing list -- lua-l@lists.lua.org
To unsubscribe send an email to lua-l-leave@lists.lua.org