mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 14:24:45 +00:00
wasm: go back to custom bytes->string transformation
CStr version is too hard to get working correctly. I get weird test failures with random characters in the middle of strings.
This commit is contained in:
parent
20e46fbda4
commit
338961d202
1 changed files with 7 additions and 6 deletions
|
@ -1,8 +1,6 @@
|
||||||
use core::cell::Cell;
|
use core::cell::Cell;
|
||||||
use libc::c_char;
|
|
||||||
use roc_gen_wasm::wasm_module::{Export, ExportType};
|
use roc_gen_wasm::wasm_module::{Export, ExportType};
|
||||||
use std::collections::hash_map::DefaultHasher;
|
use std::collections::hash_map::DefaultHasher;
|
||||||
use std::ffi::CStr;
|
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::{Hash, Hasher};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
@ -238,10 +236,13 @@ fn get_roc_panic_msg(instance: &wasmer::Instance, memory: &Memory) -> Option<Str
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let msg_index = msg_addr as usize;
|
let msg_index = msg_addr as usize;
|
||||||
let msg_ptr = memory_bytes[msg_index..].as_ptr();
|
let msg_len = memory_bytes[msg_index..]
|
||||||
let msg_cstr = unsafe { CStr::from_ptr(msg_ptr as *const c_char) };
|
.iter()
|
||||||
let msg_str = msg_cstr.to_str().unwrap();
|
.position(|c| *c == 0)
|
||||||
Some(msg_str.to_string())
|
.unwrap();
|
||||||
|
let msg_bytes = memory_bytes[msg_index..][..msg_len].to_vec();
|
||||||
|
let msg = unsafe { String::from_utf8_unchecked(msg_bytes) };
|
||||||
|
Some(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue