From 07585088955c1fe8fb815c40409ed9f5d66fd446 Mon Sep 17 00:00:00 2001 From: Araq <rumpf_a@web.de> Date: Sun, 27 Jan 2013 19:15:13 +0100 Subject: bugfix: typeinfo.extendSeq --- lib/core/typeinfo.nim | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'lib/core') 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. -- cgit 1.4.1-2-gfad0