@@ -14,6 +14,7 @@ module instead.
14
14
#endif
15
15
16
16
#include "Python.h"
17
+ #include "pycore_pyatomic_ft_wrappers.h"
17
18
18
19
#include <stddef.h> // offsetof()
19
20
#include <stdbool.h>
@@ -34,7 +35,7 @@ typedef struct {
34
35
PyTypeObject * dialect_type ;
35
36
PyTypeObject * reader_type ;
36
37
PyTypeObject * writer_type ;
37
- long field_limit ; /* max parsed field size */
38
+ Py_ssize_t field_limit ; /* max parsed field size */
38
39
PyObject * str_write ;
39
40
} _csvstate ;
40
41
@@ -702,10 +703,11 @@ parse_grow_buff(ReaderObj *self)
702
703
static int
703
704
parse_add_char (ReaderObj * self , _csvstate * module_state , Py_UCS4 c )
704
705
{
705
- if (self -> field_len >= module_state -> field_limit ) {
706
+ Py_ssize_t field_limit = FT_ATOMIC_LOAD_SSIZE_RELAXED (module_state -> field_limit );
707
+ if (self -> field_len >= field_limit ) {
706
708
PyErr_Format (module_state -> error_obj ,
707
- "field larger than field limit (%ld )" ,
708
- module_state -> field_limit );
709
+ "field larger than field limit (%zd )" ,
710
+ field_limit );
709
711
return -1 ;
710
712
}
711
713
if (self -> field_len == self -> field_size && !parse_grow_buff (self ))
@@ -1651,20 +1653,20 @@ _csv_field_size_limit_impl(PyObject *module, PyObject *new_limit)
1651
1653
/*[clinic end generated code: output=f2799ecd908e250b input=cec70e9226406435]*/
1652
1654
{
1653
1655
_csvstate * module_state = get_csv_state (module );
1654
- long old_limit = module_state -> field_limit ;
1656
+ Py_ssize_t old_limit = FT_ATOMIC_LOAD_SSIZE_RELAXED ( module_state -> field_limit ) ;
1655
1657
if (new_limit != NULL ) {
1656
1658
if (!PyLong_CheckExact (new_limit )) {
1657
1659
PyErr_Format (PyExc_TypeError ,
1658
1660
"limit must be an integer" );
1659
1661
return NULL ;
1660
1662
}
1661
- module_state -> field_limit = PyLong_AsLong (new_limit );
1662
- if (module_state -> field_limit == -1 && PyErr_Occurred ()) {
1663
- module_state -> field_limit = old_limit ;
1663
+ Py_ssize_t new_limit_value = PyLong_AsSsize_t (new_limit );
1664
+ if (new_limit_value == -1 && PyErr_Occurred ()) {
1664
1665
return NULL ;
1665
1666
}
1667
+ FT_ATOMIC_STORE_SSIZE_RELAXED (module_state -> field_limit , new_limit_value );
1666
1668
}
1667
- return PyLong_FromLong (old_limit );
1669
+ return PyLong_FromSsize_t (old_limit );
1668
1670
}
1669
1671
1670
1672
static PyType_Slot error_slots [] = {
0 commit comments