add deno_test_wasm
This commit is contained in:
5
deno_test_wasm/test_wasm/Cargo.lock
generated
Normal file
5
deno_test_wasm/test_wasm/Cargo.lock
generated
Normal file
@@ -0,0 +1,5 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
[[package]]
|
||||
name = "test_wasm"
|
||||
version = "0.1.0"
|
||||
15
deno_test_wasm/test_wasm/Cargo.toml
Normal file
15
deno_test_wasm/test_wasm/Cargo.toml
Normal file
@@ -0,0 +1,15 @@
|
||||
[package]
|
||||
name = "test_wasm"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[lib]
|
||||
crate-type =["cdylib"]
|
||||
|
||||
[dependencies]
|
||||
|
||||
[profile.release]
|
||||
lto = true
|
||||
14
deno_test_wasm/test_wasm/src/lib.rs
Normal file
14
deno_test_wasm/test_wasm/src/lib.rs
Normal file
@@ -0,0 +1,14 @@
|
||||
use std::ffi::CString;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn malloc(len: usize) -> *mut c_char {
|
||||
let s = unsafe { CString::from_vec_unchecked(Vec::with_capacity(len)) };
|
||||
s.into_raw()
|
||||
}
|
||||
|
||||
pub extern "C" fn to_uppercase(ptr: *mut c_char) -> *mut c_char {
|
||||
let s = unsafe { CString::from_raw(ptr) };
|
||||
let s2 = CString::new(s.to_string_lossy().to_uppercase()).unwrap();
|
||||
s2.into_raw()
|
||||
}
|
||||
Reference in New Issue
Block a user