Merge pull request #8966 from LemonBoy/fix-8964

Fix hashing for codegenProc (sic) types
This commit is contained in:
Andreas Rumpf 2018-09-14 22:28:12 +02:00 • committed by GitHub
commit 0c04b80651
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 14 deletions

View file

@ -68,6 +68,8 @@ else:
toBase64a(cast[cstring](unsafeAddr u), sizeof(u)) toBase64a(cast[cstring](unsafeAddr u), sizeof(u))
proc `&=`(c: var MD5Context, s: string) = md5Update(c, s, s.len) 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, 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) = proc `&=`(c: var MD5Context, i: BiggestInt) =
md5Update(c, cast[cstring](unsafeAddr i), sizeof(i)) md5Update(c, cast[cstring](unsafeAddr i), sizeof(i))
@ -185,11 +187,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 # Every cyclic type in Nim need to be constructed via some 't.sym', so this
# is actually safe without an infinite recursion check: # is actually safe without an infinite recursion check:
if t.sym != nil: if t.sym != nil:
#if "Future:" in t.sym.name.s and t.typeInst == nil: if {sfCompilerProc} * t.sym.flags != {}:
# writeStackTrace() doAssert t.sym.loc.r != nil
# echo "yes ", t.sym.name.s # The user has set a specific name for this type
# #quit 1 c &= t.sym.loc.r
if CoOwnerSig in flags: elif CoOwnerSig in flags:
c.hashTypeSym(t.sym) c.hashTypeSym(t.sym)
else: else:
c.hashSym(t.sym) c.hashSym(t.sym)

View file

@ -7,12 +7,6 @@
# distribution, for details about the copyright. # distribution, for details about the copyright.
# #
when declared(ThisIsSystem):
# we are in system module:
{.pragma: codegenType, compilerproc.}
else:
{.pragma: codegenType.}
type type
# This should be the same as ast.TTypeKind # This should be the same as ast.TTypeKind
# many enum fields are not used at runtime # many enum fields are not used at runtime
@ -79,7 +73,7 @@ type
tyVoidHidden tyVoidHidden
TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase TNimNodeKind = enum nkNone, nkSlot, nkList, nkCase
TNimNode {.codegenType.} = object TNimNode {.compilerProc.} = object
kind: TNimNodeKind kind: TNimNodeKind
offset: int offset: int
typ: ptr TNimType typ: ptr TNimType
@ -92,7 +86,7 @@ type
ntfAcyclic = 1, # type cannot form a cycle ntfAcyclic = 1, # type cannot form a cycle
ntfEnumHole = 2 # enum has holes and thus `$` for them needs the slow ntfEnumHole = 2 # enum has holes and thus `$` for them needs the slow
# version # version
TNimType {.codegenType.} = object TNimType {.compilerProc.} = object
size: int size: int
kind: TNimKind kind: TNimKind
flags: set[TNimTypeFlag] flags: set[TNimTypeFlag]
@ -109,6 +103,6 @@ type
PNimType = ptr TNimType PNimType = ptr TNimType
when defined(nimTypeNames): when defined(nimTypeNames):
var nimTypeRoot {.codegenType.}: PNimType var nimTypeRoot {.compilerProc.}: PNimType
# node.len may be the ``first`` element of a set # node.len may be the ``first`` element of a set

10
tests/ccgbugs/t8964.nim Normal file
View file

@ -0,0 +1,10 @@
discard """
targets: "c cpp"
"""
from json import JsonParsingError
import marshal
const nothing = ""
doAssertRaises(JsonParsingError):
var bar = marshal.to[int](nothing)