aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Python/codecs.c
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.ru>2022-02-10 16:44:39 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:44:39 +0300
commite9656aae26e0358d5378e5b63dcac5c8dbe0e4d0 (patch)
tree64175d5cadab313b3e7039ebaa06c5bc3295e274 /contrib/tools/python3/src/Python/codecs.c
parent2598ef1d0aee359b4b6d5fdd1758916d5907d04f (diff)
downloadydb-e9656aae26e0358d5378e5b63dcac5c8dbe0e4d0.tar.gz
Restoring authorship annotation for <shadchin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'contrib/tools/python3/src/Python/codecs.c')
-rw-r--r--contrib/tools/python3/src/Python/codecs.c172
1 files changed, 86 insertions, 86 deletions
diff --git a/contrib/tools/python3/src/Python/codecs.c b/contrib/tools/python3/src/Python/codecs.c
index 1970cb6180..0f18c27e5f 100644
--- a/contrib/tools/python3/src/Python/codecs.c
+++ b/contrib/tools/python3/src/Python/codecs.c
@@ -9,8 +9,8 @@ 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 "pycore_interp.h" // PyInterpreterState.codec_search_path
+#include "pycore_pystate.h" // _PyInterpreterState_GET()
#include "ucnhash.h"
#include <ctype.h>
@@ -33,7 +33,7 @@ static int _PyCodecRegistry_Init(void); /* Forward */
int PyCodec_Register(PyObject *search_function)
{
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
goto onError;
if (search_function == NULL) {
@@ -50,16 +50,16 @@ int PyCodec_Register(PyObject *search_function)
return -1;
}
-extern int _Py_normalize_encoding(const char *, char *, size_t);
+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
+ converted to lower case, spaces and hyphens are replaced with underscores. */
-/* Convert a string to a normalized Python string(decoded from UTF-8): all characters are
- converted to lower case, spaces and hyphens are replaced with underscores. */
-
static
PyObject *normalizestring(const char *string)
{
size_t len = strlen(string);
- char *encoding;
+ char *encoding;
PyObject *v;
if (len > PY_SSIZE_T_MAX) {
@@ -67,19 +67,19 @@ PyObject *normalizestring(const char *string)
return NULL;
}
- encoding = PyMem_Malloc(len + 1);
- if (encoding == NULL)
+ encoding = PyMem_Malloc(len + 1);
+ if (encoding == NULL)
return PyErr_NoMemory();
-
- if (!_Py_normalize_encoding(string, encoding, len + 1))
- {
- PyErr_SetString(PyExc_RuntimeError, "_Py_normalize_encoding() failed");
- PyMem_Free(encoding);
- return NULL;
+
+ if (!_Py_normalize_encoding(string, encoding, len + 1))
+ {
+ PyErr_SetString(PyExc_RuntimeError, "_Py_normalize_encoding() failed");
+ PyMem_Free(encoding);
+ return NULL;
}
-
- v = PyUnicode_FromString(encoding);
- PyMem_Free(encoding);
+
+ v = PyUnicode_FromString(encoding);
+ PyMem_Free(encoding);
return v;
}
@@ -102,36 +102,36 @@ PyObject *_PyCodec_Lookup(const char *encoding)
{
if (encoding == NULL) {
PyErr_BadArgument();
- return NULL;
+ return NULL;
}
- PyInterpreterState *interp = _PyInterpreterState_GET();
- if (interp->codec_search_path == NULL && _PyCodecRegistry_Init()) {
- return NULL;
- }
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ if (interp->codec_search_path == NULL && _PyCodecRegistry_Init()) {
+ return NULL;
+ }
/* Convert the encoding to a normalized Python string: all
characters are converted to lower case, spaces and hyphens are
replaced with underscores. */
- PyObject *v = normalizestring(encoding);
- if (v == NULL) {
- return NULL;
- }
+ PyObject *v = normalizestring(encoding);
+ if (v == NULL) {
+ return NULL;
+ }
PyUnicode_InternInPlace(&v);
/* First, try to lookup the name in the registry dictionary */
- PyObject *result = PyDict_GetItemWithError(interp->codec_search_cache, v);
+ PyObject *result = PyDict_GetItemWithError(interp->codec_search_cache, v);
if (result != NULL) {
Py_INCREF(result);
Py_DECREF(v);
return result;
}
- else if (PyErr_Occurred()) {
- goto onError;
- }
+ else if (PyErr_Occurred()) {
+ goto onError;
+ }
/* Next, scan the search functions in order of registration */
- const Py_ssize_t len = PyList_Size(interp->codec_search_path);
+ const Py_ssize_t len = PyList_Size(interp->codec_search_path);
if (len < 0)
goto onError;
if (len == 0) {
@@ -141,14 +141,14 @@ PyObject *_PyCodec_Lookup(const char *encoding)
goto onError;
}
- Py_ssize_t i;
+ Py_ssize_t i;
for (i = 0; i < len; i++) {
PyObject *func;
func = PyList_GetItem(interp->codec_search_path, i);
if (func == NULL)
goto onError;
- result = PyObject_CallOneArg(func, v);
+ result = PyObject_CallOneArg(func, v);
if (result == NULL)
goto onError;
if (result == Py_None) {
@@ -175,11 +175,11 @@ PyObject *_PyCodec_Lookup(const char *encoding)
Py_DECREF(result);
goto onError;
}
- Py_DECREF(v);
+ Py_DECREF(v);
return result;
onError:
- Py_DECREF(v);
+ Py_DECREF(v);
return NULL;
}
@@ -188,7 +188,7 @@ int _PyCodec_Forget(const char *encoding)
PyObject *v;
int result;
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->codec_search_path == NULL) {
return -1;
}
@@ -318,7 +318,7 @@ PyObject *codec_getstreamcodec(const char *encoding,
if (errors != NULL)
streamcodec = PyObject_CallFunction(codeccls, "Os", stream, errors);
else
- streamcodec = PyObject_CallOneArg(codeccls, stream);
+ streamcodec = PyObject_CallOneArg(codeccls, stream);
Py_DECREF(codecs);
return streamcodec;
}
@@ -417,7 +417,7 @@ _PyCodec_EncodeInternal(PyObject *object,
if (args == NULL)
goto onError;
- result = PyObject_Call(encoder, args, NULL);
+ result = PyObject_Call(encoder, args, NULL);
if (result == NULL) {
wrap_codec_error("encoding", encoding);
goto onError;
@@ -463,7 +463,7 @@ _PyCodec_DecodeInternal(PyObject *object,
if (args == NULL)
goto onError;
- result = PyObject_Call(decoder, args, NULL);
+ result = PyObject_Call(decoder, args, NULL);
if (result == NULL) {
wrap_codec_error("decoding", encoding);
goto onError;
@@ -621,7 +621,7 @@ PyObject *_PyCodec_DecodeText(PyObject *object,
Return 0 on success, -1 on error */
int PyCodec_RegisterError(const char *name, PyObject *error)
{
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
return -1;
if (!PyCallable_Check(error)) {
@@ -639,19 +639,19 @@ PyObject *PyCodec_LookupError(const char *name)
{
PyObject *handler = NULL;
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyInterpreterState *interp = _PyInterpreterState_GET();
if (interp->codec_search_path == NULL && _PyCodecRegistry_Init())
return NULL;
if (name==NULL)
name = "strict";
- handler = _PyDict_GetItemStringWithError(interp->codec_error_registry, name);
- if (handler) {
- Py_INCREF(handler);
- }
- else if (!PyErr_Occurred()) {
+ handler = _PyDict_GetItemStringWithError(interp->codec_error_registry, name);
+ if (handler) {
+ Py_INCREF(handler);
+ }
+ else if (!PyErr_Occurred()) {
PyErr_Format(PyExc_LookupError, "unknown error handler name '%.400s'", name);
- }
+ }
return handler;
}
@@ -659,7 +659,7 @@ static void wrong_exception_type(PyObject *exc)
{
PyErr_Format(PyExc_TypeError,
"don't know how to handle %.200s in error callback",
- Py_TYPE(exc)->tp_name);
+ Py_TYPE(exc)->tp_name);
}
PyObject *PyCodec_StrictErrors(PyObject *exc)
@@ -702,7 +702,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeEncodeError)) {
PyObject *res;
- Py_UCS1 *outp;
+ Py_UCS1 *outp;
if (PyUnicodeEncodeError_GetStart(exc, &start))
return NULL;
if (PyUnicodeEncodeError_GetEnd(exc, &end))
@@ -711,10 +711,10 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
res = PyUnicode_New(len, '?');
if (res == NULL)
return NULL;
- assert(PyUnicode_KIND(res) == PyUnicode_1BYTE_KIND);
- outp = PyUnicode_1BYTE_DATA(res);
+ assert(PyUnicode_KIND(res) == PyUnicode_1BYTE_KIND);
+ outp = PyUnicode_1BYTE_DATA(res);
for (i = 0; i < len; ++i)
- outp[i] = '?';
+ outp[i] = '?';
assert(_PyUnicode_CheckConsistency(res, 1));
return Py_BuildValue("(Nn)", res, end);
}
@@ -727,7 +727,7 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
}
else if (PyObject_TypeCheck(exc, (PyTypeObject *)PyExc_UnicodeTranslateError)) {
PyObject *res;
- Py_UCS2 *outp;
+ Py_UCS2 *outp;
if (PyUnicodeTranslateError_GetStart(exc, &start))
return NULL;
if (PyUnicodeTranslateError_GetEnd(exc, &end))
@@ -736,10 +736,10 @@ PyObject *PyCodec_ReplaceErrors(PyObject *exc)
res = PyUnicode_New(len, Py_UNICODE_REPLACEMENT_CHARACTER);
if (res == NULL)
return NULL;
- assert(PyUnicode_KIND(res) == PyUnicode_2BYTE_KIND);
- outp = PyUnicode_2BYTE_DATA(res);
- for (i = 0; i < len; i++)
- outp[i] = Py_UNICODE_REPLACEMENT_CHARACTER;
+ assert(PyUnicode_KIND(res) == PyUnicode_2BYTE_KIND);
+ outp = PyUnicode_2BYTE_DATA(res);
+ for (i = 0; i < len; i++)
+ outp[i] = Py_UNICODE_REPLACEMENT_CHARACTER;
assert(_PyUnicode_CheckConsistency(res, 1));
return Py_BuildValue("(Nn)", res, end);
}
@@ -758,7 +758,7 @@ PyObject *PyCodec_XMLCharRefReplaceErrors(PyObject *exc)
Py_ssize_t start;
Py_ssize_t end;
PyObject *res;
- Py_UCS1 *outp;
+ Py_UCS1 *outp;
Py_ssize_t ressize;
Py_UCS4 ch;
if (PyUnicodeEncodeError_GetStart(exc, &start))
@@ -854,7 +854,7 @@ PyObject *PyCodec_BackslashReplaceErrors(PyObject *exc)
Py_ssize_t start;
Py_ssize_t end;
PyObject *res;
- Py_UCS1 *outp;
+ Py_UCS1 *outp;
int ressize;
Py_UCS4 c;
@@ -965,7 +965,7 @@ PyObject *PyCodec_NameReplaceErrors(PyObject *exc)
Py_ssize_t start;
Py_ssize_t end;
PyObject *res;
- Py_UCS1 *outp;
+ Py_UCS1 *outp;
Py_ssize_t ressize;
int replsize;
Py_UCS4 c;
@@ -1406,7 +1406,7 @@ static PyObject *surrogateescape_errors(PyObject *self, PyObject *exc)
static int _PyCodecRegistry_Init(void)
{
static struct {
- const char *name;
+ const char *name;
PyMethodDef def;
} methods[] =
{
@@ -1491,38 +1491,38 @@ static int _PyCodecRegistry_Init(void)
}
};
- PyInterpreterState *interp = _PyInterpreterState_GET();
+ PyInterpreterState *interp = _PyInterpreterState_GET();
PyObject *mod;
if (interp->codec_search_path != NULL)
return 0;
interp->codec_search_path = PyList_New(0);
- if (interp->codec_search_path == NULL) {
- return -1;
- }
-
+ if (interp->codec_search_path == NULL) {
+ return -1;
+ }
+
interp->codec_search_cache = PyDict_New();
- if (interp->codec_search_cache == NULL) {
- return -1;
- }
-
+ if (interp->codec_search_cache == NULL) {
+ return -1;
+ }
+
interp->codec_error_registry = PyDict_New();
- if (interp->codec_error_registry == NULL) {
- return -1;
- }
-
- for (size_t i = 0; i < Py_ARRAY_LENGTH(methods); ++i) {
- PyObject *func = PyCFunction_NewEx(&methods[i].def, NULL, NULL);
- if (!func) {
- return -1;
+ if (interp->codec_error_registry == NULL) {
+ return -1;
+ }
+
+ for (size_t i = 0; i < Py_ARRAY_LENGTH(methods); ++i) {
+ PyObject *func = PyCFunction_NewEx(&methods[i].def, NULL, NULL);
+ if (!func) {
+ return -1;
+ }
+
+ int res = PyCodec_RegisterError(methods[i].name, func);
+ Py_DECREF(func);
+ if (res) {
+ return -1;
}
-
- int res = PyCodec_RegisterError(methods[i].name, func);
- Py_DECREF(func);
- if (res) {
- return -1;
- }
}
mod = PyImport_ImportModuleNoBlock("encodings");