Skip to content

Commit

Permalink
fix ABI for raw pointers (#3655)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrvidal committed Oct 13, 2023
1 parent 46f52e9 commit d2f9315
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 2 deletions.
12 changes: 12 additions & 0 deletions crates/cli/tests/reference/pointers.d.ts
Original file line number Diff line number Diff line change
@@ -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;
23 changes: 23 additions & 0 deletions crates/cli/tests/reference/pointers.js
Original file line number Diff line number Diff line change
@@ -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;
}

11 changes: 11 additions & 0 deletions crates/cli/tests/reference/pointers.rs
Original file line number Diff line number Diff line change
@@ -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 _
}
9 changes: 9 additions & 0 deletions crates/cli/tests/reference/pointers.wat
Original file line number Diff line number Diff line change
@@ -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))
)
4 changes: 2 additions & 2 deletions src/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ cfg_if! {

impl<T> WasmDescribe for *const T {
fn describe() {
inform(I32)
inform(U32)
}
}

impl<T> WasmDescribe for *mut T {
fn describe() {
inform(I32)
inform(U32)
}
}

Expand Down

0 comments on commit d2f9315

Please sign in to comment.