@@ -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
@@ -706,10 +707,11 @@ parse_grow_buff(ReaderObj *self)
706
707
static int
707
708
parse_add_char (ReaderObj * self , _csvstate * module_state , Py_UCS4 c )
708
709
{
709
- if (self -> field_len >= module_state -> field_limit ) {
710
+ Py_ssize_t field_limit = FT_ATOMIC_LOAD_SSIZE_RELAXED (module_state -> field_limit );
711
+ if (self -> field_len >= field_limit ) {
710
712
PyErr_Format (module_state -> error_obj ,
711
- "field larger than field limit (%ld )" ,
712
- module_state -> field_limit );
713
+ "field larger than field limit (%zd )" ,
714
+ field_limit );
713
715
return -1 ;
714
716
}
715
717
if (self -> field_len == self -> field_size && !parse_grow_buff (self ))
@@ -1659,20 +1661,20 @@ _csv_field_size_limit_impl(PyObject *module, PyObject *new_limit)
1659
1661
/*[clinic end generated code: output=f2799ecd908e250b input=cec70e9226406435]*/
1660
1662
{
1661
1663
_csvstate * module_state = get_csv_state (module );
1662
- long old_limit = module_state -> field_limit ;
1664
+ Py_ssize_t old_limit = FT_ATOMIC_LOAD_SSIZE_RELAXED ( module_state -> field_limit ) ;
1663
1665
if (new_limit != NULL ) {
1664
1666
if (!PyLong_CheckExact (new_limit )) {
1665
1667
PyErr_Format (PyExc_TypeError ,
1666
1668
"limit must be an integer" );
1667
1669
return NULL ;
1668
1670
}
1669
- module_state -> field_limit = PyLong_AsLong (new_limit );
1670
- if (module_state -> field_limit == -1 && PyErr_Occurred ()) {
1671
- module_state -> field_limit = old_limit ;
1671
+ Py_ssize_t new_limit_value = PyLong_AsSsize_t (new_limit );
1672
+ if (new_limit_value == -1 && PyErr_Occurred ()) {
1672
1673
return NULL ;
1673
1674
}
1675
+ FT_ATOMIC_STORE_SSIZE_RELAXED (module_state -> field_limit , new_limit_value );
1674
1676
}
1675
- return PyLong_FromLong (old_limit );
1677
+ return PyLong_FromSsize_t (old_limit );
1676
1678
}
1677
1679
1678
1680
static PyType_Slot error_slots [] = {
0 commit comments