From bb0c19f42cee41d5cdccbb8c47fc83669cba5540 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 1 Mar 2021 20:58:12 +0100 Subject: 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 Co-authored-by: flywind Co-authored-by: Danil Yarantsev --- lib/system/strs_v2.nim | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/system') 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)[]) -- cgit 1.4.1-2-gfad0