mirror of
https://github.com/roc-lang/roc.git
synced 2024-09-20 23:37:56 +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",
|
||||
),
|
||||
ptr_type,
|
||||
"malloc_cast_to_desired",
|
||||
"alloc_cast_to_desired",
|
||||
)
|
||||
.into_pointer_value()
|
||||
}
|
||||
@ -1952,12 +1952,12 @@ pub fn allocate_with_refcount_help<'a, 'ctx, 'env>(
|
||||
|
||||
let refcount_ptr = match extra_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) }
|
||||
}
|
||||
n if n == 2 * env.ptr_bytes => {
|
||||
// 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)
|
||||
}
|
||||
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);
|
||||
|
||||
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
|
||||
|
@ -185,7 +185,7 @@ pub fn list_prepend<'a, 'ctx, 'env>(
|
||||
|
||||
if elem_layout.safe_to_memcpy() {
|
||||
// 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?
|
||||
builder
|
||||
@ -1335,12 +1335,10 @@ fn clone_nonempty_list<'a, 'ctx, 'env>(
|
||||
// Allocate space for the new array that we'll copy into.
|
||||
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
|
||||
if elem_layout.safe_to_memcpy() {
|
||||
// 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?
|
||||
builder
|
||||
|
@ -40,8 +40,8 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
||||
/// # Safety
|
||||
///
|
||||
/// 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
|
||||
/// works out that way.
|
||||
/// not the data, and only is the start of the allocated buffer if the
|
||||
/// alignment works out that way.
|
||||
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
|
||||
let refcount_type = ptr_int(env.context, env.ptr_bytes);
|
||||
@ -277,13 +277,13 @@ impl<'ctx> PointerToRefcount<'ctx> {
|
||||
|
||||
match alignment {
|
||||
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);
|
||||
}
|
||||
n if 2 * env.ptr_bytes == n => {
|
||||
// we need to step back another ptr_bytes to get the malloced ptr
|
||||
let malloced = Self::from_ptr_to_data(env, ptr);
|
||||
env.call_dealloc(alignment, malloced.value);
|
||||
// we need to step back another ptr_bytes to get the allocated ptr
|
||||
let allocated = Self::from_ptr_to_data(env, ptr);
|
||||
env.call_dealloc(alignment, allocated.value);
|
||||
}
|
||||
n => unreachable!("invalid extra_bytes {:?}", n),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user