mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
FFI: Save GetLastError() around ffi.load() and symbol resolving, too.
This commit is contained in:
parent
8437d0c48d
commit
d4df8d7825
@ -169,7 +169,9 @@ static const char *clib_extname(lua_State *L, const char *name)
|
|||||||
|
|
||||||
static void *clib_loadlib(lua_State *L, const char *name, int global)
|
static void *clib_loadlib(lua_State *L, const char *name, int global)
|
||||||
{
|
{
|
||||||
|
DWORD oldwerr = GetLastError();
|
||||||
void *h = (void *)LoadLibraryA(clib_extname(L, name));
|
void *h = (void *)LoadLibraryA(clib_extname(L, name));
|
||||||
|
SetLastError(oldwerr);
|
||||||
if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name);
|
if (!h) clib_error(L, "cannot load module " LUA_QS ": %s", name);
|
||||||
UNUSED(global);
|
UNUSED(global);
|
||||||
return h;
|
return h;
|
||||||
@ -194,6 +196,7 @@ static void clib_unloadlib(CLibrary *cl)
|
|||||||
static void *clib_getsym(CLibrary *cl, const char *name)
|
static void *clib_getsym(CLibrary *cl, const char *name)
|
||||||
{
|
{
|
||||||
void *p = NULL;
|
void *p = NULL;
|
||||||
|
DWORD oldwerr = GetLastError();
|
||||||
if (cl->handle == CLIB_DEFHANDLE) { /* Search default libraries. */
|
if (cl->handle == CLIB_DEFHANDLE) { /* Search default libraries. */
|
||||||
MSize i;
|
MSize i;
|
||||||
for (i = 0; i < CLIB_HANDLE_MAX; i++) {
|
for (i = 0; i < CLIB_HANDLE_MAX; i++) {
|
||||||
@ -222,6 +225,7 @@ static void *clib_getsym(CLibrary *cl, const char *name)
|
|||||||
} else {
|
} else {
|
||||||
p = (void *)GetProcAddress((HINSTANCE)cl->handle, name);
|
p = (void *)GetProcAddress((HINSTANCE)cl->handle, name);
|
||||||
}
|
}
|
||||||
|
SetLastError(oldwerr);
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user