Not initializing pipewire library may lead to UB.
Not initializing the library can very easily lead to undefined behaviour using only safe code.
For example, this results in a segmentation fault:
fn main() {
// Forgetting to call this leads to undefined behaviour
// pipewire::init();
let _mainloop = pipewire::MainLoop::new().expect("Failed to create main loop");
}
To fix this, the pipewire::init()
function should change a static
variable to reflect that the library has been initialized. OnceCell could take care of any unsafeness for us.
We could then add a assert_lib_initialized()
function that checks that variable and panics if the library has not been initialized.
This method would then need to be called from any 'entry-point' function in the library, meaning it can be called without having to call another function of the library first.
A (perhaps non-exhaustive) list of these functions: (please write a comment if I missed any)
MainLoop::new()
Properties::from_dict()
- the
properties!{}
macro