mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-111545: Add Py_HashPointer() function (#112096)
* Implement _Py_HashPointerRaw() as a static inline function. * Add Py_HashPointer() tests to test_capi.test_hash. * Keep _Py_HashPointer() function as an alias to Py_HashPointer().
This commit is contained in:
parent
f8852634ed
commit
828451dfde
9 changed files with 103 additions and 22 deletions
|
|
@ -44,8 +44,24 @@ hash_getfuncdef(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
hash_pointer(PyObject *Py_UNUSED(module), PyObject *arg)
|
||||
{
|
||||
void *ptr = PyLong_AsVoidPtr(arg);
|
||||
if (ptr == NULL && PyErr_Occurred()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
Py_hash_t hash = Py_HashPointer(ptr);
|
||||
Py_BUILD_ASSERT(sizeof(long long) >= sizeof(hash));
|
||||
return PyLong_FromLongLong(hash);
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef test_methods[] = {
|
||||
{"hash_getfuncdef", hash_getfuncdef, METH_NOARGS},
|
||||
{"hash_pointer", hash_pointer, METH_O},
|
||||
{NULL},
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue