Skip to content

Commit

Permalink
Make allocator opt-in
Browse files Browse the repository at this point in the history
  • Loading branch information
filmor committed Feb 13, 2024
1 parent 897e11c commit 4a21c56
Show file tree
Hide file tree
Showing 9 changed files with 16 additions and 11 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ members = [
"rustler_tests/native/rustler_compile_tests",
"rustler_benchmarks/native/benchmark",
]
default-members = [
"rustler",
"rustler_bigint",
"rustler_codegen",
"rustler_sys",
]
2 changes: 1 addition & 1 deletion rustler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ readme = "../README.md"
edition = "2021"

[features]
default = ["derive", "nif_version_2_15", "allocator"]
default = ["derive", "nif_version_2_15"]
derive = ["rustler_codegen"]
alternative_nif_init_name = []
allocator = []
Expand Down
4 changes: 4 additions & 0 deletions rustler/src/alloc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
use std::alloc::{GlobalAlloc, Layout};

#[cfg(feature = "allocator")]
#[global_allocator]
static ALLOCATOR: EnifAllocator = EnifAllocator;

/// Allocator implementation that forwards all allocation calls to Erlang's allocator. Allows the
/// memory usage to be tracked by the BEAM.
pub struct EnifAllocator;
Expand Down
5 changes: 0 additions & 5 deletions rustler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ pub mod wrapper;
pub mod codegen_runtime;

mod alloc;
pub use alloc::EnifAllocator;

#[cfg(feature = "allocator")]
#[global_allocator]
static ALLOCATOR: EnifAllocator = EnifAllocator;

pub use lazy_static;

Expand Down
2 changes: 1 addition & 1 deletion rustler_tests/native/deprecated_macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ path = "src/lib.rs"
crate-type = ["cdylib"]

[dependencies]
rustler = { path = "../../../rustler" }
rustler = { path = "../../../rustler", features = ["allocator"]}
2 changes: 1 addition & 1 deletion rustler_tests/native/dynamic_load/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ crate-type = ["cdylib"]

[dependencies]
rustler_bigint = { path = "../../../rustler_bigint" }
rustler = { path = "../../../rustler" }
rustler = { path = "../../../rustler", features = ["allocator"] }
2 changes: 1 addition & 1 deletion rustler_tests/native/rustler_bigint_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ crate-type = ["cdylib"]

[dependencies]
rustler_bigint = { path = "../../../rustler_bigint" }
rustler = { path = "../../../rustler" }
rustler = { path = "../../../rustler", features = ["allocator"] }
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 @@ -11,4 +11,4 @@ crate-type = ["cdylib"]

[dependencies]
lazy_static = "1.4"
rustler = { path = "../../../rustler" }
rustler = { path = "../../../rustler", features = ["allocator"] }
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 @@ -21,4 +21,4 @@ nif_version_2_17 = ["nif_version_2_16", "rustler/nif_version_2_17"]

[dependencies]
lazy_static = "1.4"
rustler = { path = "../../../rustler" }
rustler = { path = "../../../rustler", features = ["allocator"] }

0 comments on commit 4a21c56

Please sign in to comment.