Skip to content

Commit

Permalink
fixes #10845
Browse files Browse the repository at this point in the history
  • Loading branch information
Araq committed Mar 15, 2019
1 parent 16355de commit 8e5c143
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions lib/system/sysstr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,27 @@ proc newOwnedString(src: NimString; n: int): NimString =

proc copyStringRC1(src: NimString): NimString {.compilerRtl.} =
if src != nil:
when declared(newObjRC1) and not defined(gcRegions):
var s = src.len
if s < 7: s = 7
result = cast[NimString](newObjRC1(addr(strDesc), sizeof(TGenericSeq) +
s+1))
result.reserved = s
when defined(gogc):
result.elemSize = 1
if (src.reserved and seqShallowFlag) != 0:
result = src
when declared(incRef):
incRef(usrToCell(result))
else:
result = rawNewStringNoInit(src.len)
result.len = src.len
copyMem(addr(result.data), addr(src.data), src.len + 1)
sysAssert((seqShallowFlag and result.reserved) == 0, "copyStringRC1")
when defined(nimShallowStrings):
if (src.reserved and strlitFlag) != 0:
result.reserved = (result.reserved and not strlitFlag) or seqShallowFlag
when declared(newObjRC1) and not defined(gcRegions):
var s = src.len
if s < 7: s = 7
result = cast[NimString](newObjRC1(addr(strDesc), sizeof(TGenericSeq) +
s+1))
result.reserved = s
when defined(gogc):
result.elemSize = 1
else:
result = rawNewStringNoInit(src.len)
result.len = src.len
copyMem(addr(result.data), addr(src.data), src.len + 1)
sysAssert((seqShallowFlag and result.reserved) == 0, "copyStringRC1")
when defined(nimShallowStrings):
if (src.reserved and strlitFlag) != 0:
result.reserved = (result.reserved and not strlitFlag) or seqShallowFlag

proc copyDeepString(src: NimString): NimString {.inline.} =
if src != nil:
Expand Down

0 comments on commit 8e5c143

Please sign in to comment.