summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2018-09-14 15:29:34 +0200
committerLemonBoy <thatlemon@gmail.com>2018-09-14 15:37:51 +0200
commit839953c3e167828f93bdddd27ae88c5909c8aca9 (patch)
treedcdb7542d3420d2405f81d56297920d94424a7ec
parent382fe446c3926f7976de09b7a1d8ad131912c7b6 (diff)
downloadNim-839953c3e167828f93bdddd27ae88c5909c8aca9.tar.gz
Fix hashing for codegenProc (sic) types
Since the name mangling is inhibited we should take the user-supplied
name during the sighash computation.

Fixes #8964
-rw-r--r--compiler/sighashes.nim12
-rw-r--r--lib/system/hti.nim12
-rw-r--r--tests/ccgbugs/t8964.nim10
3 files changed, 20 insertions, 14 deletions
diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim
index 8f95175e5..097695f82 100644
--- a/compiler/sighashes.nim
+++ b/compiler/sighashes.nim
@@ -68,6 +68,8 @@ else:
     toBase64a(cast[cstring](unsafeAddr u), sizeof(u))
   proc `&=`(c: var MD5Context, s: string) = md5Update(c, s, s.len)
   proc `&=`(c: var MD5Context, ch: char) = md5Update(c, unsafeAddr ch, 1)
+  proc `&=`(c: var MD5Context, r: Rope) =
+    for l in leaves(r): md5Update(c, l, l.len)
   proc `&=`(c: var MD5Context, i: BiggestInt) =
     md5Update(c, cast[cstring](unsafeAddr i), sizeof(i))
 
@@ -181,11 +183,11 @@ proc hashType(c: var MD5Context, t: PType; flags: set[ConsiderFlag]) =
     # Every cyclic type in Nim need to be constructed via some 't.sym', so this
     # is actually safe without an infinite recursion check:
     if t.sym != nil:
-      #if "Future:" in t.sym.name.s and t.typeInst == nil:
-      #  writeStackTrace()
-      #  echo "yes ", t.sym.name.s
-      #  #quit 1
-      if CoOwnerSig in flags:
+      if {sfCompilerProc} * t.sym.flags != {}:
+        doAssert t.sym.loc.r != nil
+        # The user has set a specific name for this type
+        c &= t.sym.loc.r
+      elif CoOwnerSig in flags:
         c.hashTypeSym(t.sym)
       else:
         c.hashSym(t.sym)
diff --git a/lib/system/hti.nim b/lib/system/hti.nim
index 9931fa11e..c7b52bbdf 100644
--- a/lib/system/hti.nim
+++ b/lib/system/hti.nim
@@ -7,12 +7,6 @@
 #    distribution, for details about the copyright.
 #
 
-when declared(ThisIsSystem):
-  # we are in system module:
-  {.pragma: codegenType, compilerproc.}
-else:
-  {.pragma: codegenType.}
-
 type
   # This should be the same as ast.TTypeKind
   # many enum fields are not used at runtime
@@ -79,7 +73,7 @@ type
     tyVoidHidden
 
   TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase
-  TNimNode {.codegenType.} = object
+  TNimNode {.compilerProc.} = object
     kind: TNimNodeKind
     offset: int
     typ: ptr TNimType
@@ -92,7 +86,7 @@ type
     ntfAcyclic = 1,    # type cannot form a cycle
     ntfEnumHole = 2    # enum has holes and thus `$` for them needs the slow
                        # version
-  TNimType {.codegenType.} = object
+  TNimType {.compilerProc.} = object
     size: int
     kind: TNimKind
     flags: set[TNimTypeFlag]
@@ -109,6 +103,6 @@ type
   PNimType = ptr TNimType
 
 when defined(nimTypeNames):
-  var nimTypeRoot {.codegenType.}: PNimType
+  var nimTypeRoot {.compilerProc.}: PNimType
 
 # node.len may be the ``first`` element of a set
diff --git a/tests/ccgbugs/t8964.nim b/tests/ccgbugs/t8964.nim
new file mode 100644
index 000000000..5b41e8bdb
--- /dev/null
+++ b/tests/ccgbugs/t8964.nim
@@ -0,0 +1,10 @@
+discard """
+  targets: "c cpp"
+"""
+
+from json import JsonParsingError
+import marshal
+
+const nothing = ""
+doAssertRaises(JsonParsingError):
+  var bar = marshal.to[int](nothing)