From d64f3caebe8f8e31ecd193e0bd25105400153ece Mon Sep 17 00:00:00 2001 From: Dong-hee Na Date: Thu, 17 Feb 2022 00:24:03 +0900 Subject: bpo-46541: Remove usage of _Py_IDENTIFIER from csv module (GH-31372) --- Modules/_csv.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Modules/_csv.c b/Modules/_csv.c index f59d42a..ebc3328 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -10,8 +10,6 @@ module instead. #define MODULE_VERSION "1.0" -#define NEEDS_PY_IDENTIFIER - #include "Python.h" #include "structmember.h" // PyMemberDef #include @@ -27,6 +25,7 @@ typedef struct { PyTypeObject *reader_type; PyTypeObject *writer_type; long field_limit; /* max parsed field size */ + PyObject *str_write; } _csvstate; static struct PyModuleDef _csvmodule; @@ -48,6 +47,7 @@ _csv_clear(PyObject *module) Py_CLEAR(module_state->dialect_type); Py_CLEAR(module_state->reader_type); Py_CLEAR(module_state->writer_type); + Py_CLEAR(module_state->str_write); return 0; } @@ -60,6 +60,7 @@ _csv_traverse(PyObject *module, visitproc visit, void *arg) Py_VISIT(module_state->dialect_type); Py_VISIT(module_state->reader_type); Py_VISIT(module_state->writer_type); + Py_VISIT(module_state->str_write); return 0; } @@ -1430,7 +1431,6 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args) PyObject * output_file, * dialect = NULL; _csvstate *module_state = get_csv_state(module); WriterObj * self = PyObject_GC_New(WriterObj, module_state->writer_type); - _Py_IDENTIFIER(write); if (!self) return NULL; @@ -1449,7 +1449,9 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args) Py_DECREF(self); return NULL; } - if (_PyObject_LookupAttrId(output_file, &PyId_write, &self->write) < 0) { + if (_PyObject_LookupAttr(output_file, + module_state->str_write, + &self->write) < 0) { Py_DECREF(self); return NULL; } @@ -1751,6 +1753,10 @@ csv_exec(PyObject *module) { return -1; } + module_state->str_write = PyUnicode_InternFromString("write"); + if (module_state->str_write == NULL) { + return -1; + } return 0; } -- cgit v0.12