securing the call to SWIG_IsOK, which is a macro
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@8131 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
769bd6a5a5
commit
7223672e09
10 changed files with 63 additions and 58 deletions
|
|
@ -1,7 +1,7 @@
|
|||
%include <std_common.i>
|
||||
%include <typemaps/implicit.swg>
|
||||
|
||||
#warning "This file provide the %implicit directive, which is an old and fragil"
|
||||
#warning "This file provides the %implicit directive, which is an old and fragile"
|
||||
#warning "way to implement the C++ implicit conversion mechanism."
|
||||
#warning "Try using the more robust '%implicitconv Type;' directive instead."
|
||||
|
||||
|
|
|
|||
|
|
@ -36,8 +36,7 @@ SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
|
|||
|
||||
/* long */
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header",
|
||||
fragment="<limits.h>") {
|
||||
%fragment(SWIG_From_frag(long),"header") {
|
||||
%define_as(SWIG_From_dec(long), PyInt_FromLong)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ namespace swig {
|
|||
struct traits_as<Type, value_category> {
|
||||
static Type as(PyObject *obj, bool throw_error) {
|
||||
Type v;
|
||||
if (!obj || !SWIG_IsOK(asval(obj, &v))) {
|
||||
int res = asval(obj, &v);
|
||||
if (!obj || !SWIG_IsOK(res)) {
|
||||
if (!PyErr_Occurred()) {
|
||||
%type_error(swig::type_name<Type>());
|
||||
}
|
||||
|
|
@ -161,20 +162,22 @@ namespace swig {
|
|||
|
||||
template <class Type>
|
||||
struct traits_check<Type, value_category> {
|
||||
static bool check(PyObject *obj) {
|
||||
return obj && SWIG_IsOK(asval(obj, (Type *)(0)));
|
||||
static int check(PyObject *obj) {
|
||||
int res = asval(obj, (Type *)(0));
|
||||
return obj && SWIG_IsOK(res) ? res : 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
struct traits_check<Type, pointer_category> {
|
||||
static bool check(PyObject *obj) {
|
||||
return obj && asptr(obj, (Type **)(0));
|
||||
static int check(PyObject *obj) {
|
||||
int res = asptr(obj, (Type **)(0));
|
||||
return obj && SWIG_IsOK(res) ? res : 0;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Type>
|
||||
inline bool check(PyObject *obj) {
|
||||
inline int check(PyObject *obj) {
|
||||
return traits_check<Type, typename traits<Type>::category>::check(obj);
|
||||
}
|
||||
}
|
||||
|
|
@ -232,8 +235,9 @@ namespace swig {
|
|||
|
||||
template <>
|
||||
struct traits_check<Type, value_category> {
|
||||
static bool check(PyObject *obj) {
|
||||
return obj && Check(obj);
|
||||
static int check(PyObject *obj) {
|
||||
int res = Check(obj);
|
||||
return obj && res ? res : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue