mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-04-01 18:01:06 +00:00
Merge pull request #1625 from alexcrichton/less-return-ptr
Remove `__wbindgen_global_argument_ptr` intrinsic
This commit is contained in:
commit
792ab403a1
@ -118,14 +118,20 @@ impl<'a, 'b> Builder<'a, 'b> {
|
|||||||
if incoming_args {
|
if incoming_args {
|
||||||
let mut webidl_params = webidl.params.iter();
|
let mut webidl_params = webidl.params.iter();
|
||||||
|
|
||||||
// If we're returning via an out pointer then it's guaranteed to be the
|
// If we're returning via an out pointer then it's guaranteed to be
|
||||||
// first argument. This isn't an argument of the function shim we're
|
// the first argument. This isn't an argument of the function shim
|
||||||
// generating so synthesize the parameter and its value.
|
// we're generating so synthesize the parameter and its value.
|
||||||
|
//
|
||||||
|
// For the actual value of the return pointer we just pick the first
|
||||||
|
// properly aligned nonzero address. We use the address for a
|
||||||
|
// BigInt64Array sometimes which means it needs to be 8-byte
|
||||||
|
// aligned. Otherwise valid code is unlikely to ever be working
|
||||||
|
// around address 8, so this should be a safe address to use for
|
||||||
|
// returning data through.
|
||||||
if binding.return_via_outptr.is_some() {
|
if binding.return_via_outptr.is_some() {
|
||||||
drop(webidl_params.next());
|
drop(webidl_params.next());
|
||||||
self.cx.expose_global_argument_ptr()?;
|
|
||||||
self.args_prelude
|
self.args_prelude
|
||||||
.push_str("const retptr = globalArgumentPtr();\n");
|
.push_str("const retptr = 8;\n");
|
||||||
arg_names.push("retptr".to_string());
|
arg_names.push("retptr".to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1558,25 +1558,6 @@ impl<'a> Context<'a> {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fn expose_global_argument_ptr(&mut self) -> Result<(), Error> {
|
|
||||||
if !self.should_write_global("global_argument_ptr") {
|
|
||||||
return Ok(());
|
|
||||||
}
|
|
||||||
self.require_internal_export("__wbindgen_global_argument_ptr")?;
|
|
||||||
self.global(
|
|
||||||
"
|
|
||||||
let cachedGlobalArgumentPtr = null;
|
|
||||||
function globalArgumentPtr() {
|
|
||||||
if (cachedGlobalArgumentPtr === null) {
|
|
||||||
cachedGlobalArgumentPtr = wasm.__wbindgen_global_argument_ptr();
|
|
||||||
}
|
|
||||||
return cachedGlobalArgumentPtr;
|
|
||||||
}
|
|
||||||
",
|
|
||||||
);
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
fn expose_get_inherited_descriptor(&mut self) {
|
fn expose_get_inherited_descriptor(&mut self) {
|
||||||
if !self.should_write_global("get_inherited_descriptor") {
|
if !self.should_write_global("get_inherited_descriptor") {
|
||||||
return;
|
return;
|
||||||
|
14
src/lib.rs
14
src/lib.rs
@ -1017,20 +1017,6 @@ 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,
|
/// This is a curious function necessary to get wasm-bindgen working today,
|
||||||
/// and it's a bit of an unfortunate hack.
|
/// and it's a bit of an unfortunate hack.
|
||||||
///
|
///
|
||||||
|
Loading…
x
Reference in New Issue
Block a user