diff options
author | Araq <rumpf_a@web.de> | 2013-01-27 19:15:13 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-01-27 19:15:13 +0100 |
commit | 07585088955c1fe8fb815c40409ed9f5d66fd446 (patch) | |
tree | 0179ff01c39469a61cdc2644ba5d9cc3b29181e8 /lib | |
parent | 0e1b67cfff7f9e7352439888e06e2c255599e193 (diff) | |
download | Nim-07585088955c1fe8fb815c40409ed9f5d66fd446.tar.gz |
bugfix: typeinfo.extendSeq
Diffstat (limited to 'lib')
-rwxr-xr-x | lib/core/typeinfo.nim | 13 | ||||
-rwxr-xr-x | lib/pure/htmlparser.nim | 6 | ||||
-rwxr-xr-x | lib/pure/marshal.nim | 2 | ||||
-rwxr-xr-x | lib/system/debugger.nim | 39 |
4 files changed, 37 insertions, 23 deletions
diff --git a/lib/core/typeinfo.nim b/lib/core/typeinfo.nim index 26a14f444..eb2a0c9e5 100755 --- a/lib/core/typeinfo.nim +++ b/lib/core/typeinfo.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2012 Dominik Picheta, Andreas Rumpf +# (c) Copyright 2013 Dominik Picheta, Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -139,12 +139,15 @@ proc invokeNewSeq*(x: TAny, len: int) = var z = newSeq(x.rawType, len) genericShallowAssign(x.value, addr(z), x.rawType) -proc extendSeq*(x: TAny, elems = 1) = - ## performs ``setLen(x, x.len+elems)``. `x` needs to represent a ``seq``. +proc extendSeq*(x: TAny) = + ## performs ``setLen(x, x.len+1)``. `x` needs to represent a ``seq``. assert x.rawType.kind == tySequence var y = cast[ptr PGenSeq](x.value)[] - var z = incrSeq(y, x.rawType.base.size * elems) - genericShallowAssign(x.value, addr(z), x.rawType) + var z = incrSeq(y, x.rawType.base.size) + # 'incrSeq' already freed the memory for us and copied over the RC! + # So we simply copy the raw pointer into 'x.value': + cast[ppointer](x.value)[] = z + #genericShallowAssign(x.value, addr(z), x.rawType) proc setObjectRuntimeType*(x: TAny) = ## this needs to be called to set `x`'s runtime object type field. diff --git a/lib/pure/htmlparser.nim b/lib/pure/htmlparser.nim index 4136ecf57..ad952fc41 100755 --- a/lib/pure/htmlparser.nim +++ b/lib/pure/htmlparser.nim @@ -123,7 +123,7 @@ type tagVar ## the HTML ``var`` element const - tagStrs = [ + tagToStr* = [ "a", "abbr", "acronym", "address", "applet", "area", "b", "base", "basefont", "bdo", "big", "blockquote", "body", "br", "button", "caption", "center", "cite", "code", @@ -243,13 +243,13 @@ proc binaryStrSearch(x: openarray[string], y: string): int = proc htmlTag*(n: PXmlNode): THtmlTag = ## gets `n`'s tag as a ``THtmlTag``. if n.clientData == 0: - n.clientData = binaryStrSearch(tagStrs, n.tag)+1 + n.clientData = binaryStrSearch(tagToStr, n.tag)+1 result = THtmlTag(n.clientData) proc htmlTag*(s: string): THtmlTag = ## converts `s` to a ``THtmlTag``. If `s` is no HTML tag, ``tagUnknown`` is ## returned. - result = THtmlTag(binaryStrSearch(tagStrs, s.toLower)+1) + result = THtmlTag(binaryStrSearch(tagToStr, s.toLower)+1) proc entityToUtf8*(entity: string): string = ## converts an HTML entity name like ``Ü`` to its UTF-8 equivalent. diff --git a/lib/pure/marshal.nim b/lib/pure/marshal.nim index bffc4ebb6..f52b554cc 100755 --- a/lib/pure/marshal.nim +++ b/lib/pure/marshal.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2012 Andreas Rumpf +# (c) Copyright 2013 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. diff --git a/lib/system/debugger.nim b/lib/system/debugger.nim index 68fbccef6..f234c9daf 100755 --- a/lib/system/debugger.nim +++ b/lib/system/debugger.nim @@ -1,7 +1,7 @@ # # # Nimrod's Runtime Library -# (c) Copyright 2012 Andreas Rumpf +# (c) Copyright 2013 Andreas Rumpf # # See the file "copying.txt", included in this # distribution, for details about the copyright. @@ -579,6 +579,10 @@ proc hash(Data: Pointer, Size: int): THash = Dec(s) result = !$h +proc hashGcHeader(data: pointer): THash = + const headerSize = sizeof(int)*2 + result = hash(cast[pointer](cast[int](data) -% headerSize), headerSize) + proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool, h: THash): THash proc genericHashAux(dest: Pointer, n: ptr TNimNode, shallow: bool, @@ -606,20 +610,22 @@ proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool, result = h if x != nil: let s = cast[NimString](x) - when true: - result = result !& hash(x, s.len) + when defined(trackGcHeaders): + result = result !& hashGcHeader(x) else: - let y = cast[pointer](cast[int](x) -% 2*sizeof(int)) - result = result !& hash(y, s.len + 2*sizeof(int)) + result = result !& hash(x, s.len) of tySequence: var x = cast[ppointer](dest) var dst = cast[taddress](cast[ppointer](dest)[]) result = h if dst != 0: - for i in 0..cast[pgenericseq](dst).len-1: - result = result !& genericHashAux( - cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize), - mt.Base, shallow, result) + when defined(trackGcHeaders): + result = result !& hashGcHeader(cast[ppointer](dest)[]) + else: + for i in 0..cast[pgenericseq](dst).len-1: + result = result !& genericHashAux( + cast[pointer](dst +% i*% mt.base.size +% GenericSeqSize), + mt.Base, shallow, result) of tyObject, tyTuple: # we don't need to copy m_type field for tyObject, as they are equal anyway result = genericHashAux(dest, mt.node, shallow, h) @@ -630,13 +636,18 @@ proc genericHashAux(dest: Pointer, mt: PNimType, shallow: bool, result = result !& genericHashAux(cast[pointer](d +% i*% mt.base.size), mt.base, shallow, result) of tyRef: - if shallow: - result = h !& hash(dest, mt.size) - else: - result = h + when defined(trackGcHeaders): var s = cast[ppointer](dest)[] if s != nil: - result = result !& genericHashAux(s, mt.base, shallow, result) + result = result !& hashGcHeader(s) + else: + if shallow: + result = h !& hash(dest, mt.size) + else: + result = h + var s = cast[ppointer](dest)[] + if s != nil: + result = result !& genericHashAux(s, mt.base, shallow, result) # hash the object header: #const headerSize = sizeof(int)*2 #result = result !& hash(cast[pointer](cast[int](s) -% headerSize), |