Skip to content

Commit

Permalink
Merge pull request #193 from tschoonj/fix-python-memleak
Browse files Browse the repository at this point in the history
Fix python memory leak
  • Loading branch information
tschoonj authored Feb 13, 2022
2 parents 9e8ab95 + bb467b3 commit 72993f3
Showing 1 changed file with 8 additions and 24 deletions.
32 changes: 8 additions & 24 deletions python/pyfragments.swg
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
SWIGINTERN int
SWIG_AsVal_dec(long)(PyObject * obj, long * val)
{
PyArray_Descr * longDescr = PyArray_DescrNewFromType(NPY_LONG);
if (PyInt_Check(obj)) {
if (val) *val = PyInt_AsLong(obj);
return SWIG_OK;
} else if (PyLong_Check(obj)) {
if (PyLong_Check(obj)) {
long v = PyLong_AsLong(obj);
if (!PyErr_Occurred()) {
if (v != -1 || !PyErr_Occurred()) {
if (val) *val = v;
return SWIG_OK;
} else {
Expand All @@ -38,8 +34,8 @@
%#ifdef SWIG_PYTHON_CAST_MODE
{
int dispatch = 0;
long v = PyInt_AsLong(obj);
if (!PyErr_Occurred()) {
long v = PyLong_AsLong(obj);
if (v != -1 || !PyErr_Occurred()) {
if (val) *val = v;
return SWIG_AddCast(SWIG_OK);
} else {
Expand All @@ -56,7 +52,9 @@
}
%#endif
if (!PyArray_IsScalar(obj,Integer)) return SWIG_TypeError;
PyArray_Descr * longDescr = PyArray_DescrFromType(NPY_LONG);
PyArray_CastScalarToCtype(obj, (void*)val, longDescr);
Py_DECREF(longDescr);
return SWIG_OK;
}
}
Expand All @@ -74,22 +72,6 @@
SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
{
PyArray_Descr * ulongDescr = PyArray_DescrNewFromType(NPY_ULONG);
%#if PY_VERSION_HEX < 0x03000000
if (PyInt_Check(obj))
{
long v = PyInt_AsLong(obj);
if (v >= 0)
{
if (val) *val = v;
return SWIG_OK;
}
else
{
return SWIG_OverflowError;
}
} else
%#endif
if (PyLong_Check(obj)) {
unsigned long v = PyLong_AsUnsignedLong(obj);
if (!PyErr_Occurred()) {
Expand Down Expand Up @@ -120,7 +102,9 @@
}
%#endif
if (!PyArray_IsScalar(obj,Integer)) return SWIG_TypeError;
PyArray_Descr * ulongDescr = PyArray_DescrFromType(NPY_ULONG);
PyArray_CastScalarToCtype(obj, (void*)val, ulongDescr);
Py_DECREF(ulongDescr);
return SWIG_OK;
}
}

0 comments on commit 72993f3

Please sign in to comment.