bpo-46541: Remove usage of _Py_IDENTIFIER from multibytecodec by corona10 · Pull Request #31475 · python/cpython
#define PY_SSIZE_T_CLEAN #define NEEDS_PY_IDENTIFIER #include "Python.h" #include "structmember.h" // PyMemberDef #include "multibytecodec.h"
static _multibytecodec_state *
#define MBENC_RESET MBENC_MAX<<1 /* reset after an encoding session */
_Py_IDENTIFIER(write);
static PyObject * make_tuple(PyObject *object, Py_ssize_t len) {
static int mbstreamwriter_iwrite(MultibyteStreamWriterObject *self, PyObject *unistr) PyObject *unistr, PyObject *str_write) { PyObject *str, *wr;
str = encoder_encode_stateful(STATEFUL_ECTX(self), unistr, 0); if (str == NULL) return -1;
wr = _PyObject_CallMethodIdOneArg(self->stream, &PyId_write, str); wr = _PyObject_CallMethodOneArg(self->stream, str_write, str); Py_DECREF(str); if (wr == NULL) return -1;
cls: defining_class strobj: object / [clinic start generated code]*/
static PyObject * _multibytecodec_MultibyteStreamWriter_write(MultibyteStreamWriterObject *self, PyObject *strobj) /*[clinic end generated code: output=e13ae841c895251e input=551dc4c018c10a2b]*/ _multibytecodec_MultibyteStreamWriter_write_impl(MultibyteStreamWriterObject *self, PyTypeObject *cls, PyObject *strobj) /*[clinic end generated code: output=68ade3aea26410ac input=199f26f68bd8425a]*/ { if (mbstreamwriter_iwrite(self, strobj)) _multibytecodec_state *state = PyType_GetModuleState(cls); assert(state != NULL); if (mbstreamwriter_iwrite(self, strobj, state->str_write)) { return NULL; else Py_RETURN_NONE; } Py_RETURN_NONE; }
/*[clinic input] _multibytecodec.MultibyteStreamWriter.writelines
cls: defining_class lines: object / [clinic start generated code]*/
static PyObject * _multibytecodec_MultibyteStreamWriter_writelines(MultibyteStreamWriterObject *self, PyObject *lines) /*[clinic end generated code: output=e5c4285ac8e7d522 input=57797fe7008d4e96]*/ _multibytecodec_MultibyteStreamWriter_writelines_impl(MultibyteStreamWriterObject *self, PyTypeObject *cls, PyObject *lines) /*[clinic end generated code: output=b4c99d2cf23ffb88 input=a6d5fe7c74972a34]*/ { PyObject *strobj; int i, r;
_multibytecodec_state *state = PyType_GetModuleState(cls); assert(state != NULL); for (i = 0; i < PySequence_Length(lines); i++) { /* length can be changed even within this loop */ strobj = PySequence_GetItem(lines, i); if (strobj == NULL) return NULL;
r = mbstreamwriter_iwrite(self, strobj); r = mbstreamwriter_iwrite(self, strobj, state->str_write); Py_DECREF(strobj); if (r == -1) return NULL;
/*[clinic input] _multibytecodec.MultibyteStreamWriter.reset
cls: defining_class /
[clinic start generated code]*/
static PyObject * _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *self) /*[clinic end generated code: output=8f54a4d9b03db5ff input=b56dbcbaf35cc10c]*/ _multibytecodec_MultibyteStreamWriter_reset_impl(MultibyteStreamWriterObject *self, PyTypeObject *cls) /*[clinic end generated code: output=32ef224c2a38aa3d input=28af6a9cd38d1979]*/ { PyObject *pwrt;
assert(PyBytes_Check(pwrt));
_multibytecodec_state *state = PyType_GetModuleState(cls); assert(state != NULL);
if (PyBytes_Size(pwrt) > 0) { PyObject *wr;
wr = _PyObject_CallMethodIdOneArg(self->stream, &PyId_write, pwrt); wr = _PyObject_CallMethodOneArg(self->stream, state->str_write, pwrt); if (wr == NULL) { Py_DECREF(pwrt); return NULL;