diff options
author | Ganesh Viswanathan <dev@genotrance.com> | 2018-09-15 14:33:33 -0500 |
---|---|---|
committer | Ganesh Viswanathan <dev@genotrance.com> | 2018-09-15 14:33:33 -0500 |
commit | ae8e907edb1ef43865c6f7d1be048dd464c51457 (patch) | |
tree | cb9bdac38f5a2e3aaf9f9211aa45c738a2775afb /lib | |
parent | 80520eef3cce0b3145dedc71a6652429adb9cc9e (diff) | |
parent | 0e33a8676e325fa4174893291ed41d59b689c577 (diff) | |
download | Nim-ae8e907edb1ef43865c6f7d1be048dd464c51457.tar.gz |
Merge remote-tracking branch 'upstream/devel' into test-6483
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pure/typetraits.nim | 13 | ||||
-rw-r--r-- | lib/system/sysio.nim | 7 |
2 files changed, 12 insertions, 8 deletions
diff --git a/lib/pure/typetraits.nim b/lib/pure/typetraits.nim index e9579e824..c53b68864 100644 --- a/lib/pure/typetraits.nim +++ b/lib/pure/typetraits.nim @@ -35,8 +35,13 @@ proc `$`*(t: typedesc): string = ## An alias for `name`. name(t) -proc arity*(t: typedesc): int {.magic: "TypeTrait".} - ## Returns the arity of the given type +proc arity*(t: typedesc): int {.magic: "TypeTrait".} = + ## Returns the arity of the given type. This is the number of "type" components or + ## the number of generic parameters a given type ``t`` has. + runnableExamples: + assert arity(seq[string]) == 1 + assert arity(array[3, int]) == 2 + assert arity((int, int, float, string)) == 4 proc genericHead*(t: typedesc): typedesc {.magic: "TypeTrait".} ## Accepts an instantiated generic type and returns its @@ -47,11 +52,11 @@ proc genericHead*(t: typedesc): typedesc {.magic: "TypeTrait".} ## seq[int].genericHead[float] will be seq[float] ## ## A compile-time error will be produced if the supplied type - ## is not generic + ## is not generic. proc stripGenericParams*(t: typedesc): typedesc {.magic: "TypeTrait".} ## This trait is similar to `genericHead`, but instead of producing - ## error for non-generic types, it will just return them unmodified + ## error for non-generic types, it will just return them unmodified. proc supportsCopyMem*(t: typedesc): bool {.magic: "TypeTrait".} ## This trait returns true iff the type ``t`` is safe to use for diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index df13ab628..61835e0f7 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -145,10 +145,9 @@ proc readLine(f: File, line: var TaintedString): bool = var pos = 0 # Use the currently reserved space for a first try - var sp = line.string.len - if sp == 0: - sp = 80 - line.string.setLen(sp) + var sp = max(line.string.len, 80) + line.string.setLen(sp) + while true: # memset to \L so that we can tell how far fgets wrote, even on EOF, where # fgets doesn't append an \L |