diff options
author | Victor Stinner <vstinner@python.org> | 2020-10-26 15:43:47 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-26 15:43:47 (GMT) |
commit | 47e1afd2a1793b5818a16c41307a4ce976331649 (patch) | |
tree | e92f8f10238092c4a9b47d6ef9d3bd6c47bde70e /Modules/unicodedata.c | |
parent | b510e101f8b5b31276bf97b921ca9247162881d2 (diff) | |
download | cpython-47e1afd2a1793b5818a16c41307a4ce976331649.zip cpython-47e1afd2a1793b5818a16c41307a4ce976331649.tar.gz cpython-47e1afd2a1793b5818a16c41307a4ce976331649.tar.bz2 |
bpo-1635741: _PyUnicode_Name_CAPI moves to internal C API (GH-22713)
The private _PyUnicode_Name_CAPI structure of the PyCapsule API
unicodedata.ucnhash_CAPI moves to the internal C API. Moreover, the
structure gets a new state member which must be passed to the
getcode() and getname() functions.
* Move Include/ucnhash.h to Include/internal/pycore_ucnhash.h
* unicodedata module is now built with Py_BUILD_CORE_MODULE.
* unicodedata: move hashAPI variable into unicodedata_module_state.
Diffstat (limited to 'Modules/unicodedata.c')
-rw-r--r-- | Modules/unicodedata.c | 28 |
1 files changed, 15 insertions, 13 deletions
diff --git a/Modules/unicodedata.c b/Modules/unicodedata.c index 941fd2f..bfd8ab5 100644 --- a/Modules/unicodedata.c +++ b/Modules/unicodedata.c @@ -16,7 +16,7 @@ #define PY_SSIZE_T_CLEAN #include "Python.h" -#include "ucnhash.h" +#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI #include "structmember.h" // PyMemberDef #include <stdbool.h> @@ -97,6 +97,8 @@ typedef struct { // Borrowed reference to &UCD_Type. It is used to prepare the code // to convert the UCD_Type static type to a heap type. PyTypeObject *ucd_type; + + _PyUnicode_Name_CAPI capi; } unicodedata_module_state; // bpo-1635741: Temporary global state until the unicodedata module @@ -1180,10 +1182,11 @@ _getucname(unicodedata_module_state *state, PyObject *self, } static int -capi_getucname(PyObject *self, Py_UCS4 code, char* buffer, int buflen, +capi_getucname(void *state_raw, PyObject *self, Py_UCS4 code, + char* buffer, int buflen, int with_alias_and_seq) { - unicodedata_module_state *state = &global_module_state; + unicodedata_module_state *state = (unicodedata_module_state *)state_raw; return _getucname(state, self, code, buffer, buflen, with_alias_and_seq); } @@ -1323,21 +1326,15 @@ _getcode(unicodedata_module_state *state, PyObject* self, } static int -capi_getcode(PyObject* self, const char* name, int namelen, Py_UCS4* code, +capi_getcode(void *state_raw, PyObject* self, + const char* name, int namelen, Py_UCS4* code, int with_named_seq) { - unicodedata_module_state *state = &global_module_state; + unicodedata_module_state *state = (unicodedata_module_state *)state_raw; return _getcode(state, self, name, namelen, code, with_named_seq); } -static const _PyUnicode_Name_CAPI hashAPI = -{ - sizeof(_PyUnicode_Name_CAPI), - capi_getucname, - capi_getcode -}; - /* -------------------------------------------------------------------- */ /* Python bindings */ @@ -1510,6 +1507,11 @@ PyInit_unicodedata(void) PyObject *m, *v; unicodedata_module_state *state = &global_module_state; + state->capi.size = sizeof(_PyUnicode_Name_CAPI); + state->capi.state = state; + state->capi.getname = capi_getucname; + state->capi.getcode = capi_getcode; + Py_SET_TYPE(&UCD_Type, &PyType_Type); state->ucd_type = &UCD_Type; @@ -1528,7 +1530,7 @@ PyInit_unicodedata(void) PyModule_AddObject(m, "ucd_3_2_0", v); /* Export C API */ - v = PyCapsule_New((void *)&hashAPI, PyUnicodeData_CAPSULE_NAME, NULL); + v = PyCapsule_New((void *)&state->capi, PyUnicodeData_CAPSULE_NAME, NULL); if (v != NULL) PyModule_AddObject(m, "ucnhash_CAPI", v); return m; |