fixes #11065
This commit is contained in:
parent
0194f43467
commit
4f93669754
2 changed files with 40 additions and 9 deletions
|
|
@ -104,6 +104,10 @@ proc newSeqPayload(cap, elemSize: int): pointer {.compilerRtl, raises: [].} =
|
||||||
proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.
|
proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.
|
||||||
compilerRtl, noSideEffect, raises: [].} =
|
compilerRtl, noSideEffect, raises: [].} =
|
||||||
{.noSideEffect.}:
|
{.noSideEffect.}:
|
||||||
|
template `+!`(p: pointer, s: int): pointer =
|
||||||
|
cast[pointer](cast[int](p) +% s)
|
||||||
|
|
||||||
|
const headerSize = sizeof(int) + sizeof(Allocator)
|
||||||
if addlen <= 0:
|
if addlen <= 0:
|
||||||
result = p
|
result = p
|
||||||
elif p == nil:
|
elif p == nil:
|
||||||
|
|
@ -112,11 +116,20 @@ proc prepareSeqAdd(len: int; p: pointer; addlen, elemSize: int): pointer {.
|
||||||
# Note: this means we cannot support things that have internal pointers as
|
# Note: this means we cannot support things that have internal pointers as
|
||||||
# they get reallocated here. This needs to be documented clearly.
|
# they get reallocated here. This needs to be documented clearly.
|
||||||
var p = cast[ptr PayloadBase](p)
|
var p = cast[ptr PayloadBase](p)
|
||||||
let allocator = if p.allocator == nil: getLocalAllocator() else: p.allocator
|
|
||||||
let cap = max(resize(p.cap), len+addlen)
|
let cap = max(resize(p.cap), len+addlen)
|
||||||
|
if p.allocator == nil:
|
||||||
|
let allocator = getLocalAllocator()
|
||||||
|
var q = cast[ptr PayloadBase](allocator.alloc(allocator,
|
||||||
|
headerSize + elemSize * cap))
|
||||||
|
copyMem(q +! headerSize, p +! headerSize, len * elemSize)
|
||||||
|
q.allocator = allocator
|
||||||
|
q.cap = cap
|
||||||
|
result = q
|
||||||
|
else:
|
||||||
|
let allocator = p.allocator
|
||||||
var q = cast[ptr PayloadBase](allocator.realloc(allocator, p,
|
var q = cast[ptr PayloadBase](allocator.realloc(allocator, p,
|
||||||
sizeof(int) + sizeof(Allocator) + elemSize * p.cap,
|
headerSize + elemSize * p.cap,
|
||||||
sizeof(int) + sizeof(Allocator) + elemSize * cap))
|
headerSize + elemSize * cap))
|
||||||
q.allocator = allocator
|
q.allocator = allocator
|
||||||
q.cap = cap
|
q.cap = cap
|
||||||
result = q
|
result = q
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,8 @@ ho
|
||||||
ha
|
ha
|
||||||
@["arg", "asdfklasdfkl", "asdkfj", "dfasj", "klfjl"]
|
@["arg", "asdfklasdfkl", "asdkfj", "dfasj", "klfjl"]
|
||||||
@[1, 2, 3]
|
@[1, 2, 3]
|
||||||
25 25'''
|
@["red", "yellow", "orange", "rtrt1", "pink"]
|
||||||
|
30 30'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import allocators
|
import allocators
|
||||||
|
|
@ -139,7 +140,7 @@ type
|
||||||
Obj* = object
|
Obj* = object
|
||||||
f*: seq[int]
|
f*: seq[int]
|
||||||
|
|
||||||
method main(o: Obj) =
|
method main(o: Obj) {.base.} =
|
||||||
for newb in o.f:
|
for newb in o.f:
|
||||||
discard
|
discard
|
||||||
|
|
||||||
|
|
@ -151,6 +152,23 @@ proc testforNoMove =
|
||||||
|
|
||||||
testforNoMove()
|
testforNoMove()
|
||||||
|
|
||||||
|
# bug #11065
|
||||||
|
type
|
||||||
|
Warm = seq[string]
|
||||||
|
|
||||||
|
proc testWarm =
|
||||||
|
var w: Warm
|
||||||
|
w = @["red", "yellow", "orange"]
|
||||||
|
|
||||||
|
var x = "rt"
|
||||||
|
var y = "rt1"
|
||||||
|
w.add(x & y)
|
||||||
|
|
||||||
|
w.add("pink")
|
||||||
|
echo w
|
||||||
|
|
||||||
|
testWarm()
|
||||||
|
|
||||||
#echo s
|
#echo s
|
||||||
let (a, d) = allocCounters()
|
let (a, d) = allocCounters()
|
||||||
discard cprintf("%ld %ld\n", a, d)
|
discard cprintf("%ld %ld\n", a, d)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue