summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-10-26 15:43:47 (GMT)
committerGitHub <noreply@github.com>2020-10-26 15:43:47 (GMT)
commit47e1afd2a1793b5818a16c41307a4ce976331649 (patch)
treee92f8f10238092c4a9b47d6ef9d3bd6c47bde70e /Objects
parentb510e101f8b5b31276bf97b921ca9247162881d2 (diff)
downloadcpython-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 'Objects')
-rw-r--r--Objects/unicodeobject.c31
1 files changed, 16 insertions, 15 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index f963deb..ba48d35 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -40,16 +40,16 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define PY_SSIZE_T_CLEAN
#include "Python.h"
-#include "pycore_abstract.h" // _PyIndex_Check()
-#include "pycore_bytes_methods.h" // _Py_bytes_lower()
-#include "pycore_initconfig.h" // _PyStatus_OK()
-#include "pycore_interp.h" // PyInterpreterState.fs_codec
-#include "pycore_object.h" // _PyObject_GC_TRACK()
-#include "pycore_pathconfig.h" // _Py_DumpPathConfig()
-#include "pycore_pylifecycle.h" // _Py_SetFileSystemEncoding()
-#include "pycore_pystate.h" // _PyInterpreterState_GET()
-#include "ucnhash.h" // _PyUnicode_Name_CAPI
-#include "stringlib/eq.h" // unicode_eq()
+#include "pycore_abstract.h" // _PyIndex_Check()
+#include "pycore_bytes_methods.h" // _Py_bytes_lower()
+#include "pycore_initconfig.h" // _PyStatus_OK()
+#include "pycore_interp.h" // PyInterpreterState.fs_codec
+#include "pycore_object.h" // _PyObject_GC_TRACK()
+#include "pycore_pathconfig.h" // _Py_DumpPathConfig()
+#include "pycore_pylifecycle.h" // _Py_SetFileSystemEncoding()
+#include "pycore_pystate.h" // _PyInterpreterState_GET()
+#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
+#include "stringlib/eq.h" // unicode_eq()
#ifdef MS_WINDOWS
#include <windows.h>
@@ -6344,7 +6344,7 @@ PyUnicode_AsUTF16String(PyObject *unicode)
/* --- Unicode Escape Codec ----------------------------------------------- */
-static _PyUnicode_Name_CAPI *ucnhash_CAPI = NULL;
+static _PyUnicode_Name_CAPI *ucnhash_capi = NULL;
PyObject *
_PyUnicode_DecodeUnicodeEscape(const char *s,
@@ -6497,11 +6497,11 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
/* \N{name} */
case 'N':
- if (ucnhash_CAPI == NULL) {
+ if (ucnhash_capi == NULL) {
/* load the unicode data module */
- ucnhash_CAPI = (_PyUnicode_Name_CAPI *)PyCapsule_Import(
+ ucnhash_capi = (_PyUnicode_Name_CAPI *)PyCapsule_Import(
PyUnicodeData_CAPSULE_NAME, 1);
- if (ucnhash_CAPI == NULL) {
+ if (ucnhash_capi == NULL) {
PyErr_SetString(
PyExc_UnicodeError,
"\\N escapes not supported (can't load unicodedata module)"
@@ -6523,7 +6523,8 @@ _PyUnicode_DecodeUnicodeEscape(const char *s,
s++;
ch = 0xffffffff; /* in case 'getcode' messes up */
if (namelen <= INT_MAX &&
- ucnhash_CAPI->getcode(NULL, start, (int)namelen,
+ ucnhash_capi->getcode(ucnhash_capi->state, NULL,
+ start, (int)namelen,
&ch, 0)) {
assert(ch <= MAX_UNICODE);
WRITE_CHAR(ch);