From c0ea647c3742d17808da346fbaba058eab558e7d Mon Sep 17 00:00:00 2001 From: Daniil Yarancev <21169548+Yardanico@users.noreply.github.com> Date: Sun, 27 May 2018 18:48:24 +0300 Subject: [PATCH 1/5] Remove # I don't even know how it got there. --- doc/nep1.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/nep1.rst b/doc/nep1.rst index 6924a86f6e..c4d4456815 100644 --- a/doc/nep1.rst +++ b/doc/nep1.rst @@ -181,7 +181,7 @@ Conventions for multi-line statements and expressions LongTupleA = tuple[wordyTupleMemberOne: int, wordyTupleMemberTwo: string, wordyTupleMemberThree: float] -- Similarly, any procedure and procedure type declarations that are longer# +- Similarly, any procedure and procedure type declarations that are longer than one line should do the same thing. .. code-block:: nim @@ -198,4 +198,4 @@ Conventions for multi-line statements and expressions .. code-block:: nim startProcess(nimExecutable, currentDirectory, compilerArguments - environment, processOptions) \ No newline at end of file + environment, processOptions) From b36c499907e923d6836c9341e494bfdd89be489e Mon Sep 17 00:00:00 2001 From: WhiteDuke Date: Sun, 27 May 2018 21:08:37 +0200 Subject: [PATCH 2/5] Set domain to client --- lib/pure/net.nim | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/pure/net.nim b/lib/pure/net.nim index fc04ef1af4..bf5f3f57e1 100644 --- a/lib/pure/net.nim +++ b/lib/pure/net.nim @@ -803,6 +803,7 @@ proc acceptAddr*(server: Socket, client: var Socket, address: var string, else: address = ret[1] client.fd = sock + client.domain = getSockDomain(sock) client.isBuffered = server.isBuffered # Handle SSL. From 21fb0db6e271148e5c8970f0f9f4805bae2ca59a Mon Sep 17 00:00:00 2001 From: Federico Ceratto Date: Mon, 28 May 2018 00:35:19 +0100 Subject: [PATCH 3/5] Update existsFile documentation (#7888) --- lib/pure/os.nim | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/pure/os.nim b/lib/pure/os.nim index 370420d37c..3ff608cfc0 100644 --- a/lib/pure/os.nim +++ b/lib/pure/os.nim @@ -70,7 +70,8 @@ when defined(windows): proc existsFile*(filename: string): bool {.rtl, extern: "nos$1", tags: [ReadDirEffect].} = - ## Returns true if the file exists, false otherwise. + ## Returns true if `filename` exists and is a regular file or symlink. + ## (directories, device files, named pipes and sockets return false) when defined(windows): when useWinUnicode: wrapUnary(a, getFileAttributesW, filename) From b6b6382e0b4f86759d07a1be150a826b9e0fe054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=83=E7=A7=92=E4=B8=8D=E8=A7=89=E6=A2=A6?= <7822577+7sDream@users.noreply.github.com> Date: Mon, 28 May 2018 10:24:04 +0800 Subject: [PATCH 4/5] Added: type name output when exception raised from unittest (#7869) --- changelog.md | 2 ++ lib/pure/unittest.nim | 10 +++++++--- tests/stdlib/tunittestexceptiontype.nim | 10 ++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 tests/stdlib/tunittestexceptiontype.nim diff --git a/changelog.md b/changelog.md index 57b54c71ef..813c4caf84 100644 --- a/changelog.md +++ b/changelog.md @@ -76,6 +76,8 @@ - The `terminal` module now exports additional procs for generating ANSI color codes as strings. - Added the parameter ``val`` for the ``CritBitTree[int].inc`` proc. +- An exception raised from ``test`` block of ``unittest`` now show its type in + error message ### Language additions diff --git a/lib/pure/unittest.nim b/lib/pure/unittest.nim index 917251a6cd..d804ba7c83 100644 --- a/lib/pure/unittest.nim +++ b/lib/pure/unittest.nim @@ -462,6 +462,8 @@ template suite*(name, body) {.dirty.} = finally: suiteEnded() +template exceptionTypeName(e: typed): string = $e.name + template test*(name, body) {.dirty.} = ## Define a single test case identified by `name`. ## @@ -476,7 +478,7 @@ template test*(name, body) {.dirty.} = ## .. code-block:: ## ## [OK] roses are red - bind shouldRun, checkpoints, formatters, ensureInitialized, testEnded + bind shouldRun, checkpoints, formatters, ensureInitialized, testEnded, exceptionTypeName ensureInitialized() @@ -495,8 +497,10 @@ template test*(name, body) {.dirty.} = except: when not defined(js): - checkpoint("Unhandled exception: " & getCurrentExceptionMsg()) - var stackTrace {.inject.} = getCurrentException().getStackTrace() + let e = getCurrentException() + let eTypeDesc = "[" & exceptionTypeName(e) & "]" + checkpoint("Unhandled exception: " & getCurrentExceptionMsg() & " " & eTypeDesc) + var stackTrace {.inject.} = e.getStackTrace() fail() finally: diff --git a/tests/stdlib/tunittestexceptiontype.nim b/tests/stdlib/tunittestexceptiontype.nim new file mode 100644 index 0000000000..e05a254099 --- /dev/null +++ b/tests/stdlib/tunittestexceptiontype.nim @@ -0,0 +1,10 @@ +discard """ + exitcode: 1 + outputsub: '''exception type is [ValueError]''' +""" + +import unittest + +suite "exception from test": + test "show exception type": + raise newException(ValueError, "exception type is") From 3221ac094398492e09ea618638204793b0990eca Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Mon, 28 May 2018 11:24:29 +0200 Subject: [PATCH 5/5] hotfix for --gc:regions --- lib/system/gc_regions.nim | 3 +++ lib/system/mmdisp.nim | 15 +++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/system/gc_regions.nim b/lib/system/gc_regions.nim index 10df0a2cb7..83c65e8ced 100644 --- a/lib/system/gc_regions.nim +++ b/lib/system/gc_regions.nim @@ -162,6 +162,7 @@ proc allocFast(r: var MemRegion; size: int): pointer = return pointer(it) prev = it it = it.next + let size = roundup(size, MemAlign) if size > r.remaining: allocSlowPath(r, size) sysAssert(size <= r.remaining, "size <= r.remaining") @@ -288,11 +289,13 @@ proc rawNewSeq(r: var MemRegion, typ: PNimType, size: int): pointer = result = res +! sizeof(SeqHeader) proc newObj(typ: PNimType, size: int): pointer {.compilerRtl.} = + sysAssert typ.kind notin {tySequence, tyString}, "newObj cannot be used to construct seqs" result = rawNewObj(tlRegion, typ, size) zeroMem(result, size) when defined(memProfiler): nimProfile(size) proc newObjNoInit(typ: PNimType, size: int): pointer {.compilerRtl.} = + sysAssert typ.kind notin {tySequence, tyString}, "newObj cannot be used to construct seqs" result = rawNewObj(tlRegion, typ, size) when defined(memProfiler): nimProfile(size) diff --git a/lib/system/mmdisp.nim b/lib/system/mmdisp.nim index 45e0c74c0e..a156e9bb05 100644 --- a/lib/system/mmdisp.nim +++ b/lib/system/mmdisp.nim @@ -561,13 +561,16 @@ else: when not declared(nimNewSeqOfCap): proc nimNewSeqOfCap(typ: PNimType, cap: int): pointer {.compilerproc.} = - let s = addInt(mulInt(cap, typ.base.size), GenericSeqSize) - when declared(newObjNoInit): - result = if ntfNoRefs in typ.base.flags: newObjNoInit(typ, s) else: newObj(typ, s) + when defined(gcRegions): + result = newStr(typ, cap, ntfNoRefs notin typ.base.flags) else: - result = newObj(typ, s) - cast[PGenericSeq](result).len = 0 - cast[PGenericSeq](result).reserved = cap + let s = addInt(mulInt(cap, typ.base.size), GenericSeqSize) + when declared(newObjNoInit): + result = if ntfNoRefs in typ.base.flags: newObjNoInit(typ, s) else: newObj(typ, s) + else: + result = newObj(typ, s) + cast[PGenericSeq](result).len = 0 + cast[PGenericSeq](result).reserved = cap {.pop.}