@@ -10,8 +10,6 @@ module instead.
10
10
11
11
#define MODULE_VERSION "1.0"
12
12
13
- #define NEEDS_PY_IDENTIFIER
14
-
15
13
#include "Python.h"
16
14
#include "structmember.h" // PyMemberDef
17
15
#include <stdbool.h>
@@ -27,6 +25,7 @@ typedef struct {
27
25
PyTypeObject * reader_type ;
28
26
PyTypeObject * writer_type ;
29
27
long field_limit ; /* max parsed field size */
28
+ PyObject * str_write ;
30
29
} _csvstate ;
31
30
32
31
static struct PyModuleDef _csvmodule ;
@@ -48,6 +47,7 @@ _csv_clear(PyObject *module)
48
47
Py_CLEAR (module_state -> dialect_type );
49
48
Py_CLEAR (module_state -> reader_type );
50
49
Py_CLEAR (module_state -> writer_type );
50
+ Py_CLEAR (module_state -> str_write );
51
51
return 0 ;
52
52
}
53
53
@@ -60,6 +60,7 @@ _csv_traverse(PyObject *module, visitproc visit, void *arg)
60
60
Py_VISIT (module_state -> dialect_type );
61
61
Py_VISIT (module_state -> reader_type );
62
62
Py_VISIT (module_state -> writer_type );
63
+ Py_VISIT (module_state -> str_write );
63
64
return 0 ;
64
65
}
65
66
@@ -1430,7 +1431,6 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
1430
1431
PyObject * output_file , * dialect = NULL ;
1431
1432
_csvstate * module_state = get_csv_state (module );
1432
1433
WriterObj * self = PyObject_GC_New (WriterObj , module_state -> writer_type );
1433
- _Py_IDENTIFIER (write );
1434
1434
1435
1435
if (!self )
1436
1436
return NULL ;
@@ -1449,7 +1449,9 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
1449
1449
Py_DECREF (self );
1450
1450
return NULL ;
1451
1451
}
1452
- if (_PyObject_LookupAttrId (output_file , & PyId_write , & self -> write ) < 0 ) {
1452
+ if (_PyObject_LookupAttr (output_file ,
1453
+ module_state -> str_write ,
1454
+ & self -> write ) < 0 ) {
1453
1455
Py_DECREF (self );
1454
1456
return NULL ;
1455
1457
}
@@ -1751,6 +1753,10 @@ csv_exec(PyObject *module) {
1751
1753
return -1 ;
1752
1754
}
1753
1755
1756
+ module_state -> str_write = PyUnicode_InternFromString ("write" );
1757
+ if (module_state -> str_write == NULL ) {
1758
+ return -1 ;
1759
+ }
1754
1760
return 0 ;
1755
1761
}
1756
1762
0 commit comments