Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGES/9999.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed crash in debug builds.

25 changes: 25 additions & 0 deletions multidict/_multidict.c
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,10 @@ multidict_repr(MultiDictObject *self)
PyObject *name =
PyObject_GetAttr((PyObject *)Py_TYPE(self), self->state->str_name);
if (name == NULL) {
PyObject *etype, *evalue, *etraceback;
PyErr_Fetch(&etype, &evalue, &etraceback);
Py_ReprLeave((PyObject *)self);
PyErr_Restore(etype, evalue, etraceback);
return NULL;
}
PyObject *ret = md_repr(self, name, true, true);
Expand Down Expand Up @@ -539,6 +542,11 @@ static int
multidict_tp_init(MultiDictObject *self, PyObject *args, PyObject *kwds)
{
mod_state *state = get_mod_state_by_def((PyObject *)self);
if (state == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"Failed to retrieve module state for MultiDict");
return -1;
}
PyObject *arg = NULL;
Py_ssize_t size =
_multidict_extend_parse_args(state, args, kwds, "MultiDict", &arg);
Expand Down Expand Up @@ -997,6 +1005,12 @@ static int
cimultidict_tp_init(MultiDictObject *self, PyObject *args, PyObject *kwds)
{
mod_state *state = get_mod_state_by_def((PyObject *)self);
if (state == NULL) {
PyErr_SetString(
PyExc_RuntimeError,
"Failed to retrieve module state for CIMultiDictProxy");
return -1;
}
PyObject *arg = NULL;
Py_ssize_t size =
_multidict_extend_parse_args(state, args, kwds, "CIMultiDict", &arg);
Expand Down Expand Up @@ -1052,6 +1066,11 @@ multidict_proxy_tp_init(MultiDictProxyObject *self, PyObject *args,
PyObject *kwds)
{
mod_state *state = get_mod_state_by_def((PyObject *)self);
if (state == NULL) {
PyErr_SetString(PyExc_RuntimeError,
"Failed to retrieve module state for MultiDict");
return -1;
}
PyObject *arg = NULL;
MultiDictObject *md = NULL;

Expand Down Expand Up @@ -1306,6 +1325,12 @@ cimultidict_proxy_tp_init(MultiDictProxyObject *self, PyObject *args,
PyObject *kwds)
{
mod_state *state = get_mod_state_by_def((PyObject *)self);
if (state == NULL) {
PyErr_SetString(
PyExc_RuntimeError,
"Failed to retrieve module state for CIMultiDictProxy");
return -1;
}
PyObject *arg = NULL;
MultiDictObject *md = NULL;

Expand Down
7 changes: 6 additions & 1 deletion multidict/_multilib/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ get_mod_state_by_def(PyObject *self)
{
PyTypeObject *tp = Py_TYPE(self);
PyObject *mod = PyType_GetModuleByDef(tp, &multidict_module);
assert(mod != NULL);
if (mod == NULL) {
if (PyErr_ExceptionMatches(PyExc_TypeError)) {
PyErr_Clear();
}
return NULL;
}
Comment thread
dynapx marked this conversation as resolved.
return get_mod_state(mod);
}

Expand Down
Loading