Move more things from the std feature to the alloc feature
This commit is contained in:
parent
bc8c713631
commit
7d3a149ca5
|
@ -20,10 +20,10 @@ rustdoc-args = ["--cfg", "docsrs"]
|
||||||
[features]
|
[features]
|
||||||
unstable = ["recovery", "rand-std"]
|
unstable = ["recovery", "rand-std"]
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
std = ["secp256k1-sys/std"]
|
std = ["alloc", "secp256k1-sys/std"]
|
||||||
# allow use of Secp256k1::new and related API that requires an allocator
|
# allow use of Secp256k1::new and related API that requires an allocator
|
||||||
alloc = []
|
alloc = ["secp256k1-sys/alloc"]
|
||||||
bitcoin-hashes-std = ["bitcoin_hashes/std"]
|
bitcoin-hashes-std = ["bitcoin_hashes/std"]
|
||||||
rand-std = ["rand/std"]
|
rand-std = ["rand/std"]
|
||||||
recovery = ["secp256k1-sys/recovery"]
|
recovery = ["secp256k1-sys/recovery"]
|
||||||
lowmemory = ["secp256k1-sys/lowmemory"]
|
lowmemory = ["secp256k1-sys/lowmemory"]
|
||||||
|
|
|
@ -30,5 +30,6 @@ libc = "0.2"
|
||||||
default = ["std"]
|
default = ["std"]
|
||||||
recovery = []
|
recovery = []
|
||||||
lowmemory = []
|
lowmemory = []
|
||||||
std = []
|
std = ["alloc"]
|
||||||
|
alloc = []
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,9 @@
|
||||||
#[cfg(any(test, feature = "std"))]
|
#[cfg(any(test, feature = "std"))]
|
||||||
extern crate core;
|
extern crate core;
|
||||||
|
|
||||||
|
#[cfg(feature = "alloc")]
|
||||||
|
extern crate alloc;
|
||||||
|
|
||||||
#[cfg(fuzzing)]
|
#[cfg(fuzzing)]
|
||||||
const THIS_UNUSED_CONSTANT_IS_YOUR_WARNING_THAT_ALL_THE_CRYPTO_IN_THIS_LIB_IS_DISABLED_FOR_FUZZING: usize = 0;
|
const THIS_UNUSED_CONSTANT_IS_YOUR_WARNING_THAT_ALL_THE_CRYPTO_IN_THIS_LIB_IS_DISABLED_FOR_FUZZING: usize = 0;
|
||||||
|
|
||||||
|
@ -540,11 +543,11 @@ extern "C" {
|
||||||
///
|
///
|
||||||
/// The newly created secp256k1 raw context.
|
/// The newly created secp256k1 raw context.
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
|
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
|
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
|
||||||
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *mut Context {
|
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *mut Context {
|
||||||
use core::mem;
|
use core::mem;
|
||||||
use std::alloc;
|
use crate::alloc::alloc;
|
||||||
assert!(ALIGN_TO >= mem::align_of::<usize>());
|
assert!(ALIGN_TO >= mem::align_of::<usize>());
|
||||||
assert!(ALIGN_TO >= mem::align_of::<&usize>());
|
assert!(ALIGN_TO >= mem::align_of::<&usize>());
|
||||||
assert!(ALIGN_TO >= mem::size_of::<usize>());
|
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) -> *
|
||||||
secp256k1_context_preallocated_create(ptr, flags)
|
secp256k1_context_preallocated_create(ptr, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
|
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
|
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
|
||||||
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
|
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
|
||||||
rustsecp256k1_v0_5_0_context_create(flags)
|
rustsecp256k1_v0_5_0_context_create(flags)
|
||||||
}
|
}
|
||||||
|
@ -573,10 +576,10 @@ pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
|
||||||
/// The pointer shouldn't be used after passing to this function, consider it as passing it to `free()`.
|
/// The pointer shouldn't be used after passing to this function, consider it as passing it to `free()`.
|
||||||
///
|
///
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
|
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
|
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
|
||||||
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_destroy(ctx: *mut Context) {
|
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_destroy(ctx: *mut Context) {
|
||||||
use std::alloc;
|
use crate::alloc::alloc;
|
||||||
secp256k1_context_preallocated_destroy(ctx);
|
secp256k1_context_preallocated_destroy(ctx);
|
||||||
let ptr = (ctx as *mut u8).sub(ALIGN_TO);
|
let ptr = (ctx as *mut u8).sub(ALIGN_TO);
|
||||||
let bytes = (ptr as *mut usize).read();
|
let bytes = (ptr as *mut usize).read();
|
||||||
|
@ -584,8 +587,8 @@ pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_destroy(ctx: *mut Context)
|
||||||
alloc::dealloc(ptr, layout);
|
alloc::dealloc(ptr, layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
|
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
|
||||||
#[cfg_attr(docsrs, doc(cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))))]
|
#[cfg_attr(docsrs, doc(cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))))]
|
||||||
pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
|
pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
|
||||||
rustsecp256k1_v0_5_0_context_destroy(ctx)
|
rustsecp256k1_v0_5_0_context_destroy(ctx)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,7 @@ impl AlignedType {
|
||||||
pub const ZERO: AlignedType = AlignedType([0u8; 16]);
|
pub const ZERO: AlignedType = AlignedType([0u8; 16]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
|
#[cfg(all(feature = "alloc", not(rust_secp_no_symbol_renaming)))]
|
||||||
pub(crate) const ALIGN_TO: usize = core::mem::align_of::<AlignedType>();
|
pub(crate) const ALIGN_TO: usize = core::mem::align_of::<AlignedType>();
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -5,8 +5,8 @@ use crate::{Error, Secp256k1};
|
||||||
use crate::ffi::{self, CPtr, types::AlignedType};
|
use crate::ffi::{self, CPtr, types::AlignedType};
|
||||||
use crate::ffi::types::{c_uint, c_void};
|
use crate::ffi::types::{c_uint, c_void};
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(feature = "alloc")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
|
||||||
pub use self::alloc_only::*;
|
pub use self::alloc_only::*;
|
||||||
|
|
||||||
#[cfg(all(feature = "global-context", feature = "std"))]
|
#[cfg(all(feature = "global-context", feature = "std"))]
|
||||||
|
@ -103,13 +103,10 @@ mod private {
|
||||||
impl<'buf> Sealed for SignOnlyPreallocated<'buf> {}
|
impl<'buf> Sealed for SignOnlyPreallocated<'buf> {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(any(feature = "std", feature = "alloc"))]
|
#[cfg(feature = "alloc")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
|
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc"))))]
|
||||||
mod alloc_only {
|
mod alloc_only {
|
||||||
#[cfg(not(feature = "std"))]
|
use crate::alloc::alloc;
|
||||||
use alloc::alloc;
|
|
||||||
#[cfg(feature = "std")]
|
|
||||||
use std::alloc;
|
|
||||||
|
|
||||||
use core::marker::PhantomData;
|
use core::marker::PhantomData;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue