MCPcopy Create free account
hub / github.com/digama0/lean-sys / lean_alloc_small_object

Function lean_alloc_small_object

src/lib.rs:156–186  ·  view source on GitHub ↗
(sz: c_uint)

Source from the content-addressed store, hash-verified

154
155#[inline]
156pub unsafe fn lean_alloc_small_object(sz: c_uint) -> *mut lean_object {
157 if LEAN_SMALL_ALLOCATOR {
158 let sz = lean_align(sz as usize, LEAN_OBJECT_SIZE_DELTA) as c_uint;
159 let slot_idx = lean_get_slot_idx(sz);
160 debug_assert!(sz <= LEAN_MAX_SMALL_OBJECT_SIZE);
161 lean_alloc_small(sz, slot_idx).cast()
162 } else {
163 lean_inc_heartbeat();
164 if LEAN_MIMALLOC {
165 // HACK: emulate behavior of small allocator to avoid `leangz` breakage for now
166 let sz = lean_align(sz as usize, LEAN_OBJECT_SIZE_DELTA) as c_uint;
167 #[cfg(feature = "libmimalloc-sys")]
168 let mem = libmimalloc_sys::mi_malloc_small(sz as usize);
169 #[cfg(not(feature = "libmimalloc-sys"))]
170 let mem = core::ptr::null_mut::<c_void>();
171 if mem.is_null() {
172 lean_internal_panic_out_of_memory()
173 }
174 let o = mem.cast::<lean_object>();
175 (*o).m_cs_sz = sz as u16;
176 o
177 } else {
178 let mem = libc::malloc(size_of::<usize>() + sz as usize) as *mut usize;
179 if mem.is_null() {
180 lean_internal_panic_out_of_memory()
181 }
182 *mem = sz as usize;
183 mem.add(1).cast()
184 }
185 }
186}
187
188#[inline]
189pub unsafe fn lean_alloc_ctor_memory(sz: c_uint) -> *mut lean_object {

Callers 5

lean_alloc_closureFunction · 0.85
lean_alloc_ctor_memoryFunction · 0.85
lean_mk_thunkFunction · 0.85
lean_obj_resFunction · 0.85
lean_alloc_externalFunction · 0.85

Calls 2

lean_alignFunction · 0.85
lean_get_slot_idxFunction · 0.85

Tested by

no test coverage detected