@@ -1104,9 +1104,7 @@ csv_reader(PyObject *module, PyObject *args, PyObject *keyword_args)
11041104 * WRITER
11051105 */
11061106static inline int
1107- _is_structural_char (Py_UCS4 c , DialectObj * dialect ) {
1108- Py_ssize_t term_len = PyUnicode_GET_LENGTH (dialect -> lineterminator );
1109-
1107+ _is_structural_char (Py_UCS4 c , DialectObj * dialect , Py_ssize_t term_len ) {
11101108 if (c == dialect -> delimiter || c == '\n' || c == '\r' ) {
11111109 return 1 ;
11121110 }
@@ -1120,6 +1118,7 @@ static int
11201118_write_field (PyUnicodeWriter * writer , WriterObj * self , PyObject * field , int * quoted )
11211119{
11221120 DialectObj * dialect = self -> dialect ;
1121+ Py_ssize_t term_len = PyUnicode_GET_LENGTH (dialect -> lineterminator );
11231122 Py_ssize_t field_len = 0 ;
11241123
11251124 bool is_none = (field == NULL );
@@ -1148,7 +1147,7 @@ _write_field(PyUnicodeWriter *writer, WriterObj *self, PyObject *field, int *quo
11481147 Py_ssize_t i ;
11491148 for (i = 0 ; i < field_len ; i ++ ) {
11501149 Py_UCS4 c = PyUnicode_READ_CHAR (field , i );
1151- if (_is_structural_char (c , dialect ) ||
1150+ if (_is_structural_char (c , dialect , term_len ) ||
11521151 (c == dialect -> quotechar && dialect -> doublequote )) {
11531152 * quoted = 1 ;
11541153 break ;
@@ -1170,7 +1169,7 @@ _write_field(PyUnicodeWriter *writer, WriterObj *self, PyObject *field, int *quo
11701169
11711170 if (dialect -> quoting == QUOTE_NONE ) {
11721171 /* escape structural characters when we cannot quote. */
1173- if (_is_structural_char (c , dialect ) ||
1172+ if (_is_structural_char (c , dialect , term_len ) ||
11741173 c == dialect -> escapechar ||
11751174 c == dialect -> quotechar ) {
11761175 if (dialect -> escapechar == NOT_SET ) {
0 commit comments