@@ -6,10 +6,6 @@ This module provides the low-level underpinnings of a CSV reading/writing
66module. Users should not use this module directly, but import the csv.py
77module instead.
88
9- **** For people modifying this code, please note that as of this writing
10- **** (2003-03-23), it is intended that this code should work with Python
11- **** 2.2.
12-
139*/
1410
1511#define MODULE_VERSION "1.0"
@@ -73,7 +69,7 @@ typedef struct {
7369 PyObject * fields ; /* field list for current record */
7470 ParserState state ; /* current CSV parse state */
7571 Py_UNICODE * field ; /* build current field in here */
76- int field_size ; /* size of allocated buffer */
72+ Py_ssize_t field_size ; /* size of allocated buffer */
7773 Py_ssize_t field_len ; /* length of current field */
7874 int numeric_field ; /* treat field as numeric */
7975 unsigned long line_num ; /* Source-file line number */
@@ -91,7 +87,7 @@ typedef struct {
9187 DialectObj * dialect ; /* parsing dialect */
9288
9389 Py_UNICODE * rec ; /* buffer for parser.join */
94- int rec_size ; /* size of allocated record */
90+ Py_ssize_t rec_size ; /* size of allocated record */
9591 Py_ssize_t rec_len ; /* length of record */
9692 int num_fields ; /* number of fields in record */
9793} WriterObj ;
@@ -533,7 +529,7 @@ parse_grow_buff(ReaderObj *self)
533529 self -> field = PyMem_New (Py_UNICODE , self -> field_size );
534530 }
535531 else {
536- if (self -> field_size > INT_MAX / 2 ) {
532+ if (self -> field_size > PY_SSIZE_T_MAX / 2 ) {
537533 PyErr_NoMemory ();
538534 return 0 ;
539535 }
@@ -948,13 +944,13 @@ join_reset(WriterObj *self)
948944/* Calculate new record length or append field to record. Return new
949945 * record length.
950946 */
951- static int
947+ static Py_ssize_t
952948join_append_data (WriterObj * self , Py_UNICODE * field , int quote_empty ,
953949 int * quoted , int copy_phase )
954950{
955951 DialectObj * dialect = self -> dialect ;
956952 int i ;
957- int rec_len ;
953+ Py_ssize_t rec_len ;
958954 Py_UNICODE * lineterm ;
959955
960956#define ADDCH (c ) \
@@ -1040,10 +1036,10 @@ join_append_data(WriterObj *self, Py_UNICODE *field, int quote_empty,
10401036}
10411037
10421038static int
1043- join_check_rec_size (WriterObj * self , int rec_len )
1039+ join_check_rec_size (WriterObj * self , Py_ssize_t rec_len )
10441040{
10451041
1046- if (rec_len < 0 || rec_len > INT_MAX - MEM_INCR ) {
1042+ if (rec_len < 0 || rec_len > PY_SSIZE_T_MAX - MEM_INCR ) {
10471043 PyErr_NoMemory ();
10481044 return 0 ;
10491045 }
@@ -1075,7 +1071,7 @@ join_check_rec_size(WriterObj *self, int rec_len)
10751071static int
10761072join_append (WriterObj * self , Py_UNICODE * field , int * quoted , int quote_empty )
10771073{
1078- int rec_len ;
1074+ Py_ssize_t rec_len ;
10791075
10801076 rec_len = join_append_data (self , field , quote_empty , quoted , 0 );
10811077 if (rec_len < 0 )
@@ -1094,7 +1090,7 @@ join_append(WriterObj *self, Py_UNICODE *field, int *quoted, int quote_empty)
10941090static int
10951091join_append_lineterminator (WriterObj * self )
10961092{
1097- int terminator_len ;
1093+ Py_ssize_t terminator_len ;
10981094 Py_UNICODE * terminator ;
10991095
11001096 terminator_len = PyUnicode_GetSize (self -> dialect -> lineterminator );
@@ -1125,7 +1121,7 @@ static PyObject *
11251121csv_writerow (WriterObj * self , PyObject * seq )
11261122{
11271123 DialectObj * dialect = self -> dialect ;
1128- int len , i ;
1124+ Py_ssize_t len , i ;
11291125
11301126 if (!PySequence_Check (seq ))
11311127 return PyErr_Format (error_obj , "sequence expected" );
0 commit comments