mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 23:37:56 +03:00
Use roc_alloc etc in roc_std
This commit is contained in:
parent
13198bce37
commit
f9241cfa01
@ -1,5 +1,6 @@
|
||||
#![crate_type = "lib"]
|
||||
#![no_std]
|
||||
use core::ffi::c_void;
|
||||
use core::fmt;
|
||||
|
||||
pub mod alloca;
|
||||
@ -7,6 +8,15 @@ pub mod alloca;
|
||||
// A list of C functions that are being imported
|
||||
extern "C" {
|
||||
pub fn printf(format: *const u8, ...) -> i32;
|
||||
|
||||
pub fn roc_alloc(alignment: usize, size: usize) -> *mut c_void;
|
||||
pub fn roc_realloc(
|
||||
alignment: usize,
|
||||
ptr: *mut c_void,
|
||||
old_size: usize,
|
||||
new_size: usize,
|
||||
) -> *mut c_void;
|
||||
pub fn roc_dealloc(alignment: usize, ptr: *mut c_void);
|
||||
}
|
||||
|
||||
const REFCOUNT_1: usize = isize::MIN as usize;
|
||||
@ -138,7 +148,7 @@ impl<T> RocList<T> {
|
||||
let num_bytes = core::mem::size_of::<usize>() + padding + element_bytes;
|
||||
|
||||
let elements = unsafe {
|
||||
let raw_ptr = libc::malloc(num_bytes) as *mut u8;
|
||||
let raw_ptr = roc_alloc(core::mem::size_of::<usize>(), num_bytes) as *mut u8;
|
||||
|
||||
// pointer to the first element
|
||||
let raw_ptr = Self::get_element_ptr(raw_ptr as *mut T) as *mut T;
|
||||
@ -369,8 +379,7 @@ impl RocStr {
|
||||
let num_bytes = core::mem::size_of::<usize>() + element_bytes;
|
||||
|
||||
let elements = unsafe {
|
||||
let raw_ptr = libc::malloc(num_bytes);
|
||||
|
||||
let raw_ptr = roc_alloc(core::mem::size_of::<usize>(), num_bytes) as *mut u8;
|
||||
// write the capacity
|
||||
let capacity_ptr = raw_ptr as *mut usize;
|
||||
*capacity_ptr = capacity;
|
||||
@ -452,7 +461,7 @@ impl Clone for RocStr {
|
||||
let capacity_size = core::mem::size_of::<usize>();
|
||||
let copy_length = self.length + capacity_size;
|
||||
let elements = unsafe {
|
||||
let raw = libc::malloc(copy_length);
|
||||
let raw = roc_alloc(core::mem::size_of::<usize>(), copy_length);
|
||||
|
||||
libc::memcpy(
|
||||
raw,
|
||||
|
Loading…
Reference in New Issue
Block a user