solve possible seg. faults and directors #1080075
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@6894 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
7ae82d1c51
commit
e67b13b202
7 changed files with 28 additions and 24 deletions
|
|
@ -7,6 +7,7 @@ class MyFoo(Foo):
|
||||||
|
|
||||||
class MyFoo2(Foo):
|
class MyFoo2(Foo):
|
||||||
def ping(self):
|
def ping(self):
|
||||||
|
return true
|
||||||
pass # error: should return a string
|
pass # error: should return a string
|
||||||
|
|
||||||
ok = 0
|
ok = 0
|
||||||
|
|
@ -31,10 +32,9 @@ b = launder(a)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
b.pong()
|
b.pong()
|
||||||
except TypeError, e:
|
|
||||||
ok = 1
|
|
||||||
except:
|
except:
|
||||||
pass
|
ok = 1
|
||||||
|
|
||||||
|
|
||||||
if not ok:
|
if not ok:
|
||||||
raise RuntimeError
|
raise RuntimeError
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,11 @@ namespace Swig {
|
||||||
class DirectorTypeMismatchException : public Swig::DirectorException {
|
class DirectorTypeMismatchException : public Swig::DirectorException {
|
||||||
public:
|
public:
|
||||||
DirectorTypeMismatchException(const char* msg="") {
|
DirectorTypeMismatchException(const char* msg="") {
|
||||||
swig_msg = "Swig director type mismatch: ";
|
if (!PyErr_Occurred()) {
|
||||||
swig_msg += msg;
|
swig_msg = "Swig director type mismatch: ";
|
||||||
PyErr_SetString(PyExc_TypeError, getMessage());
|
swig_msg += msg;
|
||||||
|
PyErr_SetString(PyExc_TypeError, getMessage());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,7 @@
|
||||||
%define PYPTR_DIRECTOROUT_TYPEMAP(asptr_meth,pyfrag,Type...)
|
%define PYPTR_DIRECTOROUT_TYPEMAP(asptr_meth,pyfrag,Type...)
|
||||||
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT ($*1_ltype temp) {
|
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT ($*1_ltype temp) {
|
||||||
Type *ptr = 0;
|
Type *ptr = 0;
|
||||||
int res = asptr_meth($input, &ptr);
|
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||||
if (!res || !ptr)
|
if (!res || !ptr)
|
||||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
||||||
temp = *ptr;
|
temp = *ptr;
|
||||||
|
|
@ -71,7 +71,7 @@
|
||||||
}
|
}
|
||||||
%typemap(directorout,fragment=pyfrag) Type {
|
%typemap(directorout,fragment=pyfrag) Type {
|
||||||
Type *ptr = 0;
|
Type *ptr = 0;
|
||||||
int res = asptr_meth($input, &ptr);
|
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||||
if (!res || !ptr)
|
if (!res || !ptr)
|
||||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
||||||
$result = *ptr;
|
$result = *ptr;
|
||||||
|
|
@ -79,7 +79,7 @@
|
||||||
}
|
}
|
||||||
%typemap(directorout,fragment=pyfrag,warning="470:Possible thread/reentrant unsafe wrapping, consider using a plain '"#Type"' return type instead.") const Type& {
|
%typemap(directorout,fragment=pyfrag,warning="470:Possible thread/reentrant unsafe wrapping, consider using a plain '"#Type"' return type instead.") const Type& {
|
||||||
Type *ptr = 0;
|
Type *ptr = 0;
|
||||||
int res = asptr_meth($input, &ptr);
|
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||||
if (!res || !ptr)
|
if (!res || !ptr)
|
||||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
||||||
$result = ptr;
|
$result = ptr;
|
||||||
|
|
|
||||||
|
|
@ -98,7 +98,7 @@
|
||||||
|
|
||||||
%typemap(directorout,fragment=#SWIG_AsCharPtr)
|
%typemap(directorout,fragment=#SWIG_AsCharPtr)
|
||||||
Char *, Char const*, Char *const, Char const* const
|
Char *, Char const*, Char *const, Char const* const
|
||||||
"if (!SWIG_AsCharPtr($input, (Char**) &$result)) {
|
"if (!$input || !SWIG_AsCharPtr($input, (Char**) &$result)) {
|
||||||
Swig::DirectorTypeMismatchException(\"Error converting Python object into Char*\");
|
Swig::DirectorTypeMismatchException(\"Error converting Python object into Char*\");
|
||||||
}";
|
}";
|
||||||
|
|
||||||
|
|
@ -106,7 +106,7 @@
|
||||||
Char const *&, Char *const &, Char const *const &
|
Char const *&, Char *const &, Char const *const &
|
||||||
{
|
{
|
||||||
Char* temp;
|
Char* temp;
|
||||||
if (!SWIG_AsCharPtr($input, &temp)) {
|
if (!$input || !SWIG_AsCharPtr($input, &temp)) {
|
||||||
Swig::DirectorTypeMismatchException("Error converting Python object into Char*");
|
Swig::DirectorTypeMismatchException("Error converting Python object into Char*");
|
||||||
}
|
}
|
||||||
$result = ($1_ltype) &temp;
|
$result = ($1_ltype) &temp;
|
||||||
|
|
@ -239,7 +239,7 @@
|
||||||
%typemap(directorout,fragment=#SWIG_AsCharArray)
|
%typemap(directorout,fragment=#SWIG_AsCharArray)
|
||||||
Char [ANY], const Char [ANY] (Char temp[$result_dim0])
|
Char [ANY], const Char [ANY] (Char temp[$result_dim0])
|
||||||
{
|
{
|
||||||
if (!SWIG_AsCharArray($input, temp, $result_dim0)) {
|
if (!$input || !SWIG_AsCharArray($input, temp, $result_dim0)) {
|
||||||
Swig::DirectorTypeMismatchException("Error converting Python object into Char[$result_dim0]");
|
Swig::DirectorTypeMismatchException("Error converting Python object into Char[$result_dim0]");
|
||||||
}
|
}
|
||||||
$result = temp;
|
$result = temp;
|
||||||
|
|
|
||||||
|
|
@ -286,13 +286,13 @@
|
||||||
/* directorout */
|
/* directorout */
|
||||||
|
|
||||||
%typemap(directorout) SWIGTYPE ($<ype argp)
|
%typemap(directorout) SWIGTYPE ($<ype argp)
|
||||||
"if ((SWIG_ConvertPtr($input, (void **)(&argp),
|
"if (!$input || (SWIG_ConvertPtr($input, (void **)(&argp),
|
||||||
$&descriptor, SWIG_POINTER_EXCEPTION | $disown)) == -1)
|
$&descriptor, SWIG_POINTER_EXCEPTION | $disown)) == -1)
|
||||||
throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");
|
throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");
|
||||||
$result = *argp;";
|
$result = *argp;";
|
||||||
|
|
||||||
%typemap(directorout) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
%typemap(directorout) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||||
"if ((SWIG_ConvertPtr($input,(void **)(&$result),
|
"if (!$input || (SWIG_ConvertPtr($input,(void **)(&$result),
|
||||||
$descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1)
|
$descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1)
|
||||||
throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
|
throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -68,20 +68,22 @@
|
||||||
/* directorout */
|
/* directorout */
|
||||||
|
|
||||||
%define PYVAL_DIRECTOROUT_TYPEMAP(as_meth,pyfrag,Type...)
|
%define PYVAL_DIRECTOROUT_TYPEMAP(as_meth,pyfrag,Type...)
|
||||||
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT {
|
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT {
|
||||||
*$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
if ($input) *$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||||
if (PyErr_Occurred())
|
if (!$input || PyErr_Occurred())
|
||||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
||||||
}
|
}
|
||||||
%typemap(directorout,fragment=pyfrag) Type {
|
%typemap(directorout,fragment=pyfrag) Type {
|
||||||
$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
if ($input) $result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||||
if (PyErr_Occurred())
|
if (!$input || PyErr_Occurred())
|
||||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
||||||
}
|
}
|
||||||
%typemap(directorout,fragment=pyfrag,warning="470:Using thread/reentrant unsafe wrapping, consider using a plain '"#Type"' return type instead.") const Type& {
|
%typemap(directorout,fragment=pyfrag,warning="470:Using thread/reentrant unsafe wrapping, consider using a plain '"#Type"' return type instead.") const Type& {
|
||||||
static $basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
|
if ($input) {
|
||||||
$result = &temp;
|
static $basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
|
||||||
if (PyErr_Occurred())
|
$result = &temp;
|
||||||
|
}
|
||||||
|
if (!$input || PyErr_Occurred())
|
||||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
||||||
}
|
}
|
||||||
%typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
|
%typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@
|
||||||
/* directorout */
|
/* directorout */
|
||||||
|
|
||||||
%typemap(directorout) void * {
|
%typemap(directorout) void * {
|
||||||
if ((SWIG_ConvertPtr($input,(void **)(&$result),
|
if (!$input || (SWIG_ConvertPtr($input,(void **)(&$result),
|
||||||
0, SWIG_POINTER_EXCEPTION | $disown )) == -1)
|
0, SWIG_POINTER_EXCEPTION | $disown )) == -1)
|
||||||
throw Swig::DirectorTypeMismatchException("Pointer conversion failed.");
|
throw Swig::DirectorTypeMismatchException("Pointer conversion failed.");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue