From a241b0f131f300c8c8827e0aed623523f19fb987 Mon Sep 17 00:00:00 2001 From: James Parkinson Date: Fri, 5 Aug 2016 20:55:25 +1000 Subject: [PATCH 1/5] Add doco on mapMem(), extend doco on open(), and add extra lines space for readability --- lib/pure/memfiles.nim | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index ff3e74d59f..aa32778c52 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -42,6 +42,10 @@ type proc mapMem*(m: var MemFile, mode: FileMode = fmRead, mappedSize = -1, offset = 0): pointer = + ## returns a pointer to a mapped portion of MemFile `m` + ## + ## ``mappedSize`` of ``-1`` maps to the whole file, and + ## ``offset`` must be multiples of the PAGE SIZE of your OS var readonly = mode == fmRead when defined(windows): result = mapViewOfFileEx( @@ -68,7 +72,9 @@ proc mapMem*(m: var MemFile, mode: FileMode = fmRead, proc unmapMem*(f: var MemFile, p: pointer, size: int) = ## unmaps the memory region ``(p, `_. ## `delim`, `eat`, and delimiting logic is exactly as for - ## `memSlices <#memSlices>`_, but Nim strings are returned. Example: + ## `memSlices <#memSlices>`_, but Nim strings are returned. + ## + ## Example: ## ## .. code-block:: nim ## var buffer: TaintedString = "" @@ -335,7 +353,9 @@ iterator lines*(mfile: MemFile, delim='\l', eat='\r'): TaintedString {.inline.} ## Return each line in a file as a Nim string, like ## `lines(File) `_. ## `delim`, `eat`, and delimiting logic is exactly as for - ## `memSlices <#memSlices>`_, but Nim strings are returned. Example: + ## `memSlices <#memSlices>`_, but Nim strings are returned. + ## + ## Example: ## ## .. code-block:: nim ## for line in lines(memfiles.open("foo")): From d00a2536c40f7d5a8dc6668db0317ce851c45a41 Mon Sep 17 00:00:00 2001 From: kingofoz Date: Fri, 5 Aug 2016 21:43:18 +0800 Subject: [PATCH 2/5] fix #4568 --- compiler/pragmas.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index 781aab6874..354e5bdc63 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -400,8 +400,12 @@ proc relativeFile(c: PContext; n: PNode; ext=""): string = s = addFileExt(s, ext) result = parentDir(n.info.toFullPath) / s if not fileExists(result): - if isAbsolute(s): result = s - else: result = findFile(s) + if isAbsolute(s): + result = s + else: + result = findFile(s) + if result.len == 0: + result = s proc processCompile(c: PContext, n: PNode) = let found = relativeFile(c, n) From e2e4df170281ca663fe023a551e2a97611a9ceca Mon Sep 17 00:00:00 2001 From: Hans Raaf Date: Fri, 5 Aug 2016 15:17:38 +0200 Subject: [PATCH 3/5] Allowing `nil` for distinct types where the base type is nilable --- compiler/sigmatch.nim | 2 ++ tests/distinct/tnil.nim | 47 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 tests/distinct/tnil.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 19ef8a1177..7cde101cbb 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -900,6 +900,8 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = if sameDistinctTypes(f, a): result = isEqual elif f.base.kind == tyAnything: result = isGeneric elif c.coerceDistincts: result = typeRel(c, f.base, a) + elif a.kind == tyNil and f.base.kind in NilableTypes: + result = f.allowsNil elif c.coerceDistincts: result = typeRel(c, f.base, a) of tySet: if a.kind == tySet: diff --git a/tests/distinct/tnil.nim b/tests/distinct/tnil.nim new file mode 100644 index 0000000000..ed0ac995a0 --- /dev/null +++ b/tests/distinct/tnil.nim @@ -0,0 +1,47 @@ +discard """ + file: "tnil.nim" + output: '''0x1 + +nil + +nil + +''' +""" + +type + MyPointer = distinct pointer + MyString = distinct string + MyStringNotNil = distinct (string not nil) + MyInt = distinct int + +proc foo(a: MyPointer) = + echo a.repr + +foo(cast[MyPointer](1)) +foo(cast[MyPointer](nil)) +foo(nil) + +var p: MyPointer +p = cast[MyPointer](1) +p = cast[MyPointer](nil) +p = nil.MyPointer +p = nil + +var c: MyString +c = "Test".MyString +c = nil.MyString +c = nil + +p = nil +doAssert(compiles(c = p) == false) + +var n: MyStringNotNil = "Test".MyStringNotNil # Cannot prove warning ... +n = "Test".MyStringNotNil +doAssert(compiles(n = nil.MyStringNotNil) == false) +doAssert(compiles(n = nil.MyStringNotNil) == false) +doAssert(compiles(n = nil) == false) + +var i: MyInt +i = 1.MyInt +doAssert(compiles(i = nil) == false) From 2a84206e8915177addb73a9b7725fa6584010982 Mon Sep 17 00:00:00 2001 From: Mathijs Saey Date: Fri, 5 Aug 2016 17:57:51 +0200 Subject: [PATCH 4/5] Fixed #4574 --- lib/pure/math.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/math.nim b/lib/pure/math.nim index c088e3d7dc..ce18f0030c 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -360,7 +360,7 @@ proc `mod`*[T: float32|float64](x, y: T): T = proc `^`*[T](x, y: T): T = ## Computes ``x`` to the power ``y`. ``x`` must be non-negative, use ## `pow <#pow,float,float>` for negative exponents. - assert y >= 0 + assert y >= T(0) var (x, y) = (x, y) result = 1 From 756beb5b5b535f02fe3559668132361e82da0565 Mon Sep 17 00:00:00 2001 From: Mathijs Saey Date: Fri, 5 Aug 2016 17:58:31 +0200 Subject: [PATCH 5/5] Removed trailing whitespace in math module --- lib/pure/math.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/pure/math.nim b/lib/pure/math.nim index ce18f0030c..58d9879b20 100644 --- a/lib/pure/math.nim +++ b/lib/pure/math.nim @@ -219,7 +219,7 @@ when not defined(JS): ## ## .. code-block:: nim ## echo ceil(-2.1) ## -2.0 - + when defined(windows) and defined(vcc): proc round0[T: float32|float64](x: T): T = ## Windows compilers prior to MSVC 2012 do not implement 'round',