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
Show file tree
Hide file tree
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
Make dialects fields on module state thread safe
  • Loading branch information
aisk committed Apr 27, 2024
commit 40e71a8717d3cf5418b329f77a8cf36a26c9e3d0
9 changes: 7 additions & 2 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,7 @@ csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)
PyObject *name_obj, *dialect_obj = NULL;
_csvstate *module_state = get_csv_state(module);
PyObject *dialect;
int res;

if (!PyArg_UnpackTuple(args, "", 1, 2, &name_obj, &dialect_obj))
return NULL;
Expand All @@ -1587,7 +1588,10 @@ csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)
dialect = _call_dialect(module_state, dialect_obj, kwargs);
if (dialect == NULL)
return NULL;
if (PyDict_SetItem(module_state->dialects, name_obj, dialect) < 0) {
Py_BEGIN_CRITICAL_SECTION(module_state->dialects);
res = PyDict_SetItem(module_state->dialects, name_obj, dialect);
Py_END_CRITICAL_SECTION();
if (res < 0) {
Py_DECREF(dialect);
return NULL;
}
Expand All @@ -1597,6 +1601,7 @@ csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)


/*[clinic input]
@critical_section
_csv.unregister_dialect

name: object
Expand All @@ -1608,7 +1613,7 @@ Delete the name/dialect mapping associated with a string name.

static PyObject *
_csv_unregister_dialect_impl(PyObject *module, PyObject *name)
/*[clinic end generated code: output=0813ebca6c058df4 input=6b5c1557bf60c7e7]*/
/*[clinic end generated code: output=0813ebca6c058df4 input=c38732b506218713]*/
{
_csvstate *module_state = get_csv_state(module);
int rc = PyDict_Pop(module_state->dialects, name, NULL);
Expand Down
4 changes: 3 additions & 1 deletion Modules/clinic/_csv.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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