Merge remote-tracking branch 'origin/main' into roc-dev-inline-expects

This commit is contained in:
Folkert 2022-10-30 15:57:07 +01:00
commit dbd0d30893
No known key found for this signature in database
GPG key ID: 1F17F6FFD112B97C
98 changed files with 4649 additions and 1433 deletions

View file

@ -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" {
@ -91,21 +91,11 @@ pub unsafe extern "C" fn roc_send_signal(pid: libc::pid_t, sig: libc::c_int) ->
#[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