Skip to content

Commit

Permalink
Remove WASM32_* const definitions
Browse files Browse the repository at this point in the history
The const definitions in `stdio.h` are causing the `wasm-pack` build to
fail due to 'duplicate symbol' errors. This can be solved by just
removing the definitions.
  • Loading branch information
tcharding committed Mar 25, 2022
1 parent 1cf2429 commit 86d95bb
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 61 deletions.
38 changes: 0 additions & 38 deletions secp256k1-sys/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,41 +66,3 @@ mod tests {
assert!(mem::align_of::<AlignedType>() >= mem::align_of::<self::libc::max_align_t>());
}
}

#[doc(hidden)]
#[cfg(target_arch = "wasm32")]
pub fn sanity_checks_for_wasm() {
use core::mem::{align_of, size_of};
extern "C" {
pub static WASM32_INT_SIZE: c_uchar;
pub static WASM32_INT_ALIGN: c_uchar;

pub static WASM32_UNSIGNED_INT_SIZE: c_uchar;
pub static WASM32_UNSIGNED_INT_ALIGN: c_uchar;

pub static WASM32_SIZE_T_SIZE: c_uchar;
pub static WASM32_SIZE_T_ALIGN: c_uchar;

pub static WASM32_UNSIGNED_CHAR_SIZE: c_uchar;
pub static WASM32_UNSIGNED_CHAR_ALIGN: c_uchar;

pub static WASM32_PTR_SIZE: c_uchar;
pub static WASM32_PTR_ALIGN: c_uchar;
}
unsafe {
assert_eq!(size_of::<c_int>(), WASM32_INT_SIZE as usize);
assert_eq!(align_of::<c_int>(), WASM32_INT_ALIGN as usize);

assert_eq!(size_of::<c_uint>(), WASM32_UNSIGNED_INT_SIZE as usize);
assert_eq!(align_of::<c_uint>(), WASM32_UNSIGNED_INT_ALIGN as usize);

assert_eq!(size_of::<size_t>(), WASM32_SIZE_T_SIZE as usize);
assert_eq!(align_of::<size_t>(), WASM32_SIZE_T_ALIGN as usize);

assert_eq!(size_of::<c_uchar>(), WASM32_UNSIGNED_CHAR_SIZE as usize);
assert_eq!(align_of::<c_uchar>(), WASM32_UNSIGNED_CHAR_ALIGN as usize);

assert_eq!(size_of::<*const ()>(), WASM32_PTR_SIZE as usize);
assert_eq!(align_of::<*const ()>(), WASM32_PTR_ALIGN as usize);
}
}
17 changes: 0 additions & 17 deletions secp256k1-sys/wasm-sysroot/stdio.h
Original file line number Diff line number Diff line change
@@ -1,17 +0,0 @@
#include <stddef.h>
#define alignof(type) offsetof (struct { char c; type member; }, member)

extern const unsigned char WASM32_INT_SIZE = sizeof(int);
extern const unsigned char WASM32_INT_ALIGN = alignof(int);

extern const unsigned char WASM32_UNSIGNED_INT_SIZE = sizeof(unsigned int);
extern const unsigned char WASM32_UNSIGNED_INT_ALIGN = alignof(unsigned int);

extern const unsigned char WASM32_SIZE_T_SIZE = sizeof(size_t);
extern const unsigned char WASM32_SIZE_T_ALIGN = alignof(size_t);

extern const unsigned char WASM32_UNSIGNED_CHAR_SIZE = sizeof(unsigned char);
extern const unsigned char WASM32_UNSIGNED_CHAR_ALIGN = alignof(unsigned char);

extern const unsigned char WASM32_PTR_SIZE = sizeof(void*);
extern const unsigned char WASM32_PTR_ALIGN = alignof(void*);
6 changes: 0 additions & 6 deletions src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,9 +192,6 @@ mod alloc_only {
/// ```
#[allow(unused_mut)] // Unused when `rand-std` is not enabled.
pub fn gen_new() -> Secp256k1<C> {
#[cfg(target_arch = "wasm32")]
ffi::types::sanity_checks_for_wasm();

let size = unsafe { ffi::secp256k1_context_preallocated_size(C::FLAGS) };
let layout = alloc::Layout::from_size_align(size, ALIGN_TO).unwrap();
let ptr = unsafe {alloc::alloc(layout)};
Expand Down Expand Up @@ -302,9 +299,6 @@ unsafe impl<'buf> Context for AllPreallocated<'buf> {
impl<'buf, C: Context + 'buf> Secp256k1<C> {
/// Lets you create a context with preallocated buffer in a generic manner(sign/verify/all)
pub fn preallocated_gen_new(buf: &'buf mut [AlignedType]) -> Result<Secp256k1<C>, Error> {
#[cfg(target_arch = "wasm32")]
ffi::types::sanity_checks_for_wasm();

if buf.len() < Self::preallocate_size_gen() {
return Err(Error::NotEnoughMemory);
}
Expand Down

0 comments on commit 86d95bb

Please sign in to comment.