From b2ec21da733200f45984516eef34c6bb570d4c23 Mon Sep 17 00:00:00 2001 From: Roberto Vidal Date: Fri, 13 Oct 2023 14:26:56 +0200 Subject: [PATCH] fix ABI for raw pointers --- crates/cli/tests/reference/pointers.d.ts | 12 ++++++++++++ crates/cli/tests/reference/pointers.js | 23 +++++++++++++++++++++++ crates/cli/tests/reference/pointers.rs | 11 +++++++++++ crates/cli/tests/reference/pointers.wat | 9 +++++++++ src/describe.rs | 4 ++-- 5 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 crates/cli/tests/reference/pointers.d.ts create mode 100644 crates/cli/tests/reference/pointers.js create mode 100644 crates/cli/tests/reference/pointers.rs create mode 100644 crates/cli/tests/reference/pointers.wat diff --git a/crates/cli/tests/reference/pointers.d.ts b/crates/cli/tests/reference/pointers.d.ts new file mode 100644 index 00000000000..2ce096435b5 --- /dev/null +++ b/crates/cli/tests/reference/pointers.d.ts @@ -0,0 +1,12 @@ +/* tslint:disable */ +/* eslint-disable */ +/** +* @param {number} input +* @returns {number} +*/ +export function const_pointer(input: number): number; +/** +* @param {number} input +* @returns {number} +*/ +export function mut_pointer(input: number): number; diff --git a/crates/cli/tests/reference/pointers.js b/crates/cli/tests/reference/pointers.js new file mode 100644 index 00000000000..cf088c2e711 --- /dev/null +++ b/crates/cli/tests/reference/pointers.js @@ -0,0 +1,23 @@ +let wasm; +export function __wbg_set_wasm(val) { + wasm = val; +} + +/** +* @param {number} input +* @returns {number} +*/ +export function const_pointer(input) { + const ret = wasm.const_pointer(input); + return ret >>> 0; +} + +/** +* @param {number} input +* @returns {number} +*/ +export function mut_pointer(input) { + const ret = wasm.mut_pointer(input); + return ret >>> 0; +} + diff --git a/crates/cli/tests/reference/pointers.rs b/crates/cli/tests/reference/pointers.rs new file mode 100644 index 00000000000..ecee8167070 --- /dev/null +++ b/crates/cli/tests/reference/pointers.rs @@ -0,0 +1,11 @@ +use wasm_bindgen::prelude::*; + +#[wasm_bindgen] +pub fn const_pointer(input: *const u8) -> *const u8 { + u32::MAX as *const _ +} + +#[wasm_bindgen] +pub fn mut_pointer(input: *mut u8) -> *mut u8 { + u32::MAX as *mut _ +} diff --git a/crates/cli/tests/reference/pointers.wat b/crates/cli/tests/reference/pointers.wat new file mode 100644 index 00000000000..e624bd832fc --- /dev/null +++ b/crates/cli/tests/reference/pointers.wat @@ -0,0 +1,9 @@ +(module + (type (;0;) (func (param i32) (result i32))) + (func $const_pointer (;0;) (type 0) (param i32) (result i32)) + (func $mut_pointer (;1;) (type 0) (param i32) (result i32)) + (memory (;0;) 17) + (export "memory" (memory 0)) + (export "const_pointer" (func $const_pointer)) + (export "mut_pointer" (func $mut_pointer)) +) diff --git a/src/describe.rs b/src/describe.rs index 12a48554ac6..d3b5fd0b546 100644 --- a/src/describe.rs +++ b/src/describe.rs @@ -104,13 +104,13 @@ cfg_if! { impl WasmDescribe for *const T { fn describe() { - inform(I32) + inform(U32) } } impl WasmDescribe for *mut T { fn describe() { - inform(I32) + inform(U32) } }