diff options
author | Mike Pall <mike> | 2011-11-15 16:37:06 +0100 |
---|---|---|
committer | Mike Pall <mike> | 2011-11-15 16:37:06 +0100 |
commit | d4df8d7825709872c779a11f53f12a00503bb948 (patch) | |
tree | be4f45a268c72a88fb1ea9acd9814b957c7c0f8b | |
parent | 8437d0c48d52267f826361cd7f38711bdc02e489 (diff) | |
download | luajit-d4df8d7825709872c779a11f53f12a00503bb948.tar.gz luajit-d4df8d7825709872c779a11f53f12a00503bb948.tar.bz2 luajit-d4df8d7825709872c779a11f53f12a00503bb948.zip |
FFI: Save GetLastError() around ffi.load() and symbol resolving, too.
-rw-r--r-- | src/lj_clib.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/src/lj_clib.c b/src/lj_clib.c index ff576d35..9f69b969 100644 --- a/src/lj_clib.c +++ b/src/lj_clib.c | |||
@@ -169,7 +169,9 @@ static const char *clib_extname(lua_State *L, const char *name) | |||
169 | 169 | ||
170 | static void *clib_loadlib(lua_State *L, const char *name, int global) | 170 | static void *clib_loadlib(lua_State *L, const char *name, int global) |
171 | { | 171 | { |
172 | DWORD oldwerr = GetLastError(); | ||
172 | void *h = (void *)LoadLibraryA(clib_extname(L, name)); | 173 | void *h = (void *)LoadLibraryA(clib_extname(L, name)); |
174 | SetLastError(oldwerr); | ||
173 | if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name); | 175 | if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name); |
174 | UNUSED(global); | 176 | UNUSED(global); |
175 | return h; | 177 | return h; |
@@ -194,6 +196,7 @@ static void clib_unloadlib(CLibrary *cl) | |||
194 | static void *clib_getsym(CLibrary *cl, const char *name) | 196 | static void *clib_getsym(CLibrary *cl, const char *name) |
195 | { | 197 | { |
196 | void *p = NULL; | 198 | void *p = NULL; |
199 | DWORD oldwerr = GetLastError(); | ||
197 | if (cl->handle == CLIB_DEFHANDLE) { /* Search default libraries. */ | 200 | if (cl->handle == CLIB_DEFHANDLE) { /* Search default libraries. */ |
198 | MSize i; | 201 | MSize i; |
199 | for (i = 0; i < CLIB_HANDLE_MAX; i++) { | 202 | for (i = 0; i < CLIB_HANDLE_MAX; i++) { |
@@ -222,6 +225,7 @@ static void *clib_getsym(CLibrary *cl, const char *name) | |||
222 | } else { | 225 | } else { |
223 | p = (void *)GetProcAddress((HINSTANCE)cl->handle, name); | 226 | p = (void *)GetProcAddress((HINSTANCE)cl->handle, name); |
224 | } | 227 | } |
228 | SetLastError(oldwerr); | ||
225 | return p; | 229 | return p; |
226 | } | 230 | } |
227 | 231 | ||