Browse Source

FFI: Save GetLastError() around ffi.load() and symbol resolving, too.

Mike Pall 13 years ago
parent
commit
d4df8d7825
1 changed files with 4 additions and 0 deletions
  1. 4 0
      src/lj_clib.c

+ 4 - 0
src/lj_clib.c

@@ -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;
 }
 }