Closed cybernetlab closed 7 years ago
It is indeed missing. The original API implements it as a macro, so that's why it was overlooked.
ErlNifPid
looks like this...
pub struct ErlNifPid {
pid: ERL_NIF_TERM,
}
... and all the macro does is return the pid member, so hopefully that gives you grounds for a work-around. Worst case you can transmute
the pid into a term.
Actually my question was about function enif_make_pid - not about type ErlNifPid. This function does not implemented in rust library. Are you mean that I can use pid field from this structure as return value from my nif function back to elixir/erlang directly without call to enif_make_pid? As I understand the returning terms should be in environment that passed to nif function - I think that enif_make_pid ensures that this is a true.
The C implementation simply yanks the pid member from the structure and returns it. Pid terms are currently environmentless, although the API is designed so that it could be changed in the future (but I don't foresee any overhauls in this department).
I will leave this open so I can add the function later when I'm not knee deep in other stuff. In the meantime I suggest just writing your own version of enif_make_pid that does a transmute.
Thank you for detailed explanation. I think that I can prepare a PR with this function - adding it to gen_api.erl inside right eyes version block should be enough.
A PR would be great! A few more points/references:
enif_make_pid
has been around since R14A so no version switching is needed.enif_make_pid
.src/lib.rs
. No need to get into gen_api.erl
.src/lib.rs
, you could do a safe member access to get the term instead of an unsafe transmute.I've prepared PR.
some remarks:
enif_make_pid
added to src/lib.rs
tests
. The code compiles api_functions_nif.rs
and api_functions_nif.erl
and then runs api_functions_nif.erl
and captures and analyzes results as it was done in struct_size.rs
. Two minimal tests added for enif_make_int
and enif_make_pid
.gitignore
becouse such files generated while erl VM crashes in tests
Hi! I can't find enif_make_pid function in your project. Is it possible to add it? Also I've try to add it in my code as a workaround:
but it crashes when nif library loading into VM with message
Failed to load NIF library: '/.../mylib.so: undefined symbol: enif_make_pid'
. Looks like it is a new feature? This is my erl banner:Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:4:4] [async-threads:10] [kernel-poll:false]
.Regards