summary refs log tree commit diff stats
path: root/lib/system.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system.nim')
-rw-r--r--lib/system.nim9
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/system.nim b/lib/system.nim
index 56746fb65..605670f44 100644
--- a/lib/system.nim
+++ b/lib/system.nim
@@ -3124,5 +3124,12 @@ when not defined(createNimHcr) and not defined(nimscript):
 when notJSnotNims and not defined(nimSeqsV2):
   proc prepareStrMutation*(s: var string) {.inline.} =
     ## String literals (e.g. "abc", etc) in the ARC/ORC mode are "copy on write",
-    ## therefore you should call `prepareStrMutation` before modifying the strings.
+    ## therefore you should call `prepareStrMutation` before modifying the strings
+    ## via `addr`.
+    runnableExamples("--gc:arc"):
+      var x = "abc"
+      var y = "defgh"
+      prepareStrMutation(y) # without this, you may get a `SIGBUS` or `SIGSEGV`
+      moveMem(addr y[0], addr x[0], x.len)
+      assert y == "abcgh"
     discard