@@ -184,7 +184,11 @@ pub fn malloc(n int) byteptr {
184184 }
185185 nr_mallocs++
186186 } $else {
187- res = unsafe { C.malloc (n) }
187+ $if gcboehm ? {
188+ res = unsafe { C.GC_MALLOC (n) }
189+ } $else {
190+ res = unsafe { C.malloc (n) }
191+ }
188192 if res == 0 {
189193 panic ('malloc($n ) failed' )
190194 }
@@ -214,7 +218,11 @@ pub fn v_realloc(b byteptr, n int) byteptr {
214218 C.memcpy (new_ptr, b, n)
215219 }
216220 } $else {
217- new_ptr = unsafe { C.realloc (b, n) }
221+ $if gcboehm ? {
222+ new_ptr = unsafe { C.GC_REALLOC (b, n) }
223+ } $else {
224+ new_ptr = unsafe { C.realloc (b, n) }
225+ }
218226 if new_ptr == 0 {
219227 panic ('realloc($n ) failed' )
220228 }
@@ -254,11 +262,16 @@ pub fn realloc_data(old_data byteptr, old_size int, new_size int) byteptr {
254262 min_size := if old_size < new_size { old_size } else { new_size }
255263 C.memcpy (new_ptr, old_data, min_size)
256264 C.memset (old_data, 0x57 , old_size)
257- C. free (old_data)
265+ free (old_data)
258266 return new_ptr
259267 }
260268 }
261- nptr := unsafe { C.realloc (old_data, new_size) }
269+ mut nptr := byteptr (0 )
270+ $if gcboehm ? {
271+ nptr = unsafe { C.GC_REALLOC (old_data, new_size) }
272+ } $else {
273+ nptr = unsafe { C.realloc (old_data, new_size) }
274+ }
262275 if nptr == 0 {
263276 panic ('realloc_data($old_data , $old_size , $new_size ) failed' )
264277 }
@@ -268,7 +281,11 @@ pub fn realloc_data(old_data byteptr, old_size int, new_size int) byteptr {
268281// v_calloc dynamically allocates a zeroed `n` bytes block of memory on the heap.
269282// v_calloc returns a `byteptr` pointing to the memory address of the allocated space.
270283pub fn v_calloc (n int ) byteptr {
271- return C.calloc (1 , n)
284+ $if gcboehm ? {
285+ return C.GC_MALLOC (n)
286+ } $else {
287+ return C.calloc (1 , n)
288+ }
272289}
273290
274291// vcalloc dynamically allocates a zeroed `n` bytes block of memory on the heap.
@@ -280,7 +297,11 @@ pub fn vcalloc(n int) byteptr {
280297 } else if n == 0 {
281298 return byteptr (0 )
282299 }
283- return C.calloc (1 , n)
300+ $if gcboehm ? {
301+ return C.GC_MALLOC (n)
302+ } $else {
303+ return C.calloc (1 , n)
304+ }
284305}
285306
286307// free allows for manually freeing memory allocated at the address `ptr`.
@@ -289,6 +310,10 @@ pub fn free(ptr voidptr) {
289310 $if prealloc {
290311 return
291312 }
313+ $if gcboehm ? {
314+ C.GC_FREE (ptr)
315+ return
316+ }
292317 C.free (ptr)
293318}
294319
@@ -306,14 +331,6 @@ pub fn memdup(src voidptr, sz int) voidptr {
306331 }
307332}
308333
309- // v_ptr_free is used internally to manually free up memory allocated at the address `ptr`.
310- fn v_ptr_free (ptr voidptr ) {
311- $if prealloc {
312- return
313- }
314- C.free (ptr)
315- }
316-
317334// is_atty returns 1 if the `fd` file descriptor is open and refers to a terminal
318335pub fn is_atty (fd int ) int {
319336 $if windows {
0 commit comments