massive typemap unification
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7676 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
5bbd841acc
commit
7e5e4fd1f9
144 changed files with 6378 additions and 7248 deletions
|
|
@ -48,12 +48,6 @@ std_wsstream.i wstring stream
|
|||
std_wstreambuf.i wstreambuf
|
||||
std_wstring.i wstring
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Backward compatibility
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
std_vectora.i vector + allocator (allocators are now supported in STD/STL)
|
||||
typemaps.i old in/out typemaps (doen't need to be included)
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
|
|
@ -87,14 +81,9 @@ pyrun.swg Python run-time code
|
|||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
pyswigtype.swg SWIGTYPE
|
||||
pyvoid.swg void *
|
||||
pyobject.swg PyObject
|
||||
pystrbase.swg String base
|
||||
pystrings.swg Char strings (char *)
|
||||
pywstrings.swg Wchar Strings (wchar_t *)
|
||||
pyprimtypes.swg Primitive types (shot,int,double,etc)
|
||||
pymisctypes.swg Miscellaneos types (size_t, ptrdiff_t, etc)
|
||||
pyenum.swg enum especializations
|
||||
pycomplex.swg PyComplex and helper for C/C++ complex types
|
||||
pydocs.swg Typemaps documentation
|
||||
|
||||
|
|
@ -107,8 +96,10 @@ std_common.i general common code for the STD/STL implementation
|
|||
std_container.i general common code for the STD/STL containers
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* deprecated
|
||||
/*-----------------------------------------------------------------------------
|
||||
* Backward compatibility and deprecated
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
std_vectora.i vector + allocator (allocators are now supported in STD/STL)
|
||||
typemaps.i old in/out typemaps (doen't need to be included)
|
||||
defarg.swg for processing default arguments with shadow classes
|
||||
|
|
|
|||
|
|
@ -2,16 +2,15 @@
|
|||
* --- Argc & Argv ---
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsArgcArgv","header",
|
||||
fragment="SWIG_AsCharPtr") {
|
||||
%fragment("SWIG_AsArgcArgv","header",fragment="SWIG_AsCharPtrAndSize") {
|
||||
SWIGINTERN char**
|
||||
SWIG_AsArgcArgv(PyObject* input,
|
||||
swig_type_info* ppchar_info,
|
||||
size_t* argc, int* owner)
|
||||
SWIG_AsArgcArgv(PyObject* input,
|
||||
swig_type_info* ppchar_info,
|
||||
size_t* argc, int* owner)
|
||||
{
|
||||
char **argv = 0;
|
||||
size_t i = 0;
|
||||
if (SWIG_ConvertPtr(input, (void **)&argv, ppchar_info, 0) == -1) {
|
||||
if (SWIG_ConvertPtr(input, (void **)&argv, ppchar_info, 0) != SWIG_OK) {
|
||||
int list = 0;
|
||||
PyErr_Clear();
|
||||
list = PyList_Check(input);
|
||||
|
|
@ -21,10 +20,17 @@ SWIGINTERN char**
|
|||
*owner = 1;
|
||||
for (; i < *argc; ++i) {
|
||||
PyObject *obj = list ? PyList_GetItem(input,i) : PyTuple_GetItem(input,i);
|
||||
if (!SWIG_AsCharPtr(obj, &(argv[i]))) {
|
||||
char *cptr = 0; size_t size = 0; int alloc = 0;
|
||||
if (SWIG_AsCharPtrAndSize(obj, &cptr, &size, &alloc) == SWIG_OK) {
|
||||
if (cptr && size) {
|
||||
argv[i] = (alloc == SWIG_NEWOBJ) ? cptr : SWIG_new_copy_array(cptr, size, char);
|
||||
} else {
|
||||
argv[i] = 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
PyErr_SetString(PyExc_TypeError,"list or tuple must contain strings only");
|
||||
}
|
||||
}
|
||||
}
|
||||
argv[i] = 0;
|
||||
return argv;
|
||||
|
|
@ -48,13 +54,11 @@ SWIGINTERN char**
|
|||
tuple
|
||||
*/
|
||||
|
||||
%typemap(in,fragment="SWIG_AsArgcArgv") (int ARGC, char **ARGV)
|
||||
(int owner) {
|
||||
size_t argc = 0;
|
||||
char **argv = SWIG_AsArgcArgv($input, $descriptor(char**), &argc, &owner);
|
||||
if (PyErr_Occurred()) {
|
||||
%typemap(in,noblock=0,fragment="SWIG_AsArgcArgv") (int ARGC, char **ARGV) (char **argv = 0, size_t argc = 0, int owner= 0) {
|
||||
argv = SWIG_AsArgcArgv($input, $descriptor(char**), &argc, &owner);
|
||||
if (!argv) {
|
||||
$1 = 0; $2 = 0;
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
SWIG_arg_fail(SWIG_TypeError, "int ARGC, char **ARGV", $argnum);
|
||||
} else {
|
||||
$1 = ($1_ltype) argc;
|
||||
$2 = ($2_ltype) argv;
|
||||
|
|
@ -62,6 +66,12 @@ SWIGINTERN char**
|
|||
}
|
||||
|
||||
%typemap(freearg) (int ARGC, char **ARGV) {
|
||||
if (owner$argnum) SWIG_delete_array($2);
|
||||
if (owner$argnum) {
|
||||
size_t i = argc$argnum;
|
||||
while (i) {
|
||||
SWIG_delete_array(argv$argnum[--i]);
|
||||
}
|
||||
SWIG_delete_array(argv$argnum);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
Attribute implementation using JOHN E LENZ ideas.
|
||||
|
||||
The following macros convert a pair of set/get methods
|
||||
into a "native" python attribute.
|
||||
into a "native" attribute.
|
||||
|
||||
Use %attribute when you have a pair of get/set methods
|
||||
like in:
|
||||
|
|
|
|||
1
Lib/python/cdata.i
Normal file
1
Lib/python/cdata.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/cdata.swg>
|
||||
|
|
@ -1,263 +0,0 @@
|
|||
/*
|
||||
* cstring.i
|
||||
* $Header$
|
||||
*
|
||||
* Author(s): David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* This file provides typemaps and macros for dealing with various forms
|
||||
* of C character string handling. The primary use of this module
|
||||
* is in returning character data that has been allocated or changed in
|
||||
* some way.
|
||||
*/
|
||||
|
||||
%include <pytuplehlp.swg>
|
||||
|
||||
%define %typemap_cstrings(Name, Char,
|
||||
SWIG_AsCharPtr,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtr,
|
||||
SWIG_FromCharArray)
|
||||
|
||||
/* %cstring_input_binary(TYPEMAP, SIZE)
|
||||
*
|
||||
* Macro makes a function accept binary string data along with
|
||||
* a size. For example:
|
||||
*
|
||||
* %cstring_input_binary(Char *buff, int size);
|
||||
* void foo(Char *buff, int size) {
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
%define Name ## _input_binary(TYPEMAP, SIZE)
|
||||
%typemap(in, fragment=#SWIG_AsCharPtrAndSize) (TYPEMAP, SIZE)
|
||||
(Char *buf, size_t size)
|
||||
{
|
||||
SWIG_AsCharPtrAndSize($input, &buf, &size);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = ($1_ltype) buf;
|
||||
$2 = ($2_ltype) size - 1;
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_bounded_output(TYPEMAP, MAX)
|
||||
*
|
||||
* This macro is used to return a NULL-terminated output string of
|
||||
* some maximum length. For example:
|
||||
*
|
||||
* %cstring_bounded_output(Char *outx, 512);
|
||||
* void foo(Char *outx) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
%define Name ## _bounded_output(TYPEMAP,MAX)
|
||||
%typemap(in,numinputs=0) TYPEMAP(Char temp[MAX+1])
|
||||
"$1 = ($1_ltype) temp;";
|
||||
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr ) TYPEMAP
|
||||
"$1[MAX] = 0; $result = t_output_helper($result, SWIG_FromCharPtr($1));";
|
||||
%enddef
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_chunk_output(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to return a chunk of binary string data.
|
||||
* Embedded NULLs are okay. For example:
|
||||
*
|
||||
* %cstring_chunk_output(Char *outx, 512);
|
||||
* void foo(Char *outx) {
|
||||
* memmove(outx, somedata, 512);
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
%define Name ## _chunk_output(TYPEMAP,SIZE)
|
||||
%typemap(in,numinputs=0) TYPEMAP(Char temp[SIZE])
|
||||
"$1 = ($1_ltype) temp;";
|
||||
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) TYPEMAP
|
||||
"$result = t_output_helper($result, SWIG_FromCharArray($1,SIZE));";
|
||||
%enddef
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_bounded_mutable(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to wrap a string that's going to mutate.
|
||||
*
|
||||
* %cstring_bounded_mutable(Char *in, 512);
|
||||
* void foo(in *x) {
|
||||
* while (*x) {
|
||||
* *x = toupper(*x);
|
||||
* x++;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
%define Name ## _bounded_mutable(TYPEMAP,MAX)
|
||||
%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP(Char temp[MAX+1]) {
|
||||
Char *t = 0; size_t n;
|
||||
SWIG_AsCharPtrAndSize($input, &t, &n);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
if ( n > (size_t)MAX ) n = (size_t)MAX;
|
||||
memcpy(temp, t, sizeof(Char)*n);
|
||||
temp[n] = 0;
|
||||
$1 = ($1_ltype) temp;
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP
|
||||
"$1[MAX] = 0; $result = t_output_helper($result, SWIG_FromCharPtr($1));";
|
||||
%enddef
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_mutable(TYPEMAP [, expansion])
|
||||
*
|
||||
* This macro is used to wrap a string that will mutate in place.
|
||||
* It may change size up to a user-defined expansion.
|
||||
*
|
||||
* %cstring_mutable(Char *in);
|
||||
* void foo(in *x) {
|
||||
* while (*x) {
|
||||
* *x = toupper(*x);
|
||||
* x++;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
%define Name ## _mutable(TYPEMAP,EXP...)
|
||||
%typemap(in,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP {
|
||||
#if #EXP == ""
|
||||
const size_t expansion = 1;
|
||||
#else
|
||||
const size_t expansion = 1 + EXP;
|
||||
#endif
|
||||
Char* t = 0; size_t n = 0;
|
||||
SWIG_AsCharPtrAndSize($input, &t, &n);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = SWIG_new_array(n+expansion, $*1_ltype);
|
||||
memcpy($1,t,sizeof(Char)*n);
|
||||
$1[n] = 0;
|
||||
}
|
||||
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP {
|
||||
$result = t_output_helper($result,SWIG_FromCharPtr($1));
|
||||
SWIG_delete_array($1);
|
||||
}
|
||||
%enddef
|
||||
|
||||
/*
|
||||
* %cstring_output_maxsize(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro returns data in a string of some user-defined size.
|
||||
*
|
||||
* %cstring_output_maxsize(Char *outx, int max) {
|
||||
* void foo(Char *outx, int max) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*/
|
||||
|
||||
%define Name ## _output_maxsize(TYPEMAP, SIZE)
|
||||
%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) {
|
||||
$2 = ($2_ltype) SWIG_As(unsigned long)($input);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = SWIG_new_array($2+1, $*1_ltype);
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) (TYPEMAP,SIZE) {
|
||||
$result = t_output_helper($result,SWIG_FromCharPtr($1));
|
||||
SWIG_delete_array($1);
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_output_withsize(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to return Character data along with a size
|
||||
* parameter.
|
||||
*
|
||||
* %cstring_output_maxsize(Char *outx, int *max) {
|
||||
* void foo(Char *outx, int *max) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* *max = strlen(outx);
|
||||
* }
|
||||
*/
|
||||
|
||||
%define Name ## _output_withsize(TYPEMAP, SIZE)
|
||||
%typemap(in,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) {
|
||||
size_t n = SWIG_As(unsigned long)($input);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = SWIG_new_array(n+1, $*1_ltype);
|
||||
$2 = SWIG_new($*2_ltype);
|
||||
*$2 = n;
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) (TYPEMAP,SIZE) {
|
||||
$result = t_output_helper($result, SWIG_FromCharArray($1,*$2));
|
||||
SWIG_delete_array($1);
|
||||
SWIG_delete($2);
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_output_allocate(TYPEMAP, RELEASE)
|
||||
*
|
||||
* This macro is used to return Character data that was
|
||||
* allocated with new or malloc.
|
||||
*
|
||||
* %cstring_output_allocated(Char **outx, free($1));
|
||||
* void foo(Char **outx) {
|
||||
* *outx = (Char *) malloc(512);
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*/
|
||||
|
||||
%define Name ## _output_allocate(TYPEMAP, RELEASE)
|
||||
%typemap(in,numinputs=0) TYPEMAP($*1_ltype temp = 0)
|
||||
"$1 = &temp;";
|
||||
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) TYPEMAP {
|
||||
if (*$1) {
|
||||
$result = t_output_helper($result,SWIG_FromCharPtr(*$1));
|
||||
RELEASE;
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
|
||||
*
|
||||
* This macro is used to return Character data that was
|
||||
* allocated with new or malloc.
|
||||
*
|
||||
* %cstring_output_allocated(Char **outx, int *sz, free($1));
|
||||
* void foo(Char **outx, int *sz) {
|
||||
* *outx = (Char *) malloc(512);
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* *sz = strlen(outx);
|
||||
* }
|
||||
*/
|
||||
|
||||
%define Name ## _output_allocate_size(TYPEMAP, SIZE, RELEASE)
|
||||
%typemap(in,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn)
|
||||
"$1 = &temp; $2 = &tempn;";
|
||||
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray)(TYPEMAP,SIZE) {
|
||||
if (*$1) {
|
||||
$result = t_output_helper($result,SWIG_FromCharArray(*$1,*$2));
|
||||
RELEASE;
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%enddef
|
||||
|
||||
|
|
@ -125,13 +125,13 @@
|
|||
* }
|
||||
*/
|
||||
|
||||
%include <typemaps/cstring.swg>
|
||||
%include <pystrings.swg>
|
||||
%include <cstrbase.swg>
|
||||
|
||||
%typemap_cstrings(%cstring,
|
||||
char,
|
||||
SWIG_AsCharPtr,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtr,
|
||||
SWIG_FromCharArray);
|
||||
SWIG_FromCharPtrAndSize);
|
||||
|
||||
|
|
|
|||
|
|
@ -125,13 +125,13 @@
|
|||
*/
|
||||
|
||||
|
||||
%include <typemaps/cstring.swg>
|
||||
%include <pywstrings.swg>
|
||||
%include <cstrbase.swg>
|
||||
|
||||
%typemap_cstrings(%cwstring,
|
||||
wchar_t,
|
||||
SWIG_AsWCharPtr,
|
||||
SWIG_AsWCharPtrAndSize,
|
||||
SWIG_FromWCharPtr,
|
||||
SWIG_FromWCharArray);
|
||||
SWIG_FromWCharPtrAndSize);
|
||||
|
||||
|
|
|
|||
|
|
@ -90,30 +90,40 @@ namespace Swig {
|
|||
protected:
|
||||
std::string swig_msg;
|
||||
public:
|
||||
DirectorException(const char* hdr ="", const char* msg ="")
|
||||
: swig_msg(hdr) {
|
||||
swig_msg += msg;
|
||||
DirectorException(PyObject *error, const char* hdr ="", const char* msg ="")
|
||||
: swig_msg(hdr)
|
||||
{
|
||||
if (strlen(msg)) {
|
||||
swig_msg += " ";
|
||||
swig_msg += msg;
|
||||
}
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_SetString(PyExc_TypeError, getMessage());
|
||||
SWIG_Python_SetErrorMsg(error, getMessage());
|
||||
} else {
|
||||
SWIG_Python_AddErrMesg(getMessage(), 1);
|
||||
SWIG_Python_AddErrorMsg(getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
const char *getMessage() const {
|
||||
const char *getMessage() const
|
||||
{
|
||||
return swig_msg.c_str();
|
||||
}
|
||||
|
||||
static void raise(const char* msg = "")
|
||||
static void raise(PyObject *error, const char *msg)
|
||||
{
|
||||
throw DirectorException(msg);
|
||||
throw DirectorException(error, msg);
|
||||
}
|
||||
|
||||
static void raise(const char *msg)
|
||||
{
|
||||
raise(PyExc_RuntimeError, msg);
|
||||
}
|
||||
};
|
||||
|
||||
/* unknown exception handler */
|
||||
class UnknownExceptionHandler
|
||||
{
|
||||
static void handler();
|
||||
|
||||
static void handler();
|
||||
public:
|
||||
|
||||
#ifdef SWIG_DIRECTOR_UEH
|
||||
|
|
@ -133,11 +143,22 @@ namespace Swig {
|
|||
/* type mismatch in the return value from a python method call */
|
||||
class DirectorTypeMismatchException : public Swig::DirectorException {
|
||||
public:
|
||||
DirectorTypeMismatchException(const char* msg="")
|
||||
: Swig::DirectorException("Swig director type mismatch: ", msg) {
|
||||
DirectorTypeMismatchException(PyObject *error, const char* msg="")
|
||||
: Swig::DirectorException(error, "Swig director type mismatch", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(const char* msg = "")
|
||||
DirectorTypeMismatchException(const char* msg="")
|
||||
: Swig::DirectorException(PyExc_TypeError, "Swig director type mismatch", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(PyObject *error, const char *msg)
|
||||
{
|
||||
throw DirectorTypeMismatchException(error, msg);
|
||||
}
|
||||
|
||||
static void raise(const char *msg)
|
||||
{
|
||||
throw DirectorTypeMismatchException(msg);
|
||||
}
|
||||
|
|
@ -147,11 +168,11 @@ namespace Swig {
|
|||
class DirectorMethodException : public Swig::DirectorException {
|
||||
public:
|
||||
DirectorMethodException(const char* msg = "")
|
||||
: DirectorException("Swig director python method error: ", msg)
|
||||
: DirectorException(PyExc_RuntimeError, "Swig director method error", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(const char* msg = "")
|
||||
static void raise(const char *msg)
|
||||
{
|
||||
throw DirectorMethodException(msg);
|
||||
}
|
||||
|
|
@ -162,11 +183,11 @@ namespace Swig {
|
|||
{
|
||||
public:
|
||||
DirectorPureVirtualException(const char* msg = "")
|
||||
: DirectorException("Swig director pure virtal method called: ", msg)
|
||||
: DirectorException(PyExc_RuntimeError, "Swig director pure virtal method called", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(const char* msg = "")
|
||||
static void raise(const char *msg)
|
||||
{
|
||||
throw DirectorPureVirtualException(msg);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,19 +14,19 @@ SWIG_AsValFilePtr(PyObject *obj, FILE **val) {
|
|||
static swig_type_info* desc = 0;
|
||||
FILE *ptr = 0;
|
||||
if (!desc) desc = SWIG_TypeQuery("FILE *");
|
||||
if ((SWIG_ConvertPtr(obj,(void **)(&ptr), desc, 0)) != -1) {
|
||||
if ((SWIG_ConvertPtr(obj,(void **)(&ptr), desc, 0)) == SWIG_OK) {
|
||||
if (val) *val = ptr;
|
||||
return 1;
|
||||
return SWIG_OK;
|
||||
}
|
||||
if (PyFile_Check(obj)) {
|
||||
if (val) *val = PyFile_AsFile(obj);
|
||||
return 1;
|
||||
return SWIG_OK;
|
||||
}
|
||||
if (val) PyErr_SetString(PyExc_TypeError, "a FILE* is expected");
|
||||
return 0;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment("SWIG_AsFilePtr","header",fragment="SWIG_AsValFilePtr") {
|
||||
SWIGINTERNINLINE FILE*
|
||||
SWIG_AsFilePtr(PyObject *obj) {
|
||||
|
|
@ -36,13 +36,5 @@ SWIG_AsFilePtr(PyObject *obj) {
|
|||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_CheckFilePtr","header",fragment="SWIG_AsValFilePtr") {
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_CheckFilePtr(PyObject *obj) {
|
||||
return SWIG_AsValFilePtr(obj, (FILE **)(0));
|
||||
}
|
||||
}
|
||||
|
||||
/* defining the typemaps */
|
||||
%typemap_ascheck(SWIG_CCode(POINTER), SWIG_AsFilePtr, SWIG_CheckFilePtr,
|
||||
"SWIG_AsFilePtr", "SWIG_CheckFilePtr", FILE*);
|
||||
%typemap_asval(SWIG_CCode(POINTER), SWIG_AsValFilePtr, "SWIG_AsValFilePtr", FILE*);
|
||||
|
|
|
|||
|
|
@ -1,217 +1,2 @@
|
|||
%include <std_common.i>
|
||||
|
||||
/*
|
||||
The %implict macro allows a SwigType to be accepted
|
||||
as an input parameter and use its implicit constructors when needed.
|
||||
|
||||
|
||||
%implicit(A, int, double, B);
|
||||
|
||||
%inline
|
||||
{
|
||||
struct B { };
|
||||
struct A
|
||||
{
|
||||
int ii;
|
||||
A(int i) { ii = 1; }
|
||||
A(double d) { ii = 2; }
|
||||
A(const B& b) { ii = 3; }
|
||||
};
|
||||
|
||||
int get(A a) { return a.ii; }
|
||||
}
|
||||
|
||||
Here, you can call 'get' as
|
||||
|
||||
get(1) ==> get(A(1))
|
||||
get(2.0) ==> get(A(2.0))
|
||||
get(B()) ==> get(A(B()))
|
||||
|
||||
and swig will construct an 'A' temporal variable using the
|
||||
corresponding implicit constructor.
|
||||
|
||||
|
||||
The plain implicit macro takes care of simple type list. If it doesn't
|
||||
work because you are passing template types with commas, then use
|
||||
the %implicit_{1,2,3} versions, and the SWIG_arg macro.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
%define %implicit_type(...)
|
||||
%traits_swigtype(__VA_ARGS__);
|
||||
%enddef
|
||||
|
||||
%define %implicit_frag(...) ,fragment=SWIG_Traits_frag(__VA_ARGS__) %enddef
|
||||
|
||||
%define %implicit_code(...)
|
||||
if (swig::check<__VA_ARGS__ >(obj)) {
|
||||
if (val) *val = new value_type(swig::as<__VA_ARGS__ >(obj));
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* implicit */
|
||||
|
||||
%define %implicit(Type, ...)
|
||||
|
||||
%formacro_1(%implicit_type,__VA_ARGS__);
|
||||
|
||||
%fragment(SWIG_Traits_frag(Type),"header",
|
||||
fragment="StdTraits"
|
||||
%formacro_1(%implicit_frag,__VA_ARGS__)) %{
|
||||
namespace swig {
|
||||
template <> struct traits<Type > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() { return "Type"; }
|
||||
};
|
||||
|
||||
template <> struct traits_asptr< Type > {
|
||||
typedef Type value_type;
|
||||
static int asptr(PyObject *obj, value_type **val) {
|
||||
Type *vptr;
|
||||
static swig_type_info* desc = SWIG_TypeQuery("Type *");
|
||||
if ((SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0) != -1)) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
if (PyErr_Occurred()) PyErr_Clear();
|
||||
%formacro_1(%implicit_code,__VA_ARGS__)
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError, "a " "Type" " is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
|
||||
%enddef
|
||||
|
||||
/* implicit_1 */
|
||||
|
||||
|
||||
%define %implicit_1(Type, Imp1)
|
||||
%traits_swigtype(Imp1);
|
||||
|
||||
%fragment(SWIG_Traits_frag(Type),"header",
|
||||
fragment="StdTraits",
|
||||
fragment=SWIG_Traits_frag(Imp1)) %{
|
||||
namespace swig {
|
||||
template <> struct traits< Type > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() { return "Type"; }
|
||||
};
|
||||
|
||||
template <> struct traits_asptr< Type > {
|
||||
typedef Type value_type;
|
||||
static int asptr(PyObject *obj, value_type **val) {
|
||||
Type *vptr;
|
||||
static swig_type_info* desc = SWIG_TypeQuery("Type *");
|
||||
if ((SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0) != -1)) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
if (PyErr_Occurred()) PyErr_Clear();
|
||||
%implicit_code(Imp1);
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError, "a " "Type" " is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
|
||||
|
||||
%enddef
|
||||
|
||||
/* implicit_2 */
|
||||
|
||||
%define %implicit_2(Type, Imp1, Imp2)
|
||||
%traits_swigtype(Imp1);
|
||||
%traits_swigtype(Imp2);
|
||||
|
||||
%fragment(SWIG_Traits_frag(Type),"header",
|
||||
fragment="StdTraits",
|
||||
fragment=SWIG_Traits_frag(Imp1),
|
||||
fragment=SWIG_Traits_frag(Imp2)) %{
|
||||
namespace swig {
|
||||
template <> struct traits< Type > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() { return "Type"; }
|
||||
};
|
||||
|
||||
template <> struct traits_asptr< Type > {
|
||||
typedef Type value_type;
|
||||
static int asptr(PyObject *obj, value_type **val) {
|
||||
Type *vptr;
|
||||
static swig_type_info* desc = SWIG_TypeQuery("Type *");
|
||||
if ((SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0) != -1)) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
if (PyErr_Occurred()) PyErr_Clear();
|
||||
%implicit_code(Imp1);
|
||||
%implicit_code(Imp2);
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError, "a " "Type" " is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
|
||||
%enddef
|
||||
|
||||
|
||||
/* implicit_3 */
|
||||
|
||||
%define %implicit_3(Type, Imp1, Imp2, Imp3)
|
||||
%traits_swigtype(Imp1);
|
||||
%traits_swigtype(Imp2);
|
||||
%traits_swigtype(Imp3);
|
||||
|
||||
%fragment(SWIG_Traits_frag(Type),"header",
|
||||
fragment="StdTraits",
|
||||
fragment=SWIG_Traits_frag(Imp1),
|
||||
fragment=SWIG_Traits_frag(Imp2),
|
||||
fragment=SWIG_Traits_frag(Imp3)) %{
|
||||
namespace swig {
|
||||
template <> struct traits< Type > {
|
||||
typedef pointer_category category;
|
||||
static const char* type_name() { return "Type"; }
|
||||
};
|
||||
|
||||
template <> struct traits_asptr< Type > {
|
||||
typedef Type value_type;
|
||||
static int asptr(PyObject *obj, value_type **val) {
|
||||
Type *vptr;
|
||||
static swig_type_info* desc = SWIG_TypeQuery("Type *");
|
||||
if ((SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0) != -1)) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
if (PyErr_Occurred()) PyErr_Clear();
|
||||
%implicit_code(Imp1);
|
||||
%implicit_code(Imp2);
|
||||
%implicit_code(Imp3);
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError, "a " "Type" " is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
|
||||
%enddef
|
||||
%include <typemaps/implicit.swg>
|
||||
|
|
|
|||
|
|
@ -1,47 +1,16 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* SWIG API. Portion that goes into the runtime
|
||||
* Python API portion that goes into the runtime
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* for internal method declarations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef SWIGINTERN
|
||||
# define SWIGINTERN static SWIGUNUSED
|
||||
#endif
|
||||
|
||||
#ifndef SWIGINTERNINLINE
|
||||
# define SWIGINTERNINLINE SWIGINTERN SWIGINLINE
|
||||
#endif
|
||||
|
||||
/*
|
||||
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
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* 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
|
||||
|
||||
|
|
@ -56,12 +25,28 @@ typedef struct swig_const_info {
|
|||
} swig_const_info;
|
||||
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Alloc. memory flags
|
||||
* Append a value to the result obj
|
||||
* ----------------------------------------------------------------------------- */
|
||||
#define SWIG_OLDOBJ 1
|
||||
#define SWIG_NEWOBJ SWIG_OLDOBJ + 1
|
||||
#define SWIG_PYSTR SWIG_NEWOBJ + 1
|
||||
SWIGINTERN PyObject*
|
||||
SWIG_Python_AppendResult(PyObject* result, PyObject* obj) {
|
||||
if (!result) {
|
||||
result = obj;
|
||||
} else if (result == Py_None) {
|
||||
Py_DECREF(result);
|
||||
result = obj;
|
||||
} else {
|
||||
if (!PyList_Check(result)) {
|
||||
PyObject *o2 = result;
|
||||
result = PyList_New(1);
|
||||
PyList_SetItem(result, 0, o2);
|
||||
}
|
||||
PyList_Append(result,obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,42 +10,36 @@
|
|||
/* the common from conversor */
|
||||
%define %swig_fromcplx_conv(Type, Real, Imag)
|
||||
%fragment(SWIG_From_frag(Type),"header")
|
||||
%{
|
||||
{
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(Type)(SWIG_cplusplus(const Type&, Type) c)
|
||||
SWIG_From(Type)(SWIG_cplusplus(const Type&, Type) c)
|
||||
{
|
||||
return PyComplex_FromDoubles(Real(c), Imag(c));
|
||||
}
|
||||
%}
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* the double case */
|
||||
%define %swig_cplxdbl_conv(Type, Constructor, Real, Imag)
|
||||
%fragment(SWIG_AsVal_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(double))
|
||||
%{
|
||||
{
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(Type) (PyObject *o, Type* val)
|
||||
SWIG_AsVal(Type) (PyObject *o, Type* val)
|
||||
{
|
||||
if (PyComplex_Check(o)) {
|
||||
if (val) *val = Constructor(PyComplex_RealAsDouble(o),
|
||||
PyComplex_ImagAsDouble(o));
|
||||
return 1;
|
||||
if (val) *val = Constructor(PyComplex_RealAsDouble(o), PyComplex_ImagAsDouble(o));
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
double d;
|
||||
if (SWIG_AsVal(double)(o, &d)) {
|
||||
if (SWIG_AsVal(double)(o, &d) == SWIG_OK) {
|
||||
if (val) *val = Constructor(d, 0.0);
|
||||
return 1;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("Type", o);
|
||||
}
|
||||
return 0;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
%}
|
||||
%swig_fromcplx_conv(Type, Real, Imag);
|
||||
%enddef
|
||||
|
||||
|
|
@ -55,37 +49,26 @@ SWIGINTERN int
|
|||
fragment="SWIG_CheckDoubleInRange",
|
||||
fragment=SWIG_AsVal_frag(float)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(Type)(PyObject *o, Type *val)
|
||||
SWIG_AsVal(Type)(PyObject *o, Type *val)
|
||||
{
|
||||
const char* errmsg = val ? #Type : 0;
|
||||
if (PyComplex_Check(o)) {
|
||||
double re = PyComplex_RealAsDouble(o);
|
||||
double im = PyComplex_ImagAsDouble(o);
|
||||
if (SWIG_CheckDoubleInRange(re, -FLT_MAX, FLT_MAX, errmsg)
|
||||
&& SWIG_CheckDoubleInRange(im, -FLT_MAX, FLT_MAX, errmsg)) {
|
||||
if ((-FLT_MAX <= re && re <= FLT_MAX) && (-FLT_MAX <= im && im <= FLT_MAX)) {
|
||||
if (val) *val = Constructor(SWIG_numeric_cast(re, float),
|
||||
SWIG_numeric_cast(im, float));
|
||||
return 1;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return 0;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
} else {
|
||||
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.0);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
float re;
|
||||
if (SWIG_AsVal(float)(o, &re) == SWIG_OK) {
|
||||
if (val) *val = Constructor(re, 0.0);
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("Type", o);
|
||||
}
|
||||
return 0;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
%}
|
||||
|
||||
%fragment("PySequence_Base","header")
|
||||
%{
|
||||
{
|
||||
namespace swig {
|
||||
inline size_t
|
||||
check_index(ptrdiff_t i, size_t size, bool insert = false) {
|
||||
|
|
@ -115,13 +115,13 @@ namespace swig {
|
|||
}
|
||||
}
|
||||
}
|
||||
%}
|
||||
}
|
||||
|
||||
%fragment("PySequence_Cont","header",
|
||||
fragment="StdTraits",
|
||||
fragment="PySequence_Base",
|
||||
fragment="PyObject_var")
|
||||
%{
|
||||
{
|
||||
#include <iterator>
|
||||
namespace swig
|
||||
{
|
||||
|
|
@ -140,12 +140,12 @@ namespace swig
|
|||
return swig::as<T>(item, true);
|
||||
} catch (std::exception& e) {
|
||||
char msg[1024];
|
||||
PyOS_snprintf(msg, sizeof(msg), "in sequence element %d ", _index);
|
||||
snprintf(msg, sizeof(msg), "in sequence element %d ", _index);
|
||||
if (!PyErr_Occurred()) {
|
||||
SWIG_type_error(swig::type_name<T>(), item);
|
||||
SWIG_set_errmsg(SWIG_TypeError,swig::type_name<T>());
|
||||
}
|
||||
SWIG_append_errmsg(msg);
|
||||
SWIG_append_errmsg(e.what());
|
||||
SWIG_Python_AddErrorMsg(msg);
|
||||
SWIG_Python_AddErrorMsg(e.what());
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
|
@ -335,9 +335,8 @@ namespace swig
|
|||
if (!swig::check<value_type>(item)) {
|
||||
if (set_err) {
|
||||
char msg[1024];
|
||||
PyOS_snprintf(msg, sizeof(msg), "in sequence element %d", i);
|
||||
SWIG_type_error(swig::type_name<value_type>(), item);
|
||||
SWIG_append_errmsg(msg);
|
||||
snprintf(msg, sizeof(msg), "in sequence element %d of type %s", i, swig::type_name<value_type>());
|
||||
SWIG_set_errmsg(SWIG_TypeError, msg);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -350,7 +349,7 @@ namespace swig
|
|||
};
|
||||
|
||||
}
|
||||
%}
|
||||
}
|
||||
|
||||
|
||||
/**** The python container methods ****/
|
||||
|
|
@ -444,20 +443,20 @@ namespace swig
|
|||
%fragment("StdSequenceTraits","header",
|
||||
fragment="StdTraits",fragment="PyObject_var",
|
||||
fragment="PySequence_Cont")
|
||||
%{
|
||||
{
|
||||
namespace swig {
|
||||
template <class PySeq, class Seq>
|
||||
inline void
|
||||
assign(const PySeq& pyseq, Seq* seq) {
|
||||
#ifdef SWIG_STD_NOASSIGN_STL
|
||||
%#ifdef SWIG_STD_NOASSIGN_STL
|
||||
typedef typename PySeq::value_type value_type;
|
||||
typename PySeq::const_iterator it = pyseq.begin();
|
||||
for (;it != pyseq.end(); ++it) {
|
||||
seq->insert(seq->end(),(value_type)(*it));
|
||||
}
|
||||
#else
|
||||
%#else
|
||||
seq->assign(pyseq.begin(), pyseq.end());
|
||||
#endif
|
||||
%#endif
|
||||
}
|
||||
|
||||
template <class Seq, class T = typename Seq::value_type >
|
||||
|
|
@ -487,7 +486,7 @@ namespace swig
|
|||
} else {
|
||||
sequence *p;
|
||||
if (SWIG_ConvertPtr(obj,(void**)&p,
|
||||
swig::type_info<sequence>(),0) != -1) {
|
||||
swig::type_info<sequence>(),0) == SWIG_OK) {
|
||||
if (seq) *seq = p;
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -525,4 +524,4 @@ namespace swig
|
|||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Enums
|
||||
* ------------------------------------------------------------ */
|
||||
%apply int { enum SWIGTYPE };
|
||||
%apply const int& { const enum SWIGTYPE& };
|
||||
|
||||
%typemap(in,fragment=SWIG_As_frag(int)) const enum SWIGTYPE& ($basetype temp) {
|
||||
temp = SWIG_static_cast(SWIG_As(int)($input),$basetype);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
|
||||
%typemap(varin,fragment=SWIG_AsVal_frag(int)) enum SWIGTYPE
|
||||
{
|
||||
if (sizeof(int) != sizeof($1)) {
|
||||
PyErr_SetString(PyExc_AttributeError, "enum variable '$name' can not be set");
|
||||
return 1;
|
||||
}
|
||||
if (!SWIG_AsVal(int)($input, (int*)(void*)(&$1))) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
typemaps needed due to unnamed enums
|
||||
*/
|
||||
%define PY_ENUM_OUT_TYPEMAPS(from_meth,pyfrag)
|
||||
%typemap(out,fragment=pyfrag) enum SWIGTYPE
|
||||
"$result = from_meth(($1));";
|
||||
%typemap(out,fragment=pyfrag) const enum SWIGTYPE&
|
||||
"$result = from_meth((*$1));";
|
||||
%typemap(varout,fragment=pyfrag) enum SWIGTYPE, const enum SWIGTYPE&
|
||||
"$result = from_meth($1);";
|
||||
%typemap(constcode,fragment=pyfrag) enum SWIGTYPE
|
||||
"PyDict_SetItemString(d,\"$symname\", from_meth($value));";
|
||||
%typemap(directorin,fragment=pyfrag) enum SWIGTYPE *DIRECTORIN
|
||||
"$input = from_meth(*$1_name);";
|
||||
%typemap(directorin,fragment=pyfrag) enum SWIGTYPE, const enum SWIGTYPE&
|
||||
"$input = from_meth($1_name);";
|
||||
%typemap(throws,fragment=pyfrag) enum SWIGTYPE
|
||||
"PyErr_SetObject(PyExc_RuntimeError, from_meth($1));
|
||||
SWIG_fail;";
|
||||
%enddef
|
||||
|
||||
PY_ENUM_OUT_TYPEMAPS(SWIG_From(int),SWIG_From_frag(int));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
81
Lib/python/pyerrors.swg
Normal file
81
Lib/python/pyerrors.swg
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* error manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
%insert("header") %{
|
||||
|
||||
SWIGINTERN PyObject*
|
||||
SWIG_Python_ErrorType(int code) {
|
||||
switch(code) {
|
||||
case SWIG_MemoryError:
|
||||
return PyExc_MemoryError;
|
||||
break;
|
||||
case SWIG_IOError:
|
||||
return PyExc_IOError;
|
||||
break;
|
||||
case SWIG_RuntimeError:
|
||||
return PyExc_RuntimeError;
|
||||
break;
|
||||
case SWIG_IndexError:
|
||||
return PyExc_IndexError;
|
||||
break;
|
||||
case SWIG_TypeError:
|
||||
return PyExc_TypeError;
|
||||
break;
|
||||
case SWIG_DivisionByZero:
|
||||
return PyExc_ZeroDivisionError;
|
||||
break;
|
||||
case SWIG_OverflowError:
|
||||
return PyExc_OverflowError;
|
||||
break;
|
||||
case SWIG_SyntaxError:
|
||||
return PyExc_SyntaxError;
|
||||
break;
|
||||
case SWIG_ValueError:
|
||||
return PyExc_ValueError;
|
||||
break;
|
||||
case SWIG_SystemError:
|
||||
return PyExc_SystemError;
|
||||
break;
|
||||
case SWIG_AttributeError:
|
||||
return PyExc_AttributeError;
|
||||
break;
|
||||
default:
|
||||
return PyExc_RuntimeError;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Python_SetErrorMsg(PyObject *type, const char *mesg) {
|
||||
PyErr_SetString(type, mesg);
|
||||
}
|
||||
|
||||
SWIGINTERNINLINE void
|
||||
SWIG_Python_SetExceptionObj(swig_type_info *desc, PyObject *obj) {
|
||||
PyErr_SetObject((desc && desc->clientdata ? (PyObject *)(desc->clientdata) : PyExc_RuntimeError), obj);
|
||||
}
|
||||
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Python_AddErrorMsg(const char* mesg)
|
||||
{
|
||||
PyObject *type = 0;
|
||||
PyObject *value = 0;
|
||||
PyObject *traceback = 0;
|
||||
|
||||
if (PyErr_Occurred()) PyErr_Fetch(&type, &value, &traceback);
|
||||
if (value) {
|
||||
PyObject *old_str = PyObject_Str(value);
|
||||
Py_XINCREF(type);
|
||||
PyErr_Clear();
|
||||
PyErr_Format(type, "%s %s", PyString_AsString(old_str), mesg);
|
||||
Py_DECREF(old_str);
|
||||
} else {
|
||||
PyErr_Format(PyExc_RuntimeError, mesg);
|
||||
}
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
|
@ -173,33 +173,18 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
|
|||
size_t i;
|
||||
for (i = 0; constants[i].type; ++i) {
|
||||
switch(constants[i].type) {
|
||||
case SWIG_PY_INT:
|
||||
obj = PyInt_FromLong(constants[i].lvalue);
|
||||
break;
|
||||
case SWIG_PY_FLOAT:
|
||||
obj = PyFloat_FromDouble(constants[i].dvalue);
|
||||
break;
|
||||
case SWIG_PY_STRING:
|
||||
if (constants[i].pvalue) {
|
||||
obj = PyString_FromString((char *) constants[i].pvalue);
|
||||
} else {
|
||||
Py_INCREF(Py_None);
|
||||
obj = Py_None;
|
||||
}
|
||||
break;
|
||||
case SWIG_PY_POINTER:
|
||||
obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
|
||||
break;
|
||||
case SWIG_PY_BINARY:
|
||||
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
|
||||
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype), 0);
|
||||
break;
|
||||
default:
|
||||
obj = 0;
|
||||
break;
|
||||
}
|
||||
if (obj) {
|
||||
PyDict_SetItemString(d,constants[i].name,obj);
|
||||
Py_DECREF(obj);
|
||||
PyDict_SetItemString(d, constants[i].name, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -250,10 +235,6 @@ SWIG_Python_FixMethods(PyMethodDef *methods,
|
|||
}
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------*
|
||||
* Initialize type list
|
||||
* -----------------------------------------------------------------------------*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,233 +0,0 @@
|
|||
//
|
||||
// Uncomment the following definition if you don't want the in/out
|
||||
// typemaps by default, ie, you prefer to use typemaps.i.
|
||||
//
|
||||
//#define SWIG_INOUT_NODEF
|
||||
|
||||
//
|
||||
// Use the following definition to enable the INPUT parameters to
|
||||
// accept both 'by value' and 'pointer' objects.
|
||||
//
|
||||
#define SWIG_INPUT_ACCEPT_PTRS
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Pointer handling
|
||||
//
|
||||
// These mappings provide support for input/output arguments and common
|
||||
// uses for C/C++ pointers.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// INPUT typemaps.
|
||||
// These remap a C pointer to be an "INPUT" value which is passed by value
|
||||
// instead of reference.
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer into a simple
|
||||
"input" value. That is, instead of passing a pointer to an object,
|
||||
you would use a real value instead.
|
||||
|
||||
To use these, suppose you had a C function like this :
|
||||
|
||||
double fadd(double *a, double *b) {
|
||||
return *a+*b;
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
double fadd(double *INPUT, double *INPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%apply double *INPUT { double *a, double *b };
|
||||
double fadd(double *a, double *b);
|
||||
|
||||
*/
|
||||
#ifdef SWIG_INPUT_ACCEPT_PTRS
|
||||
#define SWIG_CheckInputPtr(input,arg,desc,disown) (SWIG_ConvertPtr(input,arg,desc,disown) != -1)
|
||||
#else
|
||||
#define SWIG_CheckInputPtr(input,arg,desc,disown) (0)
|
||||
#endif
|
||||
|
||||
%define _PYVAL_INPUT_TYPEMAP(code,as_meth,check_meth,as_frag,check_frag,Type)
|
||||
%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 (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = &temp;
|
||||
res = SWIG_NEWOBJ;
|
||||
}
|
||||
}
|
||||
%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 (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = &temp;
|
||||
res = SWIG_NEWOBJ;
|
||||
}
|
||||
if (!$1) {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
}
|
||||
%typemap(typecheck,precedence=code,fragment=check_frag) Type *INPUT, Type &INPUT {
|
||||
void *ptr;
|
||||
$1 = (check_meth($input) || (SWIG_CheckInputPtr($input,&ptr,$1_descriptor,0)));
|
||||
}
|
||||
%enddef
|
||||
|
||||
%define _PYPTR_INPUT_TYPEMAP(code,asptr_meth,asptr_frag,Type)
|
||||
%typemap(in,fragment=asptr_frag) Type *INPUT(int res = 0) {
|
||||
res = asptr_meth($input, &$1);
|
||||
if (!res) {
|
||||
SWIG_type_error("$basetype", $input);
|
||||
}
|
||||
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("$basetype", $input);
|
||||
} else {
|
||||
if (!$1) {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
}
|
||||
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
|
||||
"$1 = asptr_meth($input, (Type**)0) != 0;"
|
||||
%enddef
|
||||
|
||||
// OUTPUT typemaps. These typemaps are used for parameters that
|
||||
// are output only. The output value is appended to the result as
|
||||
// a list element.
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer into an "output"
|
||||
value. When calling a function, no input value would be given for
|
||||
a parameter, but an output value would be returned. In the case of
|
||||
multiple output values, they are returned in the form of a Python tuple.
|
||||
|
||||
|
||||
For example, suppose you were trying to wrap the modf() function in the
|
||||
C math library which splits x into integral and fractional parts (and
|
||||
returns the integer part in one of its parameters).K:
|
||||
|
||||
double modf(double x, double *ip);
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
double modf(double x, double *OUTPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%apply double *OUTPUT { double *ip };
|
||||
double modf(double x, double *ip);
|
||||
|
||||
The Python output of the function would be a tuple containing both
|
||||
output values.
|
||||
|
||||
*/
|
||||
|
||||
// These typemaps contributed by Robin Dunn
|
||||
//----------------------------------------------------------------------
|
||||
//
|
||||
// T_OUTPUT typemap (and helper function) to return multiple argouts as
|
||||
// a tuple instead of a list.
|
||||
//
|
||||
// Author: Robin Dunn
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
%include <pytuplehlp.swg>
|
||||
|
||||
%define _PYVAL_OUTPUT_TYPEMAP(from_meth, from_frag, Type)
|
||||
%typemap(in,numinputs=0) Type *OUTPUT ($*1_ltype temp, int res = 0),
|
||||
Type &OUTPUT ($*1_ltype temp, int res = 0)
|
||||
"$1 = &temp; res = SWIG_NEWOBJ;";
|
||||
%fragment("t_out_helper"{Type},"header",
|
||||
fragment="t_output_helper",fragment=from_frag) {}
|
||||
%typemap(argout,fragment="t_out_helper"{Type}) Type *OUTPUT, Type &OUTPUT
|
||||
"$result = t_output_helper($result, ((res$argnum == SWIG_NEWOBJ) ?
|
||||
from_meth((*$1)) : SWIG_NewPointerObj((void*)($1), $1_descriptor, 0)));";
|
||||
|
||||
%enddef
|
||||
|
||||
|
||||
// INOUT
|
||||
// Mappings for an argument that is both an input and output
|
||||
// parameter
|
||||
|
||||
/*
|
||||
The following methods can be applied to make a function parameter both
|
||||
an input and output value. This combines the behavior of both the
|
||||
"INPUT" and "OUTPUT" methods described earlier. Output values are
|
||||
returned in the form of a Python tuple.
|
||||
|
||||
For example, suppose you were trying to wrap the following function :
|
||||
|
||||
void neg(double *x) {
|
||||
*x = -(*x);
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
void neg(double *INOUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%apply double *INOUT { double *x };
|
||||
void neg(double *x);
|
||||
|
||||
Unlike C, this mapping does not directly modify the input value (since
|
||||
this makes no sense in Python). Rather, the modified input value shows
|
||||
up as the return value of the function. Thus, to apply this function
|
||||
to a Python variable you might do this :
|
||||
|
||||
x = neg(x)
|
||||
|
||||
Note : previous versions of SWIG used the symbol 'BOTH' to mark
|
||||
input/output arguments. This is still supported, but will be slowly
|
||||
phased out in future releases.
|
||||
|
||||
*/
|
||||
|
||||
%define _PYVAL_INOUT_TYPEMAP(Type)
|
||||
%typemap(in) Type *INOUT = Type *INPUT;
|
||||
%typemap(in) Type &INOUT = Type &INPUT;
|
||||
%typemap(typecheck) Type *INOUT = Type *INPUT;
|
||||
%typemap(typecheck) Type &INOUT = Type &INPUT;
|
||||
%typemap(argout) Type *INOUT = Type *OUTPUT;
|
||||
%typemap(argout) Type &INOUT = Type &OUTPUT;
|
||||
%enddef
|
||||
|
||||
|
||||
%define _PYPTR_INOUT_TYPEMAP(Type)
|
||||
_PYVAL_INOUT_TYPEMAP(SWIG_arg(Type))
|
||||
%typemap(freearg) Type *INOUT = Type *INPUT;
|
||||
%typemap(freearg) Type &INOUT = Type &INPUT;
|
||||
%enddef
|
||||
|
||||
#ifndef SWIG_INOUT_NODEF
|
||||
#define PYVAL_INPUT_TYPEMAP(code,_a,_c,_af,_cf,...) \
|
||||
_PYVAL_INPUT_TYPEMAP(SWIG_arg(code),SWIG_arg(_a),SWIG_arg(_c), \
|
||||
SWIG_arg(_af),SWIG_arg(_cf),SWIG_arg(__VA_ARGS__))
|
||||
|
||||
#define PYPTR_INPUT_TYPEMAP(code,_a,_af,...) \
|
||||
_PYPTR_INPUT_TYPEMAP(SWIG_arg(code),SWIG_arg(_a),SWIG_arg(_af), \
|
||||
SWIG_arg(__VA_ARGS__))
|
||||
|
||||
#define PYVAL_OUTPUT_TYPEMAP(_f,_ff,...) \
|
||||
_PYVAL_OUTPUT_TYPEMAP(SWIG_arg(_f),SWIG_arg(_ff),SWIG_arg(__VA_ARGS__))
|
||||
|
||||
#define PYVAL_INOUT_TYPEMAP(...) _PYVAL_INOUT_TYPEMAP(SWIG_arg(__VA_ARGS__))
|
||||
#define PYPTR_INOUT_TYPEMAP(...) _PYPTR_INOUT_TYPEMAP(SWIG_arg(__VA_ARGS__))
|
||||
#else /* You need to include typemaps.i */
|
||||
#define PYVAL_OUTPUT_TYPEMAP(...)
|
||||
#define PYVAL_INPUT_TYPEMAP(...)
|
||||
#define PYVAL_INOUT_TYPEMAP(...)
|
||||
#define PYPTR_INPUT_TYPEMAP(...)
|
||||
#define PYPTR_INOUT_TYPEMAP(...)
|
||||
#endif /* SWIG_INOUT_DEFAULT */
|
||||
|
|
@ -1,159 +1 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* SWIG API. Portion only visible from SWIG
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define SWIG_arg(Arg...) Arg
|
||||
|
||||
#define SWIG_str(Type...) #Type
|
||||
|
||||
#define SWIG_Mangle(Type...) #@Type
|
||||
#define SWIG_Descriptor(Type...) SWIGTYPE_ ## #@Type
|
||||
|
||||
#define SWIG_NameType(Name, Type...) SWIG_ ## Name ## _ ## #@Type
|
||||
#define SWIG_StringType(Name, Type...) "SWIG_" #Name "_" {Type}
|
||||
|
||||
#define SWIG_AsVal(Type...) SWIG_NameType(AsVal, Type)
|
||||
#define SWIG_AsPtr(Type...) SWIG_NameType(AsPtr, Type)
|
||||
#define SWIG_As(Type...) SWIG_NameType(As, Type)
|
||||
#define SWIG_From(Type...) SWIG_NameType(From, Type)
|
||||
#define SWIG_Check(Type...) SWIG_NameType(Check, Type)
|
||||
#define SWIG_CCode(Type...) SWIG_NameType(TYPECHECK, Type)
|
||||
#define SWIG_OrderType(Type...) SWIG_NameType(OrderType, Type)
|
||||
#define SWIG_EqualType(Type...) SWIG_NameType(EqualType, Type)
|
||||
|
||||
#define SWIG_Traits_frag(Type...) SWIG_StringType(Traits, Type)
|
||||
#define SWIG_AsPtr_frag(Type...) SWIG_StringType(AsPtr, Type)
|
||||
#define SWIG_AsVal_frag(Type...) SWIG_StringType(AsVal, Type)
|
||||
#define SWIG_As_frag(Type...) SWIG_StringType(As, Type)
|
||||
#define SWIG_From_frag(Type...) SWIG_StringType(From, Type)
|
||||
#define SWIG_Check_frag(Type...) SWIG_StringType(Check, Type)
|
||||
#define SWIG_CCode_frag(Type...) SWIG_StringType(TYPECHECK, Type)
|
||||
|
||||
/* Internal C/C++ API */
|
||||
#ifdef SWIG_NO_CPLUSPLUS_CAST
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Disable 'modern' cplusplus casting operators
|
||||
* ----------------------------------------------------------------------------- */
|
||||
#ifdef SWIG_CPLUSPLUS_CAST
|
||||
#undef SWIG_CPLUSPLUS_CAST
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(__cplusplus)
|
||||
#define SWIG_new(Type...) (new Type)
|
||||
#define SWIG_new_copy(ptr,Type...) (new Type(*ptr))
|
||||
#define SWIG_new_array(size,Type...) (new Type[(size)])
|
||||
#define SWIG_delete(cptr) delete cptr
|
||||
#define SWIG_delete_array(cptr) delete[] cptr
|
||||
#else /* C case */
|
||||
#define SWIG_new(Type...) ((Type*)malloc(sizeof(Type)))
|
||||
#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)
|
||||
#endif /* __cplusplus */
|
||||
|
||||
#if defined(__cplusplus) && defined(SWIG_CPLUSPLUS_CAST)
|
||||
#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_numeric_cast(a,Type...) static_cast<Type >(a)
|
||||
#else /* C case */
|
||||
#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)
|
||||
#endif /* __cplusplus */
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Auxiliar swig macros used to write typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* define a new macro */
|
||||
%define SWIG_define(Def, Val)
|
||||
%#define Def Val
|
||||
%enddef
|
||||
|
||||
/* include C++ or C value */
|
||||
%define SWIG_cplusplus(cppval, cval)
|
||||
#ifdef __cplusplus
|
||||
cppval
|
||||
#else
|
||||
cval
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
/* for loop for macro with one argument */
|
||||
%define %_formacro_1(macro, arg1,...)
|
||||
macro(arg1)
|
||||
#if #__VA_ARGS__ != "__fordone__"
|
||||
%_formacro_1(macro, __VA_ARGS__)
|
||||
#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__"
|
||||
%_formacro_2(macro, __VA_ARGS__)
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
/* for loop for macro with two arguments */
|
||||
%define %formacro_2(macro,...)
|
||||
%_formacro_2(macro, __VA_ARGS__, __fordone__)
|
||||
%enddef
|
||||
|
||||
|
||||
/*
|
||||
mark a flag, ie, define a macro name but ignore it in
|
||||
the interface.
|
||||
|
||||
the flags latter can be used with %evalif
|
||||
*/
|
||||
|
||||
%define %swig_mark_flag(x)
|
||||
%ignore x;
|
||||
#define x 1
|
||||
%enddef
|
||||
|
||||
/*
|
||||
%swig_equal_type and %swig_order_type flagged a type of having equal (==,!=)
|
||||
and/or order methods (<=,>=,<,>).
|
||||
*/
|
||||
#define %swig_equal_type(...) %swig_mark_flag(SWIG_EqualType(__VA_ARGS__))
|
||||
#define %swig_order_type(...) \
|
||||
%swig_mark_flag(SWIG_EqualType(__VA_ARGS__)) \
|
||||
%swig_mark_flag(SWIG_OrderType(__VA_ARGS__))
|
||||
|
||||
/*
|
||||
%evalif and %evalif_2 are use to evaluate or process
|
||||
an expression if the given predicate is 'true' (1).
|
||||
*/
|
||||
%define %_evalif(_x,_expr)
|
||||
#if _x == 1
|
||||
_expr
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
%define %_evalif_2(_x,_y,_expr)
|
||||
#if _x == 1 && _y == 1
|
||||
_expr
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
%define %evalif(_x,...)
|
||||
%_evalif(SWIG_arg(_x),SWIG_arg(__VA_ARGS__))
|
||||
%enddef
|
||||
|
||||
%define %evalif_2(_x,_y,...)
|
||||
%_evalif_2(SWIG_arg(_x),SWIG_arg(_y),SWIG_arg(__VA_ARGS__))
|
||||
%enddef
|
||||
|
||||
|
||||
%include <typemaps/swigmacros.swg>
|
||||
|
|
|
|||
|
|
@ -1,29 +0,0 @@
|
|||
|
||||
/* ------------------------------------------------------------
|
||||
* --- ANSI/Posix C/C++ types ---
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%types(size_t);
|
||||
%apply unsigned long { size_t };
|
||||
%apply const unsigned long& { const size_t& };
|
||||
%apply unsigned long& { size_t& };
|
||||
|
||||
%types(ptrdiff_t);
|
||||
%apply long { ptrdiff_t };
|
||||
%apply const long& { const ptrdiff_t& };
|
||||
%apply long& { ptrdiff_t& };
|
||||
|
||||
#ifdef __cplusplus
|
||||
%types(std::size_t);
|
||||
%apply unsigned long { std::size_t };
|
||||
%apply const unsigned long& { const std::size_t& };
|
||||
%apply unsigned long& { std::size_t& };
|
||||
|
||||
%types(std::ptrdiff_t);
|
||||
%apply long { std::ptrdiff_t };
|
||||
%apply const long& { const std::ptrdiff_t& };
|
||||
%apply long& { std::ptrdiff_t& };
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* PyObject * - Just pass straight through unmodified
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(in) PyObject * "$1 = $input;";
|
||||
%typemap(out) PyObject * "$result = $1;";
|
||||
|
||||
%typemap(constcode) PyObject * "PyDict_SetItemString(d,\"$symname\", $value);";
|
||||
|
||||
%typemap(directorin, parse="O") PyObject * "";
|
||||
%typemap(directorout) PyObject * "$result = $input;";
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) PyObject * "$1 = ($input != 0);";
|
||||
|
||||
%typemap(throws) PyObject *
|
||||
"PyErr_SetObject(PyExc_RuntimeError, $1);
|
||||
SWIG_fail;";
|
||||
|
|
@ -1,561 +1,28 @@
|
|||
%include <typemaps/primtypes.swg>
|
||||
|
||||
/* Macro for 'signed long' derived types */
|
||||
|
||||
%define %type_slong(Type, Frag, Min, Max)
|
||||
%derived_type_from(long, Type)
|
||||
%signed_derived_type_asval(long, Type, Frag, Min, Max)
|
||||
%enddef
|
||||
|
||||
/* Macro for 'unsigned long' derived types */
|
||||
|
||||
%define %type_ulong(Type, Frag, Max)
|
||||
%derived_type_from(unsigned long, Type)
|
||||
%unsigned_derived_type_asval(unsigned long, Type, Frag, Max)
|
||||
%enddef
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Primitive Types
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
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.
|
||||
*/
|
||||
|
||||
%fragment(SWIG_From_frag(signed char),"header") {
|
||||
SWIG_define(SWIG_From(signed char), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned char),"header") {
|
||||
SWIG_define(SWIG_From(unsigned char), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(short),"header") {
|
||||
SWIG_define(SWIG_From(short), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned short),"header") {
|
||||
SWIG_define(SWIG_From(unsigned short), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(int),"header") {
|
||||
SWIG_define(SWIG_From(int), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header") {
|
||||
SWIG_define(SWIG_From(long), PyInt_FromLong)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(float),"header") {
|
||||
SWIG_define(SWIG_From(float), PyFloat_FromDouble)
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(double),"header") {
|
||||
SWIG_define(SWIG_From(double), PyFloat_FromDouble)
|
||||
}
|
||||
|
||||
/*
|
||||
Here, we have all the complex AsVal/From methods
|
||||
*/
|
||||
|
||||
%fragment("<limits.h>","header") %{
|
||||
#include <limits.h>
|
||||
%}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(unsigned long)(PyObject *obj, unsigned long *val)
|
||||
{
|
||||
if (PyLong_Check(obj)) {
|
||||
unsigned long v = PyLong_AsUnsignedLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return 1;
|
||||
} else {
|
||||
if (!val) PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (PyInt_Check(obj)) {
|
||||
long v = PyInt_AsLong(obj);
|
||||
if (v >= 0) {
|
||||
if (val) *val = v;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("unsigned long", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_CheckLongInRange","header",
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERN int
|
||||
SWIG_CheckLongInRange(long value, long min_value, long max_value,
|
||||
const char *errmsg)
|
||||
{
|
||||
if (value < min_value) {
|
||||
if (errmsg) {
|
||||
PyErr_Format(PyExc_OverflowError,
|
||||
"value %ld is less than '%s' minimum %ld",
|
||||
value, errmsg, min_value);
|
||||
}
|
||||
return 0;
|
||||
} else if (value > max_value) {
|
||||
if (errmsg) {
|
||||
PyErr_Format(PyExc_OverflowError,
|
||||
"value %ld is greater than '%s' maximum %ld",
|
||||
value, errmsg, max_value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_CheckUnsignedLongInRange","header",
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_CheckUnsignedLongInRange(unsigned long value,
|
||||
unsigned long max_value,
|
||||
const char *errmsg)
|
||||
{
|
||||
if (value > max_value) {
|
||||
if (errmsg) {
|
||||
PyErr_Format(PyExc_OverflowError,
|
||||
"value %lu is greater than '%s' minimum %lu",
|
||||
value, errmsg, max_value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment(SWIG_AsVal_frag(double),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(double)(PyObject *obj, double *val)
|
||||
{
|
||||
if (PyFloat_Check(obj)) {
|
||||
if (val) *val = PyFloat_AsDouble(obj);
|
||||
return 1;
|
||||
}
|
||||
if (PyInt_Check(obj)) {
|
||||
if (val) *val = PyInt_AsLong(obj);
|
||||
return 1;
|
||||
}
|
||||
if (PyLong_Check(obj)) {
|
||||
double v = PyLong_AsDouble(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return 1;
|
||||
} else {
|
||||
if (!val) PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("double", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(long)(PyObject * obj, long* val)
|
||||
{
|
||||
if (PyLong_Check(obj)) {
|
||||
long v = PyLong_AsLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return 1;
|
||||
} else {
|
||||
if (!val) PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (PyInt_Check(obj)) {
|
||||
if (val) *val = PyInt_AsLong(obj);
|
||||
return 1;
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("long", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment(SWIG_From_frag(long long),"header",
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(long long)(long long value)
|
||||
{
|
||||
return ((value < LONG_MIN) || (value > LONG_MAX)) ?
|
||||
PyLong_FromLongLong(value)
|
||||
: PyInt_FromLong(SWIG_numeric_cast(value,long));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long long),"header",
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(unsigned long long)(unsigned long long value)
|
||||
{
|
||||
return (value > LONG_MAX) ?
|
||||
PyLong_FromUnsignedLongLong(value) :
|
||||
PyInt_FromLong(SWIG_numeric_cast(value,long));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long long),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(long long)(PyObject *obj, long long *val)
|
||||
{
|
||||
if (PyLong_Check(obj)) {
|
||||
long long v = PyLong_AsLongLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return 1;
|
||||
} else {
|
||||
if (!val) PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (PyInt_Check(obj)) {
|
||||
if (val) *val = PyInt_AsLong(obj);
|
||||
return 1;
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("long long", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
|
||||
fragment=SWIG_AsVal_frag(unsigned long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(unsigned long long)(PyObject *obj, unsigned long long *val)
|
||||
{
|
||||
unsigned long v;
|
||||
if (PyLong_Check(obj)) {
|
||||
unsigned long long v = PyLong_AsUnsignedLongLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return 1;
|
||||
} else {
|
||||
if (!val) PyErr_Clear();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if (SWIG_AsVal(unsigned long)(obj,&v)) {
|
||||
if (val) *val = v;
|
||||
return 1;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("unsigned long long", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long),"header") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(unsigned long)(unsigned long value)
|
||||
{
|
||||
return (value > LONG_MAX) ?
|
||||
PyLong_FromUnsignedLong(value)
|
||||
: PyInt_FromLong(SWIG_numeric_cast(value,long));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(signed char),"header",
|
||||
fragment="SWIG_CheckLongInRange",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(signed char)(PyObject *obj, signed char *val)
|
||||
{
|
||||
const char* errmsg = val ? "signed char" : (char*) 0;
|
||||
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);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error(errmsg, obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(short),"header",
|
||||
fragment="SWIG_CheckLongInRange",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(short)(PyObject *obj, short *val)
|
||||
{
|
||||
const char* errmsg = val ? "short" : (char*)0;
|
||||
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);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error(errmsg, obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* need range checks */
|
||||
|
||||
%fragment(SWIG_AsVal_frag(int),"header",
|
||||
fragment="SWIG_CheckLongInRange",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
%#if INT_MAX != LONG_MAX
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(int)(PyObject *obj, int *val)
|
||||
{
|
||||
const char* errmsg = val ? "int" : (char*)0;
|
||||
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);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error(errmsg, obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
%#else
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_AsVal(int)(PyObject *obj, int *val)
|
||||
{
|
||||
return SWIG_AsVal(long)(obj,(long*)val);
|
||||
}
|
||||
%#endif
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned int),"header",
|
||||
fragment="SWIG_CheckUnsignedLongInRange",
|
||||
fragment=SWIG_AsVal_frag(unsigned long)) {
|
||||
%#if UINT_MAX != ULONG_MAX
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(unsigned int)(PyObject *obj, unsigned int *val)
|
||||
{
|
||||
const char* errmsg = val ? "unsigned int" : (char*)0;
|
||||
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);
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error(errmsg, obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
%#else
|
||||
SWIGINTERNINLINE unsigned int
|
||||
SWIG_AsVal(unsigned int)(PyObject *obj, unsigned int *val)
|
||||
{
|
||||
return SWIG_AsVal(unsigned long)(obj,(unsigned long *)val);
|
||||
}
|
||||
%#endif
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned int),"header",
|
||||
fragment=SWIG_From_frag(long),
|
||||
fragment=SWIG_From_frag(unsigned long)) {
|
||||
%#if UINT_MAX < LONG_MAX
|
||||
SWIG_define(SWIG_From(unsigned int), SWIG_From(long))
|
||||
%#else
|
||||
SWIG_define(SWIG_From(unsigned int), SWIG_From(unsigned long))
|
||||
%#endif
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned char),"header",
|
||||
fragment=SWIG_AsVal_frag(unsigned long),
|
||||
fragment="SWIG_CheckUnsignedLongInRange") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(unsigned char)(PyObject *obj, unsigned char *val)
|
||||
{
|
||||
const char* errmsg = val ? "unsigned char" : (char*)0;
|
||||
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);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error(errmsg, obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned short),"header",
|
||||
fragment="SWIG_CheckUnsignedLongInRange",
|
||||
fragment=SWIG_AsVal_frag(unsigned long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(unsigned short)(PyObject *obj, unsigned short *val)
|
||||
{
|
||||
const char* errmsg = val ? "unsigned short" : (char*)0;
|
||||
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);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error(errmsg, obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment("SWIG_CheckDoubleInRange","header") {
|
||||
%#include <float.h>
|
||||
SWIGINTERN int
|
||||
SWIG_CheckDoubleInRange(double value, double min_value,
|
||||
double max_value, const char* errmsg)
|
||||
{
|
||||
if (value < min_value) {
|
||||
if (errmsg) {
|
||||
PyErr_Format(PyExc_OverflowError,
|
||||
"value %g is less than %s minimum %g",
|
||||
value, errmsg, min_value);
|
||||
}
|
||||
return 0;
|
||||
} else if (value > max_value) {
|
||||
if (errmsg) {
|
||||
PyErr_Format(PyExc_OverflowError,
|
||||
"value %g is greater than %s maximum %g",
|
||||
value, errmsg, max_value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(float),"header",
|
||||
fragment="SWIG_CheckDoubleInRange",
|
||||
fragment=SWIG_AsVal_frag(double)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(float)(PyObject *obj, float *val)
|
||||
{
|
||||
const char* errmsg = val ? "float" : (char*)0;
|
||||
double v;
|
||||
if (SWIG_AsVal(double)(obj, &v)) {
|
||||
if (SWIG_CheckDoubleInRange(v, -FLT_MAX, FLT_MAX, errmsg)) {
|
||||
if (val) *val = SWIG_numeric_cast(v, float);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error(errmsg, obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(char),"header") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(char)(char c)
|
||||
{
|
||||
return PyString_FromStringAndSize(&c,1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(char),"header",
|
||||
fragment="SWIG_AsCharArray",
|
||||
fragment="SWIG_CheckLongInRange",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(char)(PyObject *obj, char *val)
|
||||
{
|
||||
const char* errmsg = val ? "char" : (char*)0;
|
||||
long v;
|
||||
if (SWIG_AsVal(long)(obj, &v)) {
|
||||
if (SWIG_CheckLongInRange(v, CHAR_MIN,CHAR_MAX, errmsg)) {
|
||||
if (val) *val = SWIG_numeric_cast(v, char);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
return SWIG_AsCharArray(obj, val, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(wchar_t),"header") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(wchar_t)(wchar_t c)
|
||||
{
|
||||
return PyUnicode_FromWideChar(&c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(wchar_t),"header",
|
||||
fragment="SWIG_AsWCharArray",
|
||||
fragment="SWIG_CheckLongInRange",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
%#include <wchar.h>
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(wchar_t)(PyObject *obj, wchar_t *val)
|
||||
{
|
||||
const char* errmsg = val ? "wchar_t" : (char*)0;
|
||||
long v;
|
||||
if (SWIG_AsVal(long)(obj, &v)) {
|
||||
if (SWIG_CheckLongInRange(v, WCHAR_MIN, WCHAR_MAX, errmsg)) {
|
||||
if (val) *val = SWIG_numeric_cast(v, wchar_t);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
return SWIG_AsWCharArray(obj, val, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/* boolean */
|
||||
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(bool)(bool value)
|
||||
SWIG_From_dec(bool)(bool value)
|
||||
{
|
||||
PyObject *obj = value ? Py_True : Py_False;
|
||||
Py_INCREF(obj);
|
||||
|
|
@ -564,111 +31,278 @@ SWIGINTERNINLINE PyObject*
|
|||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(bool),"header",
|
||||
fragment=SWIG_AsVal_frag(int)) {
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(bool)(PyObject *obj, bool *val)
|
||||
SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
|
||||
{
|
||||
if (obj == Py_True) {
|
||||
if (val) *val = true;
|
||||
return 1;
|
||||
}
|
||||
if (obj == Py_False) {
|
||||
return SWIG_OK;
|
||||
} else if (obj == Py_False) {
|
||||
if (val) *val = false;
|
||||
return 1;
|
||||
}
|
||||
int res = 0;
|
||||
if (SWIG_AsVal(int)(obj, &res)) {
|
||||
if (val) *val = res ? true : false;
|
||||
return 1;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("bool", obj);
|
||||
long v = 0;
|
||||
int res = SWIG_AsVal(long)(obj, &v);
|
||||
if (res == SWIG_OK && val) *val = v ? true : false;
|
||||
return res;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* signed/unsigned char */
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* typemap for primitive type with no pointer representation
|
||||
* ------------------------------------------------------------ */
|
||||
%type_slong(signed char, "<limits.h>", SCHAR_MIN, SCHAR_MAX)
|
||||
%type_ulong(unsigned char, "<limits.h>", UCHAR_MAX)
|
||||
|
||||
%define %typemap_primitive(Code, ...)
|
||||
%typemap_asvalfromn(SWIG_arg(Code), __VA_ARGS__);
|
||||
%enddef
|
||||
|
||||
/* short/unsigned short */
|
||||
|
||||
%type_slong(short, "<limits.h>", SHRT_MIN, SHRT_MAX)
|
||||
%type_ulong(unsigned short, "<limits.h>", USHRT_MAX)
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Primitive Type Macros
|
||||
* ------------------------------------------------------------ */
|
||||
/* int/unsigned int */
|
||||
|
||||
/* useful macros to derive typemap declarations from primitive types */
|
||||
%type_slong(int, "<limits.h>", INT_MIN, INT_MAX)
|
||||
%type_ulong(unsigned int, "<limits.h>", UINT_MAX)
|
||||
|
||||
%define _apply_macro(macro, arg, ...)
|
||||
#if #__VA_ARGS__ != ""
|
||||
macro(__VA_ARGS__,arg);
|
||||
#else
|
||||
macro(arg);
|
||||
/* signed/unsigned wchar_t */
|
||||
|
||||
#ifdef __cplusplus
|
||||
%type_slong(signed wchar_t, "<wchar.h>", WCHAR_MIN, WCHAR_MAX)
|
||||
%type_ulong(unsigned wchar_t, "<wchar.h>", UWCHAR_MAX)
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
/* Apply macro to the order types */
|
||||
%define %apply_ctypes(Macro,...)
|
||||
_apply_macro(Macro, bool , __VA_ARGS__);
|
||||
_apply_macro(Macro, signed char , __VA_ARGS__);
|
||||
_apply_macro(Macro, unsigned char , __VA_ARGS__);
|
||||
_apply_macro(Macro, short , __VA_ARGS__);
|
||||
_apply_macro(Macro, unsigned short , __VA_ARGS__);
|
||||
_apply_macro(Macro, int , __VA_ARGS__);
|
||||
_apply_macro(Macro, unsigned int , __VA_ARGS__);
|
||||
_apply_macro(Macro, long , __VA_ARGS__);
|
||||
_apply_macro(Macro, unsigned long , __VA_ARGS__);
|
||||
_apply_macro(Macro, long long , __VA_ARGS__);
|
||||
_apply_macro(Macro, unsigned long long , __VA_ARGS__);
|
||||
_apply_macro(Macro, float , __VA_ARGS__);
|
||||
_apply_macro(Macro, double , __VA_ARGS__);
|
||||
_apply_macro(Macro, char , __VA_ARGS__);
|
||||
_apply_macro(Macro, wchar_t , __VA_ARGS__);
|
||||
%enddef
|
||||
/* long */
|
||||
|
||||
/* apply the Macro(Type) to all the C++ types */
|
||||
%define %apply_cpptypes(Macro,...)
|
||||
%apply_ctypes(Macro, __VA_ARGS__)
|
||||
_apply_macro(Macro, std::string, __VA_ARGS__);
|
||||
_apply_macro(Macro, std::complex<float> , __VA_ARGS__);
|
||||
_apply_macro(Macro, std::complex<double> , __VA_ARGS__);
|
||||
%enddef
|
||||
%fragment(SWIG_From_frag(long),"header",
|
||||
fragment="<limits.h>") {
|
||||
SWIG_define(SWIG_From_dec(long), PyInt_FromLong)
|
||||
}
|
||||
|
||||
/* apply the Macro2(Type1, Type2) to all the C++ types */
|
||||
%define %apply_cpptypes_2(Macro2)
|
||||
%apply_cpptypes(%apply_cpptypes, Macro2)
|
||||
%enddef
|
||||
%fragment(SWIG_AsVal_frag(long),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long)(PyObject *obj, long* val)
|
||||
{
|
||||
if (PyInt_Check(obj)) {
|
||||
if (val) *val = PyInt_AsLong(obj);
|
||||
return SWIG_OK;
|
||||
} else if (PyLong_Check(obj)) {
|
||||
long v = PyLong_AsLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%define %apply_checkctypes(Macro)
|
||||
Macro(SWIG_CCode(BOOL), bool);
|
||||
Macro(SWIG_CCode(INT8), signed char);
|
||||
Macro(SWIG_CCode(UINT8), unsigned char);
|
||||
Macro(SWIG_CCode(INT16), short);
|
||||
Macro(SWIG_CCode(UINT16), unsigned short);
|
||||
Macro(SWIG_CCode(INT32), int);
|
||||
Macro(SWIG_CCode(UINT32), unsigned int);
|
||||
Macro(SWIG_CCode(INT64), long);
|
||||
Macro(SWIG_CCode(UINT64), unsigned long);
|
||||
Macro(SWIG_CCode(INT128), long long);
|
||||
Macro(SWIG_CCode(UINT128), unsigned long long);
|
||||
Macro(SWIG_CCode(FLOAT), float);
|
||||
Macro(SWIG_CCode(DOUBLE), double);
|
||||
Macro(SWIG_CCode(CHAR), char);
|
||||
Macro(SWIG_CCode(UNICHAR), wchar_t);
|
||||
%enddef
|
||||
/* unsigned long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long),"header",
|
||||
fragment=SWIG_From_frag(long)) {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From_dec(unsigned long)(unsigned long value)
|
||||
{
|
||||
return (value > LONG_MAX) ?
|
||||
PyLong_FromUnsignedLong(value) : PyInt_FromLong(SWIG_numeric_cast(value,long));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long)(PyObject *obj, unsigned long *val)
|
||||
{
|
||||
if (PyInt_Check(obj)) {
|
||||
long v = PyInt_AsLong(obj);
|
||||
if (v >= 0) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
} else if (PyLong_Check(obj)) {
|
||||
unsigned long v = PyLong_AsUnsignedLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* long long */
|
||||
|
||||
%fragment(SWIG_From_frag(long long),"header",
|
||||
fragment=SWIG_From_frag(long),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From_dec(long long)(long long value)
|
||||
{
|
||||
return ((value < LONG_MIN) || (value > LONG_MAX)) ?
|
||||
PyLong_FromLongLong(value) : PyInt_FromLong(SWIG_numeric_cast(value,long));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long long),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long long)(PyObject *obj, long long *val)
|
||||
{
|
||||
if (PyInt_Check(obj)) {
|
||||
if (val) *val = PyInt_AsLong(obj);
|
||||
return SWIG_OK;
|
||||
} else if (PyLong_Check(obj)) {
|
||||
long long v = PyLong_AsLongLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long long),"header",
|
||||
fragment=SWIG_From_frag(long long),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From_dec(unsigned long long)(unsigned long long value)
|
||||
{
|
||||
return (value > LONG_MAX) ?
|
||||
PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(SWIG_numeric_cast(value,long));
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
|
||||
fragment=SWIG_AsVal_frag(unsigned long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val)
|
||||
{
|
||||
if (PyLong_Check(obj)) {
|
||||
unsigned long long v = PyLong_AsUnsignedLongLong(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
} else {
|
||||
unsigned long v;
|
||||
int res = SWIG_AsVal(unsigned long)(obj,&v);
|
||||
if (res == SWIG_OK && val) *val = v;
|
||||
return res;
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* float */
|
||||
|
||||
%derived_type_from(double, float)
|
||||
%signed_derived_type_asval(double, float, "<float.h>", -FLT_MAX, FLT_MAX)
|
||||
|
||||
/* double */
|
||||
|
||||
%fragment(SWIG_From_frag(double),"header") {
|
||||
SWIG_define(SWIG_From_dec(double), PyFloat_FromDouble)
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(double),"header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(double)(PyObject *obj, double *val)
|
||||
{
|
||||
if (PyFloat_Check(obj)) {
|
||||
if (val) *val = PyFloat_AsDouble(obj);
|
||||
return SWIG_OK;
|
||||
} else if (PyInt_Check(obj)) {
|
||||
if (val) *val = PyInt_AsLong(obj);
|
||||
return SWIG_OK;
|
||||
} else if (PyLong_Check(obj)) {
|
||||
double v = PyLong_AsDouble(obj);
|
||||
if (!PyErr_Occurred()) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* char */
|
||||
|
||||
%fragment(SWIG_From_frag(char),"header") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From_dec(char)(char c)
|
||||
{
|
||||
return PyString_FromStringAndSize(&c,1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(char),"header",
|
||||
fragment="SWIG_AsCharArray",
|
||||
fragment=SWIG_AsVal_frag(signed char)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(char)(PyObject *obj, char *val)
|
||||
{
|
||||
if (SWIG_AsCharArray(obj, val, 1) == SWIG_OK) {
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
signed char v;
|
||||
int res = SWIG_AsVal(signed char)(obj, &v);
|
||||
if (res == SWIG_OK && val) *val = (char)(v);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* wchar_t */
|
||||
|
||||
|
||||
%fragment(SWIG_From_frag(wchar_t),"header") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From_dec(wchar_t)(wchar_t c)
|
||||
{
|
||||
return PyUnicode_FromWideChar(&c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(wchar_t),"header",
|
||||
fragment="SWIG_AsWCharArray",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(wchar_t)(PyObject *obj, wchar_t *val)
|
||||
{
|
||||
if (SWIG_AsWCharArray(obj, val, 1) == SWIG_OK) {
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
long v;
|
||||
int res = SWIG_AsVal(long)(obj, &v);
|
||||
if (res == SWIG_OK) {
|
||||
if (WCHAR_MIN <= v && v <= WCHAR_MAX) {
|
||||
if (val) *val = (wchar_t)(v);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
return SWIG_OverflowError;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Apply the primitive typemap for all the types with checkcode
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%apply_checkctypes(%typemap_primitive)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,165 +0,0 @@
|
|||
/*
|
||||
Value typemaps (Type, const Type&) for "Ptr" types, such as swig
|
||||
wrapped classes, that define the AsPtr/From methods
|
||||
*/
|
||||
|
||||
/* in */
|
||||
|
||||
%define PYPTR_IN_TYPEMAP(asptr_meth,pyfrag,Type...)
|
||||
%typemap(in,fragment=pyfrag) Type {
|
||||
Type *ptr = (Type *)0;
|
||||
int res = asptr_meth($input, &ptr);
|
||||
if (!res) {
|
||||
if (!PyErr_Occurred())
|
||||
SWIG_type_error("$basetype", $input);
|
||||
} else if (!ptr) {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = *ptr;
|
||||
if (res == SWIG_NEWOBJ) delete ptr;
|
||||
}
|
||||
%typemap(in,fragment=pyfrag) const Type & (int res = 0) {
|
||||
Type *ptr = (Type *)0;
|
||||
res = asptr_meth($input, &ptr);
|
||||
if (!res) {
|
||||
if (!PyErr_Occurred())
|
||||
SWIG_type_error("$basetype", $input);
|
||||
} else if (!ptr) {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = ptr;
|
||||
}
|
||||
|
||||
%typemap(freearg) const Type &
|
||||
"if (res$argnum == SWIG_NEWOBJ) delete $1;";
|
||||
%enddef
|
||||
|
||||
/* varin */
|
||||
|
||||
%define PYPTR_VARIN_TYPEMAP(asptr_meth,pyfrag,Type...)
|
||||
%typemap(varin,fragment=pyfrag) Type {
|
||||
Type *ptr = (Type *)0;
|
||||
int res = asptr_meth($input, &ptr);
|
||||
if (!res) {
|
||||
if (!PyErr_Occurred()) {
|
||||
SWIG_type_error("$basetype", $input);
|
||||
}
|
||||
SWIG_append_errmsg(" C/C++ variable '$name'");
|
||||
return 1;
|
||||
} else if (!ptr) {
|
||||
SWIG_null_ref("$basetype");
|
||||
SWIG_append_errmsg(" C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
$1 = *ptr;
|
||||
if (res == SWIG_NEWOBJ) delete ptr;
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* directorout */
|
||||
|
||||
%define PYPTR_DIRECTOROUT_TYPEMAP(asptr_meth,pyfrag,Type...)
|
||||
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT ($*1_ltype temp) {
|
||||
Type *ptr = 0;
|
||||
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||
if (!res || !ptr)
|
||||
Swig::DirectorTypeMismatchException::raise("Error converting Python object when using asptr_meth.");
|
||||
temp = *ptr;
|
||||
$result = &temp;
|
||||
if (res == SWIG_NEWOBJ) delete ptr;
|
||||
}
|
||||
|
||||
%typemap(directorout,fragment=pyfrag) Type {
|
||||
Type *ptr = 0;
|
||||
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||
if (!res || !ptr)
|
||||
Swig::DirectorTypeMismatchException::raise("Error converting Python object when using asptr_meth.");
|
||||
$result = *ptr;
|
||||
if (res == SWIG_NEWOBJ) delete ptr;
|
||||
}
|
||||
|
||||
%typemap(directorout,fragment=pyfrag,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const Type& {
|
||||
Type *ptr = 0;
|
||||
int res = $input ? asptr_meth($input, &ptr) : 0;
|
||||
if (!res || !ptr)
|
||||
Swig::DirectorTypeMismatchException::raise("Error converting Python object when using asptr_meth.");
|
||||
$result = ptr;
|
||||
if (res == SWIG_NEWOBJ) {
|
||||
/* Possible thread/reentrant problem here! */
|
||||
static $*ltype temp = *ptr;
|
||||
$result = &temp;
|
||||
delete ptr;
|
||||
} else {
|
||||
$result = ptr;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
|
||||
|
||||
%enddef
|
||||
|
||||
/* typecheck */
|
||||
|
||||
%define PYPTR_TYPECHECK_TYPEMAP(check,asptr_meth,pyfrag,Type...)
|
||||
%typemap(typecheck,precedence=check,fragment=pyfrag)
|
||||
Type, const Type&
|
||||
"$1 = asptr_meth($input, (Type**)(0));";
|
||||
%enddef
|
||||
|
||||
/*
|
||||
typemap definition for types with AsPtr/From methods
|
||||
*/
|
||||
|
||||
%define %typemap_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type...)
|
||||
%fragment(SWIG_AsVal_frag(Type),"header",
|
||||
fragment=SWIG_AsPtr_frag(Type)) %{
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_AsVal(Type)(PyObject* obj, Type *val)
|
||||
{
|
||||
Type *v = (Type *)0;
|
||||
int res = SWIG_AsPtr(Type)(obj, &v);
|
||||
if (!res || !v) return 0;
|
||||
if (val) {
|
||||
*val = *v;
|
||||
if (res == SWIG_NEWOBJ) delete v;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
%}
|
||||
%fragment(SWIG_As_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(Type)) %{
|
||||
SWIGINTERNINLINE Type
|
||||
SWIG_As(Type)(PyObject* obj)
|
||||
{
|
||||
Type v;
|
||||
SWIG_AsVal(Type)(obj, &v);
|
||||
return v;
|
||||
}
|
||||
%}
|
||||
PYPTR_IN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
|
||||
PYPTR_VARIN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
|
||||
PYPTR_DIRECTOROUT_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
|
||||
PYPTR_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsPtrMeth),
|
||||
SWIG_arg(AsPtrFrag), Type);
|
||||
%typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
|
||||
PYPTR_INPUT_TYPEMAP(SWIG_arg(CheckCode),SWIG_arg(AsPtrMeth),
|
||||
SWIG_arg(AsPtrFrag),Type);
|
||||
PYVAL_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
PYPTR_INOUT_TYPEMAP(Type);
|
||||
%enddef
|
||||
|
||||
/*
|
||||
typemap for simple swig types with only AsPtr/From methods
|
||||
*/
|
||||
|
||||
%define %typemap_asptrfromn(CheckCode, Type...)
|
||||
%typemap_asptrfrom(SWIG_arg(CheckCode),
|
||||
SWIG_arg(SWIG_AsPtr(Type)),
|
||||
SWIG_arg(SWIG_From(Type)),
|
||||
SWIG_arg(SWIG_AsPtr_frag(Type)),
|
||||
SWIG_arg(SWIG_From_frag(Type)),
|
||||
Type);
|
||||
%enddef
|
||||
|
|
@ -9,75 +9,60 @@
|
|||
************************************************************************/
|
||||
|
||||
/* 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)
|
||||
|
||||
|
||||
/* Python-specific SWIG API */
|
||||
#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)
|
||||
/* for raw pointers */
|
||||
#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags)
|
||||
|
||||
/* for raw packed data */
|
||||
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)
|
||||
#define SWIG_NewPackedObj(ptr, sz, type, flags) SWIG_Python_NewPackedObj(ptr, sz, type)
|
||||
|
||||
/* for class or struct pointers */
|
||||
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_Python_NewPointerObj(ptr, type, flags)
|
||||
|
||||
/* for C or C++ function pointers */
|
||||
#define SWIG_ConvertFunctionPtr(obj, pptr, type, flags) SWIG_Python_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Python_NewPointerObj(ptr, type, 0)
|
||||
|
||||
/* for C++ member pointers, ie, member methods */
|
||||
#define SWIG_ConvertMember(obj, ptr, sz, ty, flags) SWIG_Python_ConvertPacked(obj, ptr, sz, ty, flags)
|
||||
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)
|
||||
|
||||
|
||||
/* Runtime API */
|
||||
#define SWIG_GetModule(clientdata) SWIG_Python_GetModule()
|
||||
#define SWIG_SetModule(clientdata, pointer) SWIG_Python_SetModule(pointer)
|
||||
|
||||
/* Error manipulation */
|
||||
#define SWIG_ERROR -1
|
||||
#define SWIG_fail goto fail
|
||||
#define SWIG_var_fail return 1
|
||||
|
||||
#define SWIG_error(code, msg) SWIG_Python_SetErrorMsg(SWIG_Python_ErrorType(code), msg)
|
||||
#define SWIG_exception(code, msg) do { SWIG_error(code, msg); SWIG_fail; } while (0)
|
||||
#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_error(SWIG_RuntimeError, msg); SWIG_fail; } else
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* 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
|
||||
SWIGRUNTIMEINLINE PyObject *
|
||||
SWIG_Python_NoneObject() {
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
|
||||
/* Add PyOS_snprintf for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02020000
|
||||
#define PyOS_snprintf snprintf
|
||||
#endif
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Create a new pointer object
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Create a new pointer string
|
||||
* ----------------------------------------------------------------------------- */
|
||||
#ifndef SWIG_BUFFER_SIZE
|
||||
#define SWIG_BUFFER_SIZE 1024
|
||||
#endif
|
||||
|
||||
/* A crude PyString_FromFormat implementation for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02020000
|
||||
static PyObject *
|
||||
PyString_FromFormat(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
char buf[SWIG_BUFFER_SIZE * 2];
|
||||
int res;
|
||||
va_start(ap, fmt);
|
||||
res = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
return (res < 0 || res >= sizeof(buf)) ? 0 : PyString_FromString(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if PY_VERSION_HEX < 0x01060000
|
||||
#define PyObject_Del(op) PyMem_DEL((op))
|
||||
#endif
|
||||
|
||||
#if defined(SWIG_COBJECT_TYPES)
|
||||
#if !defined(SWIG_COBJECT_PYTHON)
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Implements a simple Swig Object type, and use it instead of PyCObject
|
||||
* ----------------------------------------------------------------------------- */
|
||||
/* PySwigObject */
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
|
|
@ -85,7 +70,6 @@ typedef struct {
|
|||
const char *desc;
|
||||
} PySwigObject;
|
||||
|
||||
/* Declarations for objects of type PySwigObject */
|
||||
|
||||
SWIGRUNTIME int
|
||||
PySwigObject_print(PySwigObject *v, FILE *fp, int flags)
|
||||
|
|
@ -457,108 +441,6 @@ PySwigPacked_Check(PyObject *op) {
|
|||
|| (strcmp((op)->ob_type->tp_name,"PySwigPacked") == 0);
|
||||
}
|
||||
|
||||
#else
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Use the old Python PyCObject instead of PySwigObject
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#define PySwigObject_GetDesc(obj) PyCObject_GetDesc(obj)
|
||||
#define PySwigObject_Check(obj) PyCObject_Check(obj)
|
||||
#define PySwigObject_AsVoidPtr(obj) PyCObject_AsVoidPtr(obj)
|
||||
#define PySwigObject_FromVoidPtrAndDesc(p, d) PyCObject_FromVoidPtrAndDesc(p, d, NULL)
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* errors manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
SWIGRUNTIME void
|
||||
SWIG_Python_TypeError(const char *type, PyObject *obj)
|
||||
{
|
||||
if (type) {
|
||||
#if defined(SWIG_COBJECT_TYPES)
|
||||
if (obj && PySwigObject_Check(obj)) {
|
||||
const char *otype = (const char *) PySwigObject_GetDesc(obj);
|
||||
if (otype) {
|
||||
PyErr_Format(PyExc_TypeError, "a '%s' is expected, 'PySwigObject(%s)' is received",
|
||||
type, otype);
|
||||
return;
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
const char *otype = (obj ? obj->ob_type->tp_name : 0);
|
||||
if (otype) {
|
||||
PyObject *str = PyObject_Str(obj);
|
||||
const char *cstr = str ? PyString_AsString(str) : 0;
|
||||
if (cstr) {
|
||||
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s(%s)' is received",
|
||||
type, otype, cstr);
|
||||
} else {
|
||||
PyErr_Format(PyExc_TypeError, "a '%s' is expected, '%s' is received",
|
||||
type, otype);
|
||||
}
|
||||
Py_XDECREF(str);
|
||||
return;
|
||||
}
|
||||
}
|
||||
PyErr_Format(PyExc_TypeError, "a '%s' is expected", type);
|
||||
} else {
|
||||
PyErr_Format(PyExc_TypeError, "unexpected type is received");
|
||||
}
|
||||
}
|
||||
|
||||
SWIGRUNTIMEINLINE 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");
|
||||
}
|
||||
}
|
||||
|
||||
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()) {
|
||||
/* add information about failing argument */
|
||||
char mesg[256];
|
||||
PyOS_snprintf(mesg, sizeof(mesg), "argument number %d:", argnum);
|
||||
return SWIG_Python_AddErrMesg(mesg, 1);
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* pointers/data manipulation
|
||||
|
|
@ -574,13 +456,12 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
|
|||
PyObject *pyobj = 0;
|
||||
void *vptr;
|
||||
|
||||
if (!obj) return 0;
|
||||
if (!obj) return SWIG_ERROR;
|
||||
if (obj == Py_None) {
|
||||
*ptr = 0;
|
||||
return 0;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
#ifdef SWIG_COBJECT_TYPES
|
||||
if (!(PySwigObject_Check(obj))) {
|
||||
if (!SWIG_this)
|
||||
SWIG_this = PyString_FromString("this");
|
||||
|
|
@ -597,25 +478,6 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
|
|||
c = (const char *) PySwigObject_GetDesc(obj);
|
||||
if (newref) { Py_DECREF(obj); }
|
||||
goto type_check;
|
||||
#else
|
||||
if (!(PyString_Check(obj))) {
|
||||
if (!SWIG_this)
|
||||
SWIG_this = PyString_FromString("this");
|
||||
pyobj = obj;
|
||||
obj = PyObject_GetAttr(obj,SWIG_this);
|
||||
newref = 1;
|
||||
if (!obj) goto type_error;
|
||||
if (!PyString_Check(obj)) {
|
||||
Py_DECREF(obj);
|
||||
goto type_error;
|
||||
}
|
||||
}
|
||||
c = PyString_AsString(obj);
|
||||
/* Pointer values must start with leading underscore */
|
||||
c = SWIG_UnpackVoidPtr(c, &vptr, ty->name);
|
||||
if (newref) { Py_DECREF(obj); }
|
||||
if (!c) goto type_error;
|
||||
#endif
|
||||
|
||||
type_check:
|
||||
if (ty) {
|
||||
|
|
@ -628,7 +490,7 @@ type_check:
|
|||
if ((pyobj) && (flags & SWIG_POINTER_DISOWN)) {
|
||||
PyObject_SetAttrString(pyobj,(char*)"thisown",Py_False);
|
||||
}
|
||||
return 0;
|
||||
return SWIG_OK;
|
||||
|
||||
type_error:
|
||||
PyErr_Clear();
|
||||
|
|
@ -645,28 +507,7 @@ type_error:
|
|||
}
|
||||
}
|
||||
}
|
||||
if (flags & SWIG_POINTER_EXCEPTION) {
|
||||
if (ty) {
|
||||
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
|
||||
} else {
|
||||
SWIG_Python_TypeError("C/C++ pointer", obj);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Convert a pointer value, signal an exception on a type mismatch */
|
||||
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) {
|
||||
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
|
||||
SWIG_Python_ArgFail(argnum);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
|
|
@ -675,40 +516,27 @@ SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *t
|
|||
swig_cast_info *tc;
|
||||
const char *c = 0;
|
||||
|
||||
#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)
|
||||
c = PySwigPacked_UnpackData(obj, ptr, sz);
|
||||
#else
|
||||
if ((!obj) || (!PyString_Check(obj))) goto type_error;
|
||||
c = PyString_AsString(obj);
|
||||
/* Pointer values must start with leading underscore */
|
||||
c = SWIG_UnpackDataName(c, ptr, sz, ty->name);
|
||||
#endif
|
||||
if (!c) goto type_error;
|
||||
if (ty) {
|
||||
tc = SWIG_TypeCheck(c,ty);
|
||||
if (!tc) goto type_error;
|
||||
}
|
||||
return 0;
|
||||
return SWIG_OK;
|
||||
|
||||
type_error:
|
||||
PyErr_Clear();
|
||||
if (flags & SWIG_POINTER_EXCEPTION) {
|
||||
if (ty) {
|
||||
SWIG_Python_TypeError(SWIG_TypePrettyName(ty), obj);
|
||||
} else {
|
||||
SWIG_Python_TypeError("C/C++ packed data", obj);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
/* Create a new array object */
|
||||
SWIGRUNTIME PyObject *
|
||||
SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {
|
||||
SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
|
||||
PyObject *robj = 0;
|
||||
int own = flags & SWIG_POINTER_OWN;
|
||||
if (!type) {
|
||||
if (!PyErr_Occurred()) {
|
||||
PyErr_Format(PyExc_TypeError, "Swig: null type passed to NewPointerObj");
|
||||
PyErr_SetString(PyExc_TypeError, "Swig: null type passed to NewPointerObj");
|
||||
}
|
||||
return robj;
|
||||
}
|
||||
|
|
@ -716,15 +544,7 @@ SWIG_Python_NewPointerObj(void *ptr, swig_type_info *type, int own) {
|
|||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
#ifdef SWIG_COBJECT_TYPES
|
||||
robj = PySwigObject_FromVoidPtrAndDesc((void *) ptr, (char *)type->name);
|
||||
#else
|
||||
{
|
||||
char result[SWIG_BUFFER_SIZE];
|
||||
robj = SWIG_PackVoidPtr(result, ptr, type->name, sizeof(result)) ?
|
||||
PyString_FromString(result) : 0;
|
||||
}
|
||||
#endif
|
||||
if (!robj || (robj == Py_None)) return robj;
|
||||
if (type->clientdata) {
|
||||
PyObject *inst;
|
||||
|
|
@ -749,15 +569,8 @@ SWIG_Python_NewPackedObj(void *ptr, size_t sz, swig_type_info *type) {
|
|||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
#if defined(SWIG_COBJECT_TYPES) && !defined(SWIG_COBJECT_PYTHON)
|
||||
|
||||
robj = PySwigPacked_FromDataAndDesc((void *) ptr, sz, (char *)type->name);
|
||||
#else
|
||||
{
|
||||
char result[SWIG_BUFFER_SIZE];
|
||||
robj = SWIG_PackDataName(result, ptr, sz, type->name, sizeof(result)) ?
|
||||
PyString_FromString(result) : 0;
|
||||
}
|
||||
#endif
|
||||
return robj;
|
||||
}
|
||||
|
||||
|
|
@ -798,12 +611,12 @@ PyModule_AddObject(PyObject *m, char *name, PyObject *o)
|
|||
if (!PyModule_Check(m)) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"PyModule_AddObject() needs module as first arg");
|
||||
return -1;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if (!o) {
|
||||
PyErr_SetString(PyExc_TypeError,
|
||||
"PyModule_AddObject() needs non-NULL value");
|
||||
return -1;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
dict = PyModule_GetDict(m);
|
||||
|
|
@ -811,12 +624,12 @@ PyModule_AddObject(PyObject *m, char *name, PyObject *o)
|
|||
/* Internal error -- modules must have a dict! */
|
||||
PyErr_Format(PyExc_SystemError, "module '%s' has no __dict__",
|
||||
PyModule_GetName(m));
|
||||
return -1;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if (PyDict_SetItemString(dict, name, o))
|
||||
return -1;
|
||||
return SWIG_ERROR;
|
||||
Py_DECREF(o);
|
||||
return 0;
|
||||
return SWIG_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -1,13 +1,41 @@
|
|||
/* Python.h has to appear first */
|
||||
%insert(runtime) %{
|
||||
#include <Python.h>
|
||||
|
||||
/* Add PyOS_snprintf for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02020000
|
||||
#define PyOS_snprintf snprintf
|
||||
#endif
|
||||
|
||||
/* A crude PyString_FromFormat implementation for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x02020000
|
||||
|
||||
#ifndef SWIG_PYBUFFER_SIZE
|
||||
#define SWIG_PYBUFFER_SIZE 1024
|
||||
#endif
|
||||
|
||||
static PyObject *
|
||||
PyString_FromFormat(const char *fmt, ...) {
|
||||
va_list ap;
|
||||
char buf[SWIG_PYBUFFER_SIZE * 2];
|
||||
int res;
|
||||
va_start(ap, fmt);
|
||||
res = vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||
va_end(ap);
|
||||
return (res < 0 || res >= sizeof(buf)) ? 0 : PyString_FromString(buf);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Add PyObject_Del for old Pythons */
|
||||
#if PY_VERSION_HEX < 0x01060000
|
||||
#define PyObject_Del(op) PyMem_DEL((op))
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%insert(runtime) "swigrun.swg"; /* Common C API type-checking code */
|
||||
%insert(runtime) "pyapi.swg"; /* SWIG/Pyton API */
|
||||
%insert(runtime) "swigrun.swg"; /* SWIG API */
|
||||
%insert(runtime) "pyapi.swg"; /* Pyton API */
|
||||
%insert(runtime) "pyrun.swg"; /* Python run-time code */
|
||||
|
||||
|
||||
/* When using -nortti, tell directors to avoid RTTI */
|
||||
#ifdef SWIG_NORTTI
|
||||
%insert("runtime") %{
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
%include <pyptrtypes.swg>
|
||||
|
||||
%fragment("PyObject_var","header")
|
||||
%{
|
||||
{
|
||||
namespace swig {
|
||||
struct PyObject_var {
|
||||
PyObject* ptr;
|
||||
|
|
@ -11,10 +9,10 @@
|
|||
PyObject* operator->() const { return ptr; }
|
||||
};
|
||||
}
|
||||
%}
|
||||
}
|
||||
|
||||
%fragment("StdTraits","header",fragment="StdTraitsCommon")
|
||||
%{
|
||||
{
|
||||
namespace swig {
|
||||
/*
|
||||
Traits that provides the from method
|
||||
|
|
@ -54,14 +52,9 @@ namespace swig {
|
|||
struct traits_asptr {
|
||||
static int asptr(PyObject *obj, Type **val) {
|
||||
Type *p;
|
||||
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) != -1)
|
||||
? SWIG_OLDOBJ : 0;
|
||||
int res = (SWIG_ConvertPtr(obj, (void**)&p, type_info<Type>(), 0) == SWIG_OK) ? SWIG_OLDOBJ : 0;
|
||||
if (res) {
|
||||
if (val) {
|
||||
*val = p;
|
||||
}
|
||||
} else {
|
||||
SWIG_type_error(type_name<Type>(), obj);
|
||||
if (val) *val = p;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
@ -81,7 +74,7 @@ namespace swig {
|
|||
if ((res != 0) && p) {
|
||||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||
*(const_cast<noconst_type*>(val)) = *p;
|
||||
if (res == SWIG_NEWOBJ) delete p;
|
||||
if (res == SWIG_NEWOBJ) SWIG_delete(p);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
|
@ -93,7 +86,7 @@ namespace swig {
|
|||
};
|
||||
|
||||
template <class Type> struct traits_asval<Type*> {
|
||||
static bool asval(PyObject *obj, Type **val) {
|
||||
static int asval(PyObject *obj, Type **val) {
|
||||
if (val) {
|
||||
typedef typename noconst_traits<Type>::noconst_type noconst_type;
|
||||
noconst_type *p = 0;
|
||||
|
|
@ -121,7 +114,7 @@ namespace swig {
|
|||
Type v;
|
||||
if (!obj || !asval(obj, &v)) {
|
||||
if (!PyErr_Occurred()) {
|
||||
SWIG_type_error(swig::type_name<Type>(), obj);
|
||||
SWIG_Python_SetErrorMsg(SWIG_Python_ErrorType(SWIG_TypeError), swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
}
|
||||
|
|
@ -137,7 +130,7 @@ namespace swig {
|
|||
if (res && v) {
|
||||
if (res == SWIG_NEWOBJ) {
|
||||
Type r(*v);
|
||||
delete v;
|
||||
SWIG_delete(v);
|
||||
return r;
|
||||
} else {
|
||||
return *v;
|
||||
|
|
@ -146,7 +139,7 @@ namespace swig {
|
|||
// Uninitialized return value, no Type() constructor required.
|
||||
static Type *v_def = (Type*) malloc(sizeof(Type));
|
||||
if (!PyErr_Occurred()) {
|
||||
SWIG_type_error(swig::type_name<Type>(), obj);
|
||||
SWIG_Python_SetErrorMsg(SWIG_Python_ErrorType(SWIG_TypeError), swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
memset(v_def,0,sizeof(Type));
|
||||
|
|
@ -164,7 +157,7 @@ namespace swig {
|
|||
return v;
|
||||
} else {
|
||||
if (!PyErr_Occurred()) {
|
||||
SWIG_type_error(swig::type_name<Type>(), obj);
|
||||
SWIG_Python_SetErrorMsg(SWIG_Python_ErrorType(SWIG_TypeError),swig::type_name<Type>());
|
||||
}
|
||||
if (throw_error) throw std::invalid_argument("bad type");
|
||||
return 0;
|
||||
|
|
@ -196,7 +189,7 @@ namespace swig {
|
|||
return traits_check<Type, typename traits<Type>::category>::check(obj);
|
||||
}
|
||||
}
|
||||
%}
|
||||
}
|
||||
|
||||
//
|
||||
// Backward compatibility
|
||||
|
|
|
|||
|
|
@ -1,330 +0,0 @@
|
|||
//
|
||||
// Use the macro SWIG_PRESERVE_CARRAY_SIZE if you prefer to preserve
|
||||
// the size of char arrays, ie
|
||||
// ------------------------------------------
|
||||
// C Side => Python Side
|
||||
// ------------------------------------------
|
||||
// char name[5] = "hola" => 'hola\0'
|
||||
//
|
||||
// the default behaviour is
|
||||
//
|
||||
// char name[5] = "hola" => 'hola'
|
||||
//
|
||||
//
|
||||
//#define SWIG_PRESERVE_CARRAY_SIZE
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* String typemaps for type Char (char or wchar_t)
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%define %typemap_pystring(Char,
|
||||
SWIG_AsCharPtr,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtr,
|
||||
SWIG_AsNewCharPtr,
|
||||
SWIG_AsCharArray,
|
||||
SWIG_FromCharArray)
|
||||
/* in */
|
||||
|
||||
%typemap(in,fragment=#SWIG_AsCharPtr)
|
||||
Char *, Char const*, Char *const, Char const *const
|
||||
"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_arg_fail($argnum);SWIG_fail;}
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
/* out */
|
||||
|
||||
%typemap(out,fragment=#SWIG_FromCharPtr)
|
||||
Char *, Char const*, Char *const, Char const *const
|
||||
"$result = SWIG_FromCharPtr($1);";
|
||||
|
||||
%typemap(out,fragment=#SWIG_FromCharPtr)
|
||||
Char *const &, Char const* &, Char const *const &
|
||||
"$result = SWIG_FromCharPtr(*$1);";
|
||||
|
||||
/* varin */
|
||||
|
||||
%typemap(varin,fragment=#SWIG_AsNewCharPtr) Char *
|
||||
{
|
||||
Char *cptr = 0;
|
||||
if (!SWIG_AsNewCharPtr($input, &cptr)) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
if ($1) SWIG_delete_array($1);
|
||||
$1 = cptr;
|
||||
}
|
||||
|
||||
%typemap(varin,fragment=#SWIG_AsNewCharPtr,
|
||||
warning="451:Setting const Char * variable may leak memory")
|
||||
const Char *
|
||||
{
|
||||
Char *cptr;
|
||||
if (!SWIG_AsNewCharPtr($input, &cptr)) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
$1 = cptr;
|
||||
}
|
||||
|
||||
/* varout */
|
||||
|
||||
%typemap(varout,fragment=#SWIG_FromCharPtr)
|
||||
Char*, Char const*, Char *const, Char const *const
|
||||
"$result = SWIG_FromCharPtr($1);";
|
||||
|
||||
/* constant */
|
||||
|
||||
%typemap(constcode,fragment=#SWIG_FromCharPtr)
|
||||
Char *, Char const*, Char * const, Char const* const
|
||||
"PyDict_SetItemString(d,\"$symname\", SWIG_FromCharPtr($value));";
|
||||
|
||||
/* directorin */
|
||||
|
||||
%typemap(directorin,fragment=#SWIG_FromCharPtr)
|
||||
Char *, Char const*, Char *const, Char const *const,
|
||||
Char const *&, Char *const &, Char const *const &
|
||||
"$input = SWIG_FromCharPtr($1_name);";
|
||||
|
||||
/* directorout */
|
||||
|
||||
%typemap(directorout,fragment=#SWIG_AsCharPtr)
|
||||
Char *, Char const*, Char *const, Char const* const
|
||||
"if (!$input || !SWIG_AsCharPtr($input, (Char**) &$result)) {
|
||||
Swig::DirectorTypeMismatchException(\"Error converting Python object into Char*\");
|
||||
}";
|
||||
|
||||
%typemap(directorout,fragment=#SWIG_AsCharPtr)
|
||||
Char const *&, Char *const &, Char const *const &
|
||||
{
|
||||
Char* temp;
|
||||
if (!$input || !SWIG_AsCharPtr($input, &temp)) {
|
||||
Swig::DirectorTypeMismatchException("Error converting Python object into Char*");
|
||||
}
|
||||
$result = ($1_ltype) &temp;
|
||||
}
|
||||
|
||||
/* typecheck */
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING,
|
||||
fragment=#SWIG_AsCharPtr)
|
||||
Char *, Char const*, Char *const, Char const *const,
|
||||
Char const*&, Char *const&, Char const *const &
|
||||
"$1 = SWIG_AsCharPtr($input, (Char **)(0));";
|
||||
|
||||
/* throws */
|
||||
|
||||
%typemap(throws,fragment=#SWIG_FromCharPtr)
|
||||
Char *, Char const*, Char * const, Char const* const
|
||||
{
|
||||
PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharPtr($1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Unknown size const Character array Char[ANY] handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%apply Char* { Char [] };
|
||||
%apply const Char* { const Char [] };
|
||||
|
||||
%typemap(varin,warning="462:Unable to set variable of type Char []") Char []
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "C/C++ variable '$name' is read-only");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Fix size Character array Char[ANY] handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* memberin and globalin typemaps */
|
||||
|
||||
%typemap(memberin) Char [ANY]
|
||||
{
|
||||
if ($input) memcpy($1,$input,$1_dim0*sizeof(Char));
|
||||
else memset($1,0,$1_dim0*sizeof(Char));
|
||||
}
|
||||
|
||||
%typemap(globalin) Char [ANY]
|
||||
{
|
||||
if ($input) memcpy($1,$input,$1_dim0*sizeof(Char));
|
||||
else memset($1,0,$1_dim0*sizeof(Char));
|
||||
}
|
||||
|
||||
/* in */
|
||||
|
||||
%typemap(in,fragment=#SWIG_AsCharArray)
|
||||
Char [ANY] (Char temp[$1_dim0]),
|
||||
const Char [ANY](Char temp[$1_dim0])
|
||||
{
|
||||
if (!SWIG_AsCharArray($input, temp, $1_dim0)) {SWIG_arg_fail($argnum);SWIG_fail;}
|
||||
$1 = temp;
|
||||
}
|
||||
|
||||
%typemap(in,fragment=#SWIG_AsCharArray) const Char (&)[ANY] (Char temp[$1_dim0])
|
||||
{
|
||||
if (!SWIG_AsCharArray($input, temp, $1_dim0)) {SWIG_arg_fail($argnum);SWIG_fail;}
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(out,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($1[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
$result = SWIG_FromCharArray($1, size);
|
||||
}
|
||||
|
||||
/* varin */
|
||||
|
||||
%typemap(varin,fragment=#SWIG_AsCharArray) Char [ANY]
|
||||
{
|
||||
if (!SWIG_AsCharArray($input, $1, $1_dim0)) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* varout */
|
||||
|
||||
%typemap(varout,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char [ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($1[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
$result = SWIG_FromCharArray($1, size);
|
||||
}
|
||||
|
||||
/* constants */
|
||||
|
||||
%typemap(constcode,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char [ANY]
|
||||
{
|
||||
size_t size = $value_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($value[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
PyDict_SetItemString(d,"$symname", SWIG_FromCharArray($value,size));
|
||||
}
|
||||
|
||||
/* directorin */
|
||||
|
||||
%typemap(directorin,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char [ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($1_name[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
$input = SWIG_FromCharArray($1_name, size);
|
||||
}
|
||||
|
||||
/* directorout */
|
||||
|
||||
%typemap(directorout,fragment=#SWIG_AsCharArray)
|
||||
Char [ANY], const Char [ANY] (Char temp[$result_dim0])
|
||||
{
|
||||
if (!$input || !SWIG_AsCharArray($input, temp, $result_dim0)) {
|
||||
Swig::DirectorTypeMismatchException("Error converting Python object into Char[$result_dim0]");
|
||||
}
|
||||
$result = temp;
|
||||
}
|
||||
|
||||
/* typecheck */
|
||||
|
||||
%typemap(typecheck,precedence=SWIG_TYPECHECK_STRING,
|
||||
fragment=#SWIG_AsCharArray)
|
||||
Char [ANY], const Char[ANY]
|
||||
"$1 = SWIG_AsCharArray($input, (Char *)0, $1_dim0);";
|
||||
|
||||
/* throws */
|
||||
|
||||
%typemap(throws,fragment=#SWIG_FromCharArray)
|
||||
Char [ANY], const Char[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
%#ifndef SWIG_PRESERVE_CARRAY_SIZE
|
||||
while (size && ($1[size - 1] == '\0')) --size;
|
||||
%#endif
|
||||
PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, size));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
* --- Really fix size Char arrays, including '\0'chars at the end ---
|
||||
* ------------------------------------------------------------------- */
|
||||
|
||||
%typemap(varout,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
$result = SWIG_FromCharArray($1, size);
|
||||
}
|
||||
|
||||
%typemap(out,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
$result = SWIG_FromCharArray($1, size);
|
||||
}
|
||||
|
||||
%typemap(constcode,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $value_dim0;
|
||||
PyDict_SetItemString(d,"$symname", SWIG_FromCharArray($value,size));
|
||||
}
|
||||
|
||||
%typemap(directorin,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
$input = SWIG_FromCharArray($1_name, size);
|
||||
}
|
||||
|
||||
%typemap(throws,fragment=#SWIG_FromCharArray)
|
||||
Char FIXSIZE[ANY], const Char FIXSIZE[ANY]
|
||||
{
|
||||
size_t size = $1_dim0;
|
||||
PyErr_SetObject(PyExc_RuntimeError, SWIG_FromCharArray($1, size));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* --- String & length ---
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* Here len doesn't include the '0' terminator */
|
||||
%typemap(in, fragment=#SWIG_AsCharPtrAndSize)
|
||||
(Char *STRING, int LENGTH) (Char *buf, size_t size)
|
||||
{
|
||||
SWIG_AsCharPtrAndSize($input, &buf, &size);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = ($1_ltype) buf;
|
||||
$2 = ($2_ltype) size - 1;
|
||||
}
|
||||
|
||||
/* Here size includes the '0' terminator */
|
||||
%typemap(in,fragment=#SWIG_AsCharPtrAndSize)
|
||||
(Char *STRING, int SIZE) (Char *buf, size_t size)
|
||||
{
|
||||
SWIG_AsCharPtrAndSize($input, &buf, &size);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = ($1_ltype) buf;
|
||||
$2 = ($2_ltype) size;
|
||||
}
|
||||
|
||||
%enddef
|
||||
|
|
@ -1,147 +1,55 @@
|
|||
|
||||
/* ------------------------------------------------------------
|
||||
* utility methods for char strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%types(char *);
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
/* returns SWIG_OLDOBJ if the input is a raw char*, SWIG_PYSTR if is a PyString */
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize)
|
||||
SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
static swig_type_info* pchar_info = 0;
|
||||
char* vptr = 0;
|
||||
if (!pchar_info) pchar_info = SWIG_TypeQuery("char *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) != -1) {
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pchar_info, 0) == SWIG_OK) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
|
||||
return SWIG_OLDOBJ;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
if (PyString_Check(obj)) {
|
||||
if (cptr) {
|
||||
*cptr = PyString_AS_STRING(obj);
|
||||
if (psize) {
|
||||
*psize = PyString_GET_SIZE(obj) + 1;
|
||||
char *cstr; int len;
|
||||
PyString_AsStringAndSize(obj, &cstr, &len);
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
if (*alloc == SWIG_NEWOBJ) {
|
||||
*cptr = SWIG_new_copy_array(cstr, len + 1, char);
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_PYSTR;
|
||||
if (psize) *psize = len + 1;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
if (cptr) {
|
||||
SWIG_type_error("char *", obj);
|
||||
}
|
||||
return 0;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsCharPtr","header",
|
||||
fragment="SWIG_AsCharPtrAndSize") {
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_AsCharPtr(PyObject *obj, char **val)
|
||||
%fragment("SWIG_FromCharPtrAndSize","header") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
||||
{
|
||||
if (SWIG_AsCharPtrAndSize(obj, val, (size_t*)(0))) {
|
||||
return 1;
|
||||
}
|
||||
if (val) {
|
||||
PyErr_Clear();
|
||||
SWIG_type_error("char *", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromCharPtr","header") {
|
||||
SWIGINTERN PyObject *
|
||||
SWIG_FromCharPtr(const char* cptr)
|
||||
{
|
||||
if (cptr) {
|
||||
size_t size = strlen(cptr);
|
||||
if (carray) {
|
||||
if (size > INT_MAX) {
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(cptr,char*),
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,char *),
|
||||
SWIG_TypeQuery("char *"), 0);
|
||||
} else {
|
||||
if (size != 0) {
|
||||
return PyString_FromStringAndSize(cptr, size);
|
||||
} else {
|
||||
return PyString_FromString(cptr);
|
||||
}
|
||||
return PyString_FromStringAndSize(carray, SWIG_numeric_cast(size,int));
|
||||
}
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsNewCharPtr","header",
|
||||
fragment="SWIG_AsCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsNewCharPtr(PyObject *obj, char **val)
|
||||
{
|
||||
char* cptr = 0; size_t csize = 0;
|
||||
int res = SWIG_AsCharPtrAndSize(obj, &cptr, &csize);
|
||||
if (res) {
|
||||
if (val) {
|
||||
if (csize) {
|
||||
*val = SWIG_new_array(csize, char);
|
||||
memcpy(*val, cptr, --csize);
|
||||
(*val)[csize] = 0;
|
||||
} else if (cptr) {
|
||||
*val = SWIG_new_array(1, char);
|
||||
(*val)[0] = 0;
|
||||
} else {
|
||||
*val = 0;
|
||||
}
|
||||
}
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("char *", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsCharArray","header",
|
||||
fragment="SWIG_AsCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharArray(PyObject *obj, char *val, size_t size)
|
||||
{
|
||||
char* cptr; size_t csize;
|
||||
if (SWIG_AsCharPtrAndSize(obj, &cptr, &csize)) {
|
||||
/* in C you can do:
|
||||
|
||||
char x[5] = "hello";
|
||||
|
||||
ie, assing the array using an extra '0' char.
|
||||
*/
|
||||
if ((csize == size + 1) && !(cptr[csize-1])) --csize;
|
||||
if (csize <= size) {
|
||||
if (val) {
|
||||
if (csize) memcpy(val, cptr, csize);
|
||||
if (csize < size) memset(val + csize, 0, size - csize);
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
PyErr_Format(PyExc_TypeError,
|
||||
"a char array of maximum size %lu is expected",
|
||||
(unsigned long) size);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromCharArray","header") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromCharArray(const char* carray, size_t size)
|
||||
{
|
||||
if (size > INT_MAX) {
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,char *),
|
||||
SWIG_TypeQuery("char *"), 0);
|
||||
} else {
|
||||
return PyString_FromStringAndSize(carray, SWIG_numeric_cast(size,int));
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -150,10 +58,5 @@ SWIG_FromCharArray(const char* carray, size_t size)
|
|||
* The plain char * handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap_pystring(char,
|
||||
SWIG_AsCharPtr,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtr,
|
||||
SWIG_AsNewCharPtr,
|
||||
SWIG_AsCharArray,
|
||||
SWIG_FromCharArray)
|
||||
%include <typemaps/strings.swg>
|
||||
%typemap_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen)
|
||||
|
|
|
|||
|
|
@ -1,405 +1,11 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* --- Input arguments ---
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
|
||||
%typemap(in) SWIGTYPE *, SWIGTYPE []
|
||||
"SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | $disown);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;";
|
||||
|
||||
%typemap(in) SWIGTYPE* const& ($*ltype temp)
|
||||
"SWIG_Python_ConvertPtr($input, (void **)&temp, $*descriptor, SWIG_POINTER_EXCEPTION | $disown);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = &temp;
|
||||
";
|
||||
|
||||
%typemap(in) SWIGTYPE *DISOWN
|
||||
"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 & {
|
||||
SWIG_Python_ConvertPtr($input, (void **)&$1, $descriptor, SWIG_POINTER_EXCEPTION | $disown);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
if ($1 == NULL) {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
}
|
||||
|
||||
/* Object passed by value. Convert to a pointer */
|
||||
%typemap(in) SWIGTYPE {
|
||||
$<ype argp;
|
||||
SWIG_Python_ConvertPtr($input, (void **)&argp, $&descriptor, SWIG_POINTER_EXCEPTION);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
if (argp == NULL) {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
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($type),$descriptor,0)) == -1) {
|
||||
SWIG_type_error("$type",$input);
|
||||
}
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* --- Output arguments ---
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
%typemap(out) SWIGTYPE *, SWIGTYPE &
|
||||
"$result = SWIG_NewPointerObj((void*)($1), $descriptor, $owner);";
|
||||
|
||||
|
||||
%typemap(out) SWIGTYPE* const&
|
||||
"$result = SWIG_NewPointerObj((void*)(*$1), $*descriptor, $owner);";
|
||||
|
||||
/* Dynamic casts */
|
||||
|
||||
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
|
||||
swig_type_info *ty = SWIG_TypeDynamicCast($descriptor, (void **) &$1);
|
||||
$result = SWIG_NewPointerObj((void *) $1, ty, $owner);
|
||||
}
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(out) SWIGTYPE (CLASS::*)
|
||||
"$result = SWIG_NewPackedObj((void*)(&$1), sizeof($type), $descriptor);";
|
||||
|
||||
/* Primitive types--return by value */
|
||||
#ifdef __cplusplus
|
||||
%typemap(out) SWIGTYPE
|
||||
{
|
||||
$<ype resultptr;
|
||||
resultptr = new $ltype(SWIG_static_cast($1,$type &));
|
||||
$result = SWIG_NewPointerObj((void *)(resultptr), $&descriptor, 1);
|
||||
}
|
||||
#else
|
||||
%typemap(out /* warning="452:Default return typemap could be unsafe" */) SWIGTYPE
|
||||
{
|
||||
$<ype resultptr;
|
||||
resultptr = ($<ype) malloc(sizeof($type));
|
||||
if (resultptr) memcpy(resultptr, &$1, sizeof($type));
|
||||
$result = SWIG_NewPointerObj((void *)(resultptr), $&descriptor, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* --- Variable input ---
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* memberin/globalin/varin, for fix arrays. */
|
||||
|
||||
%typemap(memberin) SWIGTYPE [ANY] {
|
||||
$basetype *inp = SWIG_static_cast($input, $basetype *);
|
||||
if (inp) {
|
||||
$basetype *dest = SWIG_static_cast($1, $basetype *);
|
||||
size_t ii = 0;
|
||||
for (; ii < $dim0; ++ii) dest[ii] = inp[ii];
|
||||
} else {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(globalin) SWIGTYPE [ANY] {
|
||||
$basetype *inp = SWIG_static_cast($input, $basetype *);
|
||||
if (inp) {
|
||||
$basetype *dest = SWIG_static_cast($1, $basetype *);
|
||||
size_t ii = 0;
|
||||
for (; ii < $dim0; ++ii) dest[ii] = inp[ii];
|
||||
} else {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE [ANY] {
|
||||
$basetype *inp = 0;
|
||||
if ((SWIG_ConvertPtr($input, (void **)&inp, $descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
} else if (inp) {
|
||||
size_t ii = 0;
|
||||
$basetype *dest = SWIG_static_cast($1, $basetype *);
|
||||
for (; ii < $dim0; ++ii) dest[ii] = inp[ii];
|
||||
} else {
|
||||
SWIG_null_ref("$basetype");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* memberin/globalin/varin, for fix double arrays. */
|
||||
|
||||
%typemap(memberin) SWIGTYPE [ANY][ANY] {
|
||||
$basetype (*inp)[$dim1] = SWIG_static_cast($input, $basetype (*)[$dim1]);
|
||||
if (inp) {
|
||||
$basetype (*dest)[$dim1] = SWIG_static_cast($1, $basetype (*)[$dim1]);
|
||||
size_t ii = 0;
|
||||
for (; ii < $dim0; ++ii) {
|
||||
$basetype *ip = inp[ii];
|
||||
if (ip) {
|
||||
$basetype *dp = dest[ii];
|
||||
size_t jj = 0;
|
||||
for (; jj < $dim1; ++jj) dp[jj] = ip[jj];
|
||||
} else {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SWIG_null_ref("$basetype[$dim1]");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(globalin) SWIGTYPE [ANY][ANY] {
|
||||
$basetype (*inp)[$dim1] = SWIG_static_cast($input, $basetype (*)[$dim1]);
|
||||
if (inp) {
|
||||
$basetype (*dest)[$dim1] = SWIG_static_cast($1, $basetype (*)[$dim1]);
|
||||
size_t ii = 0;
|
||||
for (; ii < $dim0; ++ii) {
|
||||
$basetype *ip = inp[ii];
|
||||
if (ip) {
|
||||
$basetype *dp = dest[ii];
|
||||
size_t jj = 0;
|
||||
for (; jj < $dim1; ++jj) dp[jj] = ip[jj];
|
||||
} else {
|
||||
SWIG_null_ref("$basetype");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SWIG_null_ref("$basetype[$dim1]");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE [ANY][ANY] {
|
||||
$basetype (*inp)[$dim1] = 0;
|
||||
if ((SWIG_ConvertPtr($input, (void **)&inp, $descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
} else if (inp) {
|
||||
$basetype (*dest)[$dim1] = SWIG_static_cast($1, $basetype (*)[$dim1]);
|
||||
size_t ii = 0;
|
||||
for (; ii < $dim0; ++ii) {
|
||||
$basetype *ip = inp[ii];
|
||||
if (ip) {
|
||||
$basetype *dp = dest[ii];
|
||||
size_t jj = 0;
|
||||
for (; jj < $dim1; ++jj) dp[jj] = ip[jj];
|
||||
} else {
|
||||
SWIG_null_ref("$basetype");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
SWIG_null_ref("$basetype[$dim1]");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Pointers, references, and variable size arrays */
|
||||
|
||||
%typemap(varin) SWIGTYPE * {
|
||||
void *temp;
|
||||
if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
$1 = ($ltype) temp;
|
||||
}
|
||||
|
||||
%typemap(varin,warning="462:Unable to set dimensionless array variable") SWIGTYPE []
|
||||
{
|
||||
PyErr_SetString(PyExc_AttributeError, "C/C++ variable '$name' is read-only");
|
||||
return 1;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE & {
|
||||
void *temp;
|
||||
if ((SWIG_ConvertPtr($input, &temp, $descriptor, SWIG_POINTER_EXCEPTION)) == -1 || temp == NULL) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
$1 = *($ltype) temp;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE (CLASS::*) {
|
||||
char temp[sizeof($type)];
|
||||
if ((SWIG_ConvertPacked($input,(void *) temp, sizeof($type), $descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
memmove((void *) &$1,temp,sizeof($type));
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE {
|
||||
$<ype temp;
|
||||
if ((SWIG_ConvertPtr($input, (void **)(&temp), $&descriptor, SWIG_POINTER_EXCEPTION)) == -1) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
$1 = *(($&type) temp);
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* --- Variable output ---
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* Pointers and arrays */
|
||||
%typemap(varout) SWIGTYPE *, SWIGTYPE []
|
||||
"$result = SWIG_NewPointerObj((void *)($1), $descriptor, 0);";
|
||||
|
||||
/* References */
|
||||
%typemap(varout) SWIGTYPE &
|
||||
"$result = SWIG_NewPointerObj((void *)(&$1), $descriptor, 0);";
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(varout) SWIGTYPE (CLASS::*)
|
||||
"$result = SWIG_NewPackedObj((void *)(&$1), sizeof($type), $descriptor);";
|
||||
|
||||
%typemap(varout) SWIGTYPE
|
||||
"$result = SWIG_NewPointerObj((void *)(&$1), $&descriptor, 0);";
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* --- Constants --- *
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
/* Pointers, arrays, objects */
|
||||
|
||||
%typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
{ SWIG_PY_POINTER, (char*)"$symname", 0, 0, (void *)$value, &$descriptor}
|
||||
|
||||
%typemap(consttab) SWIGTYPE (CLASS::*)
|
||||
{ SWIG_PY_BINARY, (char *)"$symname", sizeof($type), 0, (void *)&$value, &$descriptor}
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* --- Director typemaps --- *
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* directorin */
|
||||
|
||||
%typemap(directorin) SWIGTYPE* {
|
||||
$input = SWIG_NewPointerObj(SWIG_static_cast(SWIG_static_cast($1_name, $1_ltype), void*), $descriptor, 0);
|
||||
}
|
||||
|
||||
%typemap(directorin) SWIGTYPE {
|
||||
$input = SWIG_NewPointerObj(SWIG_static_cast(SWIG_static_cast(&$1_name, $&1_ltype), void*), $&descriptor, 0);
|
||||
}
|
||||
|
||||
%typemap(directorin) SWIGTYPE& {
|
||||
$input = SWIG_NewPointerObj(SWIG_static_cast(SWIG_static_cast(&$1_name, $1_ltype), void*), $descriptor, 0);
|
||||
}
|
||||
|
||||
/* the const cases */
|
||||
%typemap(directorin) SWIGTYPE const& {
|
||||
$input = SWIG_NewPointerObj(SWIG_static_cast(SWIG_const_cast(&$1_name, $1_ltype), void*), $descriptor, 0);
|
||||
}
|
||||
|
||||
%typemap(directorin) SWIGTYPE const* {
|
||||
$input = SWIG_NewPointerObj(SWIG_static_cast(SWIG_const_cast($1_name, $1_ltype), void*), $descriptor, 0);
|
||||
}
|
||||
|
||||
|
||||
/* directorout */
|
||||
|
||||
%typemap(directorout) SWIGTYPE ($<ype argp)
|
||||
"if (!$input || (SWIG_ConvertPtr($input, (void **)(&argp),
|
||||
$&descriptor, SWIG_POINTER_EXCEPTION | $disown)) == -1)
|
||||
Swig::DirectorTypeMismatchException::raise(\"Pointer conversion failed.\");
|
||||
$result = *argp;";
|
||||
|
||||
%typemap(directorout) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
"if (!$input || (SWIG_ConvertPtr($input,(void **)(&$result),
|
||||
$descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1)
|
||||
Swig::DirectorTypeMismatchException::raise(\"Pointer conversion failed.\");";
|
||||
|
||||
%include <typemaps/swigtype.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* --- Typechecking rules ---
|
||||
* --- Consttab --- needed for callbacks, it should be removed later.
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER)
|
||||
SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
{
|
||||
void *ptr;
|
||||
if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0) == -1) {
|
||||
$1 = 0;
|
||||
PyErr_Clear();
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
%typemap(consttab) SWIGTYPE ((*)(ANY))
|
||||
{ SWIG_PY_POINTER, (char*)"$symname", 0, 0, (void *)($value), &$descriptor }
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE &
|
||||
{
|
||||
void *ptr = 0;
|
||||
if (SWIG_ConvertPtr($input, &ptr, $descriptor, 0) == -1) {
|
||||
$1 = 0;
|
||||
PyErr_Clear();
|
||||
} else {
|
||||
$1 = (ptr != 0);
|
||||
}
|
||||
}
|
||||
%typemap(constcode) SWIGTYPE ((*)(ANY)) "";
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE
|
||||
{
|
||||
void *ptr = 0;
|
||||
if (SWIG_ConvertPtr($input, &ptr, $&descriptor, 0) == -1) {
|
||||
$1 = 0;
|
||||
PyErr_Clear();
|
||||
} else {
|
||||
$1 = (ptr != 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* --- Exception handling ---
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) SWIGTYPE {
|
||||
$<ype temp = new $ltype($1);
|
||||
if ($&descriptor->clientdata) {
|
||||
PyErr_SetObject((PyObject *) ($&descriptor->clientdata), SWIG_NewPointerObj(temp,$&descriptor,1));
|
||||
} else {
|
||||
PyErr_SetString(PyExc_RuntimeError,"$type");
|
||||
}
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
|
||||
%typemap(throws) SWIGTYPE * {
|
||||
if ($descriptor->clientdata) {
|
||||
PyErr_SetObject((PyObject *) ($descriptor->clientdata),
|
||||
SWIG_NewPointerObj((void *) $1,$descriptor,1));
|
||||
} else {
|
||||
PyErr_SetString(PyExc_RuntimeError,"$type");
|
||||
}
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
|
||||
%typemap(throws) SWIGTYPE [ANY] {
|
||||
if ($descriptor->clientdata) {
|
||||
PyErr_SetObject((PyObject *) ($descriptor->clientdata),
|
||||
SWIG_NewPointerObj((void *)$1,$descriptor,1));
|
||||
} else {
|
||||
PyErr_SetString(PyExc_RuntimeError,"$type");
|
||||
}
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE & {
|
||||
if ($descriptor->clientdata) {
|
||||
PyErr_SetObject((PyObject *) ($descriptor->clientdata),
|
||||
SWIG_NewPointerObj((void *)&($1),$descriptor,1));
|
||||
} else {
|
||||
PyErr_SetString(PyExc_RuntimeError,"$type");
|
||||
}
|
||||
SWIG_fail;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,16 @@
|
|||
resolution.
|
||||
*/
|
||||
|
||||
#undef SWIG_TYPECHECK_BOOL
|
||||
%define SWIG_TYPECHECK_BOOL 10000 %enddef
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Inner macros
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <pymacros.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Error manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <pyerrors.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* The runtime part
|
||||
|
|
@ -23,30 +30,11 @@
|
|||
* ----------------------------------------------------------------------------- */
|
||||
%include <pyuserdir.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Inner macros (ugly ones)
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <pymacros.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Look for user fragments file. If not found, include empty system one.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include "pyfragments.swg"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <pyswigtype.swg>
|
||||
%include <pyinout.swg>
|
||||
%include <pyvoid.swg>
|
||||
%include <pyobject.swg>
|
||||
%include <pystrbase.swg>
|
||||
%include <pystrings.swg>
|
||||
%include <pyvaltypes.swg>
|
||||
%include <pyptrtypes.swg>
|
||||
%include <pyprimtypes.swg>
|
||||
%include <pymisctypes.swg>
|
||||
%include <pyenum.swg>
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <pytypemaps.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
|
|
|
|||
|
|
@ -4,23 +4,5 @@
|
|||
(std::pair,std::vector,std::list,etc) return tuples.
|
||||
*/
|
||||
|
||||
%fragment("t_output_helper","header") %{
|
||||
SWIGINTERN PyObject*
|
||||
t_output_helper(PyObject* target, PyObject* o) {
|
||||
if (!target) {
|
||||
target = o;
|
||||
} else if (target == Py_None) {
|
||||
Py_DECREF(target);
|
||||
target = o;
|
||||
} else {
|
||||
if (!PyList_Check(target)) {
|
||||
PyObject *o2 = target;
|
||||
target = PyList_New(1);
|
||||
PyList_SetItem(target, 0, o2);
|
||||
}
|
||||
PyList_Append(target,o);
|
||||
Py_DECREF(o);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
%}
|
||||
#warning "Deprecated file: Don't use t_output_helper anymore,"
|
||||
#warning "use SWIG_Python_AppendResult or SWIG_append_result instead."
|
||||
|
|
|
|||
56
Lib/python/pytypemaps.swg
Normal file
56
Lib/python/pytypemaps.swg
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* directors are supported in Python */
|
||||
#ifndef SWIG_DIRECTOR_TYPEMAPS
|
||||
#define SWIG_DIRECTOR_TYPEMAPS
|
||||
#endif
|
||||
|
||||
/* bool is dangerous in Python -> C++, change precedence */
|
||||
#undef SWIG_TYPECHECK_BOOL
|
||||
%define SWIG_TYPECHECK_BOOL 10000 %enddef
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Basic definitions
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%define_swig_object(PyObject *)
|
||||
|
||||
#define SWIG_SetResultObj(obj) $result = obj
|
||||
#define SWIG_AppendResultObj(obj) $result = SWIG_Python_AppendResult($result, obj)
|
||||
#define SWIG_SetConstantObj(name, obj) PyDict_SetItemString(d, name, obj);
|
||||
#define SWIG_NoneObject() SWIG_Python_NoneObject()
|
||||
|
||||
/* error manipulation */
|
||||
#define SWIG_ErrorType(code) SWIG_Python_ErrorType(code)
|
||||
#define SWIG_SetErrorObj(code, obj) PyErr_SetObject(SWIG_ErrorType(code), obj)
|
||||
#define SWIG_SetErrorMsg(code, msg) SWIG_Python_SetErrorMsg(SWIG_ErrorType(code),msg)
|
||||
#define SWIG_ExceptionObj(desc, type, obj) SWIG_Python_SetExceptionObj(desc, obj)
|
||||
#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg)
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* All the typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
%fragment("t_output_helper","header") %{
|
||||
#define t_output_helper SWIG_Python_AppendResult
|
||||
%}
|
||||
|
||||
|
||||
%include "pyfragments.swg"
|
||||
|
||||
%include <pyswigtype.swg>
|
||||
%include <typemaps/void.swg>
|
||||
%include <typemaps/valtypes.swg>
|
||||
%include <typemaps/ptrtypes.swg>
|
||||
%include <typemaps/swigobject.swg>
|
||||
%include <typemaps/inoutlist.swg>
|
||||
%include <pyprimtypes.swg>
|
||||
%include <pystrings.swg>
|
||||
%include <typemaps/misctypes.swg>
|
||||
%include <typemaps/enumint.swg>
|
||||
|
||||
|
|
@ -105,8 +105,9 @@ These methods "may be called" if needed.
|
|||
#define %nopythoncallback %feature("python:callback","0")
|
||||
#define %clearpythoncallback %feature("python:callback","")
|
||||
|
||||
|
||||
/* Support for the old %callback directive name */
|
||||
/*
|
||||
Support for the old %callback directive name
|
||||
*/
|
||||
#ifdef %callback
|
||||
#undef %callback
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,208 +0,0 @@
|
|||
/*---------------------------------------------------------------------
|
||||
* Value typemaps (Type, const Type&) for value types, such as
|
||||
* fundamental types (int, double), that define the As/AsVal/From
|
||||
* methods.
|
||||
*---------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/* in */
|
||||
|
||||
%define PYVAL_IN_TYPEMAP(as_meth,pyfrag,Type...)
|
||||
%typemap(in,fragment=pyfrag) Type {
|
||||
$1 = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
}
|
||||
%typemap(in,fragment=pyfrag) const Type & ($*ltype temp) {
|
||||
temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = &temp;
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* out */
|
||||
|
||||
%define PYVAL_OUT_TYPEMAP(from_meth,pyfrag,Type...)
|
||||
%typemap(out,fragment=pyfrag) Type, const Type
|
||||
{ $result = from_meth(SWIG_static_cast($1,Type)); }
|
||||
|
||||
%typemap(out,fragment=pyfrag) const Type&
|
||||
{ $result = from_meth(SWIG_static_cast(*$1,Type)); }
|
||||
%enddef
|
||||
|
||||
/* varin */
|
||||
|
||||
%define PYVAL_VARIN_TYPEMAP(as_meth,pyfrag,Type...)
|
||||
%typemap(varin,fragment=pyfrag) Type {
|
||||
$1_type temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$1_type);
|
||||
if (PyErr_Occurred()) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name ($1_ltype)'");
|
||||
return 1;
|
||||
}
|
||||
$1 = temp;
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* varout */
|
||||
|
||||
%define PYVAL_VAROUT_TYPEMAP(from_meth,pyfrag,Type...)
|
||||
%typemap(varout,fragment=pyfrag) Type, const Type&
|
||||
{ $result = from_meth(SWIG_static_cast($1,$basetype)); }
|
||||
%enddef
|
||||
|
||||
/* constant installation code */
|
||||
|
||||
%define PYVAL_CONSTCODE_TYPEMAP(from_meth,pyfrag,Type...)
|
||||
%typemap(constcode,fragment=pyfrag) Type
|
||||
{ PyDict_SetItemString(d,"$symname", from_meth(SWIG_static_cast($value,$basetype))); }
|
||||
%enddef
|
||||
|
||||
/* directorin */
|
||||
|
||||
%define PYVAL_DIRECTORIN_TYPEMAP(from_meth,pyfrag,Type...)
|
||||
%typemap(directorin,fragment=pyfrag) Type *DIRECTORIN
|
||||
{ $input = from_meth(SWIG_static_cast(*$1_name,$basetype)); }
|
||||
%typemap(directorin,fragment=pyfrag) Type, const Type&
|
||||
{ $input = from_meth(SWIG_static_cast($1_name,$basetype)); }
|
||||
%enddef
|
||||
|
||||
/* directorout */
|
||||
|
||||
%define PYVAL_DIRECTOROUT_TYPEMAP(as_meth,pyfrag,Type...)
|
||||
%typemap(directorargout,fragment=pyfrag) Type *DIRECTOROUT {
|
||||
if ($input) *$result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||
if (!$input || PyErr_Occurred())
|
||||
Swig::DirectorTypeMismatchException::raise("Error converting Python object when using as_meth.");
|
||||
}
|
||||
%typemap(directorout,fragment=pyfrag) Type {
|
||||
if ($input) $result = SWIG_static_cast(SWIG_arg(as_meth($input)),$type);
|
||||
if (!$input || PyErr_Occurred())
|
||||
Swig::DirectorTypeMismatchException::raise("Error converting Python object when using as_meth.");
|
||||
}
|
||||
%typemap(directorout,fragment=pyfrag,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const Type& {
|
||||
if ($input) {
|
||||
static $basetype temp = SWIG_static_cast(SWIG_arg(as_meth($input)),$basetype);
|
||||
$result = &temp;
|
||||
}
|
||||
if (!$input || PyErr_Occurred())
|
||||
Swig::DirectorTypeMismatchException::raise("Error converting Python object when using as_meth.");
|
||||
}
|
||||
%typemap(directorout,fragment=pyfrag) Type &DIRECTOROUT = Type
|
||||
%enddef
|
||||
|
||||
/* throws */
|
||||
|
||||
%define PYVAL_THROWS_TYPEMAP(from_meth,pyfrag,Type...)
|
||||
%typemap(throws,fragment=pyfrag) Type {
|
||||
PyErr_SetObject(PyExc_RuntimeError, from_meth(SWIG_static_cast($1,$basetype)));
|
||||
SWIG_fail;
|
||||
}
|
||||
%enddef
|
||||
|
||||
/* typecheck */
|
||||
|
||||
%define PYVAL_TYPECHECK_TYPEMAP(check,pyobj_check,pyfrag,Type...)
|
||||
%typemap(typecheck,precedence=check,fragment=pyfrag)
|
||||
Type, const Type&
|
||||
"$1 = pyobj_check($input);";
|
||||
%enddef
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
* typemap definition for types with As/Check methods
|
||||
*---------------------------------------------------------------------*/
|
||||
%define %typemap_ascheck(CheckCode, AsMeth, CheckMeth,
|
||||
AsFrag, CheckFrag, Type...)
|
||||
PYVAL_IN_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
|
||||
PYVAL_VARIN_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
|
||||
PYVAL_DIRECTOROUT_TYPEMAP(SWIG_arg(AsMeth), SWIG_arg(AsFrag), Type);
|
||||
PYVAL_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(CheckMeth),
|
||||
SWIG_arg(CheckFrag), Type);
|
||||
|
||||
PYVAL_INPUT_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsMeth), SWIG_arg(CheckMeth),
|
||||
SWIG_arg(AsFrag), SWIG_arg(CheckFrag), Type);
|
||||
%enddef
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
* typemap definition for types with AsVal method
|
||||
*---------------------------------------------------------------------*/
|
||||
%define %typemap_asvaln(CheckCode, Type...)
|
||||
%fragment(SWIG_As_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(Type)) %{
|
||||
SWIGINTERNINLINE Type
|
||||
SWIG_As(Type)(PyObject* obj)
|
||||
{
|
||||
Type v;
|
||||
if (!SWIG_AsVal(Type)(obj, &v)) {
|
||||
/*
|
||||
this is needed to make valgrind/purify happier.
|
||||
*/
|
||||
memset((void*)&v, 0, sizeof(Type));
|
||||
}
|
||||
return v;
|
||||
}
|
||||
%}
|
||||
%fragment(SWIG_Check_frag(Type),"header",
|
||||
fragment=SWIG_AsVal_frag(Type)) %{
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_Check(Type)(PyObject* obj)
|
||||
{
|
||||
return SWIG_AsVal(Type)(obj, (Type*)0);
|
||||
}
|
||||
%}
|
||||
%typemap_ascheck(SWIG_arg(CheckCode),
|
||||
SWIG_As(Type),
|
||||
SWIG_Check(Type),
|
||||
SWIG_arg(SWIG_As_frag(Type)),
|
||||
SWIG_arg(SWIG_Check_frag(Type)),
|
||||
Type);
|
||||
%enddef
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
* typemap definition for types with from method
|
||||
*---------------------------------------------------------------------*/
|
||||
%define %typemap_from(FromMeth, FromFrag, Type...)
|
||||
PYVAL_OUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
PYVAL_VAROUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
PYVAL_CONSTCODE_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
PYVAL_DIRECTORIN_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
PYVAL_THROWS_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
PYVAL_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
|
||||
%enddef
|
||||
|
||||
|
||||
%define %typemap_ascheckfrom(CheckCode, AsMeth, CheckMeth, FromMeth,
|
||||
AsFrag, CheckFrag, FromFrag, Type...)
|
||||
%typemap_ascheck(SWIG_arg(CheckCode), SWIG_arg(AsMeth), SWIG_arg(CheckMeth),
|
||||
SWIG_arg(AsFrag), SWIG_arg(CheckFrag), Type);
|
||||
%typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
|
||||
|
||||
PYVAL_INOUT_TYPEMAP(Type);
|
||||
|
||||
%enddef
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
* typemap definition for types with asval/from method
|
||||
*---------------------------------------------------------------------*/
|
||||
%define %typemap_asvalfromn(CheckCode, Type...)
|
||||
%typemap_asvaln(SWIG_arg(CheckCode), Type);
|
||||
%typemap_from(SWIG_arg(SWIG_From(Type)),
|
||||
SWIG_arg(SWIG_From_frag(Type)),
|
||||
Type);
|
||||
|
||||
PYVAL_INOUT_TYPEMAP(Type);
|
||||
|
||||
%enddef
|
||||
|
||||
/*---------------------------------------------------------------------
|
||||
* typemap definition for types with as/check/from method
|
||||
*---------------------------------------------------------------------*/
|
||||
%define %typemap_ascheckfromn(CheckCode, Type...)
|
||||
%typemap_ascheckfrom(SWIG_arg(CheckCode),
|
||||
SWIG_As(Type),
|
||||
SWIG_From(Type),
|
||||
SWIG_Check(Type),
|
||||
SWIG_arg(SWIG_As_frag(Type)),
|
||||
SWIG_arg(SWIG_From_frag(Type)),
|
||||
SWIG_arg(SWIG_Check_frag(Type)),
|
||||
Type);
|
||||
%enddef
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Void * - Accepts any kind of pointer
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* in */
|
||||
|
||||
%typemap(in) void * {
|
||||
if ((SWIG_ConvertPtr($input,SWIG_reinterpret_cast(&$1,void **),0,SWIG_POINTER_EXCEPTION|$disown))== -1) {
|
||||
SWIG_arg_fail($argnum);SWIG_fail;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) void * const& ($*ltype temp) {
|
||||
SWIG_ConvertPtr($input,(void **)&temp,0,SWIG_POINTER_EXCEPTION|$disown);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
|
||||
/* out */
|
||||
|
||||
%typemap(out) void "Py_INCREF(Py_None); $result = Py_None;";
|
||||
|
||||
/* varin */
|
||||
|
||||
%typemap(varin) void * {
|
||||
void * temp;
|
||||
if ((SWIG_ConvertPtr($input, SWIG_static_cast(&temp,void **), 0,
|
||||
SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN)) == -1) {
|
||||
SWIG_append_errmsg("C/C++ variable '$name'");
|
||||
return 1;
|
||||
}
|
||||
$1 = ($1_ltype) temp;
|
||||
}
|
||||
|
||||
/* varout */
|
||||
|
||||
%typemap(varout) void "Py_INCREF(Py_None); $result = Py_None;";
|
||||
|
||||
/* directorout */
|
||||
|
||||
%typemap(directorout) void * {
|
||||
if (!$input || (SWIG_ConvertPtr($input,(void **)(&$result),
|
||||
0, SWIG_POINTER_EXCEPTION | $disown )) == -1)
|
||||
Swig::DirectorTypeMismatchException::raise("Pointer conversion failed.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* typecheck */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void *
|
||||
{
|
||||
void *ptr;
|
||||
if (SWIG_ConvertPtr($input, &ptr, 0, 0) == -1) {
|
||||
$1 = 0;
|
||||
PyErr_Clear();
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,141 +1,58 @@
|
|||
|
||||
/* ------------------------------------------------------------
|
||||
* utility methods for wchar_t strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsWCharPtrAndSize","header") {
|
||||
%fragment("SWIG_AsWCharPtrAndSize","header",fragment="<wchar.h>") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize)
|
||||
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
|
||||
{
|
||||
static swig_type_info* pwchar_info = 0;
|
||||
wchar_t * vptr = 0;
|
||||
if (!pwchar_info) pwchar_info = SWIG_TypeQuery("wchar_t *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pwchar_info, 0) != -1) {
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, pwchar_info, 0) == SWIG_OK) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (wcslen(vptr) + 1) : 0;
|
||||
return SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
PyObject *tmp = 0;
|
||||
int isunicode = PyUnicode_Check(obj);
|
||||
if (isunicode || PyString_Check(obj)) {
|
||||
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);
|
||||
PyUnicodeObject *uni = (PyUnicodeObject *)PyUnicode_FromObject(obj);
|
||||
PyUnicode_AsWideChar(uni, nptr, size);
|
||||
nptr[size] = 0;
|
||||
*cptr = nptr;
|
||||
if (psize) {
|
||||
*psize = (size_t) size + 1;
|
||||
}
|
||||
Py_DECREF(uni);
|
||||
obj = tmp = PyUnicode_FromObject(obj);
|
||||
}
|
||||
return SWIG_NEWOBJ;
|
||||
isunicode = 1;
|
||||
}
|
||||
if (isunicode) {
|
||||
int len = PyUnicode_GetSize(obj);
|
||||
if (cptr) {
|
||||
*cptr = SWIG_new_array(len + 1, wchar_t);
|
||||
PyUnicode_AsWideChar((PyUnicodeObject *)obj, *cptr, len);
|
||||
(*cptr)[len] = 0;
|
||||
}
|
||||
if (psize) *psize = (size_t) len + 1;
|
||||
if (alloc) *alloc = cptr ? SWIG_NEWOBJ : 0;
|
||||
if (tmp) Py_DECREF(tmp);
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
if (cptr) {
|
||||
SWIG_type_error("wchar_t *", obj);
|
||||
}
|
||||
return 0;
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsWCharPtr","header",
|
||||
fragment="SWIG_AsWCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsWCharPtr(PyObject *obj, wchar_t **val)
|
||||
%fragment("SWIG_FromWCharPtrAndSize","header",fragment="<wchar.h>") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
|
||||
{
|
||||
if (SWIG_AsWCharPtrAndSize(obj, val, (size_t*)(0))) {
|
||||
return 1;
|
||||
}
|
||||
if (val) {
|
||||
PyErr_Clear();
|
||||
SWIG_type_error("wchar_t *", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromWCharPtr","header") {
|
||||
SWIGINTERN PyObject *
|
||||
SWIG_FromWCharPtr(const wchar_t * cptr)
|
||||
{
|
||||
if (cptr) {
|
||||
size_t size = wcslen(cptr);
|
||||
if (carray) {
|
||||
if (size > INT_MAX) {
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(cptr,wchar_t *),
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,wchar_t *),
|
||||
SWIG_TypeQuery("wchar_t *"), 0);
|
||||
} else {
|
||||
return PyUnicode_FromWideChar(cptr, size);
|
||||
return PyUnicode_FromWideChar(carray, SWIG_numeric_cast(size,int));
|
||||
}
|
||||
}
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsNewWCharPtr","header",
|
||||
fragment="SWIG_AsWCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsNewWCharPtr(PyObject *obj, wchar_t **val)
|
||||
{
|
||||
wchar_t * cptr = 0; size_t csize = 0;
|
||||
int res = SWIG_AsWCharPtrAndSize(obj, &cptr, &csize);
|
||||
if (res) {
|
||||
if (val) {
|
||||
if (csize) {
|
||||
*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)[0] = 0;
|
||||
} else {
|
||||
*val = 0;
|
||||
}
|
||||
}
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
if (val) {
|
||||
SWIG_type_error("wchar_t *", obj);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsWCharArray","header",
|
||||
fragment="SWIG_AsWCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsWCharArray(PyObject *obj, wchar_t *val, size_t size)
|
||||
{
|
||||
wchar_t * cptr; size_t csize;
|
||||
if (SWIG_AsWCharPtrAndSize(obj, &cptr, &csize)) {
|
||||
if ((csize == size + 1) && !(cptr[csize-1])) --csize;
|
||||
if (csize <= size) {
|
||||
if (val) {
|
||||
if (csize) memcpy(val, cptr, csize*sizeof(wchar_t));
|
||||
if (csize < size) memset(val+csize, 0, (size-csize)*sizeof(wchar_t));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
if (val) {
|
||||
PyErr_Format(PyExc_ValueError,
|
||||
"a wchar_t array of maximum size %lu is expected",
|
||||
(unsigned long) size);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromWCharArray","header") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromWCharArray(const wchar_t * carray, size_t size)
|
||||
{
|
||||
if (size > INT_MAX) {
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,wchar_t *),
|
||||
SWIG_TypeQuery("wchar_t *"), 0);
|
||||
} else {
|
||||
return PyUnicode_FromWideChar(carray, SWIG_numeric_cast(size,int));
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -144,11 +61,6 @@ SWIG_FromWCharArray(const wchar_t * carray, size_t size)
|
|||
* The plain wchar_t * handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap_pystring(wchar_t,
|
||||
SWIG_AsWCharPtr,
|
||||
SWIG_AsWCharPtrAndSize,
|
||||
SWIG_FromWCharPtr,
|
||||
SWIG_AsNewWCharPtr,
|
||||
SWIG_AsWCharArray,
|
||||
SWIG_FromWCharArray);
|
||||
%include <typemaps/strings.swg>
|
||||
%typemap_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen);
|
||||
|
||||
|
|
|
|||
|
|
@ -8,40 +8,41 @@
|
|||
|
||||
%fragment(SWIG_AsPtr_frag(std::basic_string<char>),"header",
|
||||
fragment="SWIG_AsCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val)
|
||||
{
|
||||
static swig_type_info* string_info =
|
||||
SWIG_TypeQuery("std::basic_string<char> *");
|
||||
std::string *vptr;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
char* buf = 0 ; size_t size = 0;
|
||||
if (SWIG_AsCharPtrAndSize(obj, &buf, &size)) {
|
||||
if (buf) {
|
||||
if (val) *val = new std::string(buf, size - 1);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError,"a string is expected");
|
||||
}
|
||||
return 0;
|
||||
SWIGINTERN int
|
||||
SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val)
|
||||
{
|
||||
static swig_type_info* string_info =
|
||||
SWIG_TypeQuery("std::basic_string<char> *");
|
||||
std::string *vptr;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
char* buf = 0 ; size_t size = 0; int alloc = 0;
|
||||
if (SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
|
||||
if (buf) {
|
||||
if (val) *val = new std::string(buf, size - 1);
|
||||
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(buf);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError,"a string is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(std::basic_string<char>),"header",
|
||||
fragment="SWIG_FromCharArray") {
|
||||
fragment="SWIG_FromCharPtrAndSize") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(std::basic_string<char>)(const std::string& s)
|
||||
{
|
||||
return SWIG_FromCharArray(s.data(), s.size());
|
||||
return SWIG_FromCharPtrAndSize(s.data(), s.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,17 +62,16 @@ SWIGINTERN int
|
|||
static swig_type_info* string_info =
|
||||
SWIG_TypeQuery("std::basic_string<wchar_t> *");
|
||||
std::wstring *vptr;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) {
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) == SWIG_OK) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
wchar_t *buf = 0 ; size_t size = 0;
|
||||
int res = 0;
|
||||
if ((res = SWIG_AsWCharPtrAndSize(obj, &buf, &size))) {
|
||||
wchar_t *buf = 0 ; size_t size = 0; int alloc = 0;
|
||||
if (SWIG_AsWCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
|
||||
if (buf) {
|
||||
if (val) *val = new std::wstring(buf, size - 1);
|
||||
if (res == SWIG_NEWOBJ) SWIG_delete_array(buf);
|
||||
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(buf);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
|
|
@ -86,11 +86,11 @@ SWIGINTERN int
|
|||
}
|
||||
|
||||
%fragment(SWIG_From_frag(std::basic_string<wchar_t>),"header",
|
||||
fragment="SWIG_FromWCharArray") {
|
||||
fragment="SWIG_FromWCharPtrAndSize") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(std::basic_string<wchar_t>)(const std::wstring& s)
|
||||
{
|
||||
return SWIG_FromWCharArray(s.data(), s.size());
|
||||
return SWIG_FromWCharPtrAndSize(s.data(), s.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@
|
|||
T *pfirst = 0;
|
||||
U *psecond = 0;
|
||||
if (val) {
|
||||
*val = new std::pair<T,U>;
|
||||
*val = SWIG_new(std::pair<T,U>);
|
||||
pfirst = &((*val)->first);
|
||||
psecond = &((*val)->second);
|
||||
}
|
||||
if (swig::asval(first,pfirst) && swig::asval(second,psecond)) {
|
||||
return SWIG_NEWOBJ;
|
||||
} else {
|
||||
delete *val;
|
||||
SWIG_delete(*val);
|
||||
}
|
||||
} else {
|
||||
value_type *p;
|
||||
|
|
|
|||
|
|
@ -8,74 +8,18 @@
|
|||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
%include <pystrings.swg>
|
||||
|
||||
namespace std
|
||||
{
|
||||
class string;
|
||||
}
|
||||
|
||||
%include <typemaps/std_string.swg>
|
||||
%include <pystrings.swg>
|
||||
|
||||
|
||||
/* defining the std::string asptr/from methods */
|
||||
|
||||
|
||||
%fragment(SWIG_AsPtr_frag(std::string),"header",
|
||||
fragment="SWIG_AsCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsPtr(std::string)(PyObject* obj, std::string **val)
|
||||
{
|
||||
static swig_type_info* string_info = SWIG_TypeQuery("std::string *");
|
||||
std::string *vptr;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
char* buf = 0 ; size_t size = 0;
|
||||
if (SWIG_AsCharPtrAndSize(obj, &buf, &size)) {
|
||||
if (buf) {
|
||||
if (val) *val = new std::string(buf, size - 1);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError,"a string is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_From_frag(std::string),"header",
|
||||
fragment="SWIG_FromCharArray") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(std::string)(const std::string& s)
|
||||
{
|
||||
return SWIG_FromCharArray(s.data(), s.size());
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(std::string),"header",
|
||||
fragment=SWIG_AsPtr_frag(std::string)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(std::string)(PyObject* obj, std::string *val)
|
||||
{
|
||||
std::string* s;
|
||||
int res = SWIG_AsPtr(std::string)(obj, &s);
|
||||
if ((res != 0) && s) {
|
||||
if (val) *val = *s;
|
||||
if (res == SWIG_NEWOBJ) delete s;
|
||||
return res;
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError,"a string is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
%std_string_asptr(std::string, char, SWIG_AsCharPtrAndSize)
|
||||
%std_string_from(std::string, SWIG_FromCharPtrAndSize)
|
||||
%std_string_asval(std::string)
|
||||
|
||||
%typemap_asptrfromn(SWIG_CCode(STRING), std::string);
|
||||
|
||||
|
|
|
|||
|
|
@ -7,78 +7,20 @@
|
|||
|
||||
%{
|
||||
#include <cwchar>
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
%include <pywstrings.swg>
|
||||
|
||||
namespace std
|
||||
{
|
||||
%feature("novaluewrapper") wstring;
|
||||
class wstring;
|
||||
}
|
||||
|
||||
/* defining the std::string asptr/from methods */
|
||||
|
||||
%fragment(SWIG_AsPtr_frag(std::wstring),"header",
|
||||
fragment="SWIG_AsWCharPtrAndSize") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsPtr(std::wstring)(PyObject* obj, std::wstring **val)
|
||||
{
|
||||
static swig_type_info* string_info = SWIG_TypeQuery("std::wstring *");
|
||||
std::wstring *vptr;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
wchar_t *buf = 0 ; size_t size = 0;
|
||||
int res = 0;
|
||||
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);
|
||||
return SWIG_NEWOBJ;
|
||||
}
|
||||
} else {
|
||||
PyErr_Clear();
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError,"a wstring is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
%include <typemaps/std_string.swg>
|
||||
%include <pywstrings.swg>
|
||||
|
||||
%fragment(SWIG_From_frag(std::wstring),"header",
|
||||
fragment="SWIG_FromWCharArray") {
|
||||
SWIGINTERNINLINE PyObject*
|
||||
SWIG_From(std::wstring)(const std::wstring& s)
|
||||
{
|
||||
return SWIG_FromWCharArray(s.data(), s.size());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment(SWIG_AsVal_frag(std::wstring),"header",
|
||||
fragment=SWIG_AsPtr_frag(std::wstring)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal(std::wstring)(PyObject* obj, std::wstring *val)
|
||||
{
|
||||
std::wstring *s;
|
||||
int res = SWIG_AsPtr(std::wstring)(obj, &s);
|
||||
if ((res != 0) && s) {
|
||||
if (val) *val = *s;
|
||||
if (res == SWIG_NEWOBJ) delete s;
|
||||
return res;
|
||||
}
|
||||
if (val) {
|
||||
PyErr_SetString(PyExc_TypeError,"a wstring is expected");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
%std_string_asptr(std::wstring, wchar_t, SWIG_AsWCharPtrAndSize)
|
||||
%std_string_from(std::wstring, SWIG_FromWCharPtrAndSize)
|
||||
%std_string_asval(std::wstring)
|
||||
|
||||
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::wstring);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,190 +1,4 @@
|
|||
//
|
||||
// SWIG Typemap library
|
||||
// Dave Beazley
|
||||
// May 5, 1997
|
||||
//
|
||||
// Python implementation
|
||||
//
|
||||
// This library provides standard typemaps for modifying SWIG's behavior.
|
||||
// With enough entries in this file, I hope that very few people actually
|
||||
// ever need to write a typemap.
|
||||
//
|
||||
// Disclaimer : Unless you really understand how typemaps work, this file
|
||||
// probably isn't going to make much sense.
|
||||
//
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Pointer handling
|
||||
//
|
||||
// These mappings provide support for input/output arguments and common
|
||||
// uses for C/C++ pointers.
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// INPUT typemaps.
|
||||
// These remap a C pointer to be an "INPUT" value which is passed by value
|
||||
// instead of reference.
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer into a simple
|
||||
"input" value. That is, instead of passing a pointer to an object,
|
||||
you would use a real value instead.
|
||||
|
||||
int *INPUT
|
||||
short *INPUT
|
||||
long *INPUT
|
||||
long long *INPUT
|
||||
unsigned int *INPUT
|
||||
unsigned short *INPUT
|
||||
unsigned long *INPUT
|
||||
unsigned long long *INPUT
|
||||
unsigned char *INPUT
|
||||
bool *INPUT
|
||||
float *INPUT
|
||||
double *INPUT
|
||||
|
||||
To use these, suppose you had a C function like this :
|
||||
|
||||
double fadd(double *a, double *b) {
|
||||
return *a+*b;
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include <typemaps.i>
|
||||
double fadd(double *INPUT, double *INPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include <typemaps.i>
|
||||
%apply double *INPUT { double *a, double *b };
|
||||
double fadd(double *a, double *b);
|
||||
|
||||
*/
|
||||
|
||||
// OUTPUT typemaps. These typemaps are used for parameters that
|
||||
// are output only. The output value is appended to the result as
|
||||
// a list element.
|
||||
|
||||
/*
|
||||
The following methods can be applied to turn a pointer into an "output"
|
||||
value. When calling a function, no input value would be given for
|
||||
a parameter, but an output value would be returned. In the case of
|
||||
multiple output values, they are returned in the form of a Python tuple.
|
||||
|
||||
int *OUTPUT
|
||||
short *OUTPUT
|
||||
long *OUTPUT
|
||||
long long *OUTPUT
|
||||
unsigned int *OUTPUT
|
||||
unsigned short *OUTPUT
|
||||
unsigned long *OUTPUT
|
||||
unsigned long long *OUTPUT
|
||||
unsigned char *OUTPUT
|
||||
bool *OUTPUT
|
||||
float *OUTPUT
|
||||
double *OUTPUT
|
||||
|
||||
For example, suppose you were trying to wrap the modf() function in the
|
||||
C math library which splits x into integral and fractional parts (and
|
||||
returns the integer part in one of its parameters).K:
|
||||
|
||||
double modf(double x, double *ip);
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include <typemaps.i>
|
||||
double modf(double x, double *OUTPUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include <typemaps.i>
|
||||
%apply double *OUTPUT { double *ip };
|
||||
double modf(double x, double *ip);
|
||||
|
||||
The Python output of the function would be a tuple containing both
|
||||
output values.
|
||||
|
||||
*/
|
||||
|
||||
// INOUT
|
||||
// Mappings for an argument that is both an input and output
|
||||
// parameter
|
||||
|
||||
/*
|
||||
The following methods can be applied to make a function parameter both
|
||||
an input and output value. This combines the behavior of both the
|
||||
"INPUT" and "OUTPUT" methods described earlier. Output values are
|
||||
returned in the form of a Python tuple.
|
||||
|
||||
int *INOUT
|
||||
short *INOUT
|
||||
long *INOUT
|
||||
long long *INOUT
|
||||
unsigned int *INOUT
|
||||
unsigned short *INOUT
|
||||
unsigned long *INOUT
|
||||
unsigned long long *INOUT
|
||||
unsigned char *INOUT
|
||||
bool *INOUT
|
||||
float *INOUT
|
||||
double *INOUT
|
||||
|
||||
For example, suppose you were trying to wrap the following function :
|
||||
|
||||
void neg(double *x) {
|
||||
*x = -(*x);
|
||||
}
|
||||
|
||||
You could wrap it with SWIG as follows :
|
||||
|
||||
%include <typemaps.i>
|
||||
void neg(double *INOUT);
|
||||
|
||||
or you can use the %apply directive :
|
||||
|
||||
%include <typemaps.i>
|
||||
%apply double *INOUT { double *x };
|
||||
void neg(double *x);
|
||||
|
||||
Unlike C, this mapping does not directly modify the input value (since
|
||||
this makes no sense in Python). Rather, the modified input value shows
|
||||
up as the return value of the function. Thus, to apply this function
|
||||
to a Python variable you might do this :
|
||||
|
||||
x = neg(x)
|
||||
|
||||
Note : previous versions of SWIG used the symbol 'BOTH' to mark
|
||||
input/output arguments. This is still supported, but will be slowly
|
||||
phased out in future releases.
|
||||
|
||||
*/
|
||||
%include <typemaps/typemaps.swg>
|
||||
|
||||
|
||||
%include <pyinout.swg>
|
||||
|
||||
#ifdef SWIG_INOUT_NODEF
|
||||
/*
|
||||
Apply the INPUT/OUTPUT typemaps to all the C types (int, double, ...) if
|
||||
not already defined.
|
||||
*/
|
||||
%define %typemap_inout(Code,AsMeth, CheckMeth, FromMeth, AsFrag, CheckFrag, FromFrag, Type...)
|
||||
_PYVAL_INPUT_TYPEMAP(SWIG_arg(Code), SWIG_arg(AsMeth), SWIG_arg(CheckMeth),
|
||||
SWIG_arg(AsFrag), SWIG_arg(CheckFrag), SWIG_arg(Type));
|
||||
_PYVAL_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), SWIG_arg(Type));
|
||||
_PYVAL_INOUT_TYPEMAP(SWIG_arg(Type));
|
||||
%enddef
|
||||
|
||||
%define %typemap_inoutn(Code,Type...)
|
||||
%typemap_inout(SWIG_arg(Code),
|
||||
SWIG_arg(SWIG_As(Type)),
|
||||
SWIG_arg(SWIG_Check(Type)),
|
||||
SWIG_arg(SWIG_From(Type)),
|
||||
SWIG_arg(SWIG_As_frag(Type)),
|
||||
SWIG_arg(SWIG_Check_frag(Type)),
|
||||
SWIG_arg(SWIG_From_frag(Type)),
|
||||
SWIG_arg(Type));
|
||||
%enddef
|
||||
|
||||
%apply_checkctypes(%typemap_inoutn)
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue