From 9fa477de755daf76c6a2302f58553d10caa061e9 Mon Sep 17 00:00:00 2001 From: skilchen Date: Sat, 15 Sep 2018 01:04:23 +0200 Subject: [PATCH 1/4] more efficient fix for #8961 --- lib/system/sysio.nim | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index df13ab6284..672d0e0f1a 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -149,6 +149,12 @@ proc readLine(f: File, line: var TaintedString): bool = if sp == 0: sp = 80 line.string.setLen(sp) + else: + when not defined(nimscript): + sp = cint(cast[PGenericSeq](line.string).space) + else: + line.string.setLen(sp + 1) + while true: # memset to \L so that we can tell how far fgets wrote, even on EOF, where # fgets doesn't append an \L From 6af6ca6351f29d180f86a8521cf2f46f0e6934a7 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 15 Sep 2018 00:09:50 +0200 Subject: [PATCH 2/4] Fix codegen for set[T] parameters Sometimes sets are materialized as arrays and we must treat them as such: the CPP backend is pickier than the C one and would sometimes produce invalid code. Fixes #8967 --- compiler/ccgexprs.nim | 3 ++- compiler/ccgtypes.nim | 15 ++++++++------- tests/ccgbugs/t8967.nim | 10 ++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 tests/ccgbugs/t8967.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 56ecf5ba3b..a7a28a51c0 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1596,10 +1596,11 @@ proc genSwap(p: BProc, e: PNode, d: var TLoc) = genAssignment(p, a, b, {}) genAssignment(p, b, tmp, {}) -proc rdSetElemLoc(conf: ConfigRef; a: TLoc, setType: PType): Rope = +proc rdSetElemLoc(conf: ConfigRef; a: TLoc, typ: PType): Rope = # read a location of an set element; it may need a subtraction operation # before the set operation result = rdCharLoc(a) + let setType = typ.skipTypes(abstractPtrs) assert(setType.kind == tySet) if firstOrd(conf, setType) != 0: result = "($1- $2)" % [result, rope(firstOrd(conf, setType))] diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index dd79f4846b..52a4a72f2f 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -162,9 +162,9 @@ proc mapType(conf: ConfigRef; typ: PType): TCTypeKind = var base = skipTypes(typ.lastSon, typedescInst) case base.kind of tyOpenArray, tyArray, tyVarargs: result = ctPtrToArray - #of tySet: - # if mapSetType(base) == ctArray: result = ctPtrToArray - # else: result = ctPtr + of tySet: + if mapSetType(conf, base) == ctArray: result = ctPtrToArray + else: result = ctPtr # XXX for some reason this breaks the pegs module else: result = ctPtr of tyPointer: result = ctPtr @@ -641,10 +641,11 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = compileToCpp(m): "&" else: "*" var et = origTyp.skipTypes(abstractInst).lastSon var etB = et.skipTypes(abstractInst) - if etB.kind in {tyArray, tyOpenArray, tyVarargs}: - # this is correct! sets have no proper base type, so we treat - # ``var set[char]`` in `getParamTypeDesc` - et = elemType(etB) + if mapType(m.config, t) == ctPtrToArray: + if etB.kind == tySet: + et = getSysType(m.g.graph, unknownLineInfo(), tyUInt8) + else: + et = elemType(etB) etB = et.skipTypes(abstractInst) star[0] = '*' case etB.kind diff --git a/tests/ccgbugs/t8967.nim b/tests/ccgbugs/t8967.nim new file mode 100644 index 0000000000..e342b7eae2 --- /dev/null +++ b/tests/ccgbugs/t8967.nim @@ -0,0 +1,10 @@ +discard """ + targets: "c cpp" +""" + +import marshal + +let orig: set[char] = {'A'..'Z'} +let m = $$orig +let old = to[set[char]](m) +doAssert orig - old == {} From e4af0fcb6dc2e6d90a89708a1cae0edbeb0b30e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Wollenschl=C3=A4ger?= Date: Sat, 15 Sep 2018 20:22:04 +0900 Subject: [PATCH 3/4] Allow subpaths of names of length 1 --- compiler/pathutils.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/pathutils.nim b/compiler/pathutils.nim index ef0fa4abd0..03fcfe07e0 100644 --- a/compiler/pathutils.nim +++ b/compiler/pathutils.nim @@ -114,7 +114,7 @@ proc canon(x: string; result: var string; state: var int) = if d > 0: setLen(result, d-1) elif isDot(x, b): discard "discard the dot" - elif b[1] > b[0]: + elif b[1] >= b[0]: if result.len > 0 and result[^1] != DirSep: result.add DirSep result.add substr(x, b[0], b[1]) From e317745098b95418bc1bc3d76b930ab197d67110 Mon Sep 17 00:00:00 2001 From: skilchen Date: Sat, 15 Sep 2018 14:05:42 +0200 Subject: [PATCH 4/4] don't reuse code from 0.18.0 --- lib/system/sysio.nim | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim index 672d0e0f1a..61835e0f7e 100644 --- a/lib/system/sysio.nim +++ b/lib/system/sysio.nim @@ -145,15 +145,8 @@ proc readLine(f: File, line: var TaintedString): bool = var pos = 0 # Use the currently reserved space for a first try - var sp = line.string.len - if sp == 0: - sp = 80 - line.string.setLen(sp) - else: - when not defined(nimscript): - sp = cint(cast[PGenericSeq](line.string).space) - else: - line.string.setLen(sp + 1) + var sp = max(line.string.len, 80) + line.string.setLen(sp) while true: # memset to \L so that we can tell how far fgets wrote, even on EOF, where