mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 05:23:20 +00:00
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
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
10
tests/ccgbugs/t8964.nim
Normal file
10
tests/ccgbugs/t8964.nim
Normal 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)
|
||||
Reference in New Issue
Block a user