better error messages, more comments, clean up for the next major modifications

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@6284 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2004-10-02 01:43:17 +00:00
commit a4a7a2ff1f
25 changed files with 633 additions and 286 deletions

View file

@ -16,7 +16,7 @@ SWIGSTATIC(char**)
int list = PyList_Check(input);
if (list || PyTuple_Check(input)) {
*argc = list ? PyList_Size(input) : PyTuple_Size(input);
argv = swig_new_array(*argc + 1, char*);
argv = SWIG_new_array(*argc + 1, char*);
*owner = 1;
for (; i < *argc; ++i) {
PyObject *obj = list ? PyList_GetItem(input,i) : PyTuple_GetItem(input,i);
@ -53,7 +53,7 @@ SWIGSTATIC(char**)
char **argv = SWIG_AsArgcArgv($input, $descriptor(char**), &argc, &owner);
if (PyErr_Occurred()) {
$1 = 0; $2 = 0;
SWIG_fail;
if (SWIG_arg_fail($argnum)) SWIG_fail;
} else {
$1 = ($1_ltype) argc;
$2 = ($2_ltype) argv;
@ -61,6 +61,6 @@ SWIGSTATIC(char**)
}
%typemap(freearg) (int ARGC, char **ARGV) {
if (owner$argnum) swig_delete_array($2);
if (owner$argnum) SWIG_delete_array($2);
}

View file

@ -89,7 +89,7 @@
%define %cstring_bounded_mutable(TYPEMAP,MAX)
%typemap(in) TYPEMAP(char temp[MAX+1]) {
char *t = PyString_AsString($input);
if (PyErr_Occurred()) SWIG_fail;
if (SWIG_arg_fail($argnum)) SWIG_fail;
strncpy(temp,t,MAX);
$1 = ($1_ltype) temp;
}
@ -121,7 +121,7 @@
%typemap(in) TYPEMAP {
char *t = PyString_AsString($input);
int n = PyString_Size($input);
if (PyErr_Occurred()) SWIG_fail;
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = ($1_ltype) t;
#if #__VA_ARGS__ == ""
#if __cplusplus
@ -166,7 +166,7 @@
%define %cstring_output_maxsize(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE) {
$2 = PyInt_AsLong($input);
if (PyErr_Occurred()) SWIG_fail;
if (SWIG_arg_fail($argnum)) SWIG_fail;
#ifdef __cplusplus
$1 = ($1_ltype) new char[$2+1];
#else
@ -201,7 +201,7 @@
%define %cstring_output_withsize(TYPEMAP, SIZE)
%typemap(in) (TYPEMAP, SIZE) {
int n = PyInt_AsLong($input);
if (PyErr_Occurred()) SWIG_fail;
if (SWIG_arg_fail($argnum)) SWIG_fail;
#ifdef __cplusplus
$1 = ($1_ltype) new char[n+1];
$2 = ($2_ltype) new $*2_ltype;

View file

@ -11,6 +11,10 @@
#include <string>
extern "C" {
struct swig_type_info;
}
namespace Swig {
/* base class for director exceptions */
class DirectorException {
@ -31,7 +35,7 @@ namespace Swig {
DirectorTypeMismatchException(const char* msg="") {
swig_msg = "Swig director type mismatch: ";
swig_msg += msg;
PyErr_SetString(PyExc_TypeError, msg);
PyErr_SetString(PyExc_TypeError, getMessage());
}
};

View file

@ -15,5 +15,5 @@
#define SWIG_TypeQuery SWIG_Python_TypeQuery
#define SWIG_TypeClientData SWIG_Python_TypeClientData
#define SWIG_PackData SWIG_Python_PackData
#define SWIG_UnpackData SWIG_Python_UnpackData
#define SWIG_UnpackData SWIG_Python_UnpackData

View file

@ -41,7 +41,7 @@ SWIGSTATICINLINE(int)
}
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a Type is expected");
SWIG_type_error("Type", o);
}
return 0;
}
@ -64,8 +64,8 @@ SWIGSTATICINLINE(int)
double im = PyComplex_ImagAsDouble(o);
if (SWIG_CheckDoubleInRange(re, -FLT_MAX, FLT_MAX, errmsg)
&& SWIG_CheckDoubleInRange(im, -FLT_MAX, FLT_MAX, errmsg)) {
if (val) *val = Constructor(swig_numeric_cast(re, float),
swig_numeric_cast(im, float));
if (val) *val = Constructor(SWIG_numeric_cast(re, float),
SWIG_numeric_cast(im, float));
return 1;
} else {
return 0;
@ -74,7 +74,7 @@ SWIGSTATICINLINE(int)
double re;
if (SWIG_AsVal(double)(o, &re)) {
if (SWIG_CheckDoubleInRange(re, -FLT_MAX, FLT_MAX, errmsg)) {
if (val) *val = Constructor(swig_numeric_cast(re,float), 0);
if (val) *val = Constructor(SWIG_numeric_cast(re,float), 0);
return 1;
} else {
return 0;
@ -84,7 +84,7 @@ SWIGSTATICINLINE(int)
}
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a Type is expected");
SWIG_type_error("Type", o);
}
return 0;
}

View file

@ -119,8 +119,12 @@ namespace swigpy
try {
return swigpy::as<T>(item, true);
} catch (std::exception& e) {
PyErr_Format(PyExc_TypeError,
"error in sequence element %d: %s", _index, e.what());
char msg[1024];
sprintf(msg,"in sequence element %d", _index);
if (!PyErr_Occurred()) {
SWIG_type_error(swigpy::type_name<T>(), item);
}
SWIG_append_errmsg(msg);
throw;
}
}
@ -309,9 +313,10 @@ namespace swigpy
swigpy::PyObject_var item = PySequence_GetItem(_seq, i);
if (!swigpy::check<value_type>(item)) {
if (set_err) {
PyErr_Format(PyExc_TypeError,
"element %d is not of type '%s' as expected",
i, swigpy::type_name<value_type>());
char msg[1024];
sprintf(msg,"in sequence element %d", i);
SWIG_type_error(swigpy::type_name<value_type>(), item);
SWIG_append_errmsg(msg);
}
return 0;
}
@ -336,35 +341,40 @@ namespace swigpy
%exception __getitem__ {
try { $action }
catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
if (!PyErr_Occurred())
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception __setitem__ {
try { $action }
catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
if (!PyErr_Occurred())
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception __setslice__ {
try { $action }
catch (std::invalid_argument& e) {
SWIG_exception(SWIG_TypeError,const_cast<char*>(e.what()));
if (!PyErr_Occurred())
SWIG_exception(SWIG_TypeError,const_cast<char*>(e.what()));
}
}
%exception __delitem__ {
%exception __delitem__ {
try { $action }
catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
if (!PyErr_Occurred())
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}
%exception pop {
try { $action }
catch (std::out_of_range& e) {
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
if (!PyErr_Occurred())
SWIG_exception(SWIG_IndexError,const_cast<char*>(e.what()));
}
}

View file

@ -6,7 +6,7 @@
%typemap(varin,fragment=SWIG_AsVal_frag(int)) enum SWIGTYPE
{
if (sizeof(int) != sizeof($1)) {
PyErr_SetString(PyExc_TypeError, "enum variable '$name' can not be set");
PyErr_SetString(PyExc_AttributeError, "enum variable '$name' can not be set");
return 1;
}
if (!SWIG_AsVal(int)($input, (int*)(void*)&($1))) {

View file

@ -3,6 +3,8 @@
* ------------------------------------------------------------ */
%init %{
#ifdef __cplusplus
extern "C"
#endif
@ -12,6 +14,10 @@ SWIGEXPORT(void) SWIG_init(void) {
PyObject *m, *d;
int i;
if (!SWIG_globals) SWIG_globals = SWIG_newvarlink();
/* Fix SwigMethods to carry the callback ptrs when needed */
SWIG_Python_FixMethods(SwigMethods, swig_const_table, swig_types, swig_types_initial);
m = Py_InitModule((char *) SWIG_name, SwigMethods);
d = PyModule_GetDict(m);

View file

@ -52,7 +52,7 @@ or you can use the %apply directive :
%typemap(in,fragment=as_frag) Type *INPUT ($*1_ltype temp, int res = 0) {
if (!SWIG_CheckInputPtr($input,(void **)(&$1),$1_descriptor,$disown)) {
temp = as_meth($input);
if (PyErr_Occurred()) SWIG_fail;
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = &temp;
res = SWIG_NEWOBJ;
}
@ -60,11 +60,14 @@ or you can use the %apply directive :
%typemap(in,fragment=as_frag) Type &INPUT($*1_ltype temp, int res = 0) {
if (!SWIG_CheckInputPtr($input,(void **)(&$1),$1_descriptor,$disown)) {
temp = as_meth($input);
if (PyErr_Occurred()) SWIG_fail;
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = &temp;
res = SWIG_NEWOBJ;
}
if (!$1) SWIG_fail;
if (!$1) {
SWIG_null_ref(SWIG_TypePrettyName($1_descriptor));
}
if (SWIG_arg_fail($argnum)) SWIG_fail;
}
%typemap(typecheck,precedence=code,fragment=check_frag) Type *INPUT, Type &INPUT {
void *ptr;
@ -73,10 +76,29 @@ or you can use the %apply directive :
%enddef
%define _PYPTR_INPUT_TYPEMAP(code,asptr_meth,asptr_frag,Type)
%typemap(in,fragment=asptr_frag) Type *INPUT(int res = 0)
"if (!(res = asptr_meth($input, &$1))) SWIG_fail;";
%typemap(in,fragment=asptr_frag) Type &INPUT(int res = 0)
"if (!(res = asptr_meth($input, &$1)) || !($1)) SWIG_fail;";
%typemap(in,fragment=asptr_frag) Type *INPUT(int res = 0) {
res = asptr_meth($input, &$1);
if (!res) {
SWIG_type_error(SWIG_TypePrettyName($1_descriptor), $input);
} else {
if (!$1) {
SWIG_null_ref(SWIG_TypePrettyName($1_descriptor));
}
}
if (SWIG_arg_fail($argnum)) SWIG_fail;
}
%typemap(in,fragment=asptr_frag) Type &INPUT(int res = 0) {
res = asptr_meth($input, &$1);
if (!res) {
SWIG_type_error(SWIG_TypePrettyName($1_descriptor), $input);
} else {
if (!$1) {
SWIG_null_ref(SWIG_TypePrettyName($1_descriptor));
}
}
if (SWIG_arg_fail($argnum)) SWIG_fail;
}
%typemap(freearg) Type *INPUT, Type &INPUT
"if (res$argnum == SWIG_NEWOBJ) delete $1;";
%typemap(typecheck,precedence=code,fragment=asptr_frag) Type *INPUT, Type &INPUT

View file

@ -1,40 +1,71 @@
%{
/* Auxiliar swig macros that appear in the header */
/* -----------------------------------------------------------------------------
* Auxiliar swig macros that appear in the header
* ----------------------------------------------------------------------------- */
/*
for internal method declarations
*/
#ifdef __cplusplus
#define SWIGSTATICINLINE(a) static inline a
#define SWIGSTATIC(a) static a
#else /* C case */
#define SWIGSTATICINLINE(a) static a
#define SWIGSTATIC(a) static a
#endif /* __cplusplus */
/*
Alloc. memory flags
*/
#define SWIG_OLDOBJ 1
#define SWIG_NEWOBJ SWIG_OLDOBJ + 1
#define SWIG_PYSTR SWIG_NEWOBJ + 1
/*
swig internal C/C++ API
*/
#ifdef __cplusplus
#define SWIGSTATICINLINE(a) static inline a
#define SWIGSTATIC(a) static a
#define swig_new_array(size,Type) (new Type[(size)])
#define swig_delete(cptr) delete cptr
#define swig_delete_array(cptr) delete[] cptr
#define swig_const_cast(a,Type) const_cast<Type >(a)
#define swig_static_cast(a,Type) static_cast<Type >(a)
#define swig_reinterpret_cast(a,Type) reinterpret_cast<Type >(a)
#define swig_new_copy(ptr,Type) (new Type(*ptr))
#define swig_numeric_cast(a,Type) static_cast<Type >(a)
#define SWIG_new_array(size,Type) (new Type[(size)])
#define SWIG_delete(cptr) delete cptr
#define SWIG_delete_array(cptr) delete[] cptr
#define SWIG_const_cast(a,Type) const_cast<Type >(a)
#define SWIG_static_cast(a,Type) static_cast<Type >(a)
#define SWIG_reinterpret_cast(a,Type) reinterpret_cast<Type >(a)
#define SWIG_new_copy(ptr,Type) (new Type(*ptr))
#define SWIG_numeric_cast(a,Type) static_cast<Type >(a)
#else /* C case */
#define SWIGSTATICINLINE(a) static a
#define SWIGSTATIC(a) static a
#define swig_new_array(size,Type) ((Type*) malloc((size)*sizeof(Type)))
#define swig_delete(cptr) free((char*)cptr)
#define swig_delete_array(cptr) free((char*)cptr)
#define swig_const_cast(a,Type) (Type)(a)
#define swig_static_cast(a,Type) (Type)(a)
#define swig_reinterpret_cast(a,Type) (Type)(a)
#define swig_numeric_cast(a,Type) (Type)(a)
#define swig_new_copy(ptr,Type) ((Type*)memcpy(malloc(sizeof(Type)),ptr,sizeof(Type)))
#define SWIG_new_array(size,Type) ((Type*) malloc((size)*sizeof(Type)))
#define SWIG_delete(cptr) free((char*)cptr)
#define SWIG_delete_array(cptr) free((char*)cptr)
#define SWIG_const_cast(a,Type) (Type)(a)
#define SWIG_static_cast(a,Type) (Type)(a)
#define SWIG_reinterpret_cast(a,Type) (Type)(a)
#define SWIG_numeric_cast(a,Type) (Type)(a)
#define SWIG_new_copy(ptr,Type) ((Type*)memcpy(malloc(sizeof(Type)),ptr,sizeof(Type)))
#endif /* __cplusplus */
/*
Exception handling in wrappers
*/
#define SWIG_fail goto fail
#define SWIG_arg_fail(arg) SWIG_Python_ArgFail(arg)
#define SWIG_append_errmsg(msg) SWIG_Python_AddErrMesg(msg,0)
#define SWIG_preppend_errmsg(msg) SWIG_Python_AddErrMesg(msg,1)
#define SWIG_type_error(type,obj) SWIG_Python_TypeError(type,obj)
#define SWIG_null_ref(type) SWIG_Python_NullRef(type)
/*
Contract support
*/
#define SWIG_contract_assert(expr, msg) \
if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, (char *) msg ); goto fail; } else
%}
/* -----------------------------------------------------------------------------
* Auxiliar swig macros used to write typemaps
* ----------------------------------------------------------------------------- */
/* Auxiliar swig macros used to write typemaps */
#define SWIG_arg(...) __VA_ARGS__
#define SWIG_str(...) #__VA_ARGS__
@ -62,10 +93,12 @@
#define SWIG_CCode_frag(...) SWIG_StringType(TYPECHECK, __VA_ARGS__)
/* define a new macro */
%define SWIG_define(Def, Val)
%#define Def Val
%enddef
/* include C++ or C value */
%define SWIG_cplusplus(cppval, cval)
#if __cplusplus
cppval
@ -75,7 +108,6 @@ cval
%enddef
/* for loop for macro with one argument */
%define %_formacro_1(macro, arg1,...)
macro(arg1)
#if #__VA_ARGS__ != "__fordone__"
@ -83,12 +115,12 @@ macro(arg1)
#endif
%enddef
/* for loop for macro with one argument */
%define %formacro_1(macro,...)
%_formacro_1(macro,__VA_ARGS__,__fordone__)
%enddef
/* for loop for macro with two arguments */
%define %_formacro_2(macro, arg1, arg2, ...)
macro(arg1, arg2)
#if #__VA_ARGS__ != "__fordone__"
@ -96,6 +128,7 @@ macro(arg1, arg2)
#endif
%enddef
/* for loop for macro with two arguments */
%define %formacro_2(macro,...)
%_formacro_2(macro, __VA_ARGS__, __fordone__)
%enddef
@ -113,7 +146,6 @@ macro(arg1, arg2)
#define x 1
%enddef
/*
%swig_equal_type and %swig_order_type flagged a type of having equal (==,!=)
and/or order methods (<=,>=,<,>).

View file

@ -3,30 +3,62 @@
* ------------------------------------------------------------ */
#ifdef __cplusplus
%rename(__add__) *::operator+;
%rename(__pos__) *::operator+();
%rename(__pos__) *::operator+() const;
%rename(__sub__) *::operator-;
%rename(__neg__) *::operator-();
%rename(__neg__) *::operator-() const;
%rename(__mul__) *::operator*;
%rename(__div__) *::operator/;
%rename(__mod__) *::operator%;
%rename(__lshift__) *::operator<<;
%rename(__rshift__) *::operator>>;
%rename(__and__) *::operator&;
%rename(__or__) *::operator|;
%rename(__xor__) *::operator^;
%rename(__invert__) *::operator~;
%rename(__lt__) *::operator<;
%rename(__le__) *::operator<=;
%rename(__gt__) *::operator>;
%rename(__ge__) *::operator>=;
%rename(__eq__) *::operator==;
%rename(__ne__) *::operator!=;
%define %pybinoperator(pyname,oper)
%rename(pyname) oper;
%pythonmaybecall(1) oper;
%enddef
%pybinoperator(__add__, *::operator+);
%pybinoperator(__pos__, *::operator+());
%pybinoperator(__pos__, *::operator+() const);
%pybinoperator(__sub__, *::operator-);
%pybinoperator(__neg__, *::operator-());
%pybinoperator(__neg__, *::operator-() const);
%pybinoperator(__mul__, *::operator*);
%pybinoperator(__div__, *::operator/);
%pybinoperator(__mod__, *::operator%);
%pybinoperator(__lshift__, *::operator<<);
%pybinoperator(__rshift__, *::operator>>);
%pybinoperator(__and__, *::operator&);
%pybinoperator(__or__, *::operator|);
%pybinoperator(__xor__, *::operator^);
%pybinoperator(__lt__, *::operator<);
%pybinoperator(__le__, *::operator<=);
%pybinoperator(__gt__, *::operator>);
%pybinoperator(__ge__, *::operator>=);
%pybinoperator(__eq__, *::operator==);
%pybinoperator(__ne__, *::operator!=);
%define %pybinoperation(oper)
%pythonmaybecall(1) __ ## oper ## __;
%pythonmaybecall(1) __r ## oper ## __;
%enddef
%pybinoperation(add);
%pybinoperation(pos);
%pybinoperation(pos);
%pybinoperation(sub);
%pybinoperation(neg);
%pybinoperation(neg);
%pybinoperation(mul);
%pybinoperation(div);
%pybinoperation(mod);
%pybinoperation(lshift);
%pybinoperation(rshift);
%pybinoperation(and);
%pybinoperation(or);
%pybinoperation(xor);
%pybinoperation(lt);
%pybinoperation(le);
%pybinoperation(gt);
%pybinoperation(ge);
%pybinoperation(eq);
%pybinoperation(ne);
/* Special cases */
%rename(__call__) *::operator();
%rename(__invert__) *::operator~;
%rename(__call__) *::operator();
/* Ignored operators */
%ignorewarn("362:operator= ignored") operator=;

View file

@ -3,7 +3,7 @@
* ------------------------------------------------------------ */
/*
Define the SWIGAs/From methods for the basic types. In many
Define the SWIG_As/From methods for the basic types. In many
cases, these method are just aliases of the original python As/From
methods. In the other cases, some extra work is needed.
*/
@ -50,7 +50,7 @@
%fragment(SWIG_AsVal_frag(unsigned long),"header") {
SWIGSTATICINLINE(int)
SWIG_AsVal(unsigned long)(PyObject * obj, unsigned long *val)
SWIG_AsVal(unsigned long)(PyObject *obj, unsigned long *val)
{
if (PyInt_Check(obj)) {
long v = PyInt_AS_LONG(obj);
@ -70,7 +70,7 @@ SWIGSTATICINLINE(int)
}
}
if (val) {
PyErr_SetString(PyExc_TypeError, "an unsigned long is expected");
SWIG_type_error("unsigned long", obj);
}
return 0;
}
@ -144,7 +144,7 @@ SWIGSTATICINLINE(int)
}
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a double is expected");
SWIG_type_error("double", obj);
}
return 0;
}
@ -169,7 +169,7 @@ SWIGSTATICINLINE(int)
}
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a long is expected");
SWIG_type_error("long", obj);
}
return 0;
}
@ -183,7 +183,7 @@ SWIGSTATICINLINE(PyObject* )
{
return ((value < LONG_MIN) || (value > LONG_MAX)) ?
PyLong_FromLongLong(value)
: PyInt_FromLong(swig_numeric_cast(value,long));
: PyInt_FromLong(SWIG_numeric_cast(value,long));
}
}
@ -195,7 +195,7 @@ SWIGSTATICINLINE(PyObject* )
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLongLong(value) :
PyInt_FromLong(swig_numeric_cast(value,long));
PyInt_FromLong(SWIG_numeric_cast(value,long));
}
}
@ -218,7 +218,7 @@ SWIGSTATICINLINE(int)
return 1;
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a long long is expected");
SWIG_type_error("long long", obj);
}
return 0;
}
@ -247,7 +247,7 @@ SWIGSTATICINLINE(int)
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError, "an unsigned long long is expected");
SWIG_type_error("unsigned long long", obj);
}
return 0;
}
@ -259,7 +259,7 @@ SWIGSTATICINLINE(PyObject* )
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLong(value)
: PyInt_FromLong(swig_numeric_cast(value,long));
: PyInt_FromLong(SWIG_numeric_cast(value,long));
}
}
@ -273,7 +273,7 @@ SWIGSTATICINLINE(int)
long v;
if (SWIG_AsVal(long)(obj, &v)) {
if (SWIG_CheckLongInRange(v, SCHAR_MIN, SCHAR_MAX, errmsg)) {
if (val) *val = swig_numeric_cast(v, signed char);
if (val) *val = SWIG_numeric_cast(v, signed char);
return 1;
} else {
return 0;
@ -282,7 +282,7 @@ SWIGSTATICINLINE(int)
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a signed char is expected");
SWIG_type_error(errmsg, obj);
}
return 0;
}
@ -298,7 +298,7 @@ SWIGSTATICINLINE(int)
long v;
if (SWIG_AsVal(long)(obj, &v)) {
if (SWIG_CheckLongInRange(v, SHRT_MIN, SHRT_MAX, errmsg)) {
if (val) *val = swig_numeric_cast(v, short);
if (val) *val = SWIG_numeric_cast(v, short);
return 1;
} else {
return 0;
@ -307,7 +307,7 @@ SWIGSTATICINLINE(int)
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a short is expected");
SWIG_type_error(errmsg, obj);
}
return 0;
}
@ -326,7 +326,7 @@ SWIGSTATICINLINE(int)
long v;
if (SWIG_AsVal(long)(obj, &v)) {
if (SWIG_CheckLongInRange(v, INT_MIN,INT_MAX, errmsg)) {
if (val) *val = swig_numeric_cast(v, int);
if (val) *val = SWIG_numeric_cast(v, int);
return 1;
} else {
return 0;
@ -335,7 +335,7 @@ SWIGSTATICINLINE(int)
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError, "an int is expected");
SWIG_type_error(errmsg, obj);
}
return 0;
}
@ -359,14 +359,14 @@ SWIGSTATICINLINE(int)
unsigned long v;
if (SWIG_AsVal(unsigned long)(obj, &v)) {
if (SWIG_CheckUnsignedLongInRange(v, INT_MAX, errmsg)) {
if (val) *val = swig_numeric_cast(v, unsigned int);
if (val) *val = SWIG_numeric_cast(v, unsigned int);
return 1;
}
} else {
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError, "an unsigned int is expected");
SWIG_type_error(errmsg, obj);
}
return 0;
}
@ -399,7 +399,7 @@ SWIGSTATICINLINE(int)
unsigned long v;
if (SWIG_AsVal(unsigned long)(obj, &v)) {
if (SWIG_CheckUnsignedLongInRange(v, UCHAR_MAX,errmsg)) {
if (val) *val = swig_numeric_cast(v, unsigned char);
if (val) *val = SWIG_numeric_cast(v, unsigned char);
return 1;
} else {
return 0;
@ -408,7 +408,7 @@ SWIGSTATICINLINE(int)
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError, "an unsigned char is expected");
SWIG_type_error(errmsg, obj);
}
return 0;
}
@ -424,7 +424,7 @@ SWIGSTATICINLINE(int)
unsigned long v;
if (SWIG_AsVal(unsigned long)(obj, &v)) {
if (SWIG_CheckUnsignedLongInRange(v, USHRT_MAX, errmsg)) {
if (val) *val = swig_numeric_cast(v, unsigned short);
if (val) *val = SWIG_numeric_cast(v, unsigned short);
return 1;
} else {
return 0;
@ -433,7 +433,7 @@ SWIGSTATICINLINE(int)
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError, "an unsigned short is expected");
SWIG_type_error(errmsg, obj);
}
return 0;
}
@ -484,7 +484,7 @@ SWIGSTATICINLINE(int)
PyErr_Clear();
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a float is expected");
SWIG_type_error(errmsg, obj);
}
return 0;
}
@ -583,7 +583,7 @@ SWIGSTATICINLINE(int)
return 1;
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a bool is expected");
SWIG_type_error("bool", obj);
}
return 0;
}

