File tree Expand file tree Collapse file tree 2 files changed +15
-10
lines changed
Expand file tree Collapse file tree 2 files changed +15
-10
lines changed Original file line number Diff line number Diff 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+
3133var PyHash_Func = PyHash_FuncDef (
3234 hash: hashData,
3335 name: ALGO ,
3436 hash_bits: 64 ,
3537 seed_bits: 8 * sizeof (int ),
3638 )
3739proc 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)
Original file line number Diff line number Diff line change @@ -169,12 +169,7 @@ template itemSize*(self: UnicodeVariant): int =
169169
170170proc hashImpl (self: UnicodeVariant ): Hash {. inline , cdecl .} =
171171 template forLoop (ls): untyped =
172- when Py_SupHashBuffer:
173- Py_HashBuffer (ls.addr0, ls.len * self.itemSize)
174- else :
175- for i in ls:
176- result = result !& cast [int ](i)
177- result = !$ result
172+ Py_HashBuffer (ls.addr0, ls.len * self.itemSize)
178173 if self.ascii:
179174 forLoop self.asciiStr
180175 else :
You can’t perform that action at this time.
0 commit comments