@@ -356,56 +356,47 @@ elif defined(gogc):
356356
357357elif (defined (nogc) or defined (gcDestructors)) and defined (useMalloc):
358358
359- # libc realloc() does not zero memory when the buffer grows , so we need to do
360- # that here. Every allocated buffer is prepended with the size of the
361- # allocation so we know what to zero when growing the buffer with realloc()
359+ # libc realloc() does not zero out memory , so this is handled here. Every
360+ # allocated buffer is prepended with the size of the allocation which is used
361+ # to deduce which part of the buffer to zero.
362362
363363 when not defined (useNimRtl):
364+
364365 proc alloc (size: Natural ): pointer =
365366 var x = c_malloc (size + sizeof (size)).csize_t
366367 if x == nil : raiseOutOfMem ()
367-
368368 cast [ptr int ](x)[] = size
369369 result = cast [pointer ](cast [int ](x) + sizeof (size))
370370
371371 proc alloc0 (size: Natural ): pointer =
372372 result = alloc (size)
373373 zeroMem (result , size)
374+
374375 proc realloc (p: pointer , newsize: Natural ): pointer =
375376 var x = cast [pointer ](cast [int ](p) - sizeof (newsize))
376377 let oldsize = cast [ptr int ](x)[]
377-
378378 x = c_realloc (x, (newsize + sizeof (newsize)).csize_t )
379-
380379 if x == nil : raiseOutOfMem ()
381-
382380 cast [ptr int ](x)[] = newsize
383381 result = cast [pointer ](cast [int ](x) + sizeof (newsize))
384-
385382 if newsize > oldsize:
386383 zeroMem (cast [pointer ](cast [int ](result ) + oldsize), newsize - oldsize)
387384
388385 proc dealloc (p: pointer ) = c_free (cast [pointer ](cast [int ](p) - sizeof (int )))
389386
390- proc allocShared (size: Natural ): pointer =
391- result = alloc (size.csize_t )
392- if result == nil : raiseOutOfMem ()
393- proc allocShared0 (size: Natural ): pointer =
394- result = alloc (size)
395- zeroMem (result , size)
396- proc reallocShared (p: pointer , newsize: Natural ): pointer =
397- result = realloc (p, newsize.csize_t )
398- if result == nil : raiseOutOfMem ()
399- proc deallocShared (p: pointer ) =
400- dealloc (p)
387+ # Shared allocators map to the regular ones
388+
389+ proc allocShared (size: Natural ): pointer = alloc (size.csize_t )
390+ proc allocShared0 (size: Natural ): pointer = alloc0 (size)
391+ proc reallocShared (p: pointer , newsize: Natural ): pointer = realloc (p, newsize.csize_t )
392+ proc deallocShared (p: pointer ) = dealloc (p)
401393
402394 proc GC_disable () = discard
403395 proc GC_enable () = discard
404396 proc GC_fullCollect () = discard
405397 proc GC_setStrategy (strategy: GC_Strategy) = discard
406398 proc GC_enableMarkAndSweep () = discard
407399 proc GC_disableMarkAndSweep () = discard
408- # proc GC_getStatistics(): string = return ""
409400
410401 proc getOccupiedMem (): int = discard
411402 proc getFreeMem (): int = discard
0 commit comments