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
bpo-40077: Convert _csv module to use PyType_FromSpec #20974
Conversation
|
FYI, macOS CI issue is not related to this PR |
| @@ -354,25 +376,29 @@ dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) | |||
| &strict)) | |||
| return NULL; | |||
|
|
|||
| _csvstate *state = PyType_GetModuleState(type); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PyType_GetModuleState() is not safe if the type has Py_TPFLAGS_BASETYPE flag, which is the case here.
Is there a way to get the defining type in tp_new?
| PyErr_Format(_csvstate_global->error_obj, "field larger than field limit (%ld)", | ||
| _csvstate_global->field_limit); | ||
| PyTypeObject *reader_type = Py_TYPE(self); | ||
| _csvstate *state = PyType_GetModuleState(reader_type); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Reader type has Py_TPFLAGS_BASETYPE: PyType_GetModuleState() is unsafe here.
| @@ -961,7 +987,8 @@ csv_reader(PyObject *module, PyObject *args, PyObject *keyword_args) | |||
| Py_DECREF(self); | |||
| return NULL; | |||
| } | |||
| self->dialect = (DialectObj *)_call_dialect(dialect, keyword_args); | |||
| _csvstate *state = get_csv_state(module); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
state can be moved at the beginning of the function, to avoid calling get_csv_state() twice.
|
When you're done making the requested changes, leave the comment: |
|
I understand that this PR (if merged) would fix https://bugs.python.org/issue14935 |
|
The issue is now closed via #23224. |
https://bugs.python.org/issue40077