diff options
author | Araq <rumpf_a@web.de> | 2013-12-03 01:59:38 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2013-12-03 01:59:38 +0100 |
commit | fe983b13099dd8d8a93ebefc00174e98eb048dea (patch) | |
tree | 2d437512f120011dd4be4215bcc9e37d7aa29ac6 | |
parent | 5dcfa97fb959eda3cb8a41e2bd39e998c30052c8 (diff) | |
download | Nim-fe983b13099dd8d8a93ebefc00174e98eb048dea.tar.gz |
fixes a regression where memset was used without including <string.h>
-rw-r--r-- | compiler/ccgexprs.nim | 6 | ||||
-rw-r--r-- | compiler/cgen.nim | 8 | ||||
-rw-r--r-- | compiler/cgendata.nim | 1 | ||||
-rw-r--r-- | lib/system/gc.nim | 3 | ||||
-rw-r--r-- | tests/reject/twrongiter.nim | 13 |
5 files changed, 29 insertions, 2 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index c50fd4536..873c61ed4 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -240,6 +240,7 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = if needToCopy notin flags or tfShallow in skipTypes(dest.t, abstractVarRange).flags: if dest.s == OnStack or not usesNativeGC(): + useStringh(p.module) linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n", addrLoc(dest), addrLoc(src), rdLoc(dest)) @@ -316,6 +317,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = if needsComplexAssignment(dest.t): genGenericAsgn(p, dest, src, flags) else: + useStringh(p.module) linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1));$n", rdLoc(dest), rdLoc(src)) @@ -327,11 +329,13 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) = "#genericAssignOpenArray((void*)$1, (void*)$2, $1Len0, $3);$n", addrLoc(dest), addrLoc(src), genTypeInfo(p.module, dest.t)) else: + useStringh(p.module) linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($1[0])*$1Len0);$n", rdLoc(dest), rdLoc(src)) of tySet: if mapType(ty) == ctArray: + useStringh(p.module) linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, $3);$n", rdLoc(dest), rdLoc(src), toRope(getSize(dest.t))) else: @@ -1361,6 +1365,7 @@ proc genSetOp(p: BProc, e: PNode, d: var TLoc, op: TMagic) = lineF(p, cpsStmts, lookupOpr[op], [rdLoc(i), toRope(size), rdLoc(d), rdLoc(a), rdLoc(b)]) of mEqSet: + useStringh(p.module) binaryExprChar(p, e, d, "(memcmp($1, $2, " & $(size) & ")==0)") of mMulSet, mPlusSet, mMinusSet, mSymDiffSet: # we inline the simple for loop for better code generation: @@ -1612,6 +1617,7 @@ proc genSetConstr(p: BProc, e: PNode, d: var TLoc) = if d.k == locNone: getTemp(p, e.typ, d) if getSize(e.typ) > 8: # big set: + useStringh(p.module) lineF(p, cpsStmts, "memset($1, 0, sizeof($1));$n", [rdLoc(d)]) for i in countup(0, sonsLen(e) - 1): if e.sons[i].kind == nkRange: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 910e675e1..24d3c2923 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -72,6 +72,11 @@ proc isSimpleConst(typ: PType): bool = {tyTuple, tyObject, tyArray, tyArrayConstr, tySet, tySequence} and not (t.kind == tyProc and t.callConv == ccClosure) +proc useStringh(m: BModule) = + if not m.includesStringh: + m.includesStringh = true + discard lists.IncludeStr(m.headerFiles, "<string.h>") + proc useHeader(m: BModule, sym: PSym) = if lfHeader in sym.loc.Flags: assert(sym.annex != nil) @@ -358,6 +363,7 @@ proc resetLoc(p: BProc, loc: var TLoc) = # field, so disabling this should be safe: genObjectInit(p, cpsStmts, loc.t, loc, true) else: + useStringh(p.module) linefmt(p, cpsStmts, "memset((void*)$1, 0, sizeof($2));$n", addrLoc(loc), rdLoc(loc)) # XXX: We can be extra clever here and call memset only @@ -368,6 +374,7 @@ proc constructLoc(p: BProc, loc: TLoc, section = cpsStmts) = if not isComplexValueType(skipTypes(loc.t, abstractRange)): linefmt(p, section, "$1 = 0;$n", rdLoc(loc)) else: + useStringh(p.module) linefmt(p, section, "memset((void*)$1, 0, sizeof($2));$n", addrLoc(loc), rdLoc(loc)) genObjectInit(p, section, loc.t, loc, true) @@ -418,6 +425,7 @@ proc keepAlive(p: BProc, toKeepAlive: TLoc) = if not isComplexValueType(skipTypes(toKeepAlive.t, abstractVarRange)): linefmt(p, cpsStmts, "$1 = $2;$n", rdLoc(result), rdLoc(toKeepAlive)) else: + useStringh(p.module) linefmt(p, cpsStmts, "memcpy((void*)$1, (NIM_CONST void*)$2, sizeof($3));$n", addrLoc(result), addrLoc(toKeepAlive), rdLoc(result)) diff --git a/compiler/cgendata.nim b/compiler/cgendata.nim index b5888d0f4..c156c40fe 100644 --- a/compiler/cgendata.nim +++ b/compiler/cgendata.nim @@ -91,6 +91,7 @@ type FrameDeclared*: bool # hack for ROD support so that we don't declare # a frame var twice in an init proc isHeaderFile*: bool # C source file is the header file + includesStringh*: bool # C source file already includes ``<string.h>`` cfilename*: string # filename of the module (including path, # without extension) typeCache*: TIdTable # cache the generated types diff --git a/lib/system/gc.nim b/lib/system/gc.nim index 48705db96..d2b065d6b 100644 --- a/lib/system/gc.nim +++ b/lib/system/gc.nim @@ -629,8 +629,7 @@ proc doOperation(p: pointer, op: TWalkOp) = case op of waZctDecRef: #if not isAllocatedPtr(gch.region, c): - # return - # c_fprintf(c_stdout, "[GC] decref bug: %p", c) + # c_fprintf(c_stdout, "[GC] decref bug: %p", c) gcAssert(isAllocatedPtr(gch.region, c), "decRef: waZctDecRef") gcAssert(c.refcount >=% rcIncrement, "doOperation 2") #c.refcount = c.refcount -% rcIncrement diff --git a/tests/reject/twrongiter.nim b/tests/reject/twrongiter.nim new file mode 100644 index 000000000..2d2502a6a --- /dev/null +++ b/tests/reject/twrongiter.nim @@ -0,0 +1,13 @@ +discard """ +line: 14 +errormsg: "type mismatch" +""" + +proc first(it: iterator(): int): seq[int] = + return @[] + +iterator primes(): int = + yield 1 + +for i in first(primes): + break |