mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-06-29 20:51:37 +00:00
Consistently use extern "C"
This is what rustfmt favors, so let's favor it too! Closes #1042
This commit is contained in:
@ -39,7 +39,7 @@ In addition to the shims we talked about above which JS generates the macro
|
||||
|
||||
```
|
||||
#[no_mangle]
|
||||
pub extern fn __wbindgen_describe_greet() {
|
||||
pub extern "C" fn __wbindgen_describe_greet() {
|
||||
<Fn(&str)>::describe();
|
||||
}
|
||||
```
|
||||
|
@ -95,13 +95,13 @@ let's take a look at that.
|
||||
// original input to `#[wasm_bindgen]` omitted ...
|
||||
|
||||
#[export_name = "foo_new"]
|
||||
pub extern fn __wasm_bindgen_generated_Foo_new(arg0: i32) -> u32
|
||||
pub extern "C" fn __wasm_bindgen_generated_Foo_new(arg0: i32) -> u32
|
||||
let ret = Foo::new(arg0);
|
||||
Box::into_raw(Box::new(WasmRefCell::new(ret))) as u32
|
||||
}
|
||||
|
||||
#[export_name = "foo_get"]
|
||||
pub extern fn __wasm_bindgen_generated_Foo_get(me: u32) -> i32 {
|
||||
pub extern "C" fn __wasm_bindgen_generated_Foo_get(me: u32) -> i32 {
|
||||
let me = me as *mut WasmRefCell<Foo>;
|
||||
wasm_bindgen::__rt::assert_not_null(me);
|
||||
let me = unsafe { &*me };
|
||||
@ -109,7 +109,7 @@ pub extern fn __wasm_bindgen_generated_Foo_get(me: u32) -> i32 {
|
||||
}
|
||||
|
||||
#[export_name = "foo_set"]
|
||||
pub extern fn __wasm_bindgen_generated_Foo_set(me: u32, arg1: i32) {
|
||||
pub extern "C" fn __wasm_bindgen_generated_Foo_set(me: u32, arg1: i32) {
|
||||
let me = me as *mut WasmRefCell<Foo>;
|
||||
::wasm_bindgen::__rt::assert_not_null(me);
|
||||
let me = unsafe { &*me };
|
||||
@ -117,7 +117,7 @@ pub extern fn __wasm_bindgen_generated_Foo_set(me: u32, arg1: i32) {
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern fn __wbindgen_foo_free(me: u32) {
|
||||
pub unsafe extern "C" fn __wbindgen_foo_free(me: u32) {
|
||||
let me = me as *mut WasmRefCell<Foo>;
|
||||
wasm_bindgen::__rt::assert_not_null(me);
|
||||
(*me).borrow_mut(); // ensure no active borrows
|
||||
|
@ -87,12 +87,12 @@ at a mostly abbreviated and/or "simplified" in the sense of this is what it
|
||||
compiles down to:
|
||||
|
||||
```rust
|
||||
pub extern fn greet(a: &str) -> String {
|
||||
pub extern "C" fn greet(a: &str) -> String {
|
||||
format!("Hello, {}!", a)
|
||||
}
|
||||
|
||||
#[export_name = "greet"]
|
||||
pub extern fn __wasm_bindgen_generated_greet(
|
||||
pub extern "C" fn __wasm_bindgen_generated_greet(
|
||||
arg0_ptr: *const u8,
|
||||
arg0_len: usize,
|
||||
) -> *mut String {
|
||||
|
@ -10,7 +10,7 @@ As usual though, let's dive into an example!
|
||||
|
||||
```rust
|
||||
#[wasm_bindgen(module = "./bar")]
|
||||
extern {
|
||||
extern "C" {
|
||||
type Bar;
|
||||
|
||||
#[wasm_bindgen(constructor)]
|
||||
@ -125,7 +125,7 @@ pub struct Bar {
|
||||
|
||||
impl Bar {
|
||||
fn new() -> Bar {
|
||||
extern {
|
||||
extern "C" {
|
||||
fn __wbg_s_Bar_new() -> u32;
|
||||
}
|
||||
unsafe {
|
||||
@ -135,7 +135,7 @@ impl Bar {
|
||||
}
|
||||
|
||||
fn another_function() -> i32 {
|
||||
extern {
|
||||
extern "C" {
|
||||
fn __wbg_s_Bar_another_function() -> i32;
|
||||
}
|
||||
unsafe {
|
||||
@ -144,7 +144,7 @@ impl Bar {
|
||||
}
|
||||
|
||||
fn get(&self) -> i32 {
|
||||
extern {
|
||||
extern "C" {
|
||||
fn __wbg_s_Bar_get(ptr: u32) -> i32;
|
||||
}
|
||||
unsafe {
|
||||
@ -155,7 +155,7 @@ impl Bar {
|
||||
}
|
||||
|
||||
fn set(&self, val: i32) {
|
||||
extern {
|
||||
extern "C" {
|
||||
fn __wbg_s_Bar_set(ptr: u32, val: i32);
|
||||
}
|
||||
unsafe {
|
||||
@ -165,7 +165,7 @@ impl Bar {
|
||||
}
|
||||
|
||||
fn property(&self) -> i32 {
|
||||
extern {
|
||||
extern "C" {
|
||||
fn __wbg_s_Bar_property(ptr: u32) -> i32;
|
||||
}
|
||||
unsafe {
|
||||
@ -176,7 +176,7 @@ impl Bar {
|
||||
}
|
||||
|
||||
fn set_property(&self, val: i32) {
|
||||
extern {
|
||||
extern "C" {
|
||||
fn __wbg_s_Bar_set_property(ptr: u32, val: i32);
|
||||
}
|
||||
unsafe {
|
||||
|
@ -9,7 +9,7 @@ greetings in JS but call it from Rust. We might have, for example:
|
||||
|
||||
```rust
|
||||
#[wasm_bindgen(module = "./greet")]
|
||||
extern {
|
||||
extern "C" {
|
||||
fn greet(a: &str) -> String;
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@ generated Rust as well. Like before this is simplified from what's actually
|
||||
generated.
|
||||
|
||||
```rust
|
||||
extern fn greet(a: &str) -> String {
|
||||
extern {
|
||||
extern "C" fn greet(a: &str) -> String {
|
||||
extern "C" {
|
||||
fn __wbg_f_greet(a_ptr: *const u8, a_len: usize, ret_len: *mut usize) -> *mut u8;
|
||||
}
|
||||
unsafe {
|
||||
|
@ -86,7 +86,7 @@ pub fn foo(a: &JsValue) {
|
||||
}
|
||||
|
||||
#[export_name = "foo"]
|
||||
pub extern fn __wasm_bindgen_generated_foo(arg0: u32) {
|
||||
pub extern "C" fn __wasm_bindgen_generated_foo(arg0: u32) {
|
||||
let arg0 = unsafe {
|
||||
ManuallyDrop::new(JsValue::__from_idx(arg0))
|
||||
};
|
||||
@ -189,7 +189,7 @@ pub fn foo(a: JsValue) {
|
||||
}
|
||||
|
||||
#[export_name = "foo"]
|
||||
pub extern fn __wasm_bindgen_generated_foo(arg0: u32) {
|
||||
pub extern "C" fn __wasm_bindgen_generated_foo(arg0: u32) {
|
||||
let arg0 = unsafe {
|
||||
JsValue::__from_idx(arg0)
|
||||
};
|
||||
|
Reference in New Issue
Block a user