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):
|
||||
def ping(self):
|
||||
return true
|
||||
pass # error: should return a string
|
||||
|
||||
ok = 0
|
||||
|
|
@ -31,10 +32,9 @@ b = launder(a)
|
|||
|
||||
try:
|
||||
b.pong()
|
||||
except TypeError, e:
|
||||
ok = 1
|
||||
except:
|
||||
pass
|
||||
ok = 1
|
||||
|
||||
|
||||
if not ok:
|
||||
raise RuntimeError
|
||||
|
|
|
|||
|
|
@ -41,9 +41,11 @@ namespace Swig {
|
|||
class DirectorTypeMismatchException : public Swig::DirectorException {
|
||||
public:
|
||||
DirectorTypeMismatchException(const char* msg="") {
|
||||
swig_msg = "Swig director type mismatch: ";
|
||||
swig_msg += msg;
|
||||
PyErr_SetString(PyExc_TypeError, getMessage());
|
||||
if (!PyErr_Occurred()) {
|
||||
swig_msg = "Swig director type mismatch: ";
|
||||
swig_msg += msg;
|
||||
PyErr_SetString(PyExc_TypeError, getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@
|
|||
%define PYPTR_DIRECTOROUT_TYPEMAP(asptr_meth,pyfrag,Type...)
|
||||
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT ($*1_ltype temp) {
|
||||
Type *ptr = 0;
|
||||
int res = asptr_meth($input, &ptr);
|
||||
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||
if (!res || !ptr)
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
||||
temp = *ptr;
|
||||
|
|
@ -71,7 +71,7 @@
|
|||
}
|
||||
%typemap(directorout,fragment=pyfrag) Type {
|
||||
Type *ptr = 0;
|
||||
int res = asptr_meth($input, &ptr);
|
||||
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||
if (!res || !ptr)
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
||||
$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& {
|
||||
Type *ptr = 0;
|
||||
int res = asptr_meth($input, &ptr);
|
||||
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||
if (!res || !ptr)
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using asptr_meth");
|
||||
$result = ptr;
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@
|
|||
|
||||
%typemap(directorout,fragment=#SWIG_AsCharPtr)
|
||||
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*\");
|
||||
}";
|
||||
|
||||
|
|
@ -106,7 +106,7 @@
|
|||
Char const *&, Char *const &, Char const *const &
|
||||
{
|
||||
Char* temp;
|
||||
if (!SWIG_AsCharPtr($input, &temp)) {
|
||||
if (!$input || !SWIG_AsCharPtr($input, &temp)) {
|
||||
Swig::DirectorTypeMismatchException("Error converting Python object into Char*");
|
||||
}
|
||||
$result = ($1_ltype) &temp;
|
||||
|
|
@ -239,7 +239,7 @@
|
|||
%typemap(directorout,fragment=#SWIG_AsCharArray)
|
||||
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]");
|
||||
}
|
||||
$result = temp;
|
||||
|
|
|
|||
|
|
@ -286,13 +286,13 @@
|
|||
/* directorout */
|
||||
|
||||
%typemap(directorout) SWIGTYPE ($<ype argp)
|
||||
"if ((SWIG_ConvertPtr($input, (void **)(&argp),
|
||||
"if (!$input || (SWIG_ConvertPtr($input, (void **)(&argp),
|
||||
$&descriptor, SWIG_POINTER_EXCEPTION | $disown)) == -1)
|
||||
throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");
|
||||
$result = *argp;";
|
||||
|
||||
%typemap(directorout) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
"if ((SWIG_ConvertPtr($input,(void **)(&$result),
|
||||
"if (!$input || (SWIG_ConvertPtr($input,(void **)(&$result),
|
||||
$descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1)
|
||||
throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
|
||||
|
||||
|
|
|
|||
|
|
@ -68,20 +68,22 @@
|
|||
/* directorout */
|
||||
|
||||
%define PYVAL_DIRECTOROUT_TYPEMAP(as_meth,pyfrag,Type...)
|
||||
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT {
|
||||
*$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||
if (PyErr_Occurred())
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
||||
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT {
|
||||
if ($input) *$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||
if (!$input || PyErr_Occurred())
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
||||
}
|
||||
%typemap(directorout,fragment=pyfrag) Type {
|
||||
$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||
if (PyErr_Occurred())
|
||||
if ($input) $result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||
if (!$input || PyErr_Occurred())
|
||||
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& {
|
||||
static $basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
|
||||
$result = &temp;
|
||||
if (PyErr_Occurred())
|
||||
if ($input) {
|
||||
static $basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
|
||||
$result = &temp;
|
||||
}
|
||||
if (!$input || PyErr_Occurred())
|
||||
throw Swig::DirectorTypeMismatchException("Error converting Python object using as_meth");
|
||||
}
|
||||
%typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@
|
|||
/* directorout */
|
||||
|
||||
%typemap(directorout) void * {
|
||||
if ((SWIG_ConvertPtr($input,(void **)(&$result),
|
||||
if (!$input || (SWIG_ConvertPtr($input,(void **)(&$result),
|
||||
0, SWIG_POINTER_EXCEPTION | $disown )) == -1)
|
||||
throw Swig::DirectorTypeMismatchException("Pointer conversion failed.");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue