Skip to content

Commit

Permalink
Merge branch 'master' into 516-set-runtime_false
Browse files Browse the repository at this point in the history
  • Loading branch information
filmor authored Aug 29, 2023
2 parents 6dc48a3 + ef06753 commit c6e86b5
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ See [`UPGRADE.md`](./UPGRADE.md) for additional help when upgrading to newer ver
* Dropped support for `RUSTLER_NIF_VERSION`
* Deprecated `:rustler_crates` project configuration
* Mark `use Rustler` module configuration as compile-time
* Bump Rust edition to 2021
* Make `:rustler` a compile-time-only dependency (#516, #559)

## [0.29.1] - 2023-06-30
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[workspace]
resolver = "2"
members = [
"rustler",
"rustler_bigint",
Expand Down
2 changes: 1 addition & 1 deletion rustler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ version = "0.29.1" # rustler version
authors = ["Hansihe <[email protected]>"]
license = "MIT/Apache-2.0"
readme = "../README.md"
edition = "2018"
edition = "2021"

[features]
default = ["derive", "nif_version_2_15"]
Expand Down
2 changes: 1 addition & 1 deletion rustler/src/codegen_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl NifReturned {
flags as i32,
fun,
args.len() as i32,
args.as_ptr() as *const usize,
args.as_ptr(),
),
}
}
Expand Down
2 changes: 2 additions & 0 deletions rustler/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ unsafe impl Send for OwnedEnv {}

