summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorflywind <43030857+xflywind@users.noreply.github.com>2022-07-17 15:24:40 +0800
committerGitHub <noreply@github.com>2022-07-17 09:24:40 +0200
commit01ad0cdc5212a05ac31c968facdc94b732dd48ef (patch)
tree2ed3220a86e234c0f1db149cc2100012c7864d3e
parent0d8bec695606a65c5916d0da7fcb0a976a4e1f7b (diff)
downloadNim-01ad0cdc5212a05ac31c968facdc94b732dd48ef.tar.gz
defines the `gcRefc` symbol which allows writing specific code for refc (#20009)
* define gcRefc symbols

* add comments

* add a changelog item

* Update changelog.md

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

* Update changelog.md

Co-authored-by: Yardanico <tiberiumk12@gmail.com>

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
Co-authored-by: Yardanico <tiberiumk12@gmail.com>
-rw-r--r--changelog.md2
-rw-r--r--compiler/commands.nim1
-rw-r--r--tests/stdlib/tstrutils2.nim7
3 files changed, 9 insertions, 1 deletions
diff --git a/changelog.md b/changelog.md
index c1dc6e27d..d8f3ccb92 100644
--- a/changelog.md
+++ b/changelog.md
@@ -110,6 +110,8 @@ becomes an alias for `addr`.
   In the command line, this is defined as `-d:a.b.c`. Older versions can
   use accents as in ``defined(`a.b.c`)`` to access such defines.
 
+- Defines the `gcRefc` symbol which allows writing specific code for the refc GC.
+
 ## Compiler changes
 
 - `nim` can now compile version 1.4.0 as follows: `nim c --lib:lib --stylecheck:off compiler/nim`,
diff --git a/compiler/commands.nim b/compiler/commands.nim
index b849f503d..a71dae9d9 100644
--- a/compiler/commands.nim
+++ b/compiler/commands.nim
@@ -542,6 +542,7 @@ proc processMemoryManagementOption(switch, arg: string, pass: TCmdLinePass,
       incl conf.globalOptions, optTlsEmulation # Boehm GC doesn't scan the real TLS
     of "refc":
       unregisterArcOrc(conf)
+      defineSymbol(conf.symbols, "gcrefc")
       conf.selectedGC = gcRefc
     of "markandsweep":
       unregisterArcOrc(conf)
diff --git a/tests/stdlib/tstrutils2.nim b/tests/stdlib/tstrutils2.nim
index 881817f90..a8bf08eed 100644
--- a/tests/stdlib/tstrutils2.nim
+++ b/tests/stdlib/tstrutils2.nim
@@ -1,10 +1,15 @@
+discard """
+  matrix: "--gc:refc; --gc:orc"
+"""
+
 import "$lib/.." / compiler/strutils2
 
 block: # setLen
   var a = "abc"
   a.setLen 0
   a.setLen 3, isInit = false
-  doAssert a[1] == 'b'
+  when defined(gcRefc): # bug #19763
+    doAssert a[1] == 'b'
   a.setLen 0
   a.setLen 3, isInit = true
   doAssert a[1] == '\0'