aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Modules/cjkcodecs/multibytecodec.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/Modules/cjkcodecs/multibytecodec.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/Modules/cjkcodecs/multibytecodec.c')
-rw-r--r--contrib/tools/python3/src/Modules/cjkcodecs/multibytecodec.c394
1 files changed, 197 insertions, 197 deletions
diff --git a/contrib/tools/python3/src/Modules/cjkcodecs/multibytecodec.c b/contrib/tools/python3/src/Modules/cjkcodecs/multibytecodec.c
index b586836422..86402768b6 100644
--- a/contrib/tools/python3/src/Modules/cjkcodecs/multibytecodec.c
+++ b/contrib/tools/python3/src/Modules/cjkcodecs/multibytecodec.c
@@ -6,7 +6,7 @@
#define PY_SSIZE_T_CLEAN
#include "Python.h"
-#include "structmember.h" // PyMemberDef
+#include "structmember.h" // PyMemberDef
#include "multibytecodec.h"
#include "clinic/multibytecodec.c.h"
@@ -81,7 +81,7 @@ internal_error_callback(const char *errors)
static PyObject *
call_error_callback(PyObject *errors, PyObject *exc)
{
- PyObject *cb, *r;
+ PyObject *cb, *r;
const char *str;
assert(PyUnicode_Check(errors));
@@ -92,7 +92,7 @@ call_error_callback(PyObject *errors, PyObject *exc)
if (cb == NULL)
return NULL;
- r = PyObject_CallOneArg(cb, exc);
+ r = PyObject_CallOneArg(cb, exc);
Py_DECREF(cb);
return r;
}
@@ -228,7 +228,7 @@ multibytecodec_encerror(MultibyteCodec *codec,
Py_ssize_t r;
Py_ssize_t inpos;
int kind;
- const void *data;
+ const void *data;
replchar = PyUnicode_FromOrdinal('?');
if (replchar == NULL)
@@ -457,7 +457,7 @@ multibytecodec_encode(MultibyteCodec *codec,
Py_ssize_t finalsize, r = 0;
Py_ssize_t datalen;
int kind;
- const void *data;
+ const void *data;
if (PyUnicode_READY(text) < 0)
return NULL;
@@ -538,7 +538,7 @@ errorexit:
_multibytecodec.MultibyteCodec.encode
input: object
- errors: str(accept={str, NoneType}) = None
+ errors: str(accept={str, NoneType}) = None
Return an encoded string version of `input'.
@@ -552,7 +552,7 @@ static PyObject *
_multibytecodec_MultibyteCodec_encode_impl(MultibyteCodecObject *self,
PyObject *input,
const char *errors)
-/*[clinic end generated code: output=7b26652045ba56a9 input=606d0e128a577bae]*/
+/*[clinic end generated code: output=7b26652045ba56a9 input=606d0e128a577bae]*/
{
MultibyteCodec_State state;
PyObject *errorcb, *r, *ucvt;
@@ -607,7 +607,7 @@ errorexit:
_multibytecodec.MultibyteCodec.decode
input: Py_buffer
- errors: str(accept={str, NoneType}) = None
+ errors: str(accept={str, NoneType}) = None
Decodes 'input'.
@@ -621,7 +621,7 @@ static PyObject *
_multibytecodec_MultibyteCodec_decode_impl(MultibyteCodecObject *self,
Py_buffer *input,
const char *errors)
-/*[clinic end generated code: output=ff419f65bad6cc77 input=e0c78fc7ab190def]*/
+/*[clinic end generated code: output=ff419f65bad6cc77 input=e0c78fc7ab190def]*/
{
MultibyteCodec_State state;
MultibyteDecodeBuffer buf;
@@ -701,10 +701,10 @@ static PyTypeObject MultibyteCodec_Type = {
0, /* tp_itemsize */
/* methods */
(destructor)multibytecodec_dealloc, /* tp_dealloc */
- 0, /* tp_vectorcall_offset */
+ 0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_as_async */
+ 0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -890,93 +890,93 @@ _multibytecodec_MultibyteIncrementalEncoder_encode_impl(MultibyteIncrementalEnco
}
/*[clinic input]
-_multibytecodec.MultibyteIncrementalEncoder.getstate
-[clinic start generated code]*/
-
-static PyObject *
-_multibytecodec_MultibyteIncrementalEncoder_getstate_impl(MultibyteIncrementalEncoderObject *self)
-/*[clinic end generated code: output=9794a5ace70d7048 input=4a2a82874ffa40bb]*/
-{
- /* state made up of 1 byte for buffer size, up to MAXENCPENDING*4 bytes
- for UTF-8 encoded buffer (each character can use up to 4
- bytes), and required bytes for MultibyteCodec_State.c. A byte
- array is used to avoid different compilers generating different
- values for the same state, e.g. as a result of struct padding.
- */
- unsigned char statebytes[1 + MAXENCPENDING*4 + sizeof(self->state.c)];
- Py_ssize_t statesize;
- const char *pendingbuffer = NULL;
- Py_ssize_t pendingsize;
-
- if (self->pending != NULL) {
- pendingbuffer = PyUnicode_AsUTF8AndSize(self->pending, &pendingsize);
- if (pendingbuffer == NULL) {
- return NULL;
- }
- if (pendingsize > MAXENCPENDING*4) {
- PyErr_SetString(PyExc_UnicodeError, "pending buffer too large");
- return NULL;
- }
- statebytes[0] = (unsigned char)pendingsize;
- memcpy(statebytes + 1, pendingbuffer, pendingsize);
- statesize = 1 + pendingsize;
- } else {
- statebytes[0] = 0;
- statesize = 1;
- }
- memcpy(statebytes+statesize, self->state.c,
- sizeof(self->state.c));
- statesize += sizeof(self->state.c);
-
- return (PyObject *)_PyLong_FromByteArray(statebytes, statesize,
- 1 /* little-endian */ ,
- 0 /* unsigned */ );
-}
-
-/*[clinic input]
-_multibytecodec.MultibyteIncrementalEncoder.setstate
- state as statelong: object(type='PyLongObject *', subclass_of='&PyLong_Type')
- /
-[clinic start generated code]*/
-
-static PyObject *
-_multibytecodec_MultibyteIncrementalEncoder_setstate_impl(MultibyteIncrementalEncoderObject *self,
- PyLongObject *statelong)
-/*[clinic end generated code: output=4e5e98ac1f4039ca input=c80fb5830d4d2f76]*/
-{
- PyObject *pending = NULL;
- unsigned char statebytes[1 + MAXENCPENDING*4 + sizeof(self->state.c)];
-
- if (_PyLong_AsByteArray(statelong, statebytes, sizeof(statebytes),
- 1 /* little-endian */ ,
- 0 /* unsigned */ ) < 0) {
- goto errorexit;
- }
-
- if (statebytes[0] > MAXENCPENDING*4) {
- PyErr_SetString(PyExc_UnicodeError, "pending buffer too large");
- return NULL;
- }
-
- pending = PyUnicode_DecodeUTF8((const char *)statebytes+1,
- statebytes[0], "strict");
- if (pending == NULL) {
- goto errorexit;
- }
-
- Py_CLEAR(self->pending);
- self->pending = pending;
- memcpy(self->state.c, statebytes+1+statebytes[0],
- sizeof(self->state.c));
-
- Py_RETURN_NONE;
-
-errorexit:
- Py_XDECREF(pending);
- return NULL;
-}
-
-/*[clinic input]
+_multibytecodec.MultibyteIncrementalEncoder.getstate
+[clinic start generated code]*/
+
+static PyObject *
+_multibytecodec_MultibyteIncrementalEncoder_getstate_impl(MultibyteIncrementalEncoderObject *self)
+/*[clinic end generated code: output=9794a5ace70d7048 input=4a2a82874ffa40bb]*/
+{
+ /* state made up of 1 byte for buffer size, up to MAXENCPENDING*4 bytes
+ for UTF-8 encoded buffer (each character can use up to 4
+ bytes), and required bytes for MultibyteCodec_State.c. A byte
+ array is used to avoid different compilers generating different
+ values for the same state, e.g. as a result of struct padding.
+ */
+ unsigned char statebytes[1 + MAXENCPENDING*4 + sizeof(self->state.c)];
+ Py_ssize_t statesize;
+ const char *pendingbuffer = NULL;
+ Py_ssize_t pendingsize;
+
+ if (self->pending != NULL) {
+ pendingbuffer = PyUnicode_AsUTF8AndSize(self->pending, &pendingsize);
+ if (pendingbuffer == NULL) {
+ return NULL;
+ }
+ if (pendingsize > MAXENCPENDING*4) {
+ PyErr_SetString(PyExc_UnicodeError, "pending buffer too large");
+ return NULL;
+ }
+ statebytes[0] = (unsigned char)pendingsize;
+ memcpy(statebytes + 1, pendingbuffer, pendingsize);
+ statesize = 1 + pendingsize;
+ } else {
+ statebytes[0] = 0;
+ statesize = 1;
+ }
+ memcpy(statebytes+statesize, self->state.c,
+ sizeof(self->state.c));
+ statesize += sizeof(self->state.c);
+
+ return (PyObject *)_PyLong_FromByteArray(statebytes, statesize,
+ 1 /* little-endian */ ,
+ 0 /* unsigned */ );
+}
+
+/*[clinic input]
+_multibytecodec.MultibyteIncrementalEncoder.setstate
+ state as statelong: object(type='PyLongObject *', subclass_of='&PyLong_Type')
+ /
+[clinic start generated code]*/
+
+static PyObject *
+_multibytecodec_MultibyteIncrementalEncoder_setstate_impl(MultibyteIncrementalEncoderObject *self,
+ PyLongObject *statelong)
+/*[clinic end generated code: output=4e5e98ac1f4039ca input=c80fb5830d4d2f76]*/
+{
+ PyObject *pending = NULL;
+ unsigned char statebytes[1 + MAXENCPENDING*4 + sizeof(self->state.c)];
+
+ if (_PyLong_AsByteArray(statelong, statebytes, sizeof(statebytes),
+ 1 /* little-endian */ ,
+ 0 /* unsigned */ ) < 0) {
+ goto errorexit;
+ }
+
+ if (statebytes[0] > MAXENCPENDING*4) {
+ PyErr_SetString(PyExc_UnicodeError, "pending buffer too large");
+ return NULL;
+ }
+
+ pending = PyUnicode_DecodeUTF8((const char *)statebytes+1,
+ statebytes[0], "strict");
+ if (pending == NULL) {
+ goto errorexit;
+ }
+
+ Py_CLEAR(self->pending);
+ self->pending = pending;
+ memcpy(self->state.c, statebytes+1+statebytes[0],
+ sizeof(self->state.c));
+
+ Py_RETURN_NONE;
+
+errorexit:
+ Py_XDECREF(pending);
+ return NULL;
+}
+
+/*[clinic input]
_multibytecodec.MultibyteIncrementalEncoder.reset
[clinic start generated code]*/
@@ -1000,8 +1000,8 @@ _multibytecodec_MultibyteIncrementalEncoder_reset_impl(MultibyteIncrementalEncod
static struct PyMethodDef mbiencoder_methods[] = {
_MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_ENCODE_METHODDEF
- _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_GETSTATE_METHODDEF
- _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_SETSTATE_METHODDEF
+ _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_GETSTATE_METHODDEF
+ _MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_SETSTATE_METHODDEF
_MULTIBYTECODEC_MULTIBYTEINCREMENTALENCODER_RESET_METHODDEF
{NULL, NULL},
};
@@ -1067,7 +1067,7 @@ mbiencoder_dealloc(MultibyteIncrementalEncoderObject *self)
{
PyObject_GC_UnTrack(self);
ERROR_DECREF(self->errors);
- Py_CLEAR(self->pending);
+ Py_CLEAR(self->pending);
Py_TYPE(self)->tp_free(self);
}
@@ -1078,10 +1078,10 @@ static PyTypeObject MultibyteIncrementalEncoder_Type = {
0, /* tp_itemsize */
/* methods */
(destructor)mbiencoder_dealloc, /* tp_dealloc */
- 0, /* tp_vectorcall_offset */
+ 0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_as_async */
+ 0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -1204,85 +1204,85 @@ errorexit:
}
/*[clinic input]
-_multibytecodec.MultibyteIncrementalDecoder.getstate
-[clinic start generated code]*/
-
-static PyObject *
-_multibytecodec_MultibyteIncrementalDecoder_getstate_impl(MultibyteIncrementalDecoderObject *self)
-/*[clinic end generated code: output=255009c4713b7f82 input=4006aa49bddbaa75]*/
-{
- PyObject *buffer;
- PyObject *statelong;
-
- buffer = PyBytes_FromStringAndSize((const char *)self->pending,
- self->pendingsize);
- if (buffer == NULL) {
- return NULL;
- }
-
- statelong = (PyObject *)_PyLong_FromByteArray(self->state.c,
- sizeof(self->state.c),
- 1 /* little-endian */ ,
- 0 /* unsigned */ );
- if (statelong == NULL) {
- Py_DECREF(buffer);
- return NULL;
- }
-
- return Py_BuildValue("NN", buffer, statelong);
-}
-
-/*[clinic input]
-_multibytecodec.MultibyteIncrementalDecoder.setstate
- state: object(subclass_of='&PyTuple_Type')
- /
-[clinic start generated code]*/
-
-static PyObject *
-_multibytecodec_MultibyteIncrementalDecoder_setstate_impl(MultibyteIncrementalDecoderObject *self,
- PyObject *state)
-/*[clinic end generated code: output=106b2fbca3e2dcc2 input=e5d794e8baba1a47]*/
-{
- PyObject *buffer;
- PyLongObject *statelong;
- Py_ssize_t buffersize;
- const char *bufferstr;
- unsigned char statebytes[8];
-
- if (!PyArg_ParseTuple(state, "SO!;setstate(): illegal state argument",
- &buffer, &PyLong_Type, &statelong))
- {
- return NULL;
- }
-
- if (_PyLong_AsByteArray(statelong, statebytes, sizeof(statebytes),
- 1 /* little-endian */ ,
- 0 /* unsigned */ ) < 0) {
- return NULL;
- }
-
- buffersize = PyBytes_Size(buffer);
- if (buffersize == -1) {
- return NULL;
- }
-
- if (buffersize > MAXDECPENDING) {
- PyErr_SetString(PyExc_UnicodeError, "pending buffer too large");
- return NULL;
- }
-
- bufferstr = PyBytes_AsString(buffer);
- if (bufferstr == NULL) {
- return NULL;
- }
- self->pendingsize = buffersize;
- memcpy(self->pending, bufferstr, self->pendingsize);
- memcpy(self->state.c, statebytes, sizeof(statebytes));
-
- Py_RETURN_NONE;
-}
-
-/*[clinic input]
+_multibytecodec.MultibyteIncrementalDecoder.getstate
+[clinic start generated code]*/
+
+static PyObject *
+_multibytecodec_MultibyteIncrementalDecoder_getstate_impl(MultibyteIncrementalDecoderObject *self)
+/*[clinic end generated code: output=255009c4713b7f82 input=4006aa49bddbaa75]*/
+{
+ PyObject *buffer;
+ PyObject *statelong;
+
+ buffer = PyBytes_FromStringAndSize((const char *)self->pending,
+ self->pendingsize);
+ if (buffer == NULL) {
+ return NULL;
+ }
+
+ statelong = (PyObject *)_PyLong_FromByteArray(self->state.c,
+ sizeof(self->state.c),
+ 1 /* little-endian */ ,
+ 0 /* unsigned */ );
+ if (statelong == NULL) {
+ Py_DECREF(buffer);
+ return NULL;
+ }
+
+ return Py_BuildValue("NN", buffer, statelong);
+}
+
+/*[clinic input]
+_multibytecodec.MultibyteIncrementalDecoder.setstate
+ state: object(subclass_of='&PyTuple_Type')
+ /
+[clinic start generated code]*/
+
+static PyObject *
+_multibytecodec_MultibyteIncrementalDecoder_setstate_impl(MultibyteIncrementalDecoderObject *self,
+ PyObject *state)
+/*[clinic end generated code: output=106b2fbca3e2dcc2 input=e5d794e8baba1a47]*/
+{
+ PyObject *buffer;
+ PyLongObject *statelong;
+ Py_ssize_t buffersize;
+ const char *bufferstr;
+ unsigned char statebytes[8];
+
+ if (!PyArg_ParseTuple(state, "SO!;setstate(): illegal state argument",
+ &buffer, &PyLong_Type, &statelong))
+ {
+ return NULL;
+ }
+
+ if (_PyLong_AsByteArray(statelong, statebytes, sizeof(statebytes),
+ 1 /* little-endian */ ,
+ 0 /* unsigned */ ) < 0) {
+ return NULL;
+ }
+
+ buffersize = PyBytes_Size(buffer);
+ if (buffersize == -1) {
+ return NULL;
+ }
+
+ if (buffersize > MAXDECPENDING) {
+ PyErr_SetString(PyExc_UnicodeError, "pending buffer too large");
+ return NULL;
+ }
+
+ bufferstr = PyBytes_AsString(buffer);
+ if (bufferstr == NULL) {
+ return NULL;
+ }
+ self->pendingsize = buffersize;
+ memcpy(self->pending, bufferstr, self->pendingsize);
+ memcpy(self->state.c, statebytes, sizeof(statebytes));
+
+ Py_RETURN_NONE;
+}
+
+/*[clinic input]
_multibytecodec.MultibyteIncrementalDecoder.reset
[clinic start generated code]*/
@@ -1300,8 +1300,8 @@ _multibytecodec_MultibyteIncrementalDecoder_reset_impl(MultibyteIncrementalDecod
static struct PyMethodDef mbidecoder_methods[] = {
_MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_DECODE_METHODDEF
- _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_GETSTATE_METHODDEF
- _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_SETSTATE_METHODDEF
+ _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_GETSTATE_METHODDEF
+ _MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_SETSTATE_METHODDEF
_MULTIBYTECODEC_MULTIBYTEINCREMENTALDECODER_RESET_METHODDEF
{NULL, NULL},
};
@@ -1377,10 +1377,10 @@ static PyTypeObject MultibyteIncrementalDecoder_Type = {
0, /* tp_itemsize */
/* methods */
(destructor)mbidecoder_dealloc, /* tp_dealloc */
- 0, /* tp_vectorcall_offset */
+ 0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_as_async */
+ 0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -1450,7 +1450,7 @@ mbstreamreader_iread(MultibyteStreamReaderObject *self,
PyErr_Format(PyExc_TypeError,
"stream function returned a "
"non-bytes object (%.100s)",
- Py_TYPE(cres)->tp_name);
+ Py_TYPE(cres)->tp_name);
goto errorexit;
}
@@ -1724,10 +1724,10 @@ static PyTypeObject MultibyteStreamReader_Type = {
0, /* tp_itemsize */
/* methods */
(destructor)mbstreamreader_dealloc, /* tp_dealloc */
- 0, /* tp_vectorcall_offset */
+ 0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_as_async */
+ 0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -1776,7 +1776,7 @@ mbstreamwriter_iwrite(MultibyteStreamWriterObject *self,
if (str == NULL)
return -1;
- wr = _PyObject_CallMethodIdOneArg(self->stream, &PyId_write, str);
+ wr = _PyObject_CallMethodIdOneArg(self->stream, &PyId_write, str);
Py_DECREF(str);
if (wr == NULL)
return -1;
@@ -1870,7 +1870,7 @@ _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *se
if (PyBytes_Size(pwrt) > 0) {
PyObject *wr;
- wr = _PyObject_CallMethodIdOneArg(self->stream, &PyId_write, pwrt);
+ wr = _PyObject_CallMethodIdOneArg(self->stream, &PyId_write, pwrt);
if (wr == NULL) {
Py_DECREF(pwrt);
return NULL;
@@ -1970,10 +1970,10 @@ static PyTypeObject MultibyteStreamWriter_Type = {
0, /* tp_itemsize */
/* methods */
(destructor)mbstreamwriter_dealloc, /* tp_dealloc */
- 0, /* tp_vectorcall_offset */
+ 0, /* tp_vectorcall_offset */
0, /* tp_getattr */
0, /* tp_setattr */
- 0, /* tp_as_async */
+ 0, /* tp_as_async */
0, /* tp_repr */
0, /* tp_as_number */
0, /* tp_as_sequence */
@@ -2064,7 +2064,7 @@ PyInit__multibytecodec(void)
&MultibyteIncrementalEncoder_Type,
&MultibyteIncrementalDecoder_Type,
&MultibyteStreamReader_Type,
- &MultibyteStreamWriter_Type
+ &MultibyteStreamWriter_Type
};
if (PyType_Ready(&MultibyteCodec_Type) < 0)
@@ -2074,10 +2074,10 @@ PyInit__multibytecodec(void)
if (m == NULL)
return NULL;
- for (size_t i = 0; i < Py_ARRAY_LENGTH(typelist); i++) {
- if (PyModule_AddType(m, typelist[i]) < 0) {
+ for (size_t i = 0; i < Py_ARRAY_LENGTH(typelist); i++) {
+ if (PyModule_AddType(m, typelist[i]) < 0) {
return NULL;
- }
+ }
}
if (PyErr_Occurred()) {