mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-21 07:49:17 +03:00
Update comments to no longer reference malloc
This commit is contained in:
parent
f31060af34
commit
13198bce37
@ -1944,7 +1944,7 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>(
|
|||||||
"get_data_ptr",
|
"get_data_ptr",
|
||||||
),
|
),
|
||||||
ptr_type,
|
ptr_type,
|
||||||
"malloc_cast_to_desired",
|
"alloc_cast_to_desired",
|
||||||
)
|
)
|
||||||
.into_pointer_value()
|
.into_pointer_value()
|
||||||
}
|
}
|
||||||
@ -1952,12 +1952,12 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>(
|
|||||||
|
|
||||||
let refcount_ptr = match extra_bytes {
|
let refcount_ptr = match extra_bytes {
|
||||||
n if n == env.ptr_bytes => {
|
n if n == env.ptr_bytes => {
|
||||||
// the malloced pointer is the same as the refcounted pointer
|
// the allocated pointer is the same as the refcounted pointer
|
||||||
unsafe { PointerToRefcount::from_ptr(env, ptr) }
|
unsafe { PointerToRefcount::from_ptr(env, ptr) }
|
||||||
}
|
}
|
||||||
n if n == 2 * env.ptr_bytes => {
|
n if n == 2 * env.ptr_bytes => {
|
||||||
// the refcount is stored just before the start of the actual data
|
// the refcount is stored just before the start of the actual data
|
||||||
// but in this case (because of alignment) not at the start of the malloced buffer
|
// but in this case (because of alignment) not at the start of the allocated buffer
|
||||||
PointerToRefcount::from_ptr_to_data(env, data_ptr)
|
PointerToRefcount::from_ptr_to_data(env, data_ptr)
|
||||||
}
|
}
|
||||||
n => unreachable!("invalid extra_bytes {}", n),
|
n => unreachable!("invalid extra_bytes {}", n),
|
||||||
@ -1986,8 +1986,6 @@ fn list_literal<'a, 'ctx, 'env>(
|
|||||||
let len = len_type.const_int(len_u64, false);
|
let len = len_type.const_int(len_u64, false);
|
||||||
|
|
||||||
allocate_list(env, inplace, elem_layout, len)
|
allocate_list(env, inplace, elem_layout, len)
|
||||||
|
|
||||||
// TODO check if malloc returned null; if so, runtime error for OOM!
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Copy the elements from the list literal into the array
|
// Copy the elements from the list literal into the array
|
||||||
|
@ -185,7 +185,7 @@ pub fn list_prepend<'a, 'ctx, 'env>(
|
|||||||
|
|
||||||
if elem_layout.safe_to_memcpy() {
|
if elem_layout.safe_to_memcpy() {
|
||||||
// Copy the bytes from the original array into the new
|
// Copy the bytes from the original array into the new
|
||||||
// one we just malloc'd.
|
// one we just allocated
|
||||||
//
|
//
|
||||||
// TODO how do we decide when to do the small memcpy vs the normal one?
|
// TODO how do we decide when to do the small memcpy vs the normal one?
|
||||||
builder
|
builder
|
||||||
@ -1335,12 +1335,10 @@ fn clone_nonempty_list<'a, 'ctx, 'env>(
|
|||||||
// Allocate space for the new array that we'll copy into.
|
// Allocate space for the new array that we'll copy into.
|
||||||
let clone_ptr = allocate_list(env, inplace, elem_layout, list_len);
|
let clone_ptr = allocate_list(env, inplace, elem_layout, list_len);
|
||||||
|
|
||||||
// TODO check if malloc returned null; if so, runtime error for OOM!
|
|
||||||
|
|
||||||
// Either memcpy or deep clone the array elements
|
// Either memcpy or deep clone the array elements
|
||||||
if elem_layout.safe_to_memcpy() {
|
if elem_layout.safe_to_memcpy() {
|
||||||
// Copy the bytes from the original array into the new
|
// Copy the bytes from the original array into the new
|
||||||
// one we just malloc'd.
|
// one we just allocated
|
||||||
//
|
//
|
||||||
// TODO how do we decide when to do the small memcpy vs the normal one?
|
// TODO how do we decide when to do the small memcpy vs the normal one?
|
||||||
builder
|
builder
|
||||||
|
@ -40,8 +40,8 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
|||||||
/// # Safety
|
/// # Safety
|
||||||
///
|
///
|
||||||
/// the invariant is that the given pointer really points to the refcount,
|
/// the invariant is that the given pointer really points to the refcount,
|
||||||
/// not the data, and only is the start of the malloced buffer if the alignment
|
/// not the data, and only is the start of the allocated buffer if the
|
||||||
/// works out that way.
|
/// alignment works out that way.
|
||||||
pub unsafe fn from_ptr<'a, 'env>(env: &Env<'a, 'ctx, 'env>, ptr: PointerValue<'ctx>) -> Self {
|
pub unsafe fn from_ptr<'a, 'env>(env: &Env<'a, 'ctx, 'env>, ptr: PointerValue<'ctx>) -> Self {
|
||||||
// must make sure it's a pointer to usize
|
// must make sure it's a pointer to usize
|
||||||
let refcount_type = ptr_int(env.context, env.ptr_bytes);
|
let refcount_type = ptr_int(env.context, env.ptr_bytes);
|
||||||
@ -277,13 +277,13 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
|||||||
|
|
||||||
match alignment {
|
match alignment {
|
||||||
n if env.ptr_bytes == n => {
|
n if env.ptr_bytes == n => {
|
||||||
// the refcount ptr is also the ptr to the malloced region
|
// the refcount ptr is also the ptr to the allocated region
|
||||||
env.call_dealloc(alignment, ptr);
|
env.call_dealloc(alignment, ptr);
|
||||||
}
|
}
|
||||||
n if 2 * env.ptr_bytes == n => {
|
n if 2 * env.ptr_bytes == n => {
|
||||||
// we need to step back another ptr_bytes to get the malloced ptr
|
// we need to step back another ptr_bytes to get the allocated ptr
|
||||||
let malloced = Self::from_ptr_to_data(env, ptr);
|
let allocated = Self::from_ptr_to_data(env, ptr);
|
||||||
env.call_dealloc(alignment, malloced.value);
|
env.call_dealloc(alignment, allocated.value);
|
||||||
}
|
}
|
||||||
n => unreachable!("invalid extra_bytes {:?}", n),
|
n => unreachable!("invalid extra_bytes {:?}", n),
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user