diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2021-03-01 20:58:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-01 20:58:12 +0100 |
commit | bb0c19f42cee41d5cdccbb8c47fc83669cba5540 (patch) | |
tree | 00e9dcb87b8427053143b61d05e10af7d8460cb3 /lib/system | |
parent | c625ce80cb31d69f1683f299868572bd2caf2c5f (diff) | |
download | Nim-bb0c19f42cee41d5cdccbb8c47fc83669cba5540.tar.gz |
fixes #17173 (#17213)
* fixes #17173 * add testcase (#17214) * Apply suggestions from code review * fix for newruntime * Apply suggestions from code review * Update lib/system.nim * Update lib/system.nim * Update lib/system.nim Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com> Co-authored-by: flywind <xzsflywind@gmail.com> Co-authored-by: Danil Yarantsev <tiberiumk12@gmail.com>
Diffstat (limited to 'lib/system')
-rw-r--r-- | lib/system/strs_v2.nim | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/system/strs_v2.nim b/lib/system/strs_v2.nim index fe117997b..b20457d51 100644 --- a/lib/system/strs_v2.nim +++ b/lib/system/strs_v2.nim @@ -168,3 +168,10 @@ proc nimPrepareStrMutationImpl(s: var NimStringV2) = proc nimPrepareStrMutationV2(s: var NimStringV2) {.compilerRtl, inline.} = if s.p != nil and (s.p.cap and strlitFlag) == strlitFlag: nimPrepareStrMutationImpl(s) + +proc prepareStrMutation*(s: var string) {.inline.} = + # string literals are "copy on write", so you need to call + # `prepareStrMutation` before modifying the strings. + {.cast(noSideEffect).}: + let s = unsafeAddr s + nimPrepareStrMutationV2(cast[ptr NimStringV2](s)[]) |