aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/codecs.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-04-18 12:39:32 +0300
committershadchin <shadchin@yandex-team.ru>2022-04-18 12:39:32 +0300
commitd4be68e361f4258cf0848fc70018dfe37a2acc24 (patch)
tree153e294cd97ac8b5d7a989612704a0c1f58e8ad4 /contrib/tools/python3/src/Python/codecs.c
parent260c02f5ccf242d9d9b8a873afaf6588c00237d6 (diff)
downloadydb-d4be68e361f4258cf0848fc70018dfe37a2acc24.tar.gz
IGNIETFERRO-1816 Update Python 3 from 3.9.12 to 3.10.4
ref:9f96be6d02ee8044fdd6f124b799b270c20ce641
Diffstat (limited to 'contrib/tools/python3/src/Python/codecs.c')
-rw-r--r--contrib/tools/python3/src/Python/codecs.c65
1 files changed, 33 insertions, 32 deletions
diff --git a/contrib/tools/python3/src/Python/codecs.c b/contrib/tools/python3/src/Python/codecs.c
index 0f18c27e5f..fa329ce243 100644
--- a/contrib/tools/python3/src/Python/codecs.c
+++ b/contrib/tools/python3/src/Python/codecs.c
@@ -11,7 +11,7 @@ Copyright (c) Corporation for National Research Initiatives.
#include "Python.h"
#include "pycore_interp.h" // PyInterpreterState.codec_search_path
#include "pycore_pystate.h" // _PyInterpreterState_GET()
-#include "ucnhash.h"
+#include "pycore_ucnhash.h" // _PyUnicode_Name_CAPI
#include <ctype.h>
const char *Py_hexdigits = "0123456789abcdef";
@@ -50,6 +50,31 @@ int PyCodec_Register(PyObject *search_function)
return -1;
}
+int
+PyCodec_Unregister(PyObject *search_function)
+{
+ PyInterpreterState *interp = PyInterpreterState_Get();
+ PyObject *codec_search_path = interp->codec_search_path;
+ /* Do nothing if codec_search_path is not created yet or was cleared. */
+ if (codec_search_path == NULL) {
+ return 0;
+ }
+
+ assert(PyList_CheckExact(codec_search_path));
+ Py_ssize_t n = PyList_GET_SIZE(codec_search_path);
+ for (Py_ssize_t i = 0; i < n; i++) {
+ PyObject *item = PyList_GET_ITEM(codec_search_path, i);
+ if (item == search_function) {
+ if (interp->codec_search_cache != NULL) {
+ assert(PyDict_CheckExact(interp->codec_search_cache));
+ PyDict_Clear(interp->codec_search_cache);
+ }
+ return PyList_SetSlice(codec_search_path, i, i+1, NULL);
+ }
+ }
+ return 0;
+}
+
extern int _Py_normalize_encoding(const char *, char *, size_t);
/* Convert a string to a normalized Python string(decoded from UTF-8): all characters are
@@ -183,31 +208,6 @@ PyObject *_PyCodec_Lookup(const char *encoding)
return NULL;
}
-int _PyCodec_Forget(const char *encoding)
-{
- PyObject *v;
- int result;
-
- PyInterpreterState *interp = _PyInterpreterState_GET();
- if (interp->codec_search_path == NULL) {
- return -1;
- }
-
- /* Convert the encoding to a normalized Python string: all
- characters are converted to lower case, spaces and hyphens are
- replaced with underscores. */
- v = normalizestring(encoding);
- if (v == NULL) {
- return -1;
- }
-
- /* Drop the named codec from the internal cache */
- result = PyDict_DelItem(interp->codec_search_cache, v);
- Py_DECREF(v);
-
- return result;
-}
-
/* Codec registry encoding check API. */
int PyCodec_KnownEncoding(const char *encoding)
@@ -954,7 +954,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
return Py_BuildValue("(Nn)", res, end);
}
-static _PyUnicode_Name_CAPI *ucnhash_CAPI = NULL;
+static _PyUnicode_Name_CAPI *ucnhash_capi = NULL;
PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
{
@@ -976,17 +976,18 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
return NULL;
if (!(object = PyUnicodeEncodeError_GetObject(exc)))
return NULL;
- if (!ucnhash_CAPI) {
+ if (!ucnhash_capi) {
/* 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)
+ if (!ucnhash_capi) {
return NULL;
+ }
}
for (i = start, ressize = 0; i < end; ++i) {
/* object is guaranteed to be "ready" */
c = PyUnicode_READ_CHAR(object, i);
- if (ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {
+ if (ucnhash_capi->getname(c, buffer, sizeof(buffer), 1)) {
replsize = 1+1+1+(int)strlen(buffer)+1;
}
else if (c >= 0x10000) {
@@ -1009,7 +1010,7 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
i < end; ++i) {
c = PyUnicode_READ_CHAR(object, i);
*outp++ = '\\';
- if (ucnhash_CAPI->getname(NULL, c, buffer, sizeof(buffer), 1)) {
+ if (ucnhash_capi->getname(c, buffer, sizeof(buffer), 1)) {
*outp++ = 'N';
*outp++ = '{';
strcpy((char *)outp, buffer);