From 2ad8e073d87464bd0dc0bbdd4cf7e30915692032 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Tue, 6 Dec 2016 11:54:47 +0200 Subject: [PATCH 1/6] Control leakDetector from cmdline --- lib/system/mmdisp.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim index 63af49e35b..431f84bfd4 100644 --- a/lib/system/mmdisp.nim +++ b/lib/system/mmdisp.nim @@ -20,7 +20,7 @@ const alwaysCycleGC = defined(smokeCycles) alwaysGC = defined(fulldebug) # collect after every memory # allocation (for debugging) - leakDetector = false + leakDetector = defined(leakDetector) overwriteFree = defined(nimBurnFree) # overwrite memory with 0xFF before free trackAllocationSource = leakDetector From 5adb639948ed2bb6931c5de23d0148bceecb971f Mon Sep 17 00:00:00 2001 From: konqoro Date: Tue, 6 Dec 2016 20:00:21 +0200 Subject: [PATCH 2/6] strscans: Fix examples --- lib/pure/strscans.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/pure/strscans.nim b/lib/pure/strscans.nim index 246f018c50..fc400173f5 100644 --- a/lib/pure/strscans.nim +++ b/lib/pure/strscans.nim @@ -76,7 +76,7 @@ to a variable (that was passed to the ``scanf`` macro) while ``$[]`` merely optional tokens. -In this example, we define a helper proc ``skipSep`` that skips some separators +In this example, we define a helper proc ``someSep`` that skips some separators which we then use in our scanf pattern to help us in the matching process: .. code-block:: nim @@ -86,14 +86,14 @@ which we then use in our scanf pattern to help us in the matching process: result = 0 while input[start+result] in seps: inc result - if scanf(input, "$w${someSep}$w", key, value): + if scanf(input, "$w$[someSep]$w", key, value): ... It also possible to pass arguments to a user definable matcher: .. code-block:: nim - proc ndigits(input: string; start: int; intVal: var int; n: int): int = + proc ndigits(input: string; intVal: var int; start: int; n: int): int = # matches exactly ``n`` digits. Matchers need to return 0 if nothing # matched or otherwise the number of processed chars. var x = 0 From 54cbe0b7432a354837547b073f7a99609b437136 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Wed, 7 Dec 2016 20:15:31 +0200 Subject: [PATCH 3/6] More workarounds for #5098 --- lib/pure/collections/deques.nim | 5 ++++- lib/pure/collections/queues.nim | 5 ++++- lib/pure/collections/sets.nim | 4 +++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/pure/collections/deques.nim b/lib/pure/collections/deques.nim index c254297783..495d7896c7 100644 --- a/lib/pure/collections/deques.nim +++ b/lib/pure/collections/deques.nim @@ -160,7 +160,10 @@ proc peekLast*[T](deq: Deque[T]): T {.inline.} = emptyCheck(deq) result = deq.data[(deq.tail - 1) and deq.mask] -proc default[T](t: typedesc[T]): T {.inline.} = discard +template default[T](t: typedesc[T]): T = + var v: T + v + proc popFirst*[T](deq: var Deque[T]): T {.inline, discardable.} = ## Remove and returns the first element of the `deq`. emptyCheck(deq) diff --git a/lib/pure/collections/queues.nim b/lib/pure/collections/queues.nim index e4d7eeef1c..0490ae4943 100644 --- a/lib/pure/collections/queues.nim +++ b/lib/pure/collections/queues.nim @@ -154,7 +154,10 @@ proc add*[T](q: var Queue[T], item: T) = q.data[q.wr] = item q.wr = (q.wr + 1) and q.mask -proc default[T](t: typedesc[T]): T {.inline.} = discard +template default[T](t: typedesc[T]): T = + var v: T + v + proc pop*[T](q: var Queue[T]): T {.inline, discardable.} = ## Remove and returns the first (oldest) element of the queue `q`. emptyCheck(q) diff --git a/lib/pure/collections/sets.nim b/lib/pure/collections/sets.nim index 552e41ef7d..b2ffbe58d6 100644 --- a/lib/pure/collections/sets.nim +++ b/lib/pure/collections/sets.nim @@ -261,7 +261,9 @@ template doWhile(a, b) = b if not a: break -proc default[T](t: typedesc[T]): T {.inline.} = discard +template default[T](t: typedesc[T]): T = + var v: T + v proc excl*[A](s: var HashSet[A], key: A) = ## Excludes `key` from the set `s`. From dc5e4b018b064480e586318269f9f59f719f02ca Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 7 Dec 2016 20:08:03 +0100 Subject: [PATCH 4/6] macros.getType: do not copy symbols if not necessary --- compiler/vmdeps.nim | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/compiler/vmdeps.nim b/compiler/vmdeps.nim index bd6908722e..7de30b7f01 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vmdeps.nim @@ -73,6 +73,10 @@ proc atomicTypeX(name: string; m: TMagic; t: PType; info: TLineInfo): PNode = result = newSymNode(sym) result.typ = t +proc atomicTypeX(s: PSym; info: TLineInfo): PNode = + result = newSymNode(s) + result.info = info + proc mapTypeToAstX(t: PType; info: TLineInfo; inst=false; allowRecursionX=false): PNode @@ -103,6 +107,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo; inst=false; allowRecursionX=false): PNode = var allowRecursion = allowRecursionX template atomicType(name, m): untyped = atomicTypeX(name, m, t, info) + template atomicType(s): untyped = atomicTypeX(s, info) template mapTypeToAst(t,info): untyped = mapTypeToAstX(t, info, inst) template mapTypeToAstR(t,info): untyped = mapTypeToAstX(t, info, inst, true) template mapTypeToAst(t,i,info): untyped = @@ -125,7 +130,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo; if allowRecursion: # getTypeImpl behavior: turn off recursion allowRecursion = false else: # getTypeInst behavior: return symbol - return atomicType(t.sym.name.s, t.sym.magic) + return atomicType(t.sym) case t.kind of tyNone: result = atomicType("none", mNone) @@ -180,9 +185,9 @@ proc mapTypeToAstX(t: PType; info: TLineInfo; if allowRecursion or t.sym == nil: result = mapTypeToBracket("distinct", mDistinct, t, info) else: - result = atomicType(t.sym.name.s, t.sym.magic) + result = atomicType(t.sym) of tyGenericParam, tyForward: - result = atomicType(t.sym.name.s, t.sym.magic) + result = atomicType(t.sym) of tyObject: if inst: result = newNodeX(nkObjectTy) @@ -206,7 +211,7 @@ proc mapTypeToAstX(t: PType; info: TLineInfo; result.add mapTypeToAst(t.sons[0], info) result.add copyTree(t.n) else: - result = atomicType(t.sym.name.s, t.sym.magic) + result = atomicType(t.sym) of tyEnum: result = newNodeIT(nkEnumTy, if t.n.isNil: info else: t.n.info, t) result.add copyTree(t.n) From feba5acc98db3409df92cbc224b46afff1271a38 Mon Sep 17 00:00:00 2001 From: Yuriy Glukhov Date: Thu, 10 Nov 2016 13:33:53 +0200 Subject: [PATCH 5/6] Added FileSeekPos --- lib/system.nim | 10 +++++++++- lib/system/sysio.nim | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/system.nim b/lib/system.nim index 69d3db291d..8209dbc238 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2595,6 +2595,14 @@ else: if x < 0: -x else: x {.pop.} +type + FileSeekPos* = enum ## Position relative to which seek should happen + # The values are ordered so that they match with stdio + # SEEK_SET, SEEK_CUR and SEEK_END respectively. + fspSet ## Seek to absolute value + fspCur ## Seek relative to current position + fspEnd ## Seek relative to end + when not defined(JS): #and not defined(nimscript): {.push stack_trace: off, profiler:off.} @@ -2858,7 +2866,7 @@ when not defined(JS): #and not defined(nimscript): ## file `f`. Returns the number of actual written bytes, which may be less ## than `len` in case of an error. - proc setFilePos*(f: File, pos: int64) {.benign.} + proc setFilePos*(f: File, pos: int64, relativeTo: FileSeekPos = fspSet) {.benign.} ## sets the position of the file pointer that is used for read/write ## operations. The file's first byte has the index zero. diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 5c10392f1b..29c5777cc3 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -336,8 +336,8 @@ proc open(f: var File, filehandle: FileHandle, mode: FileMode): bool = f = c_fdopen(filehandle, FormatOpen[mode]) result = f != nil -proc setFilePos(f: File, pos: int64) = - if c_fseek(f, clong(pos), 0) != 0: +proc setFilePos(f: File, pos: int64, relativeTo: FileSeekPos = fspSet) = + if c_fseek(f, clong(pos), cint(relativeTo)) != 0: raiseEIO("cannot set file position") proc getFilePos(f: File): int64 = From 11db362d86a96f05b65eb96c4a59f5e6de688410 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20=C5=9Awi=C4=85tkowski?= Date: Sun, 11 Dec 2016 19:05:39 +0100 Subject: [PATCH 6/6] Fix description of CountTable's smallest proc --- lib/pure/collections/tables.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index e6e72d9edc..57e98bf5cd 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -954,7 +954,7 @@ proc inc*[A](t: var CountTable[A], key: A, val = 1) = inc(t.counter) proc smallest*[A](t: CountTable[A]): tuple[key: A, val: int] = - ## returns the largest (key,val)-pair. Efficiency: O(n) + ## returns the (key,val)-pair with the smallest `val`. Efficiency: O(n) assert t.len > 0 var minIdx = 0 for h in 1..high(t.data): @@ -1080,7 +1080,7 @@ proc inc*[A](t: CountTableRef[A], key: A, val = 1) = t[].inc(key, val) proc smallest*[A](t: CountTableRef[A]): (A, int) = - ## returns the largest (key,val)-pair. Efficiency: O(n) + ## returns the (key,val)-pair with the smallest `val`. Efficiency: O(n) t[].smallest proc largest*[A](t: CountTableRef[A]): (A, int) =