impl OwnedEnv {
/// Allocates a new process-independent environment.
#[allow(clippy::arc_with_non_send_sync)] // Likely false negative, see https://github.com/rust-lang/rust-clippy/issues/11382
pub fn new() -> OwnedEnv {
OwnedEnv {
env: Arc::new(unsafe { rustler_sys::enif_alloc_env() }),
Expand Down Expand Up @@ -228,6 +229,7 @@ impl OwnedEnv {
/// Unless you call this method after a call to `run()`, all terms created within the
/// environment hang around in memory until the `OwnedEnv` is dropped: garbage collection does
/// not continually happen as needed in a NIF environment.
#[allow(clippy::arc_with_non_send_sync)] // Likely false negative, see https://github.com/rust-lang/rust-clippy/issues/11382
pub fn clear(&mut self) {
let c_env = *self.env;
self.env = Arc::new(c_env);
Expand Down
2 changes: 1 addition & 1 deletion rustler_benchmarks/native/benchmark/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "benchmark"
version = "0.1.0"
authors = []
edition = "2018"
edition = "2021"

[lib]
name = "benchmark"
Expand Down
2 changes: 1 addition & 1 deletion rustler_sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ documentation = "https://docs.rs/rustler_sys"
repository = "https://github.com/rusterlium/rustler"
license = "MIT/Apache-2.0"
keywords = ["FFI", "Erlang", "NIF"]
edition = "2018"
edition = "2021"

build = "build.rs"

Expand Down
1 change: 0 additions & 1 deletion rustler_sys/build_common.rs

This file was deleted.

49 changes: 26 additions & 23 deletions rustler_sys/src/initmacro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ macro_rules! nif_init {
/// users of `erlang_nif-sys`. See implementation of `nif_init!` for usage.
#[macro_export]
macro_rules! platform_nif_init {
($get_entry:expr) => {
($entry:expr) => {
#[cfg(unix)]
#[no_mangle]
pub extern "C" fn nif_init() -> *const $crate::rustler_sys_api::ErlNifEntry {
$get_entry()
$entry
}

#[cfg(windows)]
Expand All @@ -42,7 +42,7 @@ macro_rules! platform_nif_init {
WIN_DYN_NIF_CALLBACKS = Some(*callbacks);
}
//std::ptr::copy_nonoverlapping(callbacks, &WinDynNifCallbacks, std::mem::size_of<TWinDynNifCallbacks>());
$get_entry()
$entry
}
};
}
Expand Down Expand Up @@ -101,7 +101,7 @@ macro_rules! get_entry {
( $module:expr, [$($funcs:tt),+,], $inits_tt:tt ) => ( get_entry!($module, [$($funcs),*], $inits_tt) );

( $module:expr, [$($funcs:tt),*], {$($inits:tt)*} ) => (
|| { // start closure
{ // start closure
use $crate::rustler_sys_api as ens;
const FUNCS: &'static [ens::ErlNifFunc] = &[$(make_func_entry!($funcs)),*];

Expand Down Expand Up @@ -135,7 +135,7 @@ macro_rules! get_entry {

// For legacy nif_init!() invocation, deprecated
($module:expr, $load:expr, $reload:expr, $upgrade:expr, $unload:expr, $($func:expr),* ) => (
|| { // start closure
{ // start closure
use $crate::rustler_sys_api as ens;
const FUNCS: &'static [ens::ErlNifFunc] = &[$($func),*];
static mut ENTRY: ens::ErlNifEntry = ens::ErlNifEntry{
Expand Down Expand Up @@ -198,7 +198,8 @@ macro_rules! make_func_entry {
argc: ens::c_int,
args: *const ens::ERL_NIF_TERM,
) -> ens::ERL_NIF_TERM {
$function(env, argc, args)
let func = $function;
func(env, argc, args)
}
wrapper
},
Expand Down Expand Up @@ -236,7 +237,8 @@ macro_rules! set_optional {
priv_data: *mut *mut ens::c_void,
load_info: ens::ERL_NIF_TERM,
) -> ens::c_int {
$val(env, priv_data, load_info)
let func = $val;
func(env, priv_data, load_info)
}
$entry.load = Some(wrapper);
}};
Expand Down Expand Up @@ -270,6 +272,7 @@ macro_rules! set_optional {
}

#[cfg(test)]
#[allow(clippy::redundant_closure_call)]
mod initmacro_namespace_tests {

// explicitly disable for this test:
Expand Down Expand Up @@ -308,7 +311,7 @@ mod initmacro_namespace_tests {

#[test]
fn opt_some2() {
let entry = get_entry!("empty", [], {load: load, unload:unload})();
let entry = get_entry!("empty", [], {load: load, unload:unload});
assert_eq!(0, entry.num_of_funcs);
assert_eq!(14, unsafe {
entry.load.unwrap()(ptr::null_mut(), ptr::null_mut(), 0)
Expand All @@ -320,7 +323,7 @@ mod initmacro_namespace_tests {

#[test]
fn nif1() {
let entry = get_entry!("nifs", [("raw1", 3, raw_nif1)])();
let entry = get_entry!("nifs", [("raw1", 3, raw_nif1)]);
let funcs = unsafe { slice::from_raw_parts(entry.funcs, entry.num_of_funcs as usize) };
assert_eq!(1, funcs.len());
assert_eq!(CString::new("raw1").unwrap().as_ref(), unsafe {
Expand All @@ -335,7 +338,7 @@ mod initmacro_namespace_tests {

#[test]
fn nif_wrapped() {
let entry = get_entry!("nifs", [("sliced", 6, slice_args!(slice_nif))])();
let entry = get_entry!("nifs", [("sliced", 6, slice_args!(slice_nif))]);
let funcs = unsafe { slice::from_raw_parts(entry.funcs, entry.num_of_funcs as usize) };
assert_eq!(1, funcs.len());
assert_eq!(CString::new("sliced").unwrap().as_ref(), unsafe {
Expand Down Expand Up @@ -413,7 +416,7 @@ mod initmacro_tests {

#[test]
fn opt_empty() {
let entry = get_entry!("empty", [])();
let entry = get_entry!("empty", []);
assert_eq!(0, entry.num_of_funcs);
assert_eq!(None, entry.load);
assert_eq!(None, entry.reload);
Expand All @@ -423,7 +426,7 @@ mod initmacro_tests {

#[test]
fn opt_some1() {
let entry = get_entry!("empty", [], { load: load })();
let entry = get_entry!("empty", [], { load: load });
assert_eq!(0, entry.num_of_funcs);
assert_eq!(14, unsafe {
entry.load.unwrap()(ptr::null_mut(), ptr::null_mut(), 0)
Expand All @@ -435,7 +438,7 @@ mod initmacro_tests {

#[test]
fn opt_some2() {
let entry = get_entry!("empty", [], {load: load, unload:unload})();
let entry = get_entry!("empty", [], {load: load, unload:unload});
assert_eq!(0, entry.num_of_funcs);
assert_eq!(14, unsafe {
entry.load.unwrap()(ptr::null_mut(), ptr::null_mut(), 0)
Expand All @@ -448,7 +451,7 @@ mod initmacro_tests {
#[test]
fn opt_some2b() {
// optionals in different order as opt_some2
let entry = get_entry!("empty", [], {unload:unload, load: load})();
let entry = get_entry!("empty", [], {unload:unload, load: load});
assert_eq!(0, entry.num_of_funcs);
assert_eq!(14, unsafe {
entry.load.unwrap()(ptr::null_mut(), ptr::null_mut(), 0)
Expand All @@ -461,23 +464,23 @@ mod initmacro_tests {
#[test]
fn opt_closure() {
// optionals in different order as opt_some2
let entry = get_entry!("empty", [], {load: |_,_,_|15})();
let entry = get_entry!("empty", [], {load: |_,_,_|15});
assert_eq!(15, unsafe {
entry.load.unwrap()(ptr::null_mut(), ptr::null_mut(), 0)
});
}

#[test]
fn modname() {
let entry = get_entry!("bananas", [])();
let entry = get_entry!("bananas", []);
assert_eq!(CString::new("bananas").unwrap().as_ref(), unsafe {
CStr::from_ptr(entry.name as *const i8)
});
}

#[test]
fn nif1() {
let entry = get_entry!("nifs", [("raw1", 3, raw_nif1)])();
let entry = get_entry!("nifs", [("raw1", 3, raw_nif1)]);
let funcs = unsafe { slice::from_raw_parts(entry.funcs, entry.num_of_funcs as usize) };
assert_eq!(1, funcs.len());
assert_eq!(CString::new("raw1").unwrap().as_ref(), unsafe {
Expand All @@ -498,7 +501,7 @@ mod initmacro_tests {
("raw1", 3, raw_nif1),
("raw2", 33, raw_nif2, ERL_NIF_DIRTY_JOB_IO_BOUND)
]
)();
);
let funcs = unsafe { slice::from_raw_parts(entry.funcs, entry.num_of_funcs as usize) };
assert_eq!(2, funcs.len());
assert_eq!(CString::new("raw1").unwrap().as_ref(), unsafe {
Expand All @@ -521,7 +524,7 @@ mod initmacro_tests {

#[test]
fn nif_closure() {
let entry = get_entry!("nifs", [("closure", 5, |_, argc, _| (argc * 13) as usize)])();
let entry = get_entry!("nifs", [("closure", 5, |_, argc, _| (argc * 13) as usize)]);
let funcs = unsafe { slice::from_raw_parts(entry.funcs, entry.num_of_funcs as usize) };
assert_eq!(1, funcs.len());
assert_eq!(CString::new("closure").unwrap().as_ref(), unsafe {
Expand All @@ -536,7 +539,7 @@ mod initmacro_tests {

#[test]
fn nif_wrapped() {
let entry = get_entry!("nifs", [("sliced", 6, slice_args!(slice_nif))])();
let entry = get_entry!("nifs", [("sliced", 6, slice_args!(slice_nif))]);
let funcs = unsafe { slice::from_raw_parts(entry.funcs, entry.num_of_funcs as usize) };
assert_eq!(1, funcs.len());
assert_eq!(CString::new("sliced").unwrap().as_ref(), unsafe {
Expand All @@ -559,7 +562,7 @@ mod initmacro_tests {
Some(c_unload),
nif!(b"cnif_1\0", 7, c_nif1, ERL_NIF_DIRTY_JOB_IO_BOUND),
nif!(b"cnif_2\0", 8, c_nif1)
)();
);
let funcs = unsafe { slice::from_raw_parts(entry.funcs, entry.num_of_funcs as usize) };

assert_eq!(CString::new("legacymod").unwrap().as_ref(), unsafe {
Expand Down Expand Up @@ -604,14 +607,14 @@ mod initmacro_tests {
{
unload: unload,
load: load, // <- trailing comma
})();
});
}

#[test]
fn unsafe_callbacks() {
let entry = get_entry!("unsafe_nifs", [("unsafe_nif", 3, unsafe_nif)], {
load: unsafe_load
})();
});
let funcs = unsafe { slice::from_raw_parts(entry.funcs, entry.num_of_funcs as usize) };
assert_eq!(15, unsafe {
entry.load.unwrap()(ptr::null_mut(), ptr::null_mut(), 0)
Expand Down
2 changes: 1 addition & 1 deletion rustler_tests/native/binary_example/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "binary_example"
version = "0.1.0"
authors = []
edition = "2018"
edition = "2021"

[[bin]]
name = "binary_example"
Expand Down
2 changes: 1 addition & 1 deletion rustler_tests/native/rustler_compile_tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rustler_compile_tests"
version = "0.1.0"
authors = []
edition = "2018"
edition = "2021"

[lib]
name = "rustler_compile_test"
Expand Down
2 changes: 1 addition & 1 deletion rustler_tests/native/rustler_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "rustler_test"
version = "0.1.0"
authors = []
edition = "2018"
edition = "2021"

[lib]
name = "rustler_test"
Expand Down

0 comments on commit c6e86b5

Please sign in to comment.