Commit db5c5739 authored by Marius Wachtler's avatar Marius Wachtler

refcounting fixes for numpy in PyTuple_GetSlice, PyErr_SetExcInfo and PyErr_GetExcInfo

parent b163e6cd
...@@ -747,18 +747,20 @@ extern "C" void Py_Exit(int sts) noexcept { ...@@ -747,18 +747,20 @@ extern "C" void Py_Exit(int sts) noexcept {
} }
extern "C" void PyErr_GetExcInfo(PyObject** ptype, PyObject** pvalue, PyObject** ptraceback) noexcept { extern "C" void PyErr_GetExcInfo(PyObject** ptype, PyObject** pvalue, PyObject** ptraceback) noexcept {
assert(0 && "check refcounting");
ExcInfo* exc = getFrameExcInfo(); ExcInfo* exc = getFrameExcInfo();
*ptype = exc->type; *ptype = xincref(exc->type);
*pvalue = exc->value; *pvalue = xincref(exc->value);
*ptraceback = exc->traceback; *ptraceback = xincref(exc->traceback);
} }
extern "C" void PyErr_SetExcInfo(PyObject* type, PyObject* value, PyObject* traceback) noexcept { extern "C" void PyErr_SetExcInfo(PyObject* type, PyObject* value, PyObject* traceback) noexcept {
assert(0 && "check refcounting");
ExcInfo* exc = getFrameExcInfo(); ExcInfo* exc = getFrameExcInfo();
exc->type = type ? type : None; AUTO_XDECREF(exc->type);
exc->value = value ? value : None; AUTO_XDECREF(exc->value);
AUTO_XDECREF(exc->traceback);
exc->type = type ? type : incref(None);
exc->value = value ? value : incref(None);
exc->traceback = traceback; exc->traceback = traceback;
} }
......
...@@ -92,9 +92,12 @@ Box* tupleGetitemSlice(BoxedTuple* self, BoxedSlice* slice) { ...@@ -92,9 +92,12 @@ Box* tupleGetitemSlice(BoxedTuple* self, BoxedSlice* slice) {
} }
extern "C" PyObject* PyTuple_GetSlice(PyObject* p, Py_ssize_t low, Py_ssize_t high) noexcept { extern "C" PyObject* PyTuple_GetSlice(PyObject* p, Py_ssize_t low, Py_ssize_t high) noexcept {
RELEASE_ASSERT(PyTuple_Check(p), ""); if (p == NULL || !PyTuple_Check(p)) {
BoxedTuple* t = static_cast<BoxedTuple*>(p); PyErr_BadInternalCall();
return NULL;
}
BoxedTuple* t = static_cast<BoxedTuple*>(p);
Py_ssize_t n = t->size(); Py_ssize_t n = t->size();
if (low < 0) if (low < 0)
low = 0; low = 0;
...@@ -103,8 +106,8 @@ extern "C" PyObject* PyTuple_GetSlice(PyObject* p, Py_ssize_t low, Py_ssize_t hi ...@@ -103,8 +106,8 @@ extern "C" PyObject* PyTuple_GetSlice(PyObject* p, Py_ssize_t low, Py_ssize_t hi
if (high < low) if (high < low)
high = low; high = low;
if (low == 0 && high == n) if (low == 0 && high == n && PyTuple_CheckExact(p))
return p; return incref(p);
return BoxedTuple::create(high - low, &t->elts[low]); return BoxedTuple::create(high - low, &t->elts[low]);
} }
......
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