about summary refs log tree commit diff stats
path: root/src/librarian
diff options
context:
space:
mode:
authorptitSeb <sebastien.chev@gmail.com>2023-04-25 14:03:28 +0200
committerptitSeb <sebastien.chev@gmail.com>2023-04-25 14:03:28 +0200
commit549c42ac1913c06547abcc99c8ebb6dc745fe4e4 (patch)
treebb469a406f9e457ad231acf5a747f715e8985726 /src/librarian
parent6bfeb156551ce98d4feafb6fe764bbe4fd1cab03 (diff)
downloadbox64-549c42ac1913c06547abcc99c8ebb6dc745fe4e4.tar.gz
box64-549c42ac1913c06547abcc99c8ebb6dc745fe4e4.zip
Improved/fixed (agaaaaain) Load/Unload of library (might help #740 &nd #742)
Diffstat (limited to 'src/librarian')
-rwxr-xr-xsrc/librarian/librarian.c23
-rwxr-xr-xsrc/librarian/library.c24
2 files changed, 33 insertions, 14 deletions
diff --git a/src/librarian/librarian.c b/src/librarian/librarian.c
index 6733c3af..e480f907 100755
--- a/src/librarian/librarian.c
+++ b/src/librarian/librarian.c
@@ -318,11 +318,6 @@ int AddNeededLib(lib_t* maplib, int local, int bindnow, needed_libs_t* needed, b
     }
     // error while loadind lib, unload...
     if(ret) {
-        for(int i=0; i<needed->size; ++i) {
-            if(box64_log>=LOG_DEBUG && needed->libs[i])
-                printf_log(LOG_DEBUG, "Will decref after failed load %s\n", needed->names[i]);
-            AddNeededLib_remove(maplib, local, &needed->libs[i], box64, emu);
-        }
         return ret;
     }
     // add dependant libs and init them
@@ -332,15 +327,19 @@ int AddNeededLib(lib_t* maplib, int local, int bindnow, needed_libs_t* needed, b
             if(!allow_missing_libs) ret = 1;
         }
     // error while loadind lib, unload...
-    if(ret) {
-        for(int i=0; i<needed->size; ++i) {
-            if(box64_log>=LOG_DEBUG && needed->libs[i])
-                printf_log(LOG_DEBUG, "Will remove after failed init %s\n", needed->names[i]);
-            AddNeededLib_remove(maplib, local, &needed->libs[i], box64, emu);
-        }
-    }
     return ret;
 }
+EXPORTDYN
+void RemoveNeededLib(lib_t* maplib, int local, needed_libs_t* needed, box64context_t* box64, x64emu_t* emu)
+{
+    if(!needed) // no needed libs, no problems
+        return;
+    for(int i=0; i<needed->size; ++i) {
+        if(box64_log>=LOG_DEBUG && needed->libs[i])
+            printf_log(LOG_DEBUG, "Will remove after failed init %s\n", needed->names[i]);
+        AddNeededLib_remove(maplib, local, &needed->libs[i], box64, emu);
+    }
+}
 
 library_t* GetLibMapLib(lib_t* maplib, const char* name)
 {
diff --git a/src/librarian/library.c b/src/librarian/library.c
index 9652fe7e..4c7995a7 100755
--- a/src/librarian/library.c
+++ b/src/librarian/library.c
@@ -1047,6 +1047,24 @@ void add1_neededlib(needed_libs_t* needed)
     needed->names = (char**)realloc(needed->names, needed->cap*sizeof(char*));
     needed->size++;
 }
+void add1lib_neededlib(needed_libs_t* needed, library_t* lib, const char* name)
+{
+    if(!needed || !lib)
+        return;
+    // check if lib is already present
+    for (int i=0; i<needed->size; ++i)
+        if(needed->libs[i]==lib)
+            return;
+    // add it
+    if(needed->size+1<=needed->cap)
+        return;
+    needed->cap = needed->size+1;
+    needed->libs = (library_t**)realloc(needed->libs, needed->cap*sizeof(library_t*));
+    needed->names = (char**)realloc(needed->names, needed->cap*sizeof(char*));
+    needed->libs[needed->size] = lib;
+    needed->names[needed->size] = name;
+    needed->size++;
+}
 needed_libs_t* copy_neededlib(needed_libs_t* needed)
 {
     if(!needed)
@@ -1098,8 +1116,10 @@ int DecRefCount(library_t** lib, x64emu_t* emu)
 {
     if(!lib || !*lib)
         return 1;
-    if((*lib)->type==LIB_UNNKNOW)
-        return 1;
+    if((*lib)->type==LIB_UNNKNOW) {
+        Free1Library(lib, emu);
+        return 0;
+    }
     int ret = 1;
     needed_libs_t* needed = NULL;
     int freed = 0;