aboutsummaryrefslogtreecommitdiff
path: root/loadlib.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-01-05 11:51:39 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2015-01-05 11:51:39 -0200
commit0adfa773b96d815cab3f17afd7bcafd3eeee7c49 (patch)
tree05c3d1313b5b9eaeabff42a92c58366941ccb1b0 /loadlib.c
parent3317f5c6d9f3c8370430bb8b412b7f7a65b797b2 (diff)
downloadlua-0adfa773b96d815cab3f17afd7bcafd3eeee7c49.tar.gz
lua-0adfa773b96d815cab3f17afd7bcafd3eeee7c49.tar.bz2
lua-0adfa773b96d815cab3f17afd7bcafd3eeee7c49.zip
new macro 'cast_func' adds '__extension__' (in gnu compilers) when
converting void* to function, to avoid warnings
Diffstat (limited to 'loadlib.c')
-rw-r--r--loadlib.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/loadlib.c b/loadlib.c
index 4e1cdf80..e7201c6c 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.122 2014/11/10 14:28:31 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.123 2014/11/12 13:31:51 roberto Exp roberto $
3** Dynamic library loader for Lua 3** Dynamic library loader for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5** 5**
@@ -135,6 +135,18 @@ static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym);
135 135
136#include <dlfcn.h> 136#include <dlfcn.h>
137 137
138/*
139** Macro to covert pointer to void* to pointer to function. This cast
140** is undefined according to ISO C, but POSIX assumes that it must work.
141** (The '__extension__' in gnu compilers is only to avoid warnings.)
142*/
143#if defined(__GNUC__)
144#define cast_func(p) (__extension__ (lua_CFunction)(p))
145#else
146#define cast_func(p) ((lua_CFunction)(p))
147#endif
148
149
138static void lsys_unloadlib (void *lib) { 150static void lsys_unloadlib (void *lib) {
139 dlclose(lib); 151 dlclose(lib);
140} 152}
@@ -148,7 +160,7 @@ static void *lsys_load (lua_State *L, const char *path, int seeglb) {
148 160
149 161
150static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) { 162static lua_CFunction lsys_sym (lua_State *L, void *lib, const char *sym) {
151 lua_CFunction f = (lua_CFunction)dlsym(lib, sym); 163 lua_CFunction f = cast_func(dlsym(lib, sym));
152 if (f == NULL) lua_pushstring(L, dlerror()); 164 if (f == NULL) lua_pushstring(L, dlerror());
153 return f; 165 return f;
154} 166}