Move more things from the std feature to the alloc feature

This commit is contained in:
Elichai Turkel 2021-09-14 17:40:16 +03:00
parent bc8c713631
commit 7d3a149ca5
No known key found for this signature in database
GPG Key ID: 9383CDE9E8E66A7F
5 changed files with 24 additions and 23 deletions

View File

@ -20,10 +20,10 @@ rustdoc-args = ["--cfg", "docsrs"]
[features]
unstable = ["recovery", "rand-std"]
default = ["std"]
std = ["secp256k1-sys/std"]
std = ["alloc", "secp256k1-sys/std"]
# allow use of Secp256k1::new and related API that requires an allocator
alloc = []
bitcoin-hashes-std = ["bitcoin_hashes/std"]
alloc = ["secp256k1-sys/alloc"]
bitcoin-hashes-std = ["bitcoin_hashes/std"]
rand-std = ["rand/std"]
recovery = ["secp256k1-sys/recovery"]
lowmemory = ["secp256k1-sys/lowmemory"]

View File

@ -30,5 +30,6 @@ libc = "0.2"
default = ["std"]
recovery = []
lowmemory = []
std = []
std = ["alloc"]
alloc = []

View File

@ -25,6 +25,9 @@
#[cfg(any(test, feature = "std"))]
extern crate core;
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(fuzzing)]
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.
#[no_mangle]
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(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 = "alloc", not(rust_secp_no_symbol_renaming)))))]
pub unsafe extern "C" fn rustsecp256k1_v0_5_0_context_create(flags: c_uint) -> *mut Context {
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::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)
}
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(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 = "alloc", not(rust_secp_no_symbol_renaming)))))]
pub unsafe fn secp256k1_context_create(flags: c_uint) -> *mut Context {
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()`.
///
#[no_mangle]
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(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 = "alloc", not(rust_secp_no_symbol_renaming)))))]
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);
let ptr = (ctx as *mut u8).sub(ALIGN_TO);
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);
}
#[cfg(all(feature = "std", not(rust_secp_no_symbol_renaming)))]
#[cfg_attr(docsrs, doc(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 = "alloc", not(rust_secp_no_symbol_renaming)))))]
pub unsafe fn secp256k1_context_destroy(ctx: *mut Context) {
rustsecp256k1_v0_5_0_context_destroy(ctx)
}

View File

@ -28,7 +28,7 @@ impl AlignedType {
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>();
#[cfg(test)]

View File

@ -5,8 +5,8 @@ use crate::{Error, Secp256k1};
use crate::ffi::{self, CPtr, types::AlignedType};
use crate::ffi::types::{c_uint, c_void};
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub use self::alloc_only::*;
#[cfg(all(feature = "global-context", feature = "std"))]
@ -103,13 +103,10 @@ mod private {
impl<'buf> Sealed for SignOnlyPreallocated<'buf> {}
}
#[cfg(any(feature = "std", feature = "alloc"))]
#[cfg_attr(docsrs, doc(cfg(any(feature = "std", feature = "alloc"))))]
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(any(feature = "alloc"))))]
mod alloc_only {
#[cfg(not(feature = "std"))]
use alloc::alloc;
#[cfg(feature = "std")]
use std::alloc;
use crate::alloc::alloc;
use core::marker::PhantomData;