#define MODULE_VERSION "1.0"
-#define NEEDS_PY_IDENTIFIER
-
#include "Python.h"
#include "structmember.h" // PyMemberDef
#include <stdbool.h>
PyTypeObject *reader_type;
PyTypeObject *writer_type;
long field_limit; /* max parsed field size */
+ PyObject *str_write;
} _csvstate;
static struct PyModuleDef _csvmodule;
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;
}
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;
}
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;
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;
}
return -1;
}
+ module_state->str_write = PyUnicode_InternFromString("write");
+ if (module_state->str_write == NULL) {
+ return -1;
+ }
return 0;
}