diff options
author | Araq <rumpf_a@web.de> | 2019-04-06 17:32:33 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-04-06 17:32:53 +0200 |
commit | 6e6a9a721fc039c88851650e4ab989aeff04fc9f (patch) | |
tree | 1cbcab26559355e7b7ee4dee87454956661dc5da /lib | |
parent | fab75fbaf1a2dd94cedfc0b41173edf49b581c6e (diff) | |
download | Nim-6e6a9a721fc039c88851650e4ab989aeff04fc9f.tar.gz |
destructors: we are cooking now
Diffstat (limited to 'lib')
-rw-r--r-- | lib/core/runtime_v2.nim | 8 | ||||
-rw-r--r-- | lib/core/strs.nim | 20 | ||||
-rw-r--r-- | lib/system.nim | 33 |
3 files changed, 33 insertions, 28 deletions
diff --git a/lib/core/runtime_v2.nim b/lib/core/runtime_v2.nim index 6463a5a27..f76fd2f3e 100644 --- a/lib/core/runtime_v2.nim +++ b/lib/core/runtime_v2.nim @@ -26,14 +26,6 @@ hash of ``package & "." & module & "." & name`` to save space. ]# type - TNimNode {.compilerProc.} = object # to keep the code generator simple - DestructorProc = proc (p: pointer) {.nimcall, benign.} - TNimType {.compilerProc.} = object - destructor: pointer - size: int - name: cstring - PNimType = ptr TNimType - RefHeader = object rc: int # the object header is now a single RC field. # we could remove it in non-debug builds but this seems diff --git a/lib/core/strs.nim b/lib/core/strs.nim index 7dd65bdb3..ccc261d95 100644 --- a/lib/core/strs.nim +++ b/lib/core/strs.nim @@ -177,17 +177,15 @@ proc nimAsgnStrV2(a: var NimStringV2, b: NimStringV2) {.compilerRtl.} = frees(a) a.len = b.len a.p = b.p - elif isLiteral(a) or a.p.cap < b.len: - let allocator = if a.p != nil and a.p.allocator != nil: a.p.allocator else: getLocalAllocator() - # we have to allocate the 'cap' here, consider - # 'let y = newStringOfCap(); var x = y' - # on the other hand... These get turned into moves now. - a.p = cast[ptr NimStrPayload](allocator.alloc(allocator, contentSize(b.len))) - a.p.allocator = allocator - a.p.cap = b.len - a.len = b.len - copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1) else: + if isLiteral(a) or a.p.cap < b.len: + let allocator = if a.p != nil and a.p.allocator != nil: a.p.allocator else: getLocalAllocator() + # we have to allocate the 'cap' here, consider + # 'let y = newStringOfCap(); var x = y' + # on the other hand... These get turned into moves now. + frees(a) + a.p = cast[ptr NimStrPayload](allocator.alloc(allocator, contentSize(b.len))) + a.p.allocator = allocator + a.p.cap = b.len a.len = b.len - # reuse the storage we already have: copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1) diff --git a/lib/system.nim b/lib/system.nim index 9d0871490..f51767950 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2971,6 +2971,30 @@ proc compiles*(x: untyped): bool {.magic: "Compiles", noSideEffect, compileTime. when not defined(js) and not defined(nimscript): include "system/ansi_c" +when not defined(js): + {.push stackTrace:off.} + + when hasThreadSupport and hostOS != "standalone": + const insideRLocksModule = false + include "system/syslocks" + include "system/threadlocalstorage" + + when defined(nimV2): + type + TNimNode {.compilerProc.} = object # to keep the code generator simple + DestructorProc = proc (p: pointer) {.nimcall, benign.} + TNimType {.compilerProc.} = object + destructor: pointer + size: int + name: cstring + PNimType = ptr TNimType + + when defined(gcDestructors) and not defined(nimscript): + include "core/strs" + include "core/seqs" + + {.pop.} + when not declared(sysFatal): include "system/fatal" @@ -3481,15 +3505,6 @@ when not defined(JS): #and not defined(nimscript): when defined(endb): proc endbStep() - when hasThreadSupport and hostOS != "standalone": - const insideRLocksModule = false - include "system/syslocks" - include "system/threadlocalstorage" - - when defined(gcDestructors) and not defined(nimscript): - include "core/strs" - include "core/seqs" - when declared(newSeq): proc cstringArrayToSeq*(a: cstringArray, len: Natural): seq[string] = ## Converts a ``cstringArray`` to a ``seq[string]``. `a` is supposed to be |