summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2016-12-13 12:18:45 +0100
committerAraq <rumpf_a@web.de>2016-12-13 12:18:45 +0100
commit414c2decbecd5dbaf96ddb28132bddbc7d55a2db (patch)
tree68fb7069d338a8b9d78a18ce73c5e047684a618a /lib
parent02d39277eb5648bb69380e7d31a0993200fe1c30 (diff)
parent30df9224091152d8209aa937d9029222ea96c663 (diff)
downloadNim-414c2decbecd5dbaf96ddb28132bddbc7d55a2db.tar.gz
Merge branch 'devel' into sighashes
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/collections/deques.nim5
-rw-r--r--lib/pure/collections/queues.nim5
-rw-r--r--lib/pure/collections/sets.nim4
-rw-r--r--lib/pure/collections/tables.nim4
-rw-r--r--lib/pure/strscans.nim6
-rw-r--r--lib/system.nim10
-rw-r--r--lib/system/mmdisp.nim2
-rw-r--r--lib/system/sysio.nim4
8 files changed, 28 insertions, 12 deletions
diff --git a/lib/pure/collections/deques.nim b/lib/pure/collections/deques.nim
index c25429778..495d7896c 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 e4d7eeef1..0490ae494 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 552e41ef7..b2ffbe58d 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`.
diff --git a/lib/pure/collections/tables.nim b/lib/pure/collections/tables.nim
index e6e72d9ed..57e98bf5c 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) =
diff --git a/lib/pure/strscans.nim b/lib/pure/strscans.nim
index 246f018c5..fc400173f 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
diff --git a/lib/system.nim b/lib/system.nim
index 69d3db291..8209dbc23 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/mmdisp.nim b/lib/system/mmdisp.nim
index 63af49e35..431f84bfd 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
 
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim
index 5c10392f1..29c5777cc 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 =