View file

@ -9,12 +9,28 @@
%typemap(in,fragment=pyfrag) __VA_ARGS__ {
__VA_ARGS__ *ptr = (__VA_ARGS__ *)0;
int res = asptr_meth($input, &ptr);
if (!res || !ptr) SWIG_fail;
if (!res) {
if (!PyErr_Occurred())
SWIG_type_error(SWIG_TypePrettyName($&1_descriptor), $input);
} else if (!ptr) {
SWIG_null_ref(SWIG_TypePrettyName($&1_descriptor));
}
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = *ptr;
if (res == SWIG_NEWOBJ) delete ptr;
}
%typemap(in,fragment=pyfrag) const __VA_ARGS__ & (int res = 0)
"if (!(res = asptr_meth($input, &$1)) || !($1)) SWIG_fail;";
%typemap(in,fragment=pyfrag) const __VA_ARGS__ & (int res = 0) {
__VA_ARGS__ *ptr = (__VA_ARGS__ *)0;
res = asptr_meth($input, &ptr);
if (!res) {
if (!PyErr_Occurred())
SWIG_type_error(SWIG_TypePrettyName($1_descriptor), $input);
} else if (!ptr) {
SWIG_null_ref(SWIG_TypePrettyName($1_descriptor));
}
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = ptr;
}
%typemap(freearg) const __VA_ARGS__ &
"if (res$argnum == SWIG_NEWOBJ) delete $1;";
@ -26,8 +42,14 @@
%typemap(varin,fragment=pyfrag) __VA_ARGS__ {
__VA_ARGS__ *ptr = (__VA_ARGS__ *)0;
int res = asptr_meth($input, &ptr);
if (!res || !ptr) {
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
if (!res) {
if (!PyErr_Occurred())
SWIG_type_error(SWIG_TypePrettyName($1_descriptor), $input);
SWIG_append_msg(" C/C++ variable '$name'");
return 1;
} else if (!ptr) {
SWIG_null_ref(SWIG_TypePrettyName($1_descriptor));
SWIG_append_msg(" C/C++ variable '$name'");
return 1;
}
$1 = *ptr;

View file

@ -12,24 +12,17 @@
extern "C" {
#endif
/* -----------------------------------------------------------------------------
* Constant declarations
* ----------------------------------------------------------------------------- */
/* Constant Types */
#define SWIG_PY_INT 1
#define SWIG_PY_FLOAT 2
#define SWIG_PY_STRING 3
#define SWIG_PY_POINTER 4
#define SWIG_PY_BINARY 5
/* Flags for pointer conversion */
#define SWIG_POINTER_EXCEPTION 0x1
#define SWIG_POINTER_DISOWN 0x2
/* Exception handling in wrappers */
#define SWIG_fail goto fail
#ifndef SWIG_NO_COBJECT_TYPES
#define SWIG_COBJECT_TYPES
#endif
/* Constant information structure */
typedef struct swig_const_info {
int type;
@ -40,42 +33,67 @@ typedef struct swig_const_info {
swig_type_info **ptype;
} swig_const_info;
/* -----------------------------------------------------------------------------
* Pointer declarations
* ----------------------------------------------------------------------------- */
/*
Use SWIG_NO_COBJECT_TYPES to force the use of strings to represent
C/C++ pointers in the python side. Very useful for debugging, but
not always safe.
*/
#if !defined(SWIG_NO_COBJECT_TYPES) && !defined(SWIG_COBJECT_TYPES)
#define SWIG_COBJECT_TYPES
#endif
/* Flags for pointer conversion */
#define SWIG_POINTER_EXCEPTION 0x1
#define SWIG_POINTER_DISOWN 0x2
/* -----------------------------------------------------------------------------
* SWIG API.
* ----------------------------------------------------------------------------- */
/* Common SWIG API */
#define SWIG_ConvertPtr(obj, pp, type, flags) \
SWIG_Python_ConvertPtr(obj, pp, type, flags)
#define SWIG_NewPointerObj(p, type, flags) \
SWIG_Python_NewPointerObj(p, type, flags)
#define SWIG_MustGetPtr(p, type, argnum, flags) \
SWIG_Python_MustGetPtr(p, type, argnum, flags)
#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Python_ConvertPtr(obj, pp, type, flags)
#define SWIG_NewPointerObj(p, type, flags) SWIG_Python_NewPointerObj(p, type, flags)
#define SWIG_MustGetPtr(p, type, argnum, flags) SWIG_Python_MustGetPtr(p, type, argnum, flags)
/* Python-specific SWIG API */
#define SWIG_newvarlink() \
SWIG_Python_newvarlink()
#define SWIG_addvarlink(p, name, get_attr, set_attr) \
SWIG_Python_addvarlink(p, name, get_attr, set_attr)
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) \
SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)
#define SWIG_NewPackedObj(ptr, sz, type) \
SWIG_Python_NewPackedObj(ptr, sz, type)
#define SWIG_InstallConstants(d, constants) \
SWIG_Python_InstallConstants(d, constants)
#define SWIG_newvarlink() SWIG_Python_newvarlink()
#define SWIG_addvarlink(p, name, get_attr, set_attr) SWIG_Python_addvarlink(p, name, get_attr, set_attr)
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)
#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)
#define SWIG_InstallConstants(d, constants) SWIG_Python_InstallConstants(d, constants)
typedef double (*py_objasdbl_conv)(PyObject *obj);
#ifdef SWIG_NOINCLUDE
SWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int);
SWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own);
SWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info *, int, int);
SWIGIMPORT(PyObject *) SWIG_Python_newvarlink(void);
SWIGIMPORT(void) SWIG_Python_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *));
SWIGIMPORT(int) SWIG_Python_ConvertPacked(PyObject *, void *, size_t sz, swig_type_info *, int);
SWIGIMPORT(PyObject *) SWIG_Python_NewPackedObj(void *, size_t sz, swig_type_info *);
SWIGIMPORT(void) SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]);
/* -----------------------------------------------------------------------------
* SWIG extern declarations
* ----------------------------------------------------------------------------- */
#else
SWIGIMPORT(int) SWIG_Python_ConvertPtr(PyObject *, void **, swig_type_info *, int);
SWIGIMPORT(PyObject *) SWIG_Python_NewPointerObj(void *, swig_type_info *,int own);
SWIGIMPORT(void *) SWIG_Python_MustGetPtr(PyObject *, swig_type_info *, int, int);
SWIGIMPORT(PyObject *) SWIG_Python_newvarlink(void);
SWIGIMPORT(void) SWIG_Python_addvarlink(PyObject *, char *, PyObject *(*)(void), int (*)(PyObject *));
SWIGIMPORT(int) SWIG_Python_ConvertPacked(PyObject *, void *, size_t sz, swig_type_info *, int);
SWIGIMPORT(PyObject *) SWIG_Python_NewPackedObj(void *, size_t sz, swig_type_info *);
SWIGIMPORT(void) SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]);
SWIGIMPORT(char *) SWIG_Python_PointerStr(char *buff, void *ptr, const char *name, size_t bsz);
SWIGIMPORT(void) SWIG_Python_FixMethods(PyMethodDef *methods,
swig_const_info *const_table,
swig_type_info **types,
swig_type_info **types_initial);
SWIGIMPORT(int) SWIG_Python_AddErrMesg(const char* mesg, int infront);
SWIGIMPORT(int) SWIG_Python_ArgFail(int argnum);
SWIGIMPORT(void) SWIG_Python_TypeError(const char *type, PyObject *obj);
SWIGIMPORT(void) SWIG_Python_NullRef(const char *type);
#else /* SWIG_NOINCLUDE */
/* -----------------------------------------------------------------------------
* global variable support code.
@ -226,6 +244,79 @@ SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int
v->vars = gv;
}
/* -----------------------------------------------------------------------------
* errors manipulation
* ----------------------------------------------------------------------------- */
SWIGRUNTIME(void)
SWIG_Python_TypeError(const char *type, PyObject *obj)
{
const char *otype = (obj ? obj->ob_type->tp_name : 0);
if (type) {
if (otype) {
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
type, otype);
} else {
PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
}
} else {
PyErr_Format(PyExc_TypeError, "unexpected type is received");
}
}
SWIGRUNTIME(void)
SWIG_Python_NullRef(const char *type)
{
if (type) {
PyErr_Format(PyExc_TypeError, "null reference of type '%s' was received",type);
} else {
PyErr_Format(PyExc_TypeError, "null reference was received");
}
}
/* add information about failing argument */
SWIGRUNTIME(int)
SWIG_Python_AddErrMesg(const char* mesg, int infront)
{
if (PyErr_Occurred()) {
PyObject *type = 0;
PyObject *value = 0;
PyObject *traceback = 0;
PyErr_Fetch(&type, &value, &traceback);
if (value) {
PyObject *old_str = PyObject_Str(value);
Py_XINCREF(type);
PyErr_Clear();
if (infront) {
PyErr_Format(type, "%s %s", mesg, PyString_AsString(old_str));
} else {
PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg);
}
Py_DECREF(old_str);
}
return 1;
} else {
return 0;
}
}
SWIGRUNTIME(int)
SWIG_Python_ArgFail(int argnum)
{
if (PyErr_Occurred()) {
char mesg[256];
sprintf(mesg, "argument number %d:", argnum);
return SWIG_Python_AddErrMesg(mesg, 1);
} else {
return 0;
}
}
/* -----------------------------------------------------------------------------
* pointers/data manipulation
* ----------------------------------------------------------------------------- */
/* Convert a pointer value */
SWIGRUNTIME(int)
SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags) {
@ -240,6 +331,20 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
*ptr = 0;
return 0;
}
if (PyCFunction_Check(obj)) {
/* here we get the method pointer for callbacks.*/
c = strstr((((PyCFunctionObject *)obj) -> m_ml -> ml_doc), "swig_ptr: ");
if (c) {
c += 10;
if (*c == '_') {
c++;
c = SWIG_UnpackData(c,ptr,sizeof(void *));
goto type_check;
}
}
goto type_error;
}
#ifdef SWIG_COBJECT_TYPES
if (!(PyCObject_Check(obj))) {
if (!SWIG_this)
@ -256,7 +361,7 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
*ptr = PyCObject_AsVoidPtr(obj);
c = (char *) PyCObject_GetDesc(obj);
if (newref) Py_DECREF(obj);
goto cobject;
goto type_check;
#else
if (!(PyString_Check(obj))) {
if (!SWIG_this)
@ -287,9 +392,7 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
if (newref) { Py_DECREF(obj); }
#endif
#ifdef SWIG_COBJECT_TYPES
cobject:
#endif
type_check:
if (ty) {
tc = SWIG_TypeCheck(c,ty);
@ -305,12 +408,10 @@ cobject:
type_error:
PyErr_Clear();
if (flags & SWIG_POINTER_EXCEPTION) {
if (ty && c) {
PyErr_Format(PyExc_TypeError,
"Type error. Got '%s', expected '%s'",
c, SWIG_TypePrettyName(ty));
if (ty) {
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
} else {
PyErr_SetString(PyExc_TypeError,"Expected a pointer");
SWIG_Python_TypeError("C/C++ pointer", obj);
}
}
return -1;
@ -321,11 +422,10 @@ SWIGRUNTIME(void *)
SWIG_Python_MustGetPtr(PyObject *obj, swig_type_info *ty, int argnum, int flags) {
void *result;
if (SWIG_Python_ConvertPtr(obj, &result, ty, flags) == -1) {
PyErr_Clear();
if (flags & SWIG_POINTER_EXCEPTION) {
PyErr_Clear();
PyErr_Format(PyExc_TypeError,
"Type error in argument %i: expected a pointer of type '%s'.",
argnum, SWIG_TypePrettyName(ty));
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
SWIG_Python_ArgFail(argnum);
}
}
return result;
@ -350,19 +450,30 @@ SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *t
return 0;
type_error:
if (flags) {
if (ty && c) {
PyErr_Format(PyExc_TypeError,
"Type error. Got '%s', expected '%s'",
c, SWIG_TypePrettyName(ty));
PyErr_Clear();
if (flags & SWIG_POINTER_EXCEPTION) {
if (ty) {
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
} else {
PyErr_SetString(PyExc_TypeError,"Expected a pointer");
SWIG_Python_TypeError("C/C++ packed data", obj);
}
}
return -1;
}
/* Create a new pointer string */
SWIGRUNTIME(char *)
SWIG_Python_PointerStr(char *buff, void *ptr, const char *name, size_t bsz) {
char *r = buff;
if ((2*sizeof(void *) + 2) > bsz) return 0;
*(r++) = '_';
r = SWIG_PackData(r,&ptr,sizeof(void *));
if (strlen(name) + 1 > (bsz - (r - buff))) return 0;
strcpy(r,name);
return buff;
}
/* Create a new pointer object */
SWIGRUNTIME(PyObject *)
SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {
@ -376,10 +487,7 @@ SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {
#else
{
char result[1024];
char *r = result;
*(r++) = '_';
r = SWIG_PackData(r,&ptr,sizeof(void *));
strcpy(r,type->name);
SWIG_Python_PointerStr(result, ptr, type->name, 1024);
robj = PyString_FromString(result);
}
#endif
@ -404,13 +512,18 @@ SWIGRUNTIME(PyObject *)
SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
char result[1024];
char *r = result;
if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
if ((2*sz + 2 + strlen(type->name)) > 1024) return 0;
*(r++) = '_';
r = SWIG_PackData(r,ptr,sz);
strcpy(r,type->name);
return PyString_FromString(result);
}
/* -----------------------------------------------------------------------------
* constants/methods manipulation
* ----------------------------------------------------------------------------- */
/* Install Constants */
SWIGRUNTIME(void)
SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
@ -449,11 +562,47 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
}
}
#endif
/* Fix SwigMethods to carry the callback ptrs when needed */
SWIGRUNTIME(void)
SWIG_Python_FixMethods(PyMethodDef *methods,
swig_const_info *const_table,
swig_type_info **types,
swig_type_info **types_initial) {
int i;
for (i = 0; methods[i].ml_name; ++i) {
char *c = methods[i].ml_doc;
if (c && (c = strstr(c, "swig_ptr: "))) {
int j;
swig_const_info *ci = 0;
char *name = c + 10;
for (j = 0; const_table[j].type; j++) {
if (strncmp(const_table[j].name, name,
strlen(const_table[j].name)) == 0) {
ci = &(const_table[j]);
break;
}
}
if (ci) {
size_t shift = (ci->ptype) - types;
swig_type_info *ty = types_initial[shift];
size_t ldoc = (c - methods[i].ml_doc);
size_t lptr = strlen(ty->name)+2*sizeof(void*)+2;
char *ndoc = (char*)malloc(ldoc + lptr + 10);
char *buff = ndoc;
void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue: (void *)(ci->lvalue);
strncpy(buff, methods[i].ml_doc, ldoc);
buff += ldoc;
strncpy(buff, "swig_ptr: ", 10);
buff += 10;
SWIG_Python_PointerStr(buff, ptr, ty->name, lptr);
methods[i].ml_doc = ndoc;
}
}
}
}
/* Contract support */
#endif /* SWIG_NOINCLUDE */
#define SWIG_contract_assert(expr, msg) if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, (char *) msg ); goto fail; } else
#ifdef __cplusplus
}

View file

@ -28,13 +28,13 @@
%typemap(in,fragment=#SWIG_AsCharPtr)
Char *, Char const*, Char *const, Char const *const
"if (!SWIG_AsCharPtr($input, (Char**)&$1)) SWIG_fail;";
"if (!SWIG_AsCharPtr($input, (Char**)&$1)) {SWIG_arg_fail($argnum);SWIG_fail;}";
%typemap(in,fragment=#SWIG_AsCharPtr)
Char const*&, Char *const&, Char const *const &
{
$*ltype temp;
if (!SWIG_AsCharPtr($input, (Char**)&temp)) SWIG_fail;
if (!SWIG_AsCharPtr($input, (Char**)&temp)) {SWIG_arg_fail($argnum);SWIG_fail;}
$1 = &temp;
}
@ -54,11 +54,10 @@
{
Char *cptr = 0;
if (!SWIG_AsNewCharPtr($input, &cptr)) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
if ($1) swig_delete_array($1);
if ($1) SWIG_delete_array($1);
$1 = cptr;
}
@ -68,8 +67,7 @@
{
Char *cptr;
if (!SWIG_AsNewCharPtr($input, &cptr)) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
$1 = cptr;
@ -142,7 +140,7 @@
%typemap(varin,fragment=#SWIG_AsCharArray,
warning="462:Unable to set variable of type Char []") Char []
{
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name' is read-only");
PyErr_SetString(PyExc_AttributeError, "C/C++ variable '$name' is read-only");
return 1;
}
@ -171,7 +169,7 @@
Char [ANY] (Char temp[$1_dim0]),
const Char [ANY](Char temp[$1_dim0])
{
if (!SWIG_AsCharArray($input, temp, $1_dim0)) SWIG_fail;
if (!SWIG_AsCharArray($input, temp, $1_dim0)) {SWIG_arg_fail($argnum);SWIG_fail;}
$1 = temp;
}
@ -190,8 +188,7 @@
%typemap(varin,fragment=#SWIG_AsCharArray) Char [ANY]
{
if (!SWIG_AsCharArray($input, $1, $1_dim0)) {
PyErr_Clear();
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
}
@ -312,7 +309,7 @@
(Char *STRING, int LENGTH) (Char *buf, size_t size)
{
int res = SWIG_AsCharPtrAndSize($input, &buf, &size);
if (!res) SWIG_fail;
if (!res) {SWIG_arg_fail($argnum);SWIG_fail;}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) size - 1;
}
@ -321,7 +318,7 @@
%typemap(in,fragment=#SWIG_AsCharPtrAndSize)
(Char *STRING, int SIZE) (Char *buf, size_t size)
{
if (!SWIG_AsCharPtrAndSize($input, &buf, &size)) SWIG_fail;
if (!SWIG_AsCharPtrAndSize($input, &buf, &size)) {SWIG_arg_fail($argnum);SWIG_fail;}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) size;
}

View file

@ -17,6 +17,7 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize)
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
return SWIG_OLDOBJ;
} else {
PyErr_Clear();
if (PyString_Check(obj)) {
if (cptr) {
*cptr = PyString_AS_STRING(obj);
@ -28,7 +29,7 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize)
}
}
if (cptr) {
PyErr_SetString(PyExc_TypeError, "a string is expected");
SWIG_type_error("char *", obj);
}
return 0;
}
@ -45,7 +46,7 @@ SWIG_AsCharPtr(PyObject *obj, char **val)
return 1;
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a char* is expected");
SWIG_type_error("char *", obj);
}
return 0;
}
@ -58,7 +59,7 @@ SWIG_FromCharPtr(const char* cptr)
if (cptr) {
size_t size = strlen(cptr);
if (size > INT_MAX) {
return SWIG_NewPointerObj(swig_const_cast(cptr,char*),
return SWIG_NewPointerObj(SWIG_const_cast(cptr,char*),
SWIG_TypeQuery("char *"), 0);
} else {
if (size != 0) {
@ -83,11 +84,11 @@ SWIG_AsNewCharPtr(PyObject *obj, char **val)
if (res) {
if (val) {
if (csize) {
*val = swig_new_array(csize, char);
*val = SWIG_new_array(csize, char);
memcpy(*val, cptr, --csize);
(*val)[csize] = 0;
} else if (cptr) {
*val = swig_new_array(1, char);
*val = SWIG_new_array(1, char);
(*val)[0] = 0;
} else {
*val = 0;
@ -96,7 +97,7 @@ SWIG_AsNewCharPtr(PyObject *obj, char **val)
return SWIG_NEWOBJ;
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a char* is expected");
SWIG_type_error("char *", obj);
}
return 0;
}
@ -125,8 +126,8 @@ SWIG_AsCharArray(PyObject *obj, char *val, size_t size)
}
}
if (val) {
PyErr_Format(PyExc_TypeError,
"a char array of maximum size %lud is expected",
PyErr_Format(PyExc_TypeError,
"a char array of maximum size %lu is expected",
(unsigned long) size);
}
return 0;
@ -138,10 +139,10 @@ SWIGSTATICINLINE(PyObject *)
SWIG_FromCharArray(const char* carray, size_t size)
{
if (size > INT_MAX) {
SWIG_NewPointerObj(swig_const_cast(carray,char*), SWIG_TypeQuery("char *"), 0);
SWIG_NewPointerObj(SWIG_const_cast(carray,char*), SWIG_TypeQuery("char *"), 0);
return Py_None;
} else {
return PyString_FromStringAndSize(carray, swig_numeric_cast(size,int));
return PyString_FromStringAndSize(carray, SWIG_numeric_cast(size,int));
}
}
}

View file

@ -5,33 +5,39 @@
/* Pointers, references, and arrays */
%typemap(in) SWIGTYPE *, SWIGTYPE []
"$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, SWIG_POINTER_EXCEPTION | $disown);
if (PyErr_Occurred()) SWIG_fail;";
"SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | $disown);
if (SWIG_arg_fail($argnum)) SWIG_fail;";
%typemap(in) SWIGTYPE *DISOWN
"$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN);
if (PyErr_Occurred()) SWIG_fail;";
"SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN);
if (SWIG_arg_fail($argnum)) SWIG_fail;";
/* Additional check for null references */
%typemap(in) SWIGTYPE &
"$1 = ($1_ltype)SWIG_MustGetPtr($input, $descriptor, $argnum, SWIG_POINTER_EXCEPTION | $disown);
if (PyErr_Occurred()) SWIG_fail;
"SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | $disown);
if (SWIG_arg_fail($argnum)) SWIG_fail;
if ($1 == NULL) {
PyErr_SetString(PyExc_TypeError,\"null reference\");
SWIG_fail;
}";
SWIG_null_ref(SWIG_TypePrettyName($descriptor));
}
if (SWIG_arg_fail($argnum)) SWIG_fail;";
/* Object passed by value. Convert to a pointer */
%typemap(in) SWIGTYPE ($&1_ltype argp)
"if ((SWIG_ConvertPtr($input,(void **)(&argp),$&1_descriptor,
SWIG_POINTER_EXCEPTION) == -1)) SWIG_fail;
%typemap(in) SWIGTYPE ($&ltype argp)
"SWIG_Python_ConvertPtr($input, (void **)&argp, $&descriptor, SWIG_POINTER_EXCEPTION);
if (SWIG_arg_fail($argnum)) SWIG_fail;
if (argp == NULL) {
SWIG_null_ref(SWIG_TypePrettyName($descriptor));
}
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = *argp;";
/* Pointer to a class member */
%typemap(in) SWIGTYPE (CLASS::*)
"if ((SWIG_ConvertPacked($input,(void *)(&$1),sizeof($1_type),
$1_descriptor,SWIG_POINTER_EXCEPTION)) == -1)
SWIG_fail;";
"if ((SWIG_ConvertPacked($input,(void *)(&$1),sizeof($type),$descriptor,0)) == -1) {
SWIG_type_error(SWIG_TypePrettyName($descriptor),$input);
}
if (SWIG_arg_fail($argnum)) SWIG_fail;
";
/* -----------------------------------------------------------------------------
@ -82,9 +88,9 @@
%typemap(varin) SWIGTYPE [ANY] {
void *temp;
size_t ii;
$1_basetype *b = 0;
if ((SWIG_ConvertPtr($input, &temp, $1_descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
$basetype *b = 0;
if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
b = ($1_basetype *) $1;
@ -94,38 +100,38 @@
%typemap(varin) SWIGTYPE * {
void *temp;
if ((SWIG_ConvertPtr($input, &temp, $1_descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) {
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
$1 = ($1_ltype) temp;
$1 = ($ltype) temp;
}
%typemap(varin) SWIGTYPE & {
void *temp;
if ((SWIG_ConvertPtr($input, &temp, $1_descriptor, SWIG_POINTER_EXCEPTION)) == -1 || temp == NULL) {
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION)) == -1 || temp == NULL) {
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
$1 = *($1_ltype) temp;
$1 = *($ltype) temp;
}
%typemap(varin) SWIGTYPE (CLASS::*) {
char temp[sizeof($1_type)];
char temp[sizeof($type)];
if ((SWIG_ConvertPacked($input,(void *) temp, sizeof($1_type), $1_descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
memmove((void *) &$1,temp,sizeof($1_type));
memmove((void *) &$1,temp,sizeof($type));
}
%typemap(varin) SWIGTYPE {
$&1_ltype temp;
if ((SWIG_ConvertPtr($input, (void **)(&temp), $&1_descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
$&ltype temp;
if ((SWIG_ConvertPtr($input, (void **)(&temp), $&descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
$1 = *(($&1_type) temp);
$1 = *(($&type) temp);
}
/* -----------------------------------------------------------------------------
@ -155,10 +161,10 @@
/* Pointers, arrays, objects */
%typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
{ SWIG_PY_POINTER, (char*)"$symname", 0, 0, (void *)$value, &$1_descriptor}
{ SWIG_PY_POINTER, (char*)"$symname", 0, 0, (void *)$value, &$descriptor}
%typemap(consttab) SWIGTYPE (CLASS::*)
{ SWIG_PY_BINARY, (char *)"$symname", sizeof($type), 0, (void *)&$value, &$1_descriptor}
{ SWIG_PY_BINARY, (char *)"$symname", sizeof($type), 0, (void *)&$value, &$descriptor}
/* -----------------------------------------------------------------------------
@ -188,7 +194,7 @@
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
{
void *ptr;
if (SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0) == -1) {
if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0) == -1) {
$1 = 0;
PyErr_Clear();
} else {
@ -199,7 +205,7 @@
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
{
void *ptr;
if (SWIG_ConvertPtr($input, &ptr, $&1_descriptor, 0) == -1) {
if (SWIG_ConvertPtr($input, &ptr, $&descriptor, 0) == -1) {
$1 = 0;
PyErr_Clear();
} else {

View file

@ -4,6 +4,15 @@
* Python configuration module.
* ----------------------------------------------------------------------------- */
/*
bool type in python is too much generic, we invert order for proper
resolution.
*/
#undef SWIG_TYPECHECK_BOOL
%define SWIG_TYPECHECK_BOOL 10000 %enddef
/* -----------------------------------------------------------------------------
* The runtime part
* ----------------------------------------------------------------------------- */
@ -53,3 +62,5 @@
* The Python initialization function
* ------------------------------------------------------------ */
%include <pyinit.swg>

