contributing docs: symbols need package prefix; changed allocStats to nimAllocStats (#13247)
This commit is contained in:
parent
4cbeddddcc
commit
981ffc912e
10 changed files with 23 additions and 9 deletions
|
|
@ -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
|
Code reviews can just point to a specific section here to save time and
|
||||||
propagate best practices.
|
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:
|
.. _noimplicitbool:
|
||||||
Take advantage of no implicit bool conversion
|
Take advantage of no implicit bool conversion
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ when hasAlloc and not defined(js):
|
||||||
let stats2 = getAllocStats()
|
let stats2 = getAllocStats()
|
||||||
echo $(stats2 - stats1)
|
echo $(stats2 - stats1)
|
||||||
|
|
||||||
when defined(allocStats):
|
when defined(nimAllocStats):
|
||||||
var stats: AllocStats
|
var stats: AllocStats
|
||||||
template incStat(what: untyped) = inc stats.what
|
template incStat(what: untyped) = inc stats.what
|
||||||
proc getAllocStats*(): AllocStats = stats
|
proc getAllocStats*(): AllocStats = stats
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
cmd: '''nim c -d:nimAllocStats --newruntime $file'''
|
||||||
output: '''0
|
output: '''0
|
||||||
(allocCount: 6, deallocCount: 6)'''
|
(allocCount: 6, deallocCount: 6)'''
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
cmd: '''nim c -d:nimAllocStats --newruntime $file'''
|
||||||
output: '''hi
|
output: '''hi
|
||||||
ho
|
ho
|
||||||
ha
|
ha
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: '''nim cpp -d:allocStats --newruntime --threads:on $file'''
|
cmd: '''nim cpp -d:nimAllocStats --newruntime --threads:on $file'''
|
||||||
output: '''(field: "value")
|
output: '''(field: "value")
|
||||||
Indeed
|
Indeed
|
||||||
axc
|
axc
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
valgrind: true
|
valgrind: true
|
||||||
cmd: '''nim c -d:allocStats --newruntime -d:useMalloc $file'''
|
cmd: '''nim c -d:nimAllocStats --newruntime -d:useMalloc $file'''
|
||||||
output: '''
|
output: '''
|
||||||
@[(input: @["KXSC", "BGMC"]), (input: @["PXFX"]), (input: @["WXRQ", "ZSCZD"])]'''
|
@[(input: @["KXSC", "BGMC"]), (input: @["PXFX"]), (input: @["WXRQ", "ZSCZD"])]'''
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
cmd: '''nim c -d:nimAllocStats --newruntime $file'''
|
||||||
output: '''a b
|
output: '''a b
|
||||||
70
|
70
|
||||||
hello
|
hello
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
discard """
|
discard """
|
||||||
valgrind: true
|
valgrind: true
|
||||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
cmd: '''nim c -d:nimAllocStats --newruntime $file'''
|
||||||
output: '''OK 3
|
output: '''OK 3
|
||||||
(allocCount: 8, deallocCount: 3)'''
|
(allocCount: 8, deallocCount: 3)'''
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: '''nim c -d:allocstats --newruntime $file'''
|
cmd: '''nim c -d:nimAllocStats --newruntime $file'''
|
||||||
output: '''button
|
output: '''button
|
||||||
clicked!
|
clicked!
|
||||||
(allocCount: 4, deallocCount: 4)'''
|
(allocCount: 4, deallocCount: 4)'''
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
cmd: '''nim c -d:allocStats --newruntime $file'''
|
cmd: '''nim c -d:nimAllocStats --newruntime $file'''
|
||||||
output: '''button
|
output: '''button
|
||||||
clicked!
|
clicked!
|
||||||
(allocCount: 9, deallocCount: 9)'''
|
(allocCount: 9, deallocCount: 9)'''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue