Merge branch 'devel' of github.com:nim-lang/Nim into devel

This commit is contained in:
Andreas Rumpf 2018-01-08 22:00:27 +01:00
commit 424532f883
2 changed files with 28 additions and 6 deletions

View file

@ -9,7 +9,7 @@
type type
Allocator* {.inheritable.} = ptr object Allocator* {.inheritable.} = ptr object
alloc*: proc (a: Allocator; size: int; alignment = 8): pointer {.nimcall.} alloc*: proc (a: Allocator; size: int; alignment: int = 8): pointer {.nimcall.}
dealloc*: proc (a: Allocator; p: pointer; size: int) {.nimcall.} dealloc*: proc (a: Allocator; p: pointer; size: int) {.nimcall.}
realloc*: proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall.} realloc*: proc (a: Allocator; p: pointer; oldSize, newSize: int): pointer {.nimcall.}
@ -22,14 +22,14 @@ proc getCurrentAllocator*(): Allocator =
proc setCurrentAllocator*(a: Allocator) = proc setCurrentAllocator*(a: Allocator) =
currentAllocator = a currentAllocator = a
proc alloc*(size: int): pointer = proc alloc*(size: int; alignment: int = 8): pointer =
let a = getCurrentAllocator() let a = getCurrentAllocator()
result = a.alloc(a, size) result = a.alloc(a, size, alignment)
proc dealloc*(p: pointer; size: int) = proc dealloc*(p: pointer; size: int) =
let a = getCurrentAllocator() let a = getCurrentAllocator()
a.dealloc(a, size) a.dealloc(a, p, size)
proc realloc*(p: pointer; oldSize, newSize: int): pointer = proc realloc*(p: pointer; oldSize, newSize: int): pointer =
let a = getCurrentAllocator() let a = getCurrentAllocator()
result = a.realloc(a, oldSize, newSize) result = a.realloc(a, p, oldSize, newSize)

View file

@ -7,7 +7,7 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
import allocators import allocators, typetraits
## Default seq implementation used by Nim's core. ## Default seq implementation used by Nim's core.
type type
@ -115,3 +115,25 @@ proc `@`*[T](elems: openArray[T]): seq[T] =
result.data[i] = elems[i] result.data[i] = elems[i]
proc len*[T](x: seq[T]): int {.inline.} = x.len proc len*[T](x: seq[T]): int {.inline.} = x.len
proc `$`*[T](x: seq[T]): string =
result = "@["
var firstElement = true
for i in 0..<x.len:
let
value = x.data[i]
if firstElement:
firstElement = false
else:
result.add(", ")
when compiles(value.isNil):
# this branch should not be necessary
if value.isNil:
result.add "nil"
else:
result.addQuoted(value)
else:
result.addQuoted(value)
result.add("]")