fixes #11098
This commit is contained in:
parent
f288e1b11a
commit
e083a1533b
3 changed files with 30 additions and 10 deletions
|
|
@ -1306,11 +1306,17 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) =
|
||||||
let seqtype = skipTypes(e.typ, abstractVarRange)
|
let seqtype = skipTypes(e.typ, abstractVarRange)
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
putIntoDest(p, d, e, ropecg(p.module,
|
if p.config.selectedGC == gcDestructors:
|
||||||
"($1)#nimNewSeqOfCap($2, $3)", [
|
if d.k == locNone: getTemp(p, e.typ, d, needsInit=false)
|
||||||
getTypeDesc(p.module, seqtype),
|
linefmt(p, cpsStmts, "$1.len = 0; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
||||||
genTypeInfo(p.module, seqtype, e.info), a.rdLoc]))
|
[d.rdLoc, a.rdLoc, getTypeDesc(p.module, seqtype.lastSon),
|
||||||
gcUsage(p.config, e)
|
getSeqPayloadType(p.module, seqtype)])
|
||||||
|
else:
|
||||||
|
putIntoDest(p, d, e, ropecg(p.module,
|
||||||
|
"($1)#nimNewSeqOfCap($2, $3)", [
|
||||||
|
getTypeDesc(p.module, seqtype),
|
||||||
|
genTypeInfo(p.module, seqtype, e.info), a.rdLoc]))
|
||||||
|
gcUsage(p.config, e)
|
||||||
|
|
||||||
proc genConstExpr(p: BProc, n: PNode): Rope
|
proc genConstExpr(p: BProc, n: PNode): Rope
|
||||||
proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
|
proc handleConstExpr(p: BProc, n: PNode, d: var TLoc): bool =
|
||||||
|
|
|
||||||
|
|
@ -997,8 +997,7 @@ proc newSeqOfCap*[T](cap: Natural): seq[T] {.
|
||||||
## assert len(x) == 1
|
## assert len(x) == 1
|
||||||
discard
|
discard
|
||||||
|
|
||||||
when not defined(JS) and not defined(gcDestructors):
|
when not defined(JS):
|
||||||
# XXX enable this for --gc:destructors
|
|
||||||
proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] =
|
proc newSeqUninitialized*[T: SomeNumber](len: Natural): seq[T] =
|
||||||
## Creates a new sequence of type ``seq[T]`` with length ``len``.
|
## Creates a new sequence of type ``seq[T]`` with length ``len``.
|
||||||
##
|
##
|
||||||
|
|
@ -1011,8 +1010,11 @@ when not defined(JS) and not defined(gcDestructors):
|
||||||
## assert len(x) == 3
|
## assert len(x) == 3
|
||||||
## x[0] = 10
|
## x[0] = 10
|
||||||
result = newSeqOfCap[T](len)
|
result = newSeqOfCap[T](len)
|
||||||
var s = cast[PGenericSeq](result)
|
when defined(gcDestructors):
|
||||||
s.len = len
|
cast[ptr int](addr result)[] = len
|
||||||
|
else:
|
||||||
|
var s = cast[PGenericSeq](result)
|
||||||
|
s.len = len
|
||||||
|
|
||||||
proc len*[TOpenArray: openArray|varargs](x: TOpenArray): int {.
|
proc len*[TOpenArray: openArray|varargs](x: TOpenArray): int {.
|
||||||
magic: "LengthOpenArray", noSideEffect.}
|
magic: "LengthOpenArray", noSideEffect.}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,9 @@ ha
|
||||||
@[1, 2, 3]
|
@[1, 2, 3]
|
||||||
@["red", "yellow", "orange", "rtrt1", "pink"]
|
@["red", "yellow", "orange", "rtrt1", "pink"]
|
||||||
a: @[4, 2, 3]
|
a: @[4, 2, 3]
|
||||||
35 35'''
|
0
|
||||||
|
30
|
||||||
|
41 41'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import allocators
|
import allocators
|
||||||
|
|
@ -178,6 +180,16 @@ proc mutConstSeq() =
|
||||||
|
|
||||||
mutConstSeq()
|
mutConstSeq()
|
||||||
|
|
||||||
|
proc mainSeqOfCap =
|
||||||
|
# bug #11098
|
||||||
|
var s = newSeqOfCap[int](10)
|
||||||
|
echo s.len
|
||||||
|
|
||||||
|
var s2 = newSeqUninitialized[int](30)
|
||||||
|
echo s2.len
|
||||||
|
|
||||||
|
mainSeqOfCap()
|
||||||
|
|
||||||
#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