View file

@ -54,3 +54,60 @@ or the inverse form
#define %pythonnondynamic(FLAG) %feature("python:nondynamic", #FLAG)
#define %pythondynamic(FLAG) %pythonnondynamic(!FLAG)
/*
Use %pythonmaybecall to flag a method like __add__ or __radd__, which
don't produce an error when called, they just return NotImplemented.
These methods "may be called" if needed.
*/
%define %pythonmaybecall(FLAG) %feature("python:maybecall",#FLAG) %enddef
/*
The %pythoncallback feature produce a more natural callback wrap
than the %callback mechanism, ie, it use the original name for
the callback and callable objects.
Just use it as
%pythoncallback(1) foo;
int foo(int a);
%pythoncallback(1) A::foo;
struct A {
static int foo(int a);
};
int bar(int, int (*pf)(int));
then, you can use it as:
a = foo(1)
b = bar(2, foo)
c = A.foo(3)
d = bar(4, A.foo)
If you use it with a member method
%pythoncallback(1) A::foom;
struct A {
int foom(int a);
};
then you can use it as
r = a.foom(3) # eval the method
mptr = A.foom_cb_ptr # returns the callback pointer
where the '_cb_ptr' termination is added for the callback pointer.
*/
%define %pythoncallback(FLAG) %feature("python:callback",#FLAG) %enddef
%define %nopythoncallback %feature("python:callback","") %enddef

View file

@ -9,10 +9,10 @@
%define PYVAL_IN_TYPEMAP(as_meth,pyfrag,...)
%typemap(in,fragment=pyfrag) __VA_ARGS__
"$1 = ($ltype)as_meth($input);
if (PyErr_Occurred()) SWIG_fail;";
if (SWIG_arg_fail($argnum)) SWIG_fail;";
%typemap(in,fragment=pyfrag) const __VA_ARGS__ & ($basetype temp)
"temp = ($basetype) as_meth($input);
if (PyErr_Occurred()) SWIG_fail;
if (SWIG_arg_fail($argnum)) SWIG_fail;
$1 = &temp;";
%enddef
@ -31,7 +31,7 @@
%typemap(varin,fragment=pyfrag) __VA_ARGS__ {
$1_type temp = ($1_type) as_meth($input);
if (PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
SWIG_append_errmsg("C/C++ variable '$name ($1_ltype)'");
return 1;
}
$1 = temp;

View file

@ -5,7 +5,7 @@
/* in */
%typemap(in) void *
"if ((SWIG_ConvertPtr($input,&$1,0,SWIG_POINTER_EXCEPTION | $disown)) == -1) SWIG_fail;";
"if ((SWIG_ConvertPtr($input,&$1,0,SWIG_POINTER_EXCEPTION | $disown)) == -1) {SWIG_arg_fail($argnum);SWIG_fail;}";
/* out */
@ -18,7 +18,7 @@
void * temp;
if ((SWIG_ConvertPtr($input, &temp, 0,
SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) {
PyErr_SetString(PyExc_TypeError, "C/C++ variable '$name ($1_ltype)'");
SWIG_append_errmsg("C/C++ variable '$name'");
return 1;
}
$1 = ($1_ltype) temp;

View file

@ -19,7 +19,7 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize)
if (isunicode || PyString_Check(obj)) {
if (cptr) {
int size = isunicode ? PyUnicode_GetSize(obj) : PyString_Size(obj);
wchar_t *nptr = swig_new_array(size + 1, wchar_t);
wchar_t *nptr = SWIG_new_array(size + 1, wchar_t);
PyUnicodeObject *uni = (PyUnicodeObject *)PyUnicode_FromObject(obj);
PyUnicode_AsWideChar(uni, nptr, size);
nptr[size] = 0;
@ -33,7 +33,7 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize)
}
}
if (cptr) {
PyErr_SetString(PyExc_TypeError, "a wchar_t * is expected");
SWIG_type_error("wchar_t *", obj);
}
return 0;
}
@ -51,7 +51,7 @@ SWIG_AsWCharPtr(PyObject *obj, wchar_t **val)
return res;
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a wchar_t * is expected");
SWIG_type_error("wchar_t *", obj);
}
return 0;
}
@ -64,7 +64,7 @@ SWIG_FromWCharPtr(const wchar_t * cptr)
if (cptr) {
size_t size = wcslen(cptr);
if (size > INT_MAX) {
return SWIG_NewPointerObj(swig_const_cast(cptr,wchar_t *),
return SWIG_NewPointerObj(SWIG_const_cast(cptr,wchar_t *),
SWIG_TypeQuery("wchar_t *"), 0);
} else {
return PyUnicode_FromWideChar(cptr, size);
@ -85,11 +85,11 @@ SWIG_AsNewWCharPtr(PyObject *obj, wchar_t **val)
if (res) {
if (val) {
if (csize) {
*val = swig_new_array(csize, wchar_t);
*val = SWIG_new_array(csize, wchar_t);
memcpy(*val, cptr, (--csize)*sizeof(wchar_t));
(*val)[csize] = 0;
} else if (cptr) {
*val = swig_new_array(1, wchar_t);
*val = SWIG_new_array(1, wchar_t);
(*val)[0] = 0;
} else {
*val = 0;
@ -98,7 +98,7 @@ SWIG_AsNewWCharPtr(PyObject *obj, wchar_t **val)
return SWIG_NEWOBJ;
}
if (val) {
PyErr_SetString(PyExc_TypeError, "a wchar_t * is expected");
SWIG_type_error("wchar_t *", obj);
}
return 0;
}
@ -121,8 +121,8 @@ SWIG_AsWCharArray(PyObject *obj, wchar_t *val, size_t size)
}
}
if (val) {
PyErr_Format(PyExc_TypeError,
"a wchar_t array of maximum size %lud is expected",
PyErr_Format(PyExc_ValueError,
"a wchar_t array of maximum size %lu is expected",
(unsigned long) size);
}
return 0;
@ -134,10 +134,10 @@ SWIGSTATICINLINE(PyObject *)
SWIG_FromWCharArray(const wchar_t * carray, size_t size)
{
if (size > INT_MAX) {
SWIG_NewPointerObj(swig_const_cast(carray,wchar_t *), SWIG_TypeQuery("wchar_t *"), 0);
SWIG_NewPointerObj(SWIG_const_cast(carray,wchar_t *), SWIG_TypeQuery("wchar_t *"), 0);
return Py_None;
} else {
return PyUnicode_FromWideChar(carray, swig_numeric_cast(size,int));
return PyUnicode_FromWideChar(carray, SWIG_numeric_cast(size,int));
}
}
%}

View file

@ -1,5 +1,6 @@
%include <exception.i>
%include <std_container.i>
%include <std_char_traits.i>
%{
#include <string>
@ -178,7 +179,7 @@ namespace std {
%ignore pop();
%pysequence_methods_val(std::basic_string<_CharT>);
#ifdef SWIG_EXPORT_ITERATOR_METHODS
#ifdef SWIG_EXPORT_ITERATOR_METHODS
iterator
insert(iterator __p, _CharT __c = _CharT());
@ -215,7 +216,7 @@ namespace std {
basic_string&
replace(iterator __i1, iterator __i2, const_iterator __k1, const_iterator __k2);
#endif
#endif
std::basic_string<_CharT>& operator +=(const basic_string& v);
@ -223,22 +224,28 @@ namespace std {
%newobject __radd__;
%extend {
std::basic_string<_CharT>* __add__(const basic_string& v) {
std::basic_string<_CharT>* res = new std::basic_string<_CharT>(*self);
*res += v;
return res;
}
std::basic_string<_CharT>* __add__(const basic_string& v) {
std::basic_string<_CharT>* res = new std::basic_string<_CharT>(*self);
*res += v;
return res;
}
std::basic_string<_CharT>* __radd__(const basic_string& v) {
std::basic_string<_CharT>* res = new std::basic_string<_CharT>(v);
*res += *self;
return res;
}
const std::basic_string<_CharT>& __str__() {
return *self;
}
std::basic_string<_CharT>* __radd__(const basic_string& v) {
std::basic_string<_CharT>* res = new std::basic_string<_CharT>(v);
*res += *self;
return res;
std::basic_ostream<_CharT, std::char_traits<_CharT> >&
__rlshift__(std::basic_ostream<_CharT, std::char_traits<_CharT> >& out) {
out << *self;
return out;
}
}
const std::basic_string<_CharT>& __str__() {
return *self;
}
}
};
}

View file

@ -69,6 +69,7 @@
PyObject_var(PyObject* obj = 0) : ptr(obj) { }
~PyObject_var() { if (ptr) Py_DECREF(ptr); }
operator PyObject*() { return ptr; }
PyObject* operator->() const { return ptr; }
};
}
%}
@ -170,8 +171,7 @@ namespace swigpy {
*val = p;
}
} else {
PyErr_Format(PyExc_TypeError, "a '%s *' is expected",
type_name<Type>());
SWIG_type_error(type_name<Type>(), obj);
}
return res;
}
@ -243,13 +243,10 @@ namespace swigpy {
static Type as(PyObject *obj, bool throw_error) {
Type v;
if (!obj || !asval(obj, &v)) {
std::string msg = "a value of type '";
msg += swigpy::type_name<Type>();
msg += "' is expected";
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, msg.c_str());
SWIG_type_error(swigpy::type_name<Type>(), obj);
}
if (throw_error) throw std::invalid_argument(msg);
if (throw_error) throw std::invalid_argument("bad type");
}
return v;
}
@ -271,13 +268,10 @@ namespace swigpy {
} else {
// Uninitialized return value, no Type() constructor required.
static Type *v_def = (Type*) malloc(sizeof(Type));
std::string msg = "a value of type '";
msg += swigpy::type_name<Type>();
msg += "' is expected";
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, msg.c_str());
SWIG_type_error(swigpy::type_name<Type>(), obj);
}
if (throw_error) throw std::invalid_argument(msg);
if (throw_error) throw std::invalid_argument("bad type");
memset(v_def,0,sizeof(Type));
return *v_def;
}
@ -292,13 +286,10 @@ namespace swigpy {
if (res) {
return v;
} else {
std::string msg = "a value of type '";
msg += swigpy::type_name<Type>();
msg += "*' is expected";
if (!PyErr_Occurred()) {
PyErr_SetString(PyExc_TypeError, msg.c_str());
SWIG_type_error(swigpy::type_name<Type>(), obj);
}
if (throw_error) throw std::invalid_argument(msg);
if (throw_error) throw std::invalid_argument("bad type");
return 0;
}
}

View file

@ -28,7 +28,7 @@ SWIGSTATICINLINE(int)
if ((res = SWIG_AsWCharPtrAndSize(obj, &buf, &size))) {
if (buf) {
if (val) *val = new std::wstring(buf, size - 1);
if (res == SWIG_NEWOBJ) swig_delete_array(buf);
if (res == SWIG_NEWOBJ) SWIG_delete_array(buf);
return SWIG_NEWOBJ;
}
} else {