'add' on a nil sequence doesn't produce a crash anymore
This commit is contained in:
parent
c71c951a64
commit
ef1b547f35
2 changed files with 16 additions and 4 deletions
|
|
@ -1086,17 +1086,17 @@ proc genSeqElemAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
# seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x));
|
# seq = (typeof seq) incrSeq(&seq->Sup, sizeof(x));
|
||||||
# seq->data[seq->len-1] = x;
|
# seq->data[seq->len-1] = x;
|
||||||
let seqAppendPattern = if not p.module.compileToCpp:
|
let seqAppendPattern = if not p.module.compileToCpp:
|
||||||
"$1 = ($2) #incrSeqV2(&($1)->Sup, sizeof($3));$n"
|
"$1 = ($2) #incrSeqV3(&($1)->Sup, $3);$n"
|
||||||
else:
|
else:
|
||||||
"$1 = ($2) #incrSeqV2($1, sizeof($3));$n"
|
"$1 = ($2) #incrSeqV3($1, $3);$n"
|
||||||
var a, b, dest, tmpL: TLoc
|
var a, b, dest, tmpL: TLoc
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
initLocExpr(p, e.sons[2], b)
|
initLocExpr(p, e.sons[2], b)
|
||||||
let bt = skipTypes(e.sons[2].typ, {tyVar})
|
let seqType = skipTypes(e.sons[1].typ, {tyVar})
|
||||||
lineCg(p, cpsStmts, seqAppendPattern, [
|
lineCg(p, cpsStmts, seqAppendPattern, [
|
||||||
rdLoc(a),
|
rdLoc(a),
|
||||||
getTypeDesc(p.module, e.sons[1].typ),
|
getTypeDesc(p.module, e.sons[1].typ),
|
||||||
getTypeDesc(p.module, bt)])
|
genTypeInfo(p.module, seqType, e.info)])
|
||||||
#if bt != b.t:
|
#if bt != b.t:
|
||||||
# echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t)
|
# echo "YES ", e.info, " new: ", typeToString(bt), " old: ", typeToString(b.t)
|
||||||
initLoc(dest, locExpr, e.sons[2], OnHeap)
|
initLoc(dest, locExpr, e.sons[2], OnHeap)
|
||||||
|
|
|
||||||
|
|
@ -261,6 +261,18 @@ proc incrSeqV2(seq: PGenericSeq, elemSize: int): PGenericSeq {.compilerProc.} =
|
||||||
GenericSeqSize))
|
GenericSeqSize))
|
||||||
result.reserved = r
|
result.reserved = r
|
||||||
|
|
||||||
|
proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.} =
|
||||||
|
if s == nil:
|
||||||
|
result = cast[PGenericSeq](newSeq(typ, 1))
|
||||||
|
result.len = 0
|
||||||
|
else:
|
||||||
|
result = s
|
||||||
|
if result.len >= result.space:
|
||||||
|
let r = resize(result.space)
|
||||||
|
result = cast[PGenericSeq](growObj(result, typ.base.size * r +
|
||||||
|
GenericSeqSize))
|
||||||
|
result.reserved = r
|
||||||
|
|
||||||
proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
proc setLengthSeq(seq: PGenericSeq, elemSize, newLen: int): PGenericSeq {.
|
||||||
compilerRtl, inl.} =
|
compilerRtl, inl.} =
|
||||||
result = seq
|
result = seq
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue