summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na@python.org>2022-02-16 15:24:03 (GMT)
committerGitHub <noreply@github.com>2022-02-16 15:24:03 (GMT)
commitd64f3caebe8f8e31ecd193e0bd25105400153ece (patch)
tree7b7f53ada683c1e54e7ae93fba48729d3f208c91 /Modules
parent562c13f5734d406b2283cfca673611f4b496fdc7 (diff)
downloadcpython-d64f3caebe8f8e31ecd193e0bd25105400153ece.zip
cpython-d64f3caebe8f8e31ecd193e0bd25105400153ece.tar.gz
cpython-d64f3caebe8f8e31ecd193e0bd25105400153ece.tar.bz2
bpo-46541: Remove usage of _Py_IDENTIFIER from csv module (GH-31372)
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_csv.c14
1 files 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 <stdbool.h>
@@ -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;
}