diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2019-08-10 15:41:24 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-08-10 15:41:24 +0200 |
commit | 212ae2f1257628bd5d1760593ce0a1bad768831a (patch) | |
tree | b66050091e82c2d891bb18f97ebc812eb34cf416 /lib/core | |
parent | 0e4a8bfb289d707909069e72ca24efd2a074a5f1 (diff) | |
download | Nim-212ae2f1257628bd5d1760593ce0a1bad768831a.tar.gz |
fixes #11891
Diffstat (limited to 'lib/core')
-rw-r--r-- | lib/core/strs.nim | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/core/strs.nim b/lib/core/strs.nim index 677e8731d..92c39331f 100644 --- a/lib/core/strs.nim +++ b/lib/core/strs.nim @@ -189,3 +189,13 @@ proc nimAsgnStrV2(a: var NimStringV2, b: NimStringV2) {.compilerRtl.} = a.p.cap = b.len a.len = b.len copyMem(unsafeAddr a.p.data[0], unsafeAddr b.p.data[0], b.len+1) + +proc nimPrepareStrMutationV2(s: var NimStringV2) {.compilerRtl.} = + if s.p != nil and s.p.allocator == nil: + let oldP = s.p + # can't mutate a literal, so we need a fresh copy here: + let allocator = getLocalAllocator() + s.p = cast[ptr NimStrPayload](allocator.alloc(allocator, contentSize(s.len))) + s.p.allocator = allocator + s.p.cap = s.len + copyMem(unsafeAddr s.p.data[0], unsafeAddr oldP.data[0], s.len+1) |