Skip to content

Commit 7d3a149

Browse files
committed
Move more things from the std feature to the alloc feature
1 parent bc8c713 commit 7d3a149

File tree

5 files changed

+24
-23
lines changed

5 files changed

+24
-23
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ rustdoc-args = ["--cfg", "docsrs"]
2020
[features]
2121
unstable = ["recovery", "rand-std"]
2222
default = ["std"]
23-
std = ["secp256k1-sys/std"]
23+
std = ["alloc", "secp256k1-sys/std"]
2424
# allow use of Secp256k1::new and related API that requires an allocator
25-
alloc = []
26-
bitcoin-hashes-std = ["bitcoin_hashes/std"]
25+
alloc = ["secp256k1-sys/alloc"]
26+
bitcoin-hashes-std = ["bitcoin_hashes/std"]
2727
rand-std = ["rand/std"]
2828
recovery = ["secp256k1-sys/recovery"]
2929
lowmemory = ["secp256k1-sys/lowmemory"]

secp256k1-sys/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ libc = "0.2"
3030
default = ["std"]
3131
recovery = []
3232
lowmemory = []
33-
std = []
33+
std = ["alloc"]
34+
alloc = []
3435

secp256k1-sys/src/lib.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#[cfg(any(test, feature = "std"))]
2626
extern crate core;
2727

28+
#[cfg(feature = "alloc")]
29+
extern crate alloc;
30+
2831
#[cfg(fuzzing)]
2932
const THIS_UNUSED_CONSTANT_IS_YOUR_WARNING_THAT_ALL_THE_CRYPTO_IN_THIS_LIB_IS_DISABLED_FOR_FUZZING: usize = 0;
3033

@@ -540,11 +543,11 @@ extern "C" {
540543
///
541544
/// The newly created secp256k1 raw context.
542545
#[no_mangle]
543-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
544-
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
546+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
547+
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
545548
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *mut Context {
546549
use core::mem;
547-
use std::alloc;
550+
use crate::alloc::alloc;
548551
assert!(ALIGN_TO >= mem::align_of::<usize>());
549552
assert!(ALIGN_TO >= mem::align_of::<&usize>());
550553
assert!(ALIGN_TO >= mem::size_of::<usize>());
@@ -560,8 +563,8 @@ pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *
560563
secp256k1_context_preallocated_create(ptr, flags)
561564
}
562565

563-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
564-
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
566+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
567+
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
565568
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
566569
rustsecp256k1_v0_5_0_context_create(flags)
567570
}
@@ -573,19 +576,19 @@ pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
573576
/// The pointer shouldn't be used after passing to this function, consider it as passing it to `free()`.
574577
///
575578
#[no_mangle]
576-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
577-
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
579+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
580+
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
578581
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_destroy(ctx: *mut Context) {
579-
use std::alloc;
582+
use crate::alloc::alloc;
580583
secp256k1_context_preallocated_destroy(ctx);
581584
let ptr = (ctx as *mut u8).sub(ALIGN_TO);
582585
let bytes = (ptr as *mut usize).read();
583586
let layout = alloc::Layout::from_size_align(bytes, ALIGN_TO).unwrap();
584587
alloc::dealloc(ptr, layout);
585588
}
586589

587-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
588-
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
590+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
591+
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
589592
pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
590593
rustsecp256k1_v0_5_0_context_destroy(ctx)
591594
}

secp256k1-sys/src/types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl AlignedType {
2828
pub const ZERO: AlignedType = AlignedType([0u8; 16]);
2929
}
3030

31-
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
31+
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
3232
pub(crate) const ALIGN_TO: usize = core::mem::align_of::<AlignedType>();
3333

3434
#[cfg(test)]

src/context.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::{Error, Secp256k1};
55
use crate::ffi::{self, CPtr, types::AlignedType};
66
use crate::ffi::types::{c_uint, c_void};
77

8-
#[cfg(any(feature = "std", feature = "alloc"))]
9-
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
8+
#[cfg(feature = "alloc")]
9+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
1010
pub use self::alloc_only::*;
1111

1212
#[cfg(all(feature = "global-context", feature = "std"))]
@@ -103,13 +103,10 @@ mod private {
103103
impl<'buf> Sealed for SignOnlyPreallocated<'buf> {}
104104
}
105105

106-
#[cfg(any(feature = "std", feature = "alloc"))]
107-
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
106+
#[cfg(feature = "alloc")]
107+
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc"))))]
108108
mod alloc_only {
109-
#[cfg(not(feature = "std"))]
110-
use alloc::alloc;
111-
#[cfg(feature = "std")]
112-
use std::alloc;
109+
use crate::alloc::alloc;
113110

114111
use core::marker::PhantomData;
115112

0 commit comments

Comments
 (0)