Skip to content

Commit 9218c40

Browse files
authored
Move __wbindgen_global_argument_ptr around (#494)
Make sure it's in the same module as our "link hack" to ensure it's always linked in. Closes #492
1 parent c26caf6 commit 9218c40

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/convert.rs

+5-16
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,6 @@ pub struct GlobalStack {
446446
next: usize,
447447
}
448448

449-
const GLOBAL_STACK_CAP: usize = 16;
450-
451-
// Increase the alignment to 8 here because this can be used as a
452-
// BigUint64Array pointer base which requires alignment 8
453-
#[repr(align(8))]
454-
struct GlobalData([u32; GLOBAL_STACK_CAP]);
455-
456-
static mut GLOBAL_STACK: GlobalData = GlobalData([0; GLOBAL_STACK_CAP]);
457-
458449
impl GlobalStack {
459450
#[inline]
460451
pub unsafe fn new() -> GlobalStack {
@@ -465,20 +456,18 @@ impl GlobalStack {
465456
impl Stack for GlobalStack {
466457
#[inline]
467458
fn push(&mut self, val: u32) {
459+
use __rt::{
460+
__wbindgen_global_argument_ptr as global_ptr,
461+
GLOBAL_STACK_CAP,
462+
};
468463
unsafe {
469464
assert!(self.next < GLOBAL_STACK_CAP);
470-
GLOBAL_STACK.0[self.next] = val;
465+
*global_ptr().offset(self.next as isize) = val;
471466
self.next += 1;
472467
}
473468
}
474469
}
475470

476-
#[doc(hidden)]
477-
#[no_mangle]
478-
pub unsafe extern "C" fn __wbindgen_global_argument_ptr() -> *mut u32 {
479-
GLOBAL_STACK.0.as_mut_ptr()
480-
}
481-
482471
macro_rules! stack_closures {
483472
($( ($($var:ident)*) )*) => ($(
484473
impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a (Fn($($var),*) -> R + 'b)

src/lib.rs

+14
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,20 @@ pub mod __rt {
687687
}
688688
}
689689

690+
pub const GLOBAL_STACK_CAP: usize = 16;
691+
692+
// Increase the alignment to 8 here because this can be used as a
693+
// BigUint64Array pointer base which requires alignment 8
694+
#[repr(align(8))]
695+
struct GlobalData([u32; GLOBAL_STACK_CAP]);
696+
697+
static mut GLOBAL_STACK: GlobalData = GlobalData([0; GLOBAL_STACK_CAP]);
698+
699+
#[no_mangle]
700+
pub unsafe extern "C" fn __wbindgen_global_argument_ptr() -> *mut u32 {
701+
GLOBAL_STACK.0.as_mut_ptr()
702+
}
703+
690704
/// This is a curious function necessary to get wasm-bindgen working today,
691705
/// and it's a bit of an unfortunate hack.
692706
///

0 commit comments

Comments
 (0)