add deno_test_wasm

This commit is contained in:
2020-05-30 20:24:44 +08:00
parent 9c86dd8637
commit 5cb322fabd
3 changed files with 34 additions and 0 deletions

5
deno_test_wasm/test_wasm/Cargo.lock generated Normal file
View 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"

View 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

View 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()
}