Skip to content

Commit ce34e4f

Browse files
committed
fixup(4328fbf),bypass(NIM-BUG): provide alt impl for Py_Hash for bytes by disallow setting when JS
1 parent 6bab12b commit ce34e4f

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

Objects/hash_def.nim

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,26 @@ type PyHash_FuncDef* = object
2828
hash_bits*,
2929
seed_bits*: int
3030

31+
const Py_SupHashBuffer* = not defined(js) #XXX:NIM-BUG: js has bug to run hashData
32+
3133
var PyHash_Func = PyHash_FuncDef(
3234
hash: hashData,
3335
name: ALGO,
3436
hash_bits: 64,
3537
seed_bits: 8*sizeof(int),
3638
)
3739
proc PyHash_GetFuncDef*: PyHash_FuncDef{.inline.} = PyHash_Func
38-
proc PyHash_SetFuncDef*(x: PyHash_FuncDef) = PyHash_Func = x
3940

40-
proc Py_HashBuffer*(p: pointer, n: int): Hash{.raises: [].} = PyHash_Func.hash(p, n)
41-
proc Py_HashBuffer*[T](p: openArray[T]): Hash = Py_HashBuffer(p.addr0, p.len * sizeof T)
41+
when Py_SupHashBuffer:
42+
proc PyHash_SetFuncDef*(x: PyHash_FuncDef) = PyHash_Func = x
43+
proc Py_HashBuffer*(p: pointer, n: int): Hash{.raises: [].} = PyHash_Func.hash(p, n)
44+
proc Py_HashBuffer*[T](p: openArray[T]): Hash = Py_HashBuffer(p.addr0, p.len * sizeof T)
45+
else:
46+
const notSup = "set Py_HashBuffer is not supported in this platform"
47+
proc PyHash_SetFuncDef*(x: PyHash_FuncDef){.error: notSup.}
48+
proc Py_HashBuffer*(p: pointer, n: int): Hash{.raises: [], error: notSup.}
49+
proc Py_HashBuffer*[T](p: openArray[T]): Hash =
50+
for i in p:
51+
result = result !& cast[int](i)
52+
result = !$result
4253

43-
const Py_SupHashBuffer* = not defined(js)

0 commit comments

Comments
 (0)