-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a proof-of-concept for a mechanism that does away with the need to list all NIF functions in the `rustler::init!` invocation. A similar mechanism will be required and implemented for resource type registrations. - Convert `Nif` to a `struct` - Use `inventory` to register the `Nif` instances - In `rustler::init!`, ignore the passed functions and instead use the registered `Nif` instances Next steps: - See whether `linkme` is not a better option (creates the array directly at build-time, no need to leak) - Implement resource registration using this mechanism - See if we can move the macros to `rustler`
- Loading branch information
Showing
9 changed files
with
93 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,25 @@ | ||
use crate::codegen_runtime::{c_char, c_int, c_uint, DEF_NIF_FUNC, NIF_ENV, NIF_TERM}; | ||
|
||
pub trait Nif { | ||
const NAME: *const c_char; | ||
const ARITY: c_uint; | ||
const FLAGS: c_uint; | ||
const FUNC: DEF_NIF_FUNC; | ||
const RAW_FUNC: unsafe extern "C" fn( | ||
nif_env: NIF_ENV, | ||
argc: c_int, | ||
argv: *const NIF_TERM, | ||
) -> NIF_TERM; | ||
pub struct Nif { | ||
pub name: *const c_char, | ||
pub arity: c_uint, | ||
pub flags: c_uint, | ||
// pub func: DEF_NIF_FUNC, | ||
pub raw_func: | ||
unsafe extern "C" fn(nif_env: NIF_ENV, argc: c_int, argv: *const NIF_TERM) -> NIF_TERM, | ||
} | ||
|
||
impl Nif { | ||
pub fn get_def(&self) -> DEF_NIF_FUNC { | ||
DEF_NIF_FUNC { | ||
arity: self.arity, | ||
flags: self.flags, | ||
function: self.raw_func, | ||
name: self.name, | ||
} | ||
} | ||
} | ||
|
||
unsafe impl Sync for Nif {} | ||
|
||
inventory::collect!(Nif); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters