@@ -10,8 +10,6 @@ module instead.
1010
1111#define  MODULE_VERSION  "1.0"
1212
13- #define  NEEDS_PY_IDENTIFIER 
14- 
1513#include  "Python.h" 
1614#include  "structmember.h"          // PyMemberDef 
1715#include  <stdbool.h> 
@@ -27,6 +25,7 @@ typedef struct {
2725    PyTypeObject  * reader_type ;
2826    PyTypeObject  * writer_type ;
2927    long  field_limit ;   /* max parsed field size */ 
28+     PyObject  * str_write ;
3029} _csvstate ;
3130
3231static  struct  PyModuleDef  _csvmodule ;
@@ -48,6 +47,7 @@ _csv_clear(PyObject *module)
4847    Py_CLEAR (module_state -> dialect_type );
4948    Py_CLEAR (module_state -> reader_type );
5049    Py_CLEAR (module_state -> writer_type );
50+     Py_CLEAR (module_state -> str_write );
5151    return  0 ;
5252}
5353
@@ -60,6 +60,7 @@ _csv_traverse(PyObject *module, visitproc visit, void *arg)
6060    Py_VISIT (module_state -> dialect_type );
6161    Py_VISIT (module_state -> reader_type );
6262    Py_VISIT (module_state -> writer_type );
63+     Py_VISIT (module_state -> str_write );
6364    return  0 ;
6465}
6566
@@ -1430,7 +1431,6 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
14301431    PyObject  *  output_file , *  dialect  =  NULL ;
14311432    _csvstate  * module_state  =  get_csv_state (module );
14321433    WriterObj  *  self  =  PyObject_GC_New (WriterObj , module_state -> writer_type );
1433-     _Py_IDENTIFIER (write );
14341434
14351435    if  (!self )
14361436        return  NULL ;
@@ -1449,7 +1449,9 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
14491449        Py_DECREF (self );
14501450        return  NULL ;
14511451    }
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 ) {
14531455        Py_DECREF (self );
14541456        return  NULL ;
14551457    }
@@ -1751,6 +1753,10 @@ csv_exec(PyObject *module) {
17511753        return  -1 ;
17521754    }
17531755
1756+     module_state -> str_write  =  PyUnicode_InternFromString ("write" );
1757+     if  (module_state -> str_write  ==  NULL ) {
1758+         return  -1 ;
1759+     }
17541760    return  0 ;
17551761}
17561762
0 commit comments