Skip to content

Commit 349b2ea

Browse files
committed
Add a 'dont_replace_c_symbols' feature for not replacing C's symbols with rust. isn't compatible with no-std
1 parent f5c8a00 commit 349b2ea

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ std = ["rand/std"]
3333
recovery = []
3434
endomorphism = []
3535
lowmemory = []
36+
dont_replace_c_symbols = []
3637

3738
[dev-dependencies]
3839
rand = "0.6"

build.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ fn main() {
5252
.define("USE_NUM_NONE", Some("1"))
5353
.define("USE_FIELD_INV_BUILTIN", Some("1"))
5454
.define("USE_SCALAR_INV_BUILTIN", Some("1"))
55-
.define("ENABLE_MODULE_ECDH", Some("1"))
56-
.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
55+
.define("ENABLE_MODULE_ECDH", Some("1"));
5756

5857
if cfg!(feature = "lowmemory") {
5958
base_config.define("ECMULT_WINDOW_SIZE", Some("4")); // A low-enough value to consume neglible memory
6059
} else {
6160
base_config.define("ECMULT_WINDOW_SIZE", Some("15")); // This is the default in the configure file (`auto`)
6261
}
62+
#[cfg(not(feature = "dont_replace_c_symbols"))]
63+
base_config.define("USE_EXTERNAL_DEFAULT_CALLBACKS", Some("1"));
6364
#[cfg(feature = "endomorphism")]
6465
base_config.define("USE_ENDOMORPHISM", Some("1"));
6566
#[cfg(feature = "recovery")]

src/ffi.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ extern "C" {
256256
}
257257

258258

259-
#[cfg(feature = "std")]
259+
#[cfg(all(feature = "std", not(feature = "dont_replace_c_symbols")))]
260260
#[no_mangle]
261261
/// A reimplementation of the C function `secp256k1_context_create` in rust.
262262
///
@@ -281,7 +281,7 @@ pub unsafe extern "C" fn secp256k1_context_create(flags: c_uint) -> *mut Context
281281
secp256k1_context_preallocated_create(ptr as *mut c_void, flags)
282282
}
283283

284-
#[cfg(feature = "std")]
284+
#[cfg(all(feature = "std", not(feature = "dont_replace_c_symbols")))]
285285
#[no_mangle]
286286
/// A reimplementation of the C function `secp256k1_context_destroy` in rust.
287287
///
@@ -300,6 +300,7 @@ pub unsafe extern "C" fn secp256k1_context_destroy(ctx: *mut Context) {
300300
}
301301

302302

303+
#[cfg(not(feature = "dont_replace_c_symbols"))]
303304
#[no_mangle]
304305
/// **This function is an override for the C function, this is the an edited version of the original description:**
305306
///
@@ -326,6 +327,7 @@ pub unsafe extern "C" fn secp256k1_default_illegal_callback_fn(message: *const c
326327
panic!("[libsecp256k1] illegal argument. {}", msg);
327328
}
328329

330+
#[cfg(not(feature = "dont_replace_c_symbols"))]
329331
#[no_mangle]
330332
/// **This function is an override for the C function, this is the an edited version of the original description:**
331333
///

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,7 @@ mod tests {
717717

718718

719719
#[test]
720+
#[cfg(not(feature = "dont_replace_c_symbols"))]
720721
fn test_manual_create_destroy() {
721722
let ctx_full = unsafe { ffi::secp256k1_context_create(AllPreallocated::FLAGS) };
722723
let ctx_sign = unsafe { ffi::secp256k1_context_create(SignOnlyPreallocated::FLAGS) };

0 commit comments

Comments
 (0)