| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1084,7 +1084,8 @@ C API changes | |||
| 1084 | 1084 | New features | |
| 1085 | 1085 | ------------ | |
| 1086 | 1086 | ||
| 1087 | - * TODO | ||
| 1087 | + * Add :c:func:`Py_HashBuffer` to the limited C API. | ||
| 1088 | + (Contributed by Victor Stinner in :gh:`148233`.) | ||
| 1088 | 1089 | ||
| 1089 | 1090 | Porting to Python 3.16 | |
| 1090 | 1091 | ---------------------- | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,5 +50,3 @@ _Py_HashPointer(const void *ptr) | |||
| 50 | 50 | } | |
| 51 | 51 | ||
| 52 | 52 | PyAPI_FUNC(Py_hash_t) PyObject_GenericHash(PyObject *); | |
| 53 | - | ||
| 54 | - PyAPI_FUNC(Py_hash_t) Py_HashBuffer(const void *ptr, Py_ssize_t len); | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -47,6 +47,10 @@ extern "C" { | |||
| 47 | 47 | # endif /* uint64_t && uint32_t && aligned */ | |
| 48 | 48 | #endif /* Py_HASH_ALGORITHM */ | |
| 49 | 49 | ||
| 50 | + #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= _Py_PACK_VERSION(3, 16) | ||
| 51 | + PyAPI_FUNC(Py_hash_t) Py_HashBuffer(const void *ptr, Py_ssize_t len); | ||
| 52 | + #endif | ||
| 53 | + | ||
| 50 | 54 | #ifndef Py_LIMITED_API | |
| 51 | 55 | # define Py_CPYTHON_HASH_H | |
| 52 | 56 | # include "cpython/pyhash.h" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,9 @@ | |||
| 1 | 1 | import sys | |
| 2 | 2 | import unittest | |
| 3 | 3 | from test.support import import_helper | |
| 4 | + | ||
| 4 | 5 | _testcapi = import_helper.import_module('_testcapi') | |
| 6 | + _testlimitedcapi = import_helper.import_module('_testlimitedcapi') | ||
| 5 | 7 | ||
| 6 | 8 | ||
| 7 | 9 | SIZEOF_VOID_P = _testcapi.SIZEOF_VOID_P | |
@@ -79,7 +81,8 @@ def python_hash_pointer(x): | |||
| 79 | 81 | self.assertEqual(hash_pointer(VOID_P_MAX), -2) | |
| 80 | 82 | ||
| 81 | 83 | def test_hash_buffer(self): | |
| 82 | - hash_buffer = _testcapi.hash_buffer | ||
| 84 | + # Test Py_HashBuffer() | ||
| 85 | + hash_buffer = _testlimitedcapi.hash_buffer | ||
| 83 | 86 | ||
| 84 | 87 | def check(data): | |
| 85 | 88 | self.assertEqual(hash_buffer(data), hash(data)) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1 @@ | |||
| 1 | + Add :c:func:`Py_HashBuffer` to the limited C API. Patch by Victor Stinner. | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2773,6 +2773,8 @@ | |||
| 2773 | 2773 | added = '3.15' | |
| 2774 | 2774 | [const.Py_tp_module] | |
| 2775 | 2775 | added = '3.15' | |
| 2776 | + [function.Py_HashBuffer] | ||
| 2777 | + added = '3.16' | ||
| 2776 | 2778 | ||
| 2777 | 2779 | # PEP 757 import/export API. | |
| 2778 | 2780 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -174,7 +174,7 @@ | |||
| 174 | 174 | @MODULE__TESTBUFFER_TRUE@_testbuffer _testbuffer.c | |
| 175 | 175 | @MODULE__TESTINTERNALCAPI_TRUE@_testinternalcapi _testinternalcapi.c _testinternalcapi/test_lock.c _testinternalcapi/pytime.c _testinternalcapi/set.c _testinternalcapi/test_critical_sections.c _testinternalcapi/complex.c _testinternalcapi/interpreter.c _testinternalcapi/tokenizer.c _testinternalcapi/tuple.c _testinternalcapi/typecache.c | |
| 176 | 176 | @MODULE__TESTCAPI_TRUE@_testcapi _testcapimodule.c _testcapi/vectorcall.c _testcapi/heaptype.c _testcapi/abstract.c _testcapi/unicode.c _testcapi/dict.c _testcapi/set.c _testcapi/list.c _testcapi/tuple.c _testcapi/getargs.c _testcapi/datetime.c _testcapi/docstring.c _testcapi/mem.c _testcapi/watchers.c _testcapi/long.c _testcapi/float.c _testcapi/complex.c _testcapi/numbers.c _testcapi/structmember.c _testcapi/exceptions.c _testcapi/code.c _testcapi/buffer.c _testcapi/pyatomic.c _testcapi/run.c _testcapi/file.c _testcapi/codec.c _testcapi/immortal.c _testcapi/gc.c _testcapi/hash.c _testcapi/time.c _testcapi/bytes.c _testcapi/object.c _testcapi/modsupport.c _testcapi/monitoring.c _testcapi/config.c _testcapi/import.c _testcapi/frame.c _testcapi/type.c _testcapi/function.c _testcapi/module.c _testcapi/weakref.c _testcapi/marshal.c | |
| 177 | - @MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/capsule.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/slots.c _testlimitedcapi/sys.c _testlimitedcapi/threadstate.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c _testlimitedcapi/file.c _testlimitedcapi/weakref.c _testlimitedcapi/run.c _testlimitedcapi/type.c | ||
| 177 | + @MODULE__TESTLIMITEDCAPI_TRUE@_testlimitedcapi _testlimitedcapi.c _testlimitedcapi/abstract.c _testlimitedcapi/bytearray.c _testlimitedcapi/bytes.c _testlimitedcapi/capsule.c _testlimitedcapi/codec.c _testlimitedcapi/complex.c _testlimitedcapi/dict.c _testlimitedcapi/eval.c _testlimitedcapi/float.c _testlimitedcapi/heaptype_relative.c _testlimitedcapi/import.c _testlimitedcapi/list.c _testlimitedcapi/long.c _testlimitedcapi/object.c _testlimitedcapi/pyos.c _testlimitedcapi/set.c _testlimitedcapi/slots.c _testlimitedcapi/sys.c _testlimitedcapi/threadstate.c _testlimitedcapi/tuple.c _testlimitedcapi/unicode.c _testlimitedcapi/vectorcall_limited.c _testlimitedcapi/version.c _testlimitedcapi/file.c _testlimitedcapi/weakref.c _testlimitedcapi/run.c _testlimitedcapi/type.c _testlimitedcapi/hash.c | ||
| 178 | 178 | @MODULE__TESTCLINIC_TRUE@_testclinic _testclinic.c | |
| 179 | 179 | @MODULE__TESTCLINIC_LIMITED_TRUE@_testclinic_limited _testclinic_limited.c | |
| 180 | 180 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,20 +66,6 @@ hash_pointer(PyObject *Py_UNUSED(module), PyObject *arg) | |||
| 66 | 66 | } | |
| 67 | 67 | ||
| 68 | 68 | ||
| 69 | - static PyObject * | ||
| 70 | - hash_buffer(PyObject *Py_UNUSED(module), PyObject *args) | ||
| 71 | - { | ||
| 72 | - char *ptr; | ||
| 73 | - Py_ssize_t len; | ||
| 74 | - if (!PyArg_ParseTuple(args, "y#", &ptr, &len)) { | ||
| 75 | - return NULL; | ||
| 76 | - } | ||
| 77 | - | ||
| 78 | - Py_hash_t hash = Py_HashBuffer(ptr, len); | ||
| 79 | - return long_from_hash(hash); | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - | ||
| 83 | 69 | static PyObject * | |
| 84 | 70 | object_generichash(PyObject *Py_UNUSED(module), PyObject *arg) | |
| 85 | 71 | { | |
@@ -92,7 +78,6 @@ object_generichash(PyObject *Py_UNUSED(module), PyObject *arg) | |||
| 92 | 78 | static PyMethodDef test_methods[] = { | |
| 93 | 79 | {"hash_getfuncdef", hash_getfuncdef, METH_NOARGS}, | |
| 94 | 80 | {"hash_pointer", hash_pointer, METH_O}, | |
| 95 | - {"hash_buffer", hash_buffer, METH_VARARGS}, | ||
| 96 | 81 | {"object_generichash", object_generichash, METH_O}, | |
| 97 | 82 | {NULL}, | |
| 98 | 83 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments