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
This commit is contained in:
Alex Crichton 2018-07-17 16:56:22 -05:00 committed by GitHub
parent c26caf6354
commit 9218c40613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 16 deletions

View File

@ -446,15 +446,6 @@ pub struct GlobalStack {
next: usize,
}
const GLOBAL_STACK_CAP: usize = 16;
// Increase the alignment to 8 here because this can be used as a
// BigUint64Array pointer base which requires alignment 8
#[repr(align(8))]
struct GlobalData([u32; GLOBAL_STACK_CAP]);
static mut GLOBAL_STACK: GlobalData = GlobalData([0; GLOBAL_STACK_CAP]);
impl GlobalStack {
#[inline]
pub unsafe fn new() -> GlobalStack {
@ -465,20 +456,18 @@ impl GlobalStack {
impl Stack for GlobalStack {
#[inline]
fn push(&mut self, val: u32) {
use __rt::{
__wbindgen_global_argument_ptr as global_ptr,
GLOBAL_STACK_CAP,
};
unsafe {
assert!(self.next < GLOBAL_STACK_CAP);
GLOBAL_STACK.0[self.next] = val;
*global_ptr().offset(self.next as isize) = val;
self.next += 1;
}
}
}
#[doc(hidden)]
#[no_mangle]
pub unsafe extern "C" fn __wbindgen_global_argument_ptr() -> *mut u32 {
GLOBAL_STACK.0.as_mut_ptr()
}
macro_rules! stack_closures {
($( ($($var:ident)*) )*) => ($(
impl<'a, 'b, $($var,)* R> IntoWasmAbi for &'a (Fn($($var),*) -> R + 'b)

View File

@ -687,6 +687,20 @@ pub mod __rt {
}
}
pub const GLOBAL_STACK_CAP: usize = 16;
// Increase the alignment to 8 here because this can be used as a
// BigUint64Array pointer base which requires alignment 8
#[repr(align(8))]
struct GlobalData([u32; GLOBAL_STACK_CAP]);
static mut GLOBAL_STACK: GlobalData = GlobalData([0; GLOBAL_STACK_CAP]);
#[no_mangle]
pub unsafe extern "C" fn __wbindgen_global_argument_ptr() -> *mut u32 {
GLOBAL_STACK.0.as_mut_ptr()
}
/// This is a curious function necessary to get wasm-bindgen working today,
/// and it's a bit of an unfortunate hack.
///