I have trouble with propertly running Rust function
and call this from C. I would like to using error returning code. Panic, Error etc.
----- lib.rs ----
#![crate_type = "dylib"]
#![crate_type = "staticlib"]
#[no_mangle]
pub extern "C" fn z_c()
{
let result = std::panic::catch_unwind(|| {
println!("Po prostu wypisz napis!"); });
if result.is_err()
{ eprintln!("Łojej: rust panikuje"); }
}
--- main.c ----
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
extern void z_c();
int main(void)
{
z_c();
return 0;
}
--- Makefile -----
clang -c main.c
rustc --crate-type staticlib --crate-name ex lib.rs
clang -L. -o main main.o -lex -lpthread -lgcc_s -ldl
the trouble is with
$valgrind -v --leak-check=full --show-leak-kinds=all --track-origins=yes --tool=memcheck ./main
I have memory leak