Remove debug prints

This commit is contained in:
Steve Akinyemi 2018-12-17 09:15:08 +01:00
parent 05aa3bc62a
commit a2bd8d170f
2 changed files with 6 additions and 8 deletions

View File

@ -8,12 +8,13 @@ use std::os::raw::c_char;
use super::utils::{copy_cstr_into_wasm, copy_terminated_array_of_cstrs};
use crate::webassembly::Instance;
#[no_mangle]
/// emscripten: _getenv // (name: *const char) -> *const c_char;
pub extern "C" fn _getenv(name_ptr: c_int, instance: &mut Instance) -> u32 {
debug!("emscripten::_getenv {}", name_ptr);
pub extern "C" fn _getenv(name: c_int, instance: &mut Instance) -> u32 {
debug!("emscripten::_getenv {}", name);
let name = unsafe {
let memory_name_ptr = instance.memory_offset_addr(0, name_ptr as usize) as *const c_char;
CStr::from_ptr(memory_name_ptr).to_str().unwrap()
let name_addr = instance.memory_offset_addr(0, name as usize) as *const c_char;
CStr::from_ptr(name_addr).to_str().unwrap()
};
match host::get_env(name, instance) {
Ok(env_value) => {
@ -25,6 +26,7 @@ pub extern "C" fn _getenv(name_ptr: c_int, instance: &mut Instance) -> u32 {
let c_str = instance.memory_offset_addr(0, res as _) as *mut i8;
use std::ffi::CStr;
debug!("#### cstr = {:?}", unsafe { CStr::from_ptr(c_str) });
debug!("res = {}", res);
res
}
Err(_) => 0,

View File

@ -33,21 +33,17 @@ pub fn write_to_buf(string: *const c_char, buf: u32, max: u32, instance: &Instan
pub unsafe fn copy_cstr_into_wasm(instance: &mut Instance, cstr: *const c_char) -> u32 {
let s = CStr::from_ptr(cstr).to_str().unwrap();
let cstr_len = s.len();
debug!("### 1!");
let space_offset = (instance.emscripten_data.as_ref().unwrap().malloc)((cstr_len as i32) + 1, instance);
debug!("### 2!");
let raw_memory = instance.memory_offset_addr(0, space_offset as _) as *mut u8;
let slice = slice::from_raw_parts_mut(raw_memory, cstr_len);
for (byte, loc) in s.bytes().zip(slice.iter_mut()) {
*loc = byte;
}
debug!("### KABOOM 10!");
// TODO: Appending null byte won't work, because there is CStr::from_ptr(cstr)
// at the top that crashes when there is no null byte
*raw_memory.add(cstr_len) = 0;
debug!("### KABOOM 15!");
space_offset
}