I think open should probably be marked unsafe, because it could call a unsafe function, although not directly.
For example, below code demonstrates a constructor function is called on library load (no unsafe code needed):
cargo new dlopen-test
cd dlopen-test/
cat > hello.c << EOF
#include <stdio.h>
void __attribute__ ((constructor)) hello(void)
{
printf("hello from C\n");
}
EOF
gcc -Wall -shared -fPIC -o hello.so hello.c
cat > src/main.rs << EOF
extern crate dlopen;
use dlopen::raw::Library;
fn main() {
let lib = Library::open("./hello.so").unwrap();
}
EOF
cargo add dlopen
cargo run
# some cargo outputs, ends with this print from C code
hello from C
I think
openshould probably be markedunsafe, because it could call a unsafe function, although not directly.For example, below code demonstrates a constructor function is called on library load (no
unsafecode needed):