Commit 3ed04ee9 authored by Marius Wachtler's avatar Marius Wachtler

Merge pull request #1163 from undingen/ref_integration2

refcounting fixes for numpy in PyTuple_GetSlice, PyErr_SetExcInfo and PyErr_GetExcInfo
parents b163e6cd db5c5739
......@@ -747,18 +747,20 @@ extern "C" void Py_Exit(int sts) noexcept {
}
extern "C" void PyErr_GetExcInfo(PyObject** ptype, PyObject** pvalue, PyObject** ptraceback) noexcept {
assert(0 && "check refcounting");
ExcInfo* exc = getFrameExcInfo();
*ptype = exc->type;
*pvalue = exc->value;
*ptraceback = exc->traceback;
*ptype = xincref(exc->type);
*pvalue = xincref(exc->value);
*ptraceback = xincref(exc->traceback);
}
extern "C" void PyErr_SetExcInfo(PyObject* type, PyObject* value, PyObject* traceback) noexcept {
assert(0 && "check refcounting");
ExcInfo* exc = getFrameExcInfo();
exc->type = type ? type : None;
exc->value = value ? value : None;
AUTO_XDECREF(exc->type);
AUTO_XDECREF(exc->value);
AUTO_XDECREF(exc->traceback);
exc->type = type ? type : incref(None);
exc->value = value ? value : incref(None);
exc->traceback = traceback;
}
......
......@@ -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 {
RELEASE_ASSERT(PyTuple_Check(p), "");
BoxedTuple* t = static_cast<BoxedTuple*>(p);
if (p == NULL || !PyTuple_Check(p)) {
PyErr_BadInternalCall();
return NULL;
}
BoxedTuple* t = static_cast<BoxedTuple*>(p);
Py_ssize_t n = t->size();
if (low < 0)
low = 0;
......@@ -103,8 +106,8 @@ extern "C" PyObject* PyTuple_GetSlice(PyObject* p, Py_ssize_t low, Py_ssize_t hi
if (high < low)
high = low;
if (low == 0 && high == n)
return p;
if (low == 0 && high == n && PyTuple_CheckExact(p))
return incref(p);
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