Commit 158465fc authored by Kevin Modzelewski's avatar Kevin Modzelewski

More refcount fixes

parent 42014a09
......@@ -93,7 +93,7 @@ PyAPI_FUNC(void) PyErr_SetString(PyObject *, const char *) PYSTON_NOEXCEPT;
PyAPI_FUNC(PyObject *) PyErr_Occurred(void) PYSTON_NOEXCEPT;
PyAPI_FUNC(void) PyErr_Clear(void) PYSTON_NOEXCEPT;
PyAPI_FUNC(void) PyErr_Fetch(PyObject **, PyObject **, PyObject **) PYSTON_NOEXCEPT;
PyAPI_FUNC(void) PyErr_Restore(PyObject *, PyObject *, PyObject *) PYSTON_NOEXCEPT;
PyAPI_FUNC(void) PyErr_Restore(STOLEN(PyObject *), STOLEN(PyObject *), STOLEN(PyObject *)) PYSTON_NOEXCEPT;
// Pyton change: This functions are normally only available in CPython >= 3.3 and PyPy but Cython can use them.
PyAPI_FUNC(void) PyErr_GetExcInfo(PyObject **ptype, PyObject **pvalue, PyObject **ptraceback) PYSTON_NOEXCEPT;
......
......@@ -779,9 +779,7 @@ finally:
}
void setCAPIException(const ExcInfo& e) {
cur_thread_state.curexc_type = e.type;
cur_thread_state.curexc_value = e.value;
cur_thread_state.curexc_traceback = e.traceback;
PyErr_Restore(e.type, e.value, e.traceback);
}
void ensureCAPIExceptionSet() {
......
......@@ -405,14 +405,18 @@ extern "C" PyObject* PyDict_GetItemString(PyObject* dict, const char* key) noexc
Box* dictSetitem(BoxedDict* self, Box* k, Box* v) {
Box*& pos = self->d[k];
Py_INCREF(v);
if (pos != NULL) {
Box* old = pos;
pos = v;
if (old) {
Py_DECREF(old);
} else {
pos = v;
Py_INCREF(k);
}
return None;
Py_RETURN_NONE;
}
Box* dictDelitem(BoxedDict* self, Box* k) {
......@@ -420,6 +424,7 @@ Box* dictDelitem(BoxedDict* self, Box* k) {
raiseExcHelper(TypeError, "descriptor '__delitem__' requires a 'dict' object but received a '%s'",
getTypeName(self));
assert(0 && "check refcounting");
auto it = self->d.find(k);
if (it == self->d.end()) {
raiseExcHelper(KeyError, k);
......@@ -427,7 +432,7 @@ Box* dictDelitem(BoxedDict* self, Box* k) {
self->d.erase(it);
return None;
Py_RETURN_NONE;
}
// Analoguous to CPython's, used for sq_ slots.
......@@ -440,6 +445,7 @@ static int dict_ass_sub(PyDictObject* mp, PyObject* v, PyObject* w) noexcept {
res = dictSetitem((BoxedDict*)mp, v, w);
}
assert(res == None);
Py_DECREF(res);
} catch (ExcInfo e) {
setCAPIException(e);
return -1;
......
......@@ -170,7 +170,7 @@ void checkAndThrowCAPIException();
void throwCAPIException() __attribute__((noreturn));
void ensureCAPIExceptionSet();
struct ExcInfo;
void setCAPIException(const ExcInfo& e);
void setCAPIException(STOLEN(const ExcInfo&) e);
// Finalizer-related
void dealloc_null(Box* box);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment