pharo
pharo copied to clipboard
[Feature Request] Unload Library in Windows environment
In pharo, you can use FFI to call library functions. I would like a way to reload a C library in Pharo without restarting the VM. On windows for the moment but it will be necessary in other OS like Linux or MacOs.
Because the VM is a UI application an restarting the UI will be not acceptable by the user each time.
Describe the solution you'd like a unloadLibrary: in the FFILibrary class for example ?
or a reloadLibrary: should be used.
Thanks by advance for discussions on this topic This is a major improvement in our current library test environment
Hi eric can you explain the why you want to reload a library? What is your scenario?
S
On Windows you can use
BOOL FreeLibrary(
[in] HMODULE hLibModule
);
https://learn.microsoft.com/en-us/windows/win32/api/libloaderapi/nf-libloaderapi-freelibrary
Frees the loaded dynamic-link library (DLL) module and, if necessary, decrements its reference count.
I have some libraries which I have which don't be able to restart their context... it is internal one shot function in library called by a command line program... I just want to reuse the function ... and if I start the function 2 times ... it crashes... when I reload the lib with other C binding (python or ... ) no crash... I just reload, and restart to call the function another time. (releasing the memory before to avoir memory leak... )
i will try to implement it ... or it is present in OS-Windows ?
I agree this could be nice to have.
Just be careful that unloading the lib is only part of the deal :) We need also to flush/regenerate all the loaded functions cached in the (already called) ffi methods for that library.
Ok, i should try a pull request for Windows Environment doing a unloadLibrary: aLib calling the FFI on the function and regenerating the cached ffi functions of that library ?
Is there a way to find all ffiCall on a FFILibrary from the ffi cache ? It should be very usefull to reload a library completely. I succeeded in reloading a Windows library... but in order to do that : "We need also to flush/regenerate all the loaded functions cached in the (already called) ffi methods for that library"... i need to know ! :)
Hi Eric, you can do for a class:
FFIMethodRegistry uniqueInstance resetSingleClass: aClass
or for a method
FFIMethodRegistry uniqueInstance removeMethod: aMethod
Cheers, Pablo
Very nice... i've just found it !
I proposed a solution in OS-Windows . Maybe Pharo should have a portable solution for every OS...
Take a look to WinLibrary ... i think it can be enhanced and generalized... Do we close the issue ?
We would like but this is a problem of manpower. For example for calling OS function.