diff options
author | Araq <rumpf_a@web.de> | 2012-01-02 23:12:12 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-01-02 23:12:12 +0100 |
commit | d849463af22f02d4a5e4fa7edd5e756aa6cc39fe (patch) | |
tree | bc835f5e80f7c1ec00fdb3574591be65398ed2e1 | |
parent | 4f1b89c30cff4b91d5656c856f05be4604adaeaa (diff) | |
download | Nim-d849463af22f02d4a5e4fa7edd5e756aa6cc39fe.tar.gz |
serious allocator bugfixes
-rwxr-xr-x | lib/system/alloc.nim | 13 | ||||
-rwxr-xr-x | todo.txt | 2 |
2 files changed, 11 insertions, 4 deletions
diff --git a/lib/system/alloc.nim b/lib/system/alloc.nim index e31ef47df..8522e6877 100755 --- a/lib/system/alloc.nim +++ b/lib/system/alloc.nim @@ -219,7 +219,10 @@ proc allocAvlNode(a: var TMemRegion, key, upperBound: int): PAvlNode = result.upperBound = upperBound result.link[0] = bottom result.link[1] = bottom - result.level = 0 + result.level = 1 + sysAssert(bottom == addr(bottomData), "bottom data") + sysAssert(bottom.link[0] == bottom, "bottom link[0]") + sysAssert(bottom.link[1] == bottom, "bottom link[1]") proc deallocAvlNode(a: var TMemRegion, n: PAvlNode) {.inline.} = n.link[0] = a.freeAvlNodes @@ -632,7 +635,11 @@ proc interiorAllocatedPtr(a: TMemRegion, p: pointer): pointer = proc ptrSize(p: pointer): int = var x = cast[pointer](cast[TAddress](p) -% sizeof(TFreeCell)) - result = pageAddr(x).size - sizeof(TFreeCell) + var c = pageAddr(p) + sysAssert(not chunkUnused(c), "ptrSize") + result = c.size -% sizeof(TFreeCell) + if not isSmallChunk(c): + dec result, bigChunkOverhead() proc alloc(allocator: var TMemRegion, size: int): pointer = result = rawAlloc(allocator, size+sizeof(TFreeCell)) @@ -652,7 +659,7 @@ proc dealloc(allocator: var TMemRegion, p: pointer) = proc realloc(allocator: var TMemRegion, p: pointer, newsize: int): pointer = if newsize > 0: - result = alloc(allocator, newsize) + result = alloc0(allocator, newsize) if p != nil: copyMem(result, p, ptrSize(p)) dealloc(allocator, p) diff --git a/todo.txt b/todo.txt index 62f9977e2..27d192dcd 100755 --- a/todo.txt +++ b/todo.txt @@ -5,7 +5,7 @@ version 0.8.14 - BUG: type TX = TTable[string, int] - BUG: len(openArray) breaks symbol files - BUG: temp3.nim triggers weird compiler bug -- BUG: --debugger:on does not work the talloc.nim +- BUG: --debugger:on does not work with talloc.nim - warning for implicit openArray -> varargs conversion - implement explicit varargs; **but** ``len(varargs)`` problem remains! --> solve by implicit conversion from varargs to openarray |