Skip to content

gh-116738: Make _csv module thread-safe #118344

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
Oct 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Change field_limit to Py_ssize_t
  • Loading branch information
aisk committed Jul 10, 2024
commit 3739c46a51cf338c02eb8d34971f983e0f80a07e
8 changes: 4 additions & 4 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ typedef struct {
PyTypeObject *dialect_type;
PyTypeObject *reader_type;
PyTypeObject *writer_type;
long field_limit; /* max parsed field size */
Py_ssize_t field_limit; /* max parsed field size */
PyObject *str_write;
} _csvstate;

Expand Down Expand Up @@ -703,7 +703,7 @@ parse_grow_buff(ReaderObj *self)
static int
parse_add_char(ReaderObj *self, _csvstate *module_state, Py_UCS4 c)
{
long field_limit = FT_ATOMIC_LOAD_LONG(module_state->field_limit);
Py_ssize_t field_limit = FT_ATOMIC_LOAD_SSIZE_RELAXED(module_state->field_limit);
if (self->field_len >= field_limit) {
PyErr_Format(module_state->error_obj,
"field larger than field limit (%ld)",
Expand Down Expand Up @@ -1654,7 +1654,7 @@ _csv_field_size_limit_impl(PyObject *module, PyObject *new_limit)
/*[clinic end generated code: output=f2799ecd908e250b input=cec70e9226406435]*/
{
_csvstate *module_state = get_csv_state(module);
long old_limit = FT_ATOMIC_LOAD_LONG(module_state->field_limit);
Py_ssize_t old_limit = FT_ATOMIC_LOAD_SSIZE_RELAXED(module_state->field_limit);
if (new_limit != NULL) {
if (!PyLong_CheckExact(new_limit)) {
PyErr_Format(PyExc_TypeError,
Expand All @@ -1665,7 +1665,7 @@ _csv_field_size_limit_impl(PyObject *module, PyObject *new_limit)
if (new_limit_value == -1 && PyErr_Occurred()) {
return NULL;
}
FT_ATOMIC_STORE_LONG(module_state->field_limit, new_limit_value);
FT_ATOMIC_STORE_SSIZE_RELAXED(module_state->field_limit, new_limit_value);
}
return PyLong_FromLong(old_limit);
}
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy