diff options
author | yatsen1 <kitech@sixlan.tk> | 2019-06-18 02:47:18 +0800 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-06-17 20:47:18 +0200 |
commit | c8268330be4de61541aa34eb82f7a93dc62e627c (patch) | |
tree | c6532b431e466e7db5f12fae15a33c67ce658b15 /lib/system | |
parent | ac3449b93b9e7e97c2d4a75ed7f032a9fc088f80 (diff) | |
download | Nim-c8268330be4de61541aa34eb82f7a93dc62e627c.tar.gz |
[feature] Add boehm gc finalizer (#11446)
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/mmdisp.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim index 905fdcc94..a56be3d23 100644 --- a/lib/system/mmdisp.nim +++ b/lib/system/mmdisp.nim @@ -99,6 +99,8 @@ when defined(boehmgc): ## Return the total number of bytes allocated in this process. ## Never decreases. + proc boehmRegisterFinalizer(obj, ff, cd, off, ocd: pointer) {.importc: "GC_register_finalizer", boehmGC.} + proc allocAtomic(size: int): pointer = result = boehmAllocAtomic(size) zeroMem(result, size) @@ -155,9 +157,14 @@ when defined(boehmgc): when hasThreadSupport: boehmGC_allow_register_threads() + proc boehmgc_finalizer(obj: pointer, typedFinalizer: (proc(x: pointer) {.cdecl.})) = + typedFinalizer(obj) + proc newObj(typ: PNimType, size: int): pointer {.compilerproc.} = if ntfNoRefs in typ.flags: result = allocAtomic(size) else: result = alloc(size) + if typ.finalizer != nil: + boehmRegisterFinalizer(result, boehmgc_finalizer, typ.finalizer, nil, nil) proc newSeq(typ: PNimType, len: int): pointer {.compilerproc.} = result = newObj(typ, addInt(mulInt(len, typ.base.size), GenericSeqSize)) cast[PGenericSeq](result).len = len |