From bd8f5c8392fc6f28381170d029f67801789fd78d Mon Sep 17 00:00:00 2001 From: Billingsly Wetherfordshire Date: Thu, 19 Jun 2014 13:00:11 -0500 Subject: [PATCH 1/5] json.== handles nil now --- lib/pure/json.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 4e369b854d..871713f1ce 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -621,9 +621,13 @@ proc `%`*(elements: openArray[PJsonNode]): PJsonNode = proc `==`* (a,b: PJsonNode): bool = ## Check two nodes for equality - if a.kind != b.kind: false + if a.isNil: + if b.isNil: return true + return false + elif b.isNil or a.kind != b.kind: + return false else: - case a.kind + return case a.kind of JString: a.str == b.str of JInt: From f59ca2736dac0e544c11aaca431408931d3e21de Mon Sep 17 00:00:00 2001 From: Felix Krause Date: Fri, 27 Jun 2014 16:57:01 +0200 Subject: [PATCH 2/5] Fixed `==` for PTables, added test. --- lib/pure/collections/tables.nim | 7 +++++-- tests/table/ptables.nim | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index ce9df09e10..146cb76c9a 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -246,7 +246,8 @@ template equalsImpl() = # different insertion orders mean different 'data' seqs, so we have # to use the slow route here: for key, val in s: - if not hasKey(t, key): return false + # prefix notation leads to automatic dereference in case of PTable + if not t.hasKey(key): return false if t[key] != val: return false return true @@ -332,7 +333,9 @@ proc `$`*[A, B](t: PTable[A, B]): string = dollarImpl() proc `==`*[A, B](s, t: PTable[A, B]): bool = - equalsImpl() + if isNil(s): result = isNil(t) + elif isNil(t): result = false + else: equalsImpl() proc newTableFrom*[A, B, C](collection: A, index: proc(x: B): C): PTable[C, B] = ## Index the collection with the proc provided. diff --git a/tests/table/ptables.nim b/tests/table/ptables.nim index ec52d08c33..79a9aab171 100644 --- a/tests/table/ptables.nim +++ b/tests/table/ptables.nim @@ -104,6 +104,15 @@ block countTableTest1: block SyntaxTest: var x = newTable[int, string]({:}) +block nilTest: + var i, j: PTable[int, int] = nil + assert i == j + j = newTable[int, int]() + assert i != j + assert j != i + i = newTable[int, int]() + assert i == j + proc orderedTableSortTest() = var t = newOrderedTable[string, int](2) for key, val in items(data): t[key] = val From ed68286c592b0f2ff0d27496c740b9e9f6b761a7 Mon Sep 17 00:00:00 2001 From: Flaviu Tamas Date: Tue, 22 Jul 2014 15:34:49 -0400 Subject: [PATCH 3/5] Fix #1392 --- compiler/ccgexprs.nim | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 95167e1576..691feeb472 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1578,15 +1578,15 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) = of mGetTypeInfo: genGetTypeInfo(p, e, d) of mSwap: genSwap(p, e, d) of mUnaryLt: - if not (optOverflowCheck in p.options): unaryExpr(p, e, d, "$1 - 1") + if not (optOverflowCheck in p.options): unaryExpr(p, e, d, "($1 - 1)") else: unaryExpr(p, e, d, "#subInt($1, 1)") of mPred: # XXX: range checking? - if not (optOverflowCheck in p.options): binaryExpr(p, e, d, "$1 - $2") + if not (optOverflowCheck in p.options): binaryExpr(p, e, d, "($1 - $2)") else: binaryExpr(p, e, d, "#subInt($1, $2)") of mSucc: # XXX: range checking? - if not (optOverflowCheck in p.options): binaryExpr(p, e, d, "$1 + $2") + if not (optOverflowCheck in p.options): binaryExpr(p, e, d, "($1 + $2)") else: binaryExpr(p, e, d, "#addInt($1, $2)") of mInc: if not (optOverflowCheck in p.options): From 26ba9e6d3286adddaff0d3c13e91d973f443bf51 Mon Sep 17 00:00:00 2001 From: jfhg Date: Wed, 23 Jul 2014 22:47:16 +0200 Subject: [PATCH 4/5] fix build on DragonFly BSD and FreeBSD --- lib/pure/osproc.nim | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/pure/osproc.nim b/lib/pure/osproc.nim index 04a0c2403a..c74fa1ceb6 100644 --- a/lib/pure/osproc.nim +++ b/lib/pure/osproc.nim @@ -763,7 +763,7 @@ elif not defined(useNimRtl): discard write(data.pErrorPipe[writeIdx], addr error, sizeof(error)) exitnow(1) - when defined(macosx): + when defined(macosx) or defined(freebsd): var environ {.importc.}: cstringArray proc startProcessAfterFork(data: ptr TStartProcessData) = @@ -793,7 +793,7 @@ elif not defined(useNimRtl): discard fcntl(data.pErrorPipe[writeIdx], F_SETFD, FD_CLOEXEC) if data.optionPoUsePath: - when defined(macosx): + when defined(macosx) or defined(freebsd): # MacOSX doesn't have execvpe, so we need workaround. # On MacOSX we can arrive here only from fork, so this is safe: environ = data.sysEnv From 18003ff1966fc54ed1b2b39988dda6961ce35c80 Mon Sep 17 00:00:00 2001 From: Clay Sweetser Date: Thu, 24 Jul 2014 18:17:20 -0400 Subject: [PATCH 5/5] Added stylistic consistancy. --- lib/pure/collections/tables.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim index 146cb76c9a..dcf2ab4811 100644 --- a/lib/pure/collections/tables.nim +++ b/lib/pure/collections/tables.nim @@ -335,7 +335,7 @@ proc `$`*[A, B](t: PTable[A, B]): string = proc `==`*[A, B](s, t: PTable[A, B]): bool = if isNil(s): result = isNil(t) elif isNil(t): result = false - else: equalsImpl() + else: result = equalsImpl() proc newTableFrom*[A, B, C](collection: A, index: proc(x: B): C): PTable[C, B] = ## Index the collection with the proc provided.