diff --git a/doc/contributing.rst b/doc/contributing.rst index d43cd6196a693..19064b8f98490 100644 --- a/doc/contributing.rst +++ b/doc/contributing.rst @@ -271,6 +271,20 @@ Note: these are general guidelines, not hard rules; there are always exceptions. Code reviews can just point to a specific section here to save time and propagate best practices. +.. _define_needs_prefix: +New `defined(foo)` symbols need to be prefixed by the nimble package name, or +by `nim` for symbols in nim sources (e.g. compiler, standard library). This is +to avoid name conflicts across packages. + +.. code-block:: nim + + # if in nim sources + when defined(allocStats): discard # bad, can cause conflicts + when defined(nimAllocStats): discard # preferred + # if in a pacakge `cligen`: + when defined(debug): discard # bad, can cause conflicts + when defined(cligenDebug): discard # preferred + .. _noimplicitbool: Take advantage of no implicit bool conversion diff --git a/lib/system/memalloc.nim b/lib/system/memalloc.nim index 201e92e98566d..df4df2c150909 100644 --- a/lib/system/memalloc.nim +++ b/lib/system/memalloc.nim @@ -65,7 +65,7 @@ when hasAlloc and not defined(js): let stats2 = getAllocStats() echo $(stats2 - stats1) - when defined(allocStats): + when defined(nimAllocStats): var stats: AllocStats template incStat(what: untyped) = inc stats.what proc getAllocStats*(): AllocStats = stats diff --git a/tests/destructor/tbintree2.nim b/tests/destructor/tbintree2.nim index 6c9047b9a99a2..e910f430a0a7a 100644 --- a/tests/destructor/tbintree2.nim +++ b/tests/destructor/tbintree2.nim @@ -1,5 +1,5 @@ discard """ - cmd: '''nim c -d:allocStats --newruntime $file''' + cmd: '''nim c -d:nimAllocStats --newruntime $file''' output: '''0 (allocCount: 6, deallocCount: 6)''' """ diff --git a/tests/destructor/tgcdestructors.nim b/tests/destructor/tgcdestructors.nim index c63060af54bf1..7169daaf18e13 100644 --- a/tests/destructor/tgcdestructors.nim +++ b/tests/destructor/tgcdestructors.nim @@ -1,5 +1,5 @@ discard """ - cmd: '''nim c -d:allocStats --newruntime $file''' + cmd: '''nim c -d:nimAllocStats --newruntime $file''' output: '''hi ho ha diff --git a/tests/destructor/tnewruntime_misc.nim b/tests/destructor/tnewruntime_misc.nim index 7522bc168c88f..263ea1bd43503 100644 --- a/tests/destructor/tnewruntime_misc.nim +++ b/tests/destructor/tnewruntime_misc.nim @@ -1,5 +1,5 @@ discard """ - cmd: '''nim cpp -d:allocStats --newruntime --threads:on $file''' + cmd: '''nim cpp -d:nimAllocStats --newruntime --threads:on $file''' output: '''(field: "value") Indeed axc diff --git a/tests/destructor/tnewruntime_strutils.nim b/tests/destructor/tnewruntime_strutils.nim index 27c5a77d58625..9afb507f709d0 100644 --- a/tests/destructor/tnewruntime_strutils.nim +++ b/tests/destructor/tnewruntime_strutils.nim @@ -1,6 +1,6 @@ discard """ valgrind: true - cmd: '''nim c -d:allocStats --newruntime -d:useMalloc $file''' + cmd: '''nim c -d:nimAllocStats --newruntime -d:useMalloc $file''' output: ''' @[(input: @["KXSC", "BGMC"]), (input: @["PXFX"]), (input: @["WXRQ", "ZSCZD"])]''' """ diff --git a/tests/destructor/tsimpleclosure.nim b/tests/destructor/tsimpleclosure.nim index bebd1fe72aedc..4916f4bab583e 100644 --- a/tests/destructor/tsimpleclosure.nim +++ b/tests/destructor/tsimpleclosure.nim @@ -1,5 +1,5 @@ discard """ - cmd: '''nim c -d:allocStats --newruntime $file''' + cmd: '''nim c -d:nimAllocStats --newruntime $file''' output: '''a b 70 hello diff --git a/tests/destructor/tv2_raise.nim b/tests/destructor/tv2_raise.nim index ed53649234df9..828d0a3964079 100644 --- a/tests/destructor/tv2_raise.nim +++ b/tests/destructor/tv2_raise.nim @@ -1,6 +1,6 @@ discard """ valgrind: true - cmd: '''nim c -d:allocStats --newruntime $file''' + cmd: '''nim c -d:nimAllocStats --newruntime $file''' output: '''OK 3 (allocCount: 8, deallocCount: 3)''' """ diff --git a/tests/destructor/twidgets.nim b/tests/destructor/twidgets.nim index 4f32ebfa6f441..f138681107523 100644 --- a/tests/destructor/twidgets.nim +++ b/tests/destructor/twidgets.nim @@ -1,5 +1,5 @@ discard """ - cmd: '''nim c -d:allocstats --newruntime $file''' + cmd: '''nim c -d:nimAllocStats --newruntime $file''' output: '''button clicked! (allocCount: 4, deallocCount: 4)''' diff --git a/tests/destructor/twidgets_unown.nim b/tests/destructor/twidgets_unown.nim index 333181307f3de..1d2f26f2a0e81 100644 --- a/tests/destructor/twidgets_unown.nim +++ b/tests/destructor/twidgets_unown.nim @@ -1,5 +1,5 @@ discard """ - cmd: '''nim c -d:allocStats --newruntime $file''' + cmd: '''nim c -d:nimAllocStats --newruntime $file''' output: '''button clicked! (allocCount: 9, deallocCount: 9)'''