fix memory PyObject * typemaps to avoid memory leaks with iterators
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8375 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
07011f2e95
commit
5daf66c0db
4 changed files with 30 additions and 4 deletions
|
|
@ -1,7 +1,13 @@
|
||||||
|
import sys
|
||||||
from langobj import *
|
from langobj import *
|
||||||
|
|
||||||
|
|
||||||
x ="hello"
|
x ="hello"
|
||||||
|
rx = sys.getrefcount(x)
|
||||||
if identity(x) != x:
|
v = identity(x)
|
||||||
|
rv = sys.getrefcount(v)
|
||||||
|
if v != x:
|
||||||
|
raise RuntimeError
|
||||||
|
|
||||||
|
if rv - rx != 1:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
|
||||||
|
|
@ -42,6 +42,18 @@ namespace swig {
|
||||||
struct PyObject_ptr {};
|
struct PyObject_ptr {};
|
||||||
%apply PyObject * {PyObject_ptr};
|
%apply PyObject * {PyObject_ptr};
|
||||||
%apply PyObject * const& {PyObject_ptr const&};
|
%apply PyObject * const& {PyObject_ptr const&};
|
||||||
|
|
||||||
|
/* For output */
|
||||||
|
%typemap(out,noblock=1) PyObject_ptr {
|
||||||
|
$result = (PyObject *)$1;
|
||||||
|
Py_INCREF($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
%typemap(out,noblock=1) PyObject_ptr const & {
|
||||||
|
$result = (PyObject *)*$1;
|
||||||
|
Py_INCREF($result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@ namespace swig
|
||||||
Mark methods that return new objects
|
Mark methods that return new objects
|
||||||
*/
|
*/
|
||||||
%newobject PySwigIterator::copy;
|
%newobject PySwigIterator::copy;
|
||||||
|
%newobject PySwigIterator::value;
|
||||||
|
%newobject PySwigIterator::next;
|
||||||
|
%newobject PySwigIterator::previous;
|
||||||
%newobject PySwigIterator::operator + (ptrdiff_t n) const;
|
%newobject PySwigIterator::operator + (ptrdiff_t n) const;
|
||||||
%newobject PySwigIterator::operator - (ptrdiff_t n) const;
|
%newobject PySwigIterator::operator - (ptrdiff_t n) const;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -85,13 +85,18 @@
|
||||||
|
|
||||||
/* For output, we increase the reference object */
|
/* For output, we increase the reference object */
|
||||||
%typemap(out,noblock=1) PyObject * {
|
%typemap(out,noblock=1) PyObject * {
|
||||||
Py_XINCREF($1);
|
/* hello */
|
||||||
$result = $1;
|
$result = $1;
|
||||||
|
%#if !($owner)
|
||||||
|
Py_XINCREF($result);
|
||||||
|
%#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
%typemap(out,noblock=1) PyObject * const & {
|
%typemap(out,noblock=1) PyObject * const & {
|
||||||
Py_XINCREF(*$1);
|
|
||||||
$result = *$1;
|
$result = *$1;
|
||||||
|
%#if !($owner)
|
||||||
|
Py_XINCREF($result);
|
||||||
|
%#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Consttab, needed for callbacks, it should be removed later */
|
/* Consttab, needed for callbacks, it should be removed later */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue