mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-29 06:44:46 +00:00
update the rust platform
This commit is contained in:
parent
215cacb260
commit
bd05186503
2 changed files with 10 additions and 15 deletions
|
@ -3,7 +3,7 @@
|
|||
use core::ffi::c_void;
|
||||
use roc_std::RocStr;
|
||||
use std::ffi::CStr;
|
||||
use std::mem::ManuallyDrop;
|
||||
use std::io::Write;
|
||||
use std::os::raw::c_char;
|
||||
|
||||
extern "C" {
|
||||
|
@ -56,21 +56,11 @@ pub unsafe extern "C" fn roc_memset(dst: *mut c_void, c: i32, n: usize) -> *mut
|
|||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn rust_main() -> i32 {
|
||||
unsafe {
|
||||
// ManuallyDrop must be used here in order to prevent the RocStr from
|
||||
// getting dropped as soon as it's no longer referenced anywhere, which
|
||||
// happens earlier than the libc::write that receives a pointer to its data.
|
||||
let mut roc_str = ManuallyDrop::new(RocStr::default());
|
||||
roc_main(&mut roc_str);
|
||||
let mut roc_str = RocStr::default();
|
||||
unsafe { roc_main(&mut roc_str) };
|
||||
|
||||
let len = roc_str.len();
|
||||
let str_bytes = roc_str.as_bytes().as_ptr() as *const libc::c_void;
|
||||
|
||||
if libc::write(1, str_bytes, len) < 0 {
|
||||
panic!("Writing to stdout failed!");
|
||||
}
|
||||
|
||||
ManuallyDrop::drop(&mut roc_str)
|
||||
if let Err(e) = std::io::stdout().write_all(roc_str.as_bytes()) {
|
||||
panic!("Writing to stdout failed! {:?}", e);
|
||||
}
|
||||
|
||||
// Exit code
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue