Closed bobi6666 closed 2 years ago
Is https://docs.rs/libloading/latest/libloading/os/windows/struct.Library.html#method.into_raw what you are thinking of?
close is there but close is not what i need because that taking ownership and dropping lib but i would like to free library handle and in to same struct load new library with some external function or load with flags
2022-07-12 21:26 GMT+02:00, Simonas Kazlauskas @.***>:
Is https://docs.rs/libloading/latest/libloading/os/windows/struct.Library.html#method.into_raw what you are thinking of?
-- Reply to this email directly or view it on GitHub: https://github.com/nagisa/rust_libloading/issues/106#issuecomment-1182347762 You are receiving this because you authored the thread.
Message ID: @.***>
Sorry, I have no idea what you’re trying to achieve from your explanation, nor how close
is relevant to your problem. The methods I linked you were into_raw
and from_raw
. These would give you an ability to convert os::*::Library
to and from a raw OS handle, which is what I understood your question to be about. You can convert between the top-level Library
and os::*::Library
throug their From
trait implementations.
If that does not in any way help, then you’ll need to provide some code examples demonstrating your use case, or failing that describe your problem in a different way.
I would need a getter to get the handle of the library inside the lib structure, but then also a setter to be able to change it, because if I wanted a free library now, for example, I wouldn't be able to do that free_current_lib(library.0); due to the fact that this field is private and therefore it is not possible to reload it again via load_with_flags, but it is also not possible to use free without losing the owner ship of the structure
2022-07-12 23:00 GMT+02:00, Simonas Kazlauskas @.***>:
Sorry, I have no idea what you’re trying to achieve from your explanation, nor how
close
is relevant to your problem. The methods I linked you wereinto_raw
andfrom_raw
. These would give you an ability to convertos::*::Library
to and from a raw OS handle, which is what I understood your question to be about. You can convert between the top-levelLibrary
andos::*::Library
throug theirFrom
trait implementations.If that does not in any way help, then you’ll need to provide some code examples demonstrating your use case, or failing that describe your problem in a different way.
--
Reply to this email directly or view it on GitHub:
https://github.com/nagisa/rust_libloading/issues/106#issuecomment-1182495896
You are receiving this because you authored the thread.
Message ID: @.***>
hope you understood my explanation now but if no i will try to create some pseudo code
2022-07-12 23:07 GMT+02:00, Peter Kubek @.***>:
I would need a getter to get the handle of the library inside the lib structure, but then also a setter to be able to change it, because if I wanted a free library now, for example, I wouldn't be able to do that free_current_lib(library.0); due to the fact that this field is private and therefore it is not possible to reload it again via load_with_flags, but it is also not possible to use free without losing the owner ship of the structure
2022-07-12 23:00 GMT+02:00, Simonas Kazlauskas @.***>:
Sorry, I have no idea what you’re trying to achieve from your explanation, nor how
close
is relevant to your problem. The methods I linked you wereinto_raw
andfrom_raw
. These would give you an ability to convertos::*::Library
to and from a raw OS handle, which is what I understood your question to be about. You can convert between the top-levelLibrary
andos::*::Library
throug theirFrom
trait implementations.If that does not in any way help, then you’ll need to provide some code examples demonstrating your use case, or failing that describe your problem in a different way.
--
Reply to this email directly or view it on GitHub:
https://github.com/nagisa/rust_libloading/issues/106#issuecomment-1182495896
You are receiving this because you authored the thread.
Message ID: @.***>
Ah, so what you’re asking for is for Library
to internally support nullary states. Doing so is generally frowned upon in the Rust ecosystem, primarily because composition provides a more flexible and elegant mechanism to achieve that already.
Have you considered composing the Library
with an Option
and potentially some type with interior mutability? Perhaps RefCell<Option<Library>>
, or maybe something with a Mutex
? In that case a None
would represent a “freed” library, and as long as you have a Some(...)
, you can Option::take
out of it and do whatever you want with the library – including close
ing it, or converting it to native handles. Once you have a library opened with new flags or whatever, you can Option::replace
it to the place of the old Library
as well. All without Library
needing any special support for nullary states.
do you have some example how to do that? because i tried that with refcell but if i want to free old library and load new static init tells me that i can't move out of static because free calling drop
2022-07-13 15:19 GMT+02:00, Simonas Kazlauskas @.***>:
Ah, so what you’re asking for is for
Library
to internally support nullary states. Doing so is generally frowned upon in the Rust ecosystem, primarily because composition provides a more flexible and elegant mechanism to achieve that already.Have you considered composing the
Library
with anOption
and potentially some type with interior mutability? PerhapsRefCell<Option<Library>>
, or maybe something with aMutex
? In that case aNone
would represent a “freed” library, and as long as you have aSome(...)
, you canOption::take
out of it and do whatever you want with the library – includingclose
ing it, or converting it to native handles. Once you have a library opened with new flags or whatever, you canOption::replace
it to the place of the oldLibrary
as well. All withoutLibrary
needing any special support for nullary states.--
Reply to this email directly or view it on GitHub:
https://github.com/nagisa/rust_libloading/issues/106#issuecomment-1183215175
You are receiving this because you authored the thread.
Message ID: @.***>
Something like this perhaps?
Solved my problem with idea from last message
Hello, I suggest that a function be added to libloading that would allow me to read the handle of the library and manually read it externally for free, but so that I could then add a new handle there, for example via winapi, because this would help me when reinitializing the library when I use it via lazy static.