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
17
Lib/cdata.i
17
Lib/cdata.i
|
|
@ -19,27 +19,12 @@ typedef struct SWIGCDATA {
|
|||
* Typemaps for returning binary data
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#if SWIGPYTHON
|
||||
%typemap(out) SWIGCDATA {
|
||||
$result = PyString_FromStringAndSize($1.data,$1.len);
|
||||
}
|
||||
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
|
||||
#elif SWIGPERL
|
||||
if SWIGPERL
|
||||
%typemap(out) SWIGCDATA {
|
||||
ST(argvi) = sv_newmortal();
|
||||
sv_setpvn((SV*)ST(argvi++),$1.data,$1.len);
|
||||
}
|
||||
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
|
||||
#elif SWIGTCL
|
||||
%typemap(out) SWIGCDATA {
|
||||
Tcl_SetObjResult(interp,Tcl_NewStringObj($1.data,$1.len));
|
||||
}
|
||||
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
|
||||
#elif SWIGRUBY
|
||||
%typemap(out) SWIGCDATA {
|
||||
$result = rb_str_new($1.data,$1.len);
|
||||
}
|
||||
%typemap(in) (const void *indata, int inlen) = (char *STRING, int LENGTH);
|
||||
#elif SWIGGUILE
|
||||
%typemap(out) SWIGCDATA {
|
||||
$result = gh_str2scm($1.data,$1.len);
|
||||
|
|
|
|||
|
|
@ -84,7 +84,6 @@ extern "C" {
|
|||
func = C_SCHEME_FALSE; \
|
||||
}
|
||||
|
||||
#define SWIG_POINTER_DISOWN 1
|
||||
|
||||
enum {
|
||||
SWIG_BARF1_BAD_ARGUMENT_TYPE /* 1 arg */,
|
||||
|
|
|
|||
119
Lib/exception.i
119
Lib/exception.i
|
|
@ -5,36 +5,6 @@
|
|||
//
|
||||
// This SWIG library file provides language independent exception handling
|
||||
|
||||
%{
|
||||
#define SWIG_MemoryError 1
|
||||
#define SWIG_IOError 2
|
||||
#define SWIG_RuntimeError 3
|
||||
#define SWIG_IndexError 4
|
||||
#define SWIG_TypeError 5
|
||||
#define SWIG_DivisionByZero 6
|
||||
#define SWIG_OverflowError 7
|
||||
#define SWIG_SyntaxError 8
|
||||
#define SWIG_ValueError 9
|
||||
#define SWIG_SystemError 10
|
||||
#define SWIG_UnknownError 99
|
||||
%}
|
||||
|
||||
#ifdef SWIGTCL8
|
||||
%{
|
||||
/* We cast from 'const char*' to 'char*' since TCL_VOLATILE ensure
|
||||
that an internal copy of the strng will be stored.
|
||||
|
||||
NOTE: Later use const_cast<char*> via SWIG_const_cast or so.
|
||||
*/
|
||||
#define SWIG_exception(a,b) { Tcl_SetResult(interp,(char *)b,TCL_VOLATILE); SWIG_fail; }
|
||||
%}
|
||||
#else
|
||||
#ifdef SWIGTCL
|
||||
%{
|
||||
#define SWIG_exception(a,b) { Tcl_SetResult(interp,(char *)b,TCL_VOLATILE); return TCL_ERROR; }
|
||||
%}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SWIGPERL5
|
||||
%{
|
||||
|
|
@ -49,50 +19,6 @@
|
|||
%}
|
||||
#endif
|
||||
|
||||
#ifdef SWIGPYTHON
|
||||
%{
|
||||
SWIGINTERN void SWIG_exception_(int code, const char *msg) {
|
||||
switch(code) {
|
||||
case SWIG_MemoryError:
|
||||
PyErr_SetString(PyExc_MemoryError,msg);
|
||||
break;
|
||||
case SWIG_IOError:
|
||||
PyErr_SetString(PyExc_IOError,msg);
|
||||
break;
|
||||
case SWIG_RuntimeError:
|
||||
PyErr_SetString(PyExc_RuntimeError,msg);
|
||||
break;
|
||||
case SWIG_IndexError:
|
||||
PyErr_SetString(PyExc_IndexError,msg);
|
||||
break;
|
||||
case SWIG_TypeError:
|
||||
PyErr_SetString(PyExc_TypeError,msg);
|
||||
break;
|
||||
case SWIG_DivisionByZero:
|
||||
PyErr_SetString(PyExc_ZeroDivisionError,msg);
|
||||
break;
|
||||
case SWIG_OverflowError:
|
||||
PyErr_SetString(PyExc_OverflowError,msg);
|
||||
break;
|
||||
case SWIG_SyntaxError:
|
||||
PyErr_SetString(PyExc_SyntaxError,msg);
|
||||
break;
|
||||
case SWIG_ValueError:
|
||||
PyErr_SetString(PyExc_ValueError,msg);
|
||||
break;
|
||||
case SWIG_SystemError:
|
||||
PyErr_SetString(PyExc_SystemError,msg);
|
||||
break;
|
||||
default:
|
||||
PyErr_SetString(PyExc_RuntimeError,msg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define SWIG_exception(a,b) { SWIG_exception_(a,b); SWIG_fail; }
|
||||
%}
|
||||
#endif
|
||||
|
||||
#ifdef SWIGGUILE
|
||||
%{
|
||||
SWIGINTERN void SWIG_exception_ (int code, const char *msg,
|
||||
|
|
@ -215,51 +141,6 @@ SWIGINTERN void SWIG_exception_(int code, const char *msg) {
|
|||
%}
|
||||
#endif
|
||||
|
||||
#ifdef SWIGRUBY
|
||||
%{
|
||||
SWIGINTERN void SWIG_exception_(int code, const char *msg) {
|
||||
switch (code) {
|
||||
case SWIG_MemoryError:
|
||||
rb_raise(rb_eNoMemError, msg);
|
||||
break;
|
||||
case SWIG_IOError:
|
||||
rb_raise(rb_eIOError, msg);
|
||||
break;
|
||||
case SWIG_RuntimeError:
|
||||
rb_raise(rb_eRuntimeError, msg);
|
||||
break;
|
||||
case SWIG_IndexError:
|
||||
rb_raise(rb_eIndexError, msg);
|
||||
break;
|
||||
case SWIG_TypeError:
|
||||
rb_raise(rb_eTypeError, msg);
|
||||
break;
|
||||
case SWIG_DivisionByZero:
|
||||
rb_raise(rb_eZeroDivError, msg);
|
||||
break;
|
||||
case SWIG_OverflowError:
|
||||
rb_raise(rb_eRangeError, msg);
|
||||
break;
|
||||
case SWIG_SyntaxError:
|
||||
rb_raise(rb_eSyntaxError, msg);
|
||||
break;
|
||||
case SWIG_ValueError:
|
||||
rb_raise(rb_eArgError, msg);
|
||||
break;
|
||||
case SWIG_SystemError:
|
||||
rb_raise(rb_eFatal, msg);
|
||||
break;
|
||||
case SWIG_UnknownError:
|
||||
rb_raise(rb_eRuntimeError, msg);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#define SWIG_exception(a, b) SWIG_exception_((a), (b))
|
||||
%}
|
||||
#endif
|
||||
|
||||
#ifdef SWIGCHICKEN
|
||||
%{
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@
|
|||
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE
|
||||
{
|
||||
$<ype argp;
|
||||
if(SWIG_ConvertPtr(L,$input,(void**)(&argp),$&descriptor,SWIG_POINTER_EXCEPTION) == -1) SWIG_fail;
|
||||
if(SWIG_ConvertPtr(L,$input,(void**)(&argp),$&descriptor,0)) SWIG_fail;
|
||||
$1 = *argp;
|
||||
}
|
||||
|
||||
|
|
@ -462,4 +462,4 @@ SWIGEXPORT int SWIG_import(lua_State* L)
|
|||
/* Note: the initialization function is closed after all code is generated */
|
||||
|
||||
|
||||
/*************************** end lua.swg ******************************/
|
||||
/*************************** end lua.swg ******************************/
|
||||
|
|
|
|||
|
|
@ -26,9 +26,6 @@ extern "C" {
|
|||
#define SWIG_LUA_POINTER 4
|
||||
#define SWIG_LUA_BINARY 5
|
||||
|
||||
/* Flags for pointer conversion */
|
||||
#define SWIG_POINTER_EXCEPTION 0x1
|
||||
|
||||
/* type for all wrapper fns */
|
||||
typedef int (*swig_lua_wrapper_func)(lua_State*);
|
||||
|
||||
|
|
@ -678,4 +675,4 @@ SWIG_Lua_SetModule(lua_State* L, swig_module_info *module) {
|
|||
}
|
||||
#endif
|
||||
|
||||
/*************************** end luarun.swg ******************************/
|
||||
/*************************** end luarun.swg ******************************/
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ extern "C" {
|
|||
make PHP type calls later as we handle php resources */
|
||||
#define SWIG_ConvertPtr(obj,pp,type,flags) SWIG_ZTS_ConvertPtr(obj,pp,type,flags TSRMLS_CC)
|
||||
|
||||
/* Flags for SWIG_ConvertPtr */
|
||||
#define SWIG_POINTER_DISOWN 0x1
|
||||
|
||||
#define SWIG_fail goto fail
|
||||
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
@ -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,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
|
||||
|
|
|
|||
1
Lib/ruby/cdata.i
Normal file
1
Lib/ruby/cdata.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/cdata.swg>
|
||||
137
Lib/ruby/cstring.i
Normal file
137
Lib/ruby/cstring.i
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cstring_input_binary(TYPEMAP, SIZE)
|
||||
*
|
||||
* Macro makes a function accept binary string data along with
|
||||
* a size.
|
||||
*/
|
||||
|
||||
/*
|
||||
* %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");
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %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);
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %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++;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %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++;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %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");
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %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);
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %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");
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %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);
|
||||
* }
|
||||
*/
|
||||
|
||||
%include <typemaps/cstring.swg>
|
||||
%include <rubystrings.swg>
|
||||
|
||||
%typemap_cstrings(%cstring,
|
||||
char,
|
||||
SWIG_AsCharPtr,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtr,
|
||||
SWIG_FromCharPtrAndSize);
|
||||
|
||||
|
|
@ -20,42 +20,94 @@ namespace Swig {
|
|||
int argc;
|
||||
VALUE *argv;
|
||||
};
|
||||
|
||||
|
||||
/* Base class for director exceptions */
|
||||
class DirectorException {
|
||||
protected:
|
||||
VALUE swig_error;
|
||||
protected:
|
||||
DirectorException(VALUE error=Qnil) : swig_error(error) {}
|
||||
public:
|
||||
VALUE getType() const {
|
||||
return CLASS_OF(swig_error);
|
||||
protected:
|
||||
VALUE swig_error;
|
||||
std::string swig_msg;
|
||||
protected:
|
||||
DirectorException(VALUE error)
|
||||
: swig_error(error)
|
||||
{
|
||||
}
|
||||
|
||||
DirectorException(VALUE error, const char* hdr, const char* msg ="")
|
||||
: swig_error(error), swig_msg(hdr) {
|
||||
if (strlen(msg)) {
|
||||
swig_msg += " ";
|
||||
swig_msg += msg;
|
||||
}
|
||||
VALUE getError() const {
|
||||
return swig_error;
|
||||
if (swig_msg.size()) {
|
||||
VALUE str = rb_str_new2(swig_msg.c_str());
|
||||
swig_error = rb_exc_new3(error, str);
|
||||
} else {
|
||||
swig_error = error;
|
||||
}
|
||||
virtual ~DirectorException() {}
|
||||
}
|
||||
public:
|
||||
VALUE getType() const {
|
||||
return CLASS_OF(swig_error);
|
||||
}
|
||||
VALUE getError() const {
|
||||
return swig_error;
|
||||
}
|
||||
virtual ~DirectorException() {}
|
||||
};
|
||||
|
||||
|
||||
/* Type mismatch in the return value from a Ruby method call */
|
||||
class DirectorTypeMismatchException : public Swig::DirectorException {
|
||||
public:
|
||||
DirectorTypeMismatchException(const char *msg="") {
|
||||
VALUE str = rb_str_new2("Swig director type mismatch: ");
|
||||
rb_str_concat(str, rb_str_new2(msg));
|
||||
swig_error = rb_exc_new3(rb_eTypeError, str);
|
||||
}
|
||||
public:
|
||||
DirectorTypeMismatchException(VALUE error, const char *msg="")
|
||||
: Swig::DirectorException(error, "Swig director type mismatch", msg)
|
||||
{
|
||||
}
|
||||
|
||||
DirectorTypeMismatchException(const char *msg="")
|
||||
: Swig::DirectorException(rb_eTypeError, "Swig director type mismatch", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(VALUE error, const char *msg) {
|
||||
throw DirectorTypeMismatchException(error, msg);
|
||||
}
|
||||
|
||||
static void raise(const char *msg) {
|
||||
throw DirectorTypeMismatchException(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/* Any Ruby exception that occurs during a director method call */
|
||||
class DirectorMethodException : public Swig::DirectorException {
|
||||
public:
|
||||
DirectorMethodException(VALUE error) : Swig::DirectorException(error) {}
|
||||
public:
|
||||
DirectorMethodException(VALUE error)
|
||||
: Swig::DirectorException(error) {
|
||||
}
|
||||
|
||||
DirectorMethodException(const char* msg = "")
|
||||
: Swig::DirectorException(rb_eRuntimeError, "Swig director method error", msg) {
|
||||
}
|
||||
|
||||
static void raise(VALUE error)
|
||||
{
|
||||
throw DirectorMethodException(error);
|
||||
}
|
||||
};
|
||||
|
||||
/* Attempted to call a pure virtual method via a director method */
|
||||
class DirectorPureVirtualException : public Swig::DirectorException {};
|
||||
class DirectorPureVirtualException : public Swig::DirectorException
|
||||
{
|
||||
public:
|
||||
DirectorPureVirtualException(const char* msg = "")
|
||||
: DirectorException(rb_eRuntimeError, "Swig director pure virtal method called", msg)
|
||||
{
|
||||
}
|
||||
|
||||
static void raise(const char *msg)
|
||||
{
|
||||
throw DirectorPureVirtualException(msg);
|
||||
}
|
||||
};
|
||||
|
||||
/* Simple thread abstraction for pthreads on win32 */
|
||||
#ifdef __THREAD__
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
// Helper function for Array output
|
||||
|
||||
%fragment("output_helper", "header") %{
|
||||
static VALUE output_helper(VALUE target, VALUE o) {
|
||||
if (NIL_P(target)) {
|
||||
target = o;
|
||||
} else {
|
||||
if (TYPE(target) != T_ARRAY) {
|
||||
VALUE o2 = target;
|
||||
target = rb_ary_new();
|
||||
rb_ary_push(target, o2);
|
||||
}
|
||||
rb_ary_push(target, o);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
%}
|
||||
|
|
@ -1,47 +1,53 @@
|
|||
/* ----------------------------------------------------------------------
|
||||
/* -----------------------------------------------------------------------------
|
||||
* ruby.swg
|
||||
*
|
||||
* Ruby configuation file.
|
||||
* ---------------------------------------------------------------------- */
|
||||
|
||||
%runtime "rubyhead.swg"
|
||||
%runtime "swigrun.swg" /* Common C API type-checking code */
|
||||
%runtime "rubytracking.swg" /* API for tracking C++ classes to Ruby objects */
|
||||
%runtime "rubydef.swg"
|
||||
|
||||
%insert(initbeforefunc) "swiginit.swg"
|
||||
|
||||
#define %alias %feature("alias")
|
||||
#define %freefunc %feature("freefunc")
|
||||
#define %markfunc %feature("markfunc")
|
||||
#define %mixin %feature("mixin")
|
||||
#define %predicate %feature("predicate", "1")
|
||||
#define %trackobjects %feature("trackobjects")
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* SWIGTYPE typemaps
|
||||
* Ruby configuration module.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "rubyswigtype.swg"
|
||||
/* -----------------------------------------------------------------------------
|
||||
* The runtime part
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <rubyruntime.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Special user directives
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <rubyuserdir.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Inner macros
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <rubymacros.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Error manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include <rubyerrors.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Look for user fragments file. If not found, include empty system one.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include "rubyfragments.swg"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "rubyvoid.swg"
|
||||
%include "rubyobject.swg"
|
||||
%include "rubystrings.swg"
|
||||
%include "rubyprimtypes.swg"
|
||||
%include "rubymisctypes.swg"
|
||||
%include "rubyenum.swg"
|
||||
%include <rubytypemaps.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
%include "rubyopers.swg"
|
||||
%include <rubyopers.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Warnings for Ruby keywords
|
||||
* Warnings for Python keywords
|
||||
* ------------------------------------------------------------ */
|
||||
%include "rubykw.swg"
|
||||
%include <rubykw.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The Python initialization function
|
||||
* ------------------------------------------------------------ */
|
||||
%include <rubyinit.swg>
|
||||
|
||||
|
||||
|
|
|
|||
27
Lib/ruby/rubyapi.swg
Normal file
27
Lib/ruby/rubyapi.swg
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Ruby API portion that goes into the runtime
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
SWIGINTERN VALUE
|
||||
SWIG_Ruby_AppendResult(VALUE target, VALUE o) {
|
||||
if (NIL_P(target)) {
|
||||
target = o;
|
||||
} else {
|
||||
if (TYPE(target) != T_ARRAY) {
|
||||
VALUE o2 = target;
|
||||
target = rb_ary_new();
|
||||
rb_ary_push(target, o2);
|
||||
}
|
||||
rb_ary_push(target, o);
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,267 +0,0 @@
|
|||
/* Common SWIG API */
|
||||
#define SWIG_ConvertPtr(obj, pp, type, flags) \
|
||||
SWIG_Ruby_ConvertPtr(obj, pp, type, flags)
|
||||
#define SWIG_NewPointerObj(p, type, flags) \
|
||||
SWIG_Ruby_NewPointerObj(p, type, flags)
|
||||
#define SWIG_MustGetPtr(p, type, argnum, flags) \
|
||||
SWIG_Ruby_MustGetPtr(p, type, argnum, flags)
|
||||
#define SWIG_GetModule(clientdata) \
|
||||
SWIG_Ruby_GetModule()
|
||||
#define SWIG_SetModule(clientdata, pointer) \
|
||||
SWIG_Ruby_SetModule(pointer)
|
||||
|
||||
/* Ruby-specific SWIG API */
|
||||
|
||||
#define SWIG_InitRuntime() \
|
||||
SWIG_Ruby_InitRuntime()
|
||||
#define SWIG_define_class(ty) \
|
||||
SWIG_Ruby_define_class(ty)
|
||||
#define SWIG_NewClassInstance(value, ty) \
|
||||
SWIG_Ruby_NewClassInstance(value, ty)
|
||||
#define SWIG_MangleStr(value) \
|
||||
SWIG_Ruby_MangleStr(value)
|
||||
#define SWIG_CheckConvert(value, ty) \
|
||||
SWIG_Ruby_CheckConvert(value, ty)
|
||||
#define SWIG_NewPackedObj(ptr, sz, ty) \
|
||||
SWIG_Ruby_NewPackedObj(ptr, sz, ty)
|
||||
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) \
|
||||
SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
|
||||
|
||||
/* rubydef.swg */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
static VALUE _mSWIG = Qnil;
|
||||
static VALUE _cSWIG_Pointer = Qnil;
|
||||
static VALUE swig_runtime_data_type_pointer = Qnil;
|
||||
|
||||
/* Initialize Ruby runtime support */
|
||||
static void
|
||||
SWIG_Ruby_InitRuntime(void)
|
||||
{
|
||||
if (_mSWIG == Qnil) {
|
||||
_mSWIG = rb_define_module("SWIG");
|
||||
}
|
||||
}
|
||||
|
||||
/* Define Ruby class for C type */
|
||||
static void
|
||||
SWIG_Ruby_define_class(swig_type_info *type)
|
||||
{
|
||||
VALUE klass;
|
||||
char *klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
if (NIL_P(_cSWIG_Pointer)) {
|
||||
_cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");
|
||||
}
|
||||
klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
|
||||
free((void *) klass_name);
|
||||
}
|
||||
|
||||
/* Create a new pointer object */
|
||||
static VALUE
|
||||
SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
|
||||
{
|
||||
int own = flags & SWIG_POINTER_OWN;
|
||||
int track = flags & SWIG_TRACK_OBJECTS;
|
||||
|
||||
char *klass_name;
|
||||
swig_class *sklass;
|
||||
VALUE klass;
|
||||
VALUE obj;
|
||||
|
||||
if (!ptr)
|
||||
return Qnil;
|
||||
|
||||
/* Have we already wrapped this pointer? */
|
||||
if (track) {
|
||||
obj = SWIG_RubyInstanceFor(ptr);
|
||||
if (obj != Qnil) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
if (type->clientdata) {
|
||||
sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : 0), ptr);
|
||||
} else {
|
||||
klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
klass = rb_const_get(_mSWIG, rb_intern(klass_name));
|
||||
free((void *) klass_name);
|
||||
obj = Data_Wrap_Struct(klass, 0, 0, ptr);
|
||||
}
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
|
||||
/* Keep track of this object if necessary */
|
||||
if (track) {
|
||||
SWIG_RubyAddTracking(ptr, obj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Create a new class instance (always owned) */
|
||||
static VALUE
|
||||
SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type)
|
||||
{
|
||||
VALUE obj;
|
||||
swig_class *sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0);
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Get type mangle from class name */
|
||||
static SWIGINLINE char *
|
||||
SWIG_Ruby_MangleStr(VALUE obj)
|
||||
{
|
||||
VALUE stype = rb_iv_get(obj, "__swigtype__");
|
||||
return StringValuePtr(stype);
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
static int
|
||||
SWIG_Ruby_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags)
|
||||
{
|
||||
char *c;
|
||||
swig_cast_info *tc;
|
||||
|
||||
/* Grab the pointer */
|
||||
if (NIL_P(obj)) {
|
||||
*ptr = 0;
|
||||
return 0;
|
||||
} else {
|
||||
Data_Get_Struct(obj, void, *ptr);
|
||||
}
|
||||
|
||||
/* Check to see if the input object is giving up ownership
|
||||
of the underlying C struct or C++ object. If so then we
|
||||
need to reset the destructor since the Ruby object no
|
||||
longer owns the underlying C++ object.*/
|
||||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
if (flags & SWIG_TRACK_OBJECTS) {
|
||||
/* We are tracking objects. Thus we change the destructor
|
||||
* to SWIG_RubyRemoveTracking. This allows us to
|
||||
* remove the mapping from the C++ to Ruby object
|
||||
* when the Ruby object is garbage collected. If we don't
|
||||
* do this, then it is possible we will return a reference
|
||||
* to a Ruby object that no longer exists thereby crashing Ruby. */
|
||||
RDATA(obj)->dfree = SWIG_RubyRemoveTracking;
|
||||
} else {
|
||||
RDATA(obj)->dfree = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Do type-checking if type info was provided */
|
||||
if (ty) {
|
||||
if (ty->clientdata) {
|
||||
if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
|
||||
if (*ptr == 0)
|
||||
rb_raise(rb_eRuntimeError, "This %s already released", ty->str);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((c = SWIG_MangleStr(obj)) == NULL) {
|
||||
if (flags & SWIG_POINTER_EXCEPTION)
|
||||
rb_raise(rb_eTypeError, "Expected %s", ty->str);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) {
|
||||
if (flags & SWIG_POINTER_EXCEPTION)
|
||||
rb_raise(rb_eTypeError, "Expected %s", ty->str);
|
||||
else
|
||||
return -1;
|
||||
}
|
||||
*ptr = SWIG_TypeCast(tc, *ptr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Convert a pointer value, signal an exception on a type mismatch */
|
||||
static SWIGINLINE void *
|
||||
SWIG_Ruby_MustGetPtr(VALUE obj, swig_type_info *ty, int argnum, int flags)
|
||||
{
|
||||
void *result;
|
||||
SWIG_ConvertPtr(obj, &result, ty, flags | SWIG_POINTER_EXCEPTION);
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Check convert */
|
||||
static SWIGINLINE int
|
||||
SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty)
|
||||
{
|
||||
char *c = SWIG_MangleStr(obj);
|
||||
if (!c)
|
||||
return 0;
|
||||
return SWIG_TypeCheck(c,ty) != 0;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
|
||||
char result[1024];
|
||||
char *r = result;
|
||||
if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
|
||||
*(r++) = '_';
|
||||
r = SWIG_PackData(r, ptr, sz);
|
||||
strcpy(r, type->name);
|
||||
return rb_str_new2(result);
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
static void
|
||||
SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags) {
|
||||
swig_cast_info *tc;
|
||||
const char *c;
|
||||
|
||||
if (TYPE(obj) != T_STRING) goto type_error;
|
||||
c = StringValuePtr(obj);
|
||||
/* Pointer values must start with leading underscore */
|
||||
if (*c != '_') goto type_error;
|
||||
c++;
|
||||
c = SWIG_UnpackData(c, ptr, sz);
|
||||
if (ty) {
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) goto type_error;
|
||||
}
|
||||
return;
|
||||
|
||||
type_error:
|
||||
|
||||
if (flags) {
|
||||
if (ty) {
|
||||
rb_raise(rb_eTypeError, "Type error. Expected %s", ty->name);
|
||||
} else {
|
||||
rb_raise(rb_eTypeError, "Expected a pointer");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static swig_module_info *SWIG_Ruby_GetModule() {
|
||||
VALUE pointer;
|
||||
swig_module_info *ret = 0;
|
||||
|
||||
/* first check if pointer already created */
|
||||
pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
|
||||
if (pointer != Qnil) {
|
||||
Data_Get_Struct(pointer, swig_module_info, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void SWIG_Ruby_SetModule(swig_module_info *pointer) {
|
||||
/* register a new class */
|
||||
VALUE cl = rb_define_class("swig_runtime_data", rb_cObject);
|
||||
/* create and store the structure pointer to a global variable */
|
||||
swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer);
|
||||
rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Enums
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* --- Input typemaps --- */
|
||||
%typemap(in) enum SWIGTYPE "$1 = ($1_ltype) NUM2INT($input);";
|
||||
|
||||
%typemap(in) const enum SWIGTYPE & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) NUM2INT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
|
||||
%typemap(directorout) enum SWIGTYPE "$result = ($1_ltype) NUM2INT($input);";
|
||||
%typemap(directorout,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const enum SWIGTYPE &
|
||||
%{ static $*1_ltype temp = ($*1_ltype) NUM2INT($input);
|
||||
$result = &temp; %}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
%typemap(out) enum SWIGTYPE "$result = INT2NUM($1);";
|
||||
|
||||
%typemap(out) const enum SWIGTYPE & "$result = INT2NUM((long) *($1));";
|
||||
|
||||
%typemap(directorin) enum SWIGTYPE "$input = INT2NUM($1);";
|
||||
%typemap(directorin) const enum SWIGTYPE& "$input = INT2NUM($1);";
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
%{
|
||||
static void SWIG_AsVal(VALUE obj, int *val)
|
||||
{
|
||||
*val = (int) NUM2INT(obj);
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap(varin) enum SWIGTYPE {
|
||||
if (sizeof(int) != sizeof($1)) {
|
||||
rb_raise(rb_eTypeError, "enum variable '$name' can not be set.");
|
||||
}
|
||||
SWIG_AsVal($input, (int *)(void *) &$1);
|
||||
}
|
||||
|
||||
/* --- Variable Output --- */
|
||||
|
||||
%typemap(varout) enum SWIGTYPE "$result = INT2NUM($1);";
|
||||
|
||||
/* --- Constants --- */
|
||||
%typemap(constant) enum SWIGTYPE "rb_define_const($module,\"$symname\", INT2NUM($1));";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER) enum SWIGTYPE, const enum SWIGTYPE &
|
||||
{
|
||||
$1 = ((TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) enum SWIGTYPE
|
||||
"(void)$1; rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(INT2NUM($1))));"
|
||||
|
||||
61
Lib/ruby/rubyerrors.swg
Normal file
61
Lib/ruby/rubyerrors.swg
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* error manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
%insert("header") %{
|
||||
|
||||
SWIGINTERN VALUE
|
||||
SWIG_Ruby_ErrorType(int SWIG_code) {
|
||||
switch (SWIG_code) {
|
||||
case SWIG_MemoryError:
|
||||
return rb_eNoMemError;
|
||||
break;
|
||||
case SWIG_IOError:
|
||||
return rb_eIOError;
|
||||
break;
|
||||
case SWIG_RuntimeError:
|
||||
return rb_eRuntimeError;
|
||||
break;
|
||||
case SWIG_IndexError:
|
||||
return rb_eIndexError;
|
||||
break;
|
||||
case SWIG_TypeError:
|
||||
return rb_eTypeError;
|
||||
break;
|
||||
case SWIG_DivisionByZero:
|
||||
return rb_eZeroDivError;
|
||||
break;
|
||||
case SWIG_OverflowError:
|
||||
return rb_eRangeError;
|
||||
break;
|
||||
case SWIG_SyntaxError:
|
||||
return rb_eSyntaxError;
|
||||
break;
|
||||
case SWIG_ValueError:
|
||||
return rb_eArgError;
|
||||
break;
|
||||
case SWIG_SystemError:
|
||||
return rb_eFatal;
|
||||
break;
|
||||
case SWIG_AttributeError:
|
||||
return rb_eRuntimeError;
|
||||
break;
|
||||
case SWIG_UnknownError:
|
||||
return rb_eRuntimeError;
|
||||
break;
|
||||
default:
|
||||
return rb_eRuntimeError;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Ruby_SetErrorMsg(VALUE type, const char *msg) {
|
||||
rb_raise(type, msg);
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
|
||||
23
Lib/ruby/rubyfragments.swg
Normal file
23
Lib/ruby/rubyfragments.swg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
|
||||
Create a file with this name, 'fragments.i', in your working
|
||||
directory and add all the %fragments you want to take precedence
|
||||
over the ones defined by default by swig.
|
||||
|
||||
For example, if you add:
|
||||
|
||||
%fragment(SWIG_AsVal_frag(int),"header") {
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_AsVal(int)(PyObject *obj, int *val)
|
||||
{
|
||||
<your code here>;
|
||||
}
|
||||
}
|
||||
|
||||
this will replace the code used to retreive an integer value for all
|
||||
the typemaps that need it, including:
|
||||
|
||||
int, std::vector<int>, std::list<std::pair<int,int> >, etc.
|
||||
|
||||
|
||||
*/
|
||||
1
Lib/ruby/rubyinit.swg
Normal file
1
Lib/ruby/rubyinit.swg
Normal file
|
|
@ -0,0 +1 @@
|
|||
%insert(initbeforefunc) "swiginit.swg"
|
||||
1
Lib/ruby/rubymacros.swg
Normal file
1
Lib/ruby/rubymacros.swg
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/swigmacros.swg>
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* --- ANSI/Posix C/C++ types ---
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%apply unsigned long { size_t };
|
||||
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* VALUE - Just pass straight through unmodified
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
typedef unsigned long VALUE;
|
||||
|
||||
%typemap(in) VALUE "$1 = $input;";
|
||||
%typemap(out) VALUE "$result = $1;";
|
||||
|
||||
%typemap(directorin) VALUE "$input = $1;";
|
||||
%typemap(directorout) VALUE "$result = $input;";
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) VALUE "$1 = ($input != T_NONE);";
|
||||
|
|
@ -1,257 +1,317 @@
|
|||
%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
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* --- Input Values --- */
|
||||
|
||||
%typemap(in) int "$1 = NUM2INT($input);";
|
||||
%typemap(in) unsigned int "$1 = NUM2UINT($input);";
|
||||
%typemap(in) short "$1 = NUM2SHRT($input);";
|
||||
%typemap(in) unsigned short "$1 = NUM2USHRT($input);";
|
||||
%typemap(in) long "$1 = NUM2LONG($input);";
|
||||
%typemap(in) unsigned long "$1 = NUM2ULONG($input);";
|
||||
%typemap(in) signed char "$1 = ($1_ltype) NUM2INT($input);";
|
||||
%typemap(in) unsigned char "$1 = ($1_ltype) NUM2INT($input);";
|
||||
%typemap(in) char "$1 = NUM2CHR($input);";
|
||||
%typemap(in) float, double "$1 = ($1_ltype) NUM2DBL($input);";
|
||||
%typemap(in) bool "$1 = RTEST($input);";
|
||||
|
||||
/* Long long */
|
||||
|
||||
%typemap(in) long long "$1 = ($1_ltype) NUM2LL($input);";
|
||||
%typemap(in) unsigned long long "$1 = ($1_ltype) NUM2ULL($input);";
|
||||
|
||||
/* Const primitive references. Passed by value */
|
||||
|
||||
%typemap(in) const int & (int temp),
|
||||
const signed char & (signed char temp),
|
||||
const unsigned char & (unsigned char temp)
|
||||
"temp = ($*1_ltype) NUM2INT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const short & (short temp)
|
||||
"temp = ($*1_ltype) NUM2SHRT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const long & (long temp)
|
||||
"temp = ($*1_ltype) NUM2LONG($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned int & (unsigned int temp)
|
||||
"temp = ($*1_ltype) NUM2UINT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned short & (unsigned short temp)
|
||||
"temp = ($*1_ltype) NUM2USHRT($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned long & (unsigned long temp)
|
||||
"temp = ($*1_ltype) NUM2ULONG($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const bool & (bool temp)
|
||||
"temp = ($*1_ltype) RTEST($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const float & (float temp),
|
||||
const double & (double temp)
|
||||
"temp = ($*1_ltype) NUM2DBL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const long long & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) NUM2LL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned long long & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) NUM2ULL($input);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const char &(char temp) {
|
||||
char *stemp = StringValuePtr($input);
|
||||
temp = *stemp;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
%typemap(out) int, short, long, signed char
|
||||
"$result = INT2NUM($1);";
|
||||
|
||||
%typemap(out) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"$result = UINT2NUM($1);";
|
||||
|
||||
/* Long long */
|
||||
|
||||
%typemap(out) long long "$result = LL2NUM($1);";
|
||||
%typemap(out) unsigned long long "$result = ULL2NUM($1);";
|
||||
|
||||
/* Floating point output values */
|
||||
%typemap(out) double, float
|
||||
"$result = rb_float_new($1);";
|
||||
|
||||
/* Boolean */
|
||||
%typemap(out) bool
|
||||
"$result = $1 ? Qtrue : Qfalse;";
|
||||
|
||||
/* References to primitive types. Return by value */
|
||||
|
||||
%typemap(out) const int &,
|
||||
const short &,
|
||||
const long &,
|
||||
const signed char &
|
||||
"$result = INT2NUM((long) *($1));";
|
||||
|
||||
%typemap(out) const unsigned int &,
|
||||
const unsigned short &,
|
||||
const unsigned long &,
|
||||
const unsigned char &
|
||||
"$result = UINT2NUM((unsigned long) *($1));";
|
||||
|
||||
%typemap(out) const bool &
|
||||
"$result = *($1) ? Qtrue : Qfalse;";
|
||||
|
||||
%typemap(out) const float &, const double &
|
||||
"$result = rb_float_new((double) *($1));";
|
||||
|
||||
%typemap(out) const long long &
|
||||
"$result = LL2NUM(*($1));";
|
||||
|
||||
%typemap(out) const unsigned long long &
|
||||
"$result = ULL2NUM(*($1));";
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
%typemap(varin) int "$1 = NUM2INT($input);";
|
||||
%typemap(varin) unsigned int "$1 = NUM2UINT($input);";
|
||||
%typemap(varin) short "$1 = NUM2SHRT($input);";
|
||||
%typemap(varin) unsigned short "$1 = NUM2USHRT($input);";
|
||||
%typemap(varin) long "$1 = NUM2LONG($input);";
|
||||
%typemap(varin) unsigned long "$1 = NUM2ULONG($input);";
|
||||
%typemap(varin) signed char "$1 = (signed char) NUM2INT($input);";
|
||||
%typemap(varin) unsigned char "$1 = (unsigned char) NUM2INT($input);";
|
||||
%typemap(varin) char "$1 = NUM2CHR($input);";
|
||||
%typemap(varin) float, double "$1 = ($1_ltype) NUM2DBL($input);";
|
||||
%typemap(varin) bool "$1 = RTEST($input);";
|
||||
|
||||
%typemap(varin) long long "$1 = NUM2LL($input);";
|
||||
%typemap(varin) unsigned long long "$1 = NUM2ULL($input);";
|
||||
|
||||
/* --- Variable Output --- */
|
||||
|
||||
%typemap(varout) int, short, long, signed char
|
||||
"$result = INT2NUM($1);";
|
||||
|
||||
%typemap(varout) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"$result = UINT2NUM($1);";
|
||||
|
||||
%typemap(varout) long long "$result = LL2NUM($1);";
|
||||
%typemap(varout) unsigned long long "$result = ULL2NUM($1);";
|
||||
|
||||
/* Floats and doubles */
|
||||
%typemap(varout) double, float
|
||||
"$result = rb_float_new($1);";
|
||||
|
||||
/* Boolean */
|
||||
%typemap(varout) bool
|
||||
"$result = $1 ? Qtrue : Qfalse;";
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
%typemap(constant) int, short, long, signed char
|
||||
"rb_define_const($module,\"$symname\", INT2NUM($1));";
|
||||
|
||||
%typemap(constant) unsigned int, unsigned short, unsigned long, unsigned char
|
||||
"rb_define_const($module,\"$symname\", UINT2NUM($1));";
|
||||
|
||||
%typemap(constant) long long
|
||||
"rb_define_const($module,\"$symname\", LL2NUM($1));";
|
||||
|
||||
%typemap(constant) unsigned long long
|
||||
"rb_define_const($module,\"$symname\", ULL2NUM($1));";
|
||||
|
||||
%typemap(constant) double, float
|
||||
"rb_define_const($module,\"$symname\", rb_float_new($1));";
|
||||
|
||||
%typemap(constant) bool
|
||||
"rb_define_const($module,\"$symname\", ($1 ? Qtrue : Qfalse));";
|
||||
|
||||
/* directorin typemaps */
|
||||
|
||||
%typemap(directorin) int , const int& "$input = INT2NUM($1);";
|
||||
%typemap(directorin) short , const short& "$input = INT2NUM($1);";
|
||||
%typemap(directorin) long , const long& "$input = LONG2NUM($1);";
|
||||
%typemap(directorin) signed char , const signed char& "$input = INT2NUM($1);";
|
||||
%typemap(directorin) float , const float& "$input = rb_float_new($1);";
|
||||
%typemap(directorin) double , const double& "$input = rb_float_new($1);";
|
||||
%typemap(directorin) bool , const bool& "$input = $1 ? Qtrue : Qfalse;";
|
||||
%typemap(directorin) unsigned int , const unsigned int& "$input = UINT2NUM($1);";
|
||||
%typemap(directorin) unsigned short, const unsigned short& "$input = UINT2NUM($1);";
|
||||
%typemap(directorin) unsigned long , const unsigned long& "$input = ULONG2NUM($1);";
|
||||
%typemap(directorin) unsigned char , const unsigned char& "$input = UINT2NUM($1);";
|
||||
|
||||
/* --- directorout typemaps --- */
|
||||
|
||||
%define DIRECTOROUT_TYPEMAP(type, converter)
|
||||
%typemap(directorargout) type *DIRECTOROUT "*$result = (type) converter($input);";
|
||||
%typemap(directorout) type "$result = (type) converter($input);";
|
||||
%typemap(directorout) const type& {
|
||||
$basetype temp = converter($input);
|
||||
$result = &temp;
|
||||
}
|
||||
%typemap(directorout) type &DIRECTOROUT = type
|
||||
%enddef
|
||||
|
||||
DIRECTOROUT_TYPEMAP(char, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned char, NUM2UINT);
|
||||
DIRECTOROUT_TYPEMAP(short, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned short, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(int, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned int, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(long, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned long, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(long long, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(unsigned long long, NUM2INT);
|
||||
DIRECTOROUT_TYPEMAP(float, NUM2DBL);
|
||||
DIRECTOROUT_TYPEMAP(double, NUM2DBL);
|
||||
DIRECTOROUT_TYPEMAP(bool, RTEST);
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_BOOL) bool {
|
||||
$1 = ($input == Qtrue || $input == Qfalse) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER)
|
||||
int, short, long,
|
||||
unsigned int, unsigned short, unsigned long,
|
||||
signed char, unsigned char,
|
||||
long long, unsigned long long,
|
||||
const int &, const short &, const long &,
|
||||
const unsigned int &, const unsigned short &, const unsigned long &,
|
||||
const long long &, const unsigned long long &
|
||||
%fragment("SWIG_ruby_failed","header")
|
||||
{
|
||||
$1 = ((TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
|
||||
SWIGINTERN VALUE
|
||||
SWIG_ruby_failed()
|
||||
{
|
||||
return Qnil;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_DOUBLE)
|
||||
float, double,
|
||||
const float &, const double &
|
||||
|
||||
/* boolean */
|
||||
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(bool)(bool value)
|
||||
{
|
||||
$1 = ((TYPE($input) == T_FLOAT) || (TYPE($input) == T_FIXNUM) || (TYPE($input) == T_BIGNUM)) ? 1 : 0;
|
||||
return value ? Qtrue : Qfalse;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(bool),"header",
|
||||
fragment=SWIG_AsVal_frag(int)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(bool)(VALUE obj, bool *val)
|
||||
{
|
||||
if (obj == Qtrue) {
|
||||
if (val) *val = true;
|
||||
return SWIG_OK;
|
||||
} else if (obj == Qfalse) {
|
||||
if (val) *val = false;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
int res = 0;
|
||||
if (SWIG_AsVal(int)(obj, &res) == SWIG_OK) {
|
||||
if (val) *val = res ? true : false;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* signed/unsigned char */
|
||||
|
||||
%type_slong(signed char, "<limits.h>", SCHAR_MIN, SCHAR_MAX)
|
||||
%type_ulong(unsigned char, "<limits.h>", UCHAR_MAX)
|
||||
|
||||
/* short/unsigned short */
|
||||
|
||||
%type_slong(short, "<limits.h>", SHRT_MIN, SHRT_MAX)
|
||||
%type_ulong(unsigned short, "<limits.h>", USHRT_MAX)
|
||||
|
||||
/* int/unsigned int */
|
||||
|
||||
%type_slong(int, "<limits.h>", INT_MIN, INT_MAX)
|
||||
%type_ulong(unsigned int, "<limits.h>", UINT_MAX)
|
||||
|
||||
/* 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
|
||||
|
||||
/* long */
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header",
|
||||
fragment="<limits.h>") {
|
||||
SWIG_define(SWIG_From_dec(long), LONG2NUM)
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2long(VALUE *args)
|
||||
{
|
||||
*((long *)(args[1])) = NUM2LONG(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long)(VALUE obj, long* val)
|
||||
{
|
||||
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
long v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2long), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long),"header",
|
||||
fragment=SWIG_From_frag(long)) {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(unsigned long)(unsigned long value)
|
||||
{
|
||||
return ULONG2NUM(value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2ulong(VALUE *args)
|
||||
{
|
||||
*((unsigned long *)(args[1])) = NUM2ULONG(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long)(VALUE obj, unsigned long *val)
|
||||
{
|
||||
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
unsigned long v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2ulong), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* long long */
|
||||
|
||||
%fragment(SWIG_From_frag(long long),"header",
|
||||
fragment=SWIG_From_frag(long),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(long long)(long long value)
|
||||
{
|
||||
return LL2NUM(value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long long),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2longlong(VALUE *args)
|
||||
{
|
||||
*((long long *)(args[1])) = NUM2LL(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long long)(VALUE obj, long long *val)
|
||||
{
|
||||
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
long long v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2longlong), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long long),"header",
|
||||
fragment=SWIG_From_frag(long long),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(unsigned long long)(unsigned long long value)
|
||||
{
|
||||
return ULL2NUM(value);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2ulonglong(VALUE *args)
|
||||
{
|
||||
*((unsigned long long *)(args[1])) = NUM2ULL(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val)
|
||||
{
|
||||
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
unsigned long long v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2ulonglong), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
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), rb_float_new)
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(double),"header",fragment="SWIG_ruby_failed") {
|
||||
SWIGINTERN VALUE SWIG_num2dbl(VALUE *args)
|
||||
{
|
||||
*((double *)(args[1])) = NUM2DBL(args[0]);
|
||||
return args[0];
|
||||
}
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(double)(VALUE obj, double *val)
|
||||
{
|
||||
if (obj != Qnil &&((TYPE(obj) == T_FLOAT) || (TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
|
||||
double v;
|
||||
VALUE a[2] = { obj, (VALUE)(&v) };
|
||||
if (rb_rescue(RUBY_METHOD_FUNC(SWIG_num2dbl), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* char */
|
||||
|
||||
%fragment(SWIG_From_frag(char),"header") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(char)(char c)
|
||||
{
|
||||
return rb_str_new(&c,1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(char),"header",
|
||||
fragment="SWIG_AsCharArray",
|
||||
fragment=SWIG_AsVal_frag(signed char)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(char)(VALUE obj, char *val)
|
||||
{
|
||||
signed char v;
|
||||
if (SWIG_AsVal(signed char)(obj, &v) == SWIG_OK) {
|
||||
if (val) *val = (char)(v);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (SWIG_AsCharArray(obj, val, 1) == SWIG_OK) {
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* wchar_t */
|
||||
|
||||
|
||||
%fragment(SWIG_From_frag(wchar_t),"header",
|
||||
fragment=SWIG_From_frag(char),
|
||||
fragment=SWIG_From_frag(long)) {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_From_dec(wchar_t)(wchar_t c)
|
||||
{
|
||||
if (CHAR_MIN <= v && v <= CHAR_MAX) {
|
||||
return SWIG_From(char)((char)c);
|
||||
} else {
|
||||
return SWIG_From(long)((long)c);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(wchar_t),"header",
|
||||
fragment="SWIG_AsWCharArray",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(wchar_t)(VALUE obj, wchar_t *val)
|
||||
{
|
||||
char v;
|
||||
if (SWIG_AsVal(char)(obj, &v) == SWIG_OK) {
|
||||
if (val) *val = (wchar_t)(v);
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
long v;
|
||||
if (SWIG_AsVal(long)(obj, &v) == SWIG_OK) {
|
||||
if (WCHAR_MIN <= v && v <= WCHAR_MAX) {
|
||||
if (val) *val = (wchar_t)(v);
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* Apply the primitive typemap for all the types with checkcode
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) int,
|
||||
long,
|
||||
short,
|
||||
unsigned int,
|
||||
unsigned long,
|
||||
unsigned short {
|
||||
rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(INT2NUM($1))));
|
||||
}
|
||||
|
||||
%apply_checkctypes(%typemap_primitive)
|
||||
|
|
|
|||
289
Lib/ruby/rubyrun.swg
Normal file
289
Lib/ruby/rubyrun.swg
Normal file
|
|
@ -0,0 +1,289 @@
|
|||
/***********************************************************************
|
||||
* rubyrun.swg
|
||||
*
|
||||
* This file contains the runtime support for Ruby modules
|
||||
* and includes code for managing global variables and pointer
|
||||
* type checking.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
/* for raw pointers */
|
||||
#define SWIG_ConvertPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags)
|
||||
|
||||
/* for raw packed data */
|
||||
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
|
||||
#define SWIG_NewPackedObj(ptr, sz, type, flags) SWIG_Ruby_NewPackedObj(ptr, sz, type)
|
||||
|
||||
/* for class or struct pointers */
|
||||
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_Ruby_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_Ruby_NewPointerObj(ptr, type, flags)
|
||||
|
||||
/* for C or C++ function pointers */
|
||||
#define SWIG_ConvertFunctionPtr(obj, pptr, type, flags) SWIG_Ruby_ConvertPtr(obj, pptr, type, flags)
|
||||
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Ruby_NewPointerObj(ptr, type, 0)
|
||||
|
||||
/* for C++ member pointers, ie, member methods */
|
||||
#define SWIG_ConvertMember(obj, ptr, sz, ty, flags) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
|
||||
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
|
||||
|
||||
|
||||
/* Runtime API */
|
||||
#define SWIG_GetModule(clientdata) SWIG_Ruby_GetModule()
|
||||
#define SWIG_SetModule(clientdata, pointer) SWIG_Ruby_SetModule(pointer)
|
||||
|
||||
/* Ruby-specific SWIG API */
|
||||
|
||||
#define SWIG_InitRuntime() SWIG_Ruby_InitRuntime()
|
||||
#define SWIG_define_class(ty) SWIG_Ruby_define_class(ty)
|
||||
#define SWIG_NewClassInstance(value, ty) SWIG_Ruby_NewClassInstance(value, ty)
|
||||
#define SWIG_MangleStr(value) SWIG_Ruby_MangleStr(value)
|
||||
#define SWIG_CheckConvert(value, ty) SWIG_Ruby_CheckConvert(value, ty)
|
||||
|
||||
/* Error manipulation */
|
||||
#define SWIG_ERROR -1
|
||||
#define SWIG_fail return Qnil
|
||||
#define SWIG_var_fail return Qnil
|
||||
|
||||
#define SWIG_error(code, msg) SWIG_Ruby_SetErrorMsg(SWIG_Ruby_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
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Flags for new pointer objects */
|
||||
#define SWIG_TRACK_OBJECTS 0x4
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* pointers/data manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
typedef struct {
|
||||
VALUE klass;
|
||||
VALUE mImpl;
|
||||
void (*mark)(void *);
|
||||
void (*destroy)(void *);
|
||||
} swig_class;
|
||||
|
||||
|
||||
static VALUE _mSWIG = Qnil;
|
||||
static VALUE _cSWIG_Pointer = Qnil;
|
||||
static VALUE swig_runtime_data_type_pointer = Qnil;
|
||||
|
||||
/* Initialize Ruby runtime support */
|
||||
SWIGRUNTIME void
|
||||
SWIG_Ruby_InitRuntime(void)
|
||||
{
|
||||
if (_mSWIG == Qnil) {
|
||||
_mSWIG = rb_define_module("SWIG");
|
||||
}
|
||||
}
|
||||
|
||||
/* Define Ruby class for C type */
|
||||
SWIGRUNTIME void
|
||||
SWIG_Ruby_define_class(swig_type_info *type)
|
||||
{
|
||||
VALUE klass;
|
||||
char *klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
if (NIL_P(_cSWIG_Pointer)) {
|
||||
_cSWIG_Pointer = rb_define_class_under(_mSWIG, "Pointer", rb_cObject);
|
||||
rb_undef_method(CLASS_OF(_cSWIG_Pointer), "new");
|
||||
}
|
||||
klass = rb_define_class_under(_mSWIG, klass_name, _cSWIG_Pointer);
|
||||
free((void *) klass_name);
|
||||
}
|
||||
|
||||
/* Create a new pointer object */
|
||||
SWIGRUNTIME VALUE
|
||||
SWIG_Ruby_NewPointerObj(void *ptr, swig_type_info *type, int flags)
|
||||
{
|
||||
int own = flags & SWIG_POINTER_OWN;
|
||||
int track = flags & SWIG_TRACK_OBJECTS;
|
||||
|
||||
char *klass_name;
|
||||
swig_class *sklass;
|
||||
VALUE klass;
|
||||
VALUE obj;
|
||||
|
||||
if (!ptr)
|
||||
return Qnil;
|
||||
|
||||
/* Have we already wrapped this pointer? */
|
||||
if (track) {
|
||||
obj = SWIG_RubyInstanceFor(ptr);
|
||||
if (obj != Qnil) {
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
if (type->clientdata) {
|
||||
sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(sklass->klass, VOIDFUNC(sklass->mark), (own ? VOIDFUNC(sklass->destroy) : 0), ptr);
|
||||
} else {
|
||||
klass_name = (char *) malloc(4 + strlen(type->name) + 1);
|
||||
sprintf(klass_name, "TYPE%s", type->name);
|
||||
klass = rb_const_get(_mSWIG, rb_intern(klass_name));
|
||||
free((void *) klass_name);
|
||||
obj = Data_Wrap_Struct(klass, 0, 0, ptr);
|
||||
}
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
|
||||
/* Keep track of this object if necessary */
|
||||
if (track) {
|
||||
SWIG_RubyAddTracking(ptr, obj);
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Create a new class instance (always owned) */
|
||||
SWIGRUNTIME VALUE
|
||||
SWIG_Ruby_NewClassInstance(VALUE klass, swig_type_info *type)
|
||||
{
|
||||
VALUE obj;
|
||||
swig_class *sklass = (swig_class *) type->clientdata;
|
||||
obj = Data_Wrap_Struct(klass, VOIDFUNC(sklass->mark), VOIDFUNC(sklass->destroy), 0);
|
||||
rb_iv_set(obj, "__swigtype__", rb_str_new2(type->name));
|
||||
return obj;
|
||||
}
|
||||
|
||||
/* Get type mangle from class name */
|
||||
SWIGRUNTIMEINLINE char *
|
||||
SWIG_Ruby_MangleStr(VALUE obj)
|
||||
{
|
||||
VALUE stype = rb_iv_get(obj, "__swigtype__");
|
||||
return StringValuePtr(stype);
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
SWIGRUNTIME int
|
||||
SWIG_Ruby_ConvertPtr(VALUE obj, void **ptr, swig_type_info *ty, int flags)
|
||||
{
|
||||
char *c;
|
||||
swig_cast_info *tc;
|
||||
|
||||
/* Grab the pointer */
|
||||
if (NIL_P(obj)) {
|
||||
*ptr = 0;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (TYPE(obj) != T_DATA) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
Data_Get_Struct(obj, void, *ptr);
|
||||
}
|
||||
|
||||
|
||||
/* Check to see if the input object is giving up ownership
|
||||
of the underlying C struct or C++ object. If so then we
|
||||
need to reset the destructor since the Ruby object no
|
||||
longer owns the underlying C++ object.*/
|
||||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
if (flags & SWIG_TRACK_OBJECTS) {
|
||||
/* We are tracking objects. Thus we change the destructor
|
||||
* to SWIG_RubyRemoveTracking. This allows us to
|
||||
* remove the mapping from the C++ to Ruby object
|
||||
* when the Ruby object is garbage collected. If we don't
|
||||
* do this, then it is possible we will return a reference
|
||||
* to a Ruby object that no longer exists thereby crashing Ruby. */
|
||||
RDATA(obj)->dfree = SWIG_RubyRemoveTracking;
|
||||
} else {
|
||||
RDATA(obj)->dfree = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* Do type-checking if type info was provided */
|
||||
if (ty) {
|
||||
if (ty->clientdata) {
|
||||
if (rb_obj_is_kind_of(obj, ((swig_class *) (ty->clientdata))->klass)) {
|
||||
if (*ptr == 0) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
if ((c = SWIG_MangleStr(obj)) == NULL) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) {
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
*ptr = SWIG_TypeCast(tc, *ptr);
|
||||
}
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* Check convert */
|
||||
SWIGRUNTIMEINLINE int
|
||||
SWIG_Ruby_CheckConvert(VALUE obj, swig_type_info *ty)
|
||||
{
|
||||
char *c = SWIG_MangleStr(obj);
|
||||
if (!c) return 0;
|
||||
return SWIG_TypeCheck(c,ty) != 0;
|
||||
}
|
||||
|
||||
SWIGRUNTIME VALUE
|
||||
SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
|
||||
char result[1024];
|
||||
char *r = result;
|
||||
if ((2*sz + 1 + strlen(type->name)) > 1000) return 0;
|
||||
*(r++) = '_';
|
||||
r = SWIG_PackData(r, ptr, sz);
|
||||
strcpy(r, type->name);
|
||||
return rb_str_new2(result);
|
||||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
SWIGRUNTIME int
|
||||
SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags) {
|
||||
swig_cast_info *tc;
|
||||
const char *c;
|
||||
|
||||
if (TYPE(obj) != T_STRING) goto type_error;
|
||||
c = StringValuePtr(obj);
|
||||
/* Pointer values must start with leading underscore */
|
||||
if (*c != '_') goto type_error;
|
||||
c++;
|
||||
c = SWIG_UnpackData(c, ptr, sz);
|
||||
if (ty) {
|
||||
tc = SWIG_TypeCheck(c, ty);
|
||||
if (!tc) goto type_error;
|
||||
}
|
||||
return SWIG_OK;
|
||||
|
||||
type_error:
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
SWIGRUNTIME swig_module_info *
|
||||
SWIG_Ruby_GetModule()
|
||||
{
|
||||
VALUE pointer;
|
||||
swig_module_info *ret = 0;
|
||||
|
||||
/* first check if pointer already created */
|
||||
pointer = rb_gv_get("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME);
|
||||
if (pointer != Qnil) {
|
||||
Data_Get_Struct(pointer, swig_module_info, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
SWIGRUNTIME void
|
||||
SWIG_Ruby_SetModule(swig_module_info *pointer)
|
||||
{
|
||||
/* register a new class */
|
||||
VALUE cl = rb_define_class("swig_runtime_data", rb_cObject);
|
||||
/* create and store the structure pointer to a global variable */
|
||||
swig_runtime_data_type_pointer = Data_Wrap_Struct(cl, 0, 0, pointer);
|
||||
rb_define_readonly_variable("$swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, &swig_runtime_data_type_pointer);
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
@ -1,28 +1,5 @@
|
|||
/* ruby.swg */
|
||||
/* Implementation : RUBY */
|
||||
#define SWIGRUBY 1
|
||||
|
||||
#include "ruby.h"
|
||||
|
||||
/* Flags for pointer conversion */
|
||||
#define SWIG_POINTER_EXCEPTION 0x1
|
||||
#define SWIG_POINTER_OWN 0x1
|
||||
#define SWIG_POINTER_DISOWN 0x2
|
||||
#define SWIG_TRACK_OBJECTS 0x4
|
||||
|
||||
#define NUM2USHRT(n) (\
|
||||
(0 <= NUM2UINT(n) && NUM2UINT(n) <= USHRT_MAX)\
|
||||
? (unsigned short) NUM2UINT(n) \
|
||||
: (rb_raise(rb_eArgError, "integer %d out of range of `unsigned short'",\
|
||||
NUM2UINT(n)), (short)0)\
|
||||
)
|
||||
|
||||
#define NUM2SHRT(n) (\
|
||||
(SHRT_MIN <= NUM2INT(n) && NUM2INT(n) <= SHRT_MAX)\
|
||||
? (short)NUM2INT(n)\
|
||||
: (rb_raise(rb_eArgError, "integer %d out of range of `short'",\
|
||||
NUM2INT(n)), (short)0)\
|
||||
)
|
||||
%insert(runtime) %{
|
||||
#include <ruby.h>
|
||||
|
||||
/* Ruby 1.7 defines NUM2LL(), LL2NUM() and ULL2NUM() macros */
|
||||
#ifndef NUM2LL
|
||||
|
|
@ -79,13 +56,6 @@
|
|||
# define VOIDFUNC(f) (f)
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
VALUE klass;
|
||||
VALUE mImpl;
|
||||
void (*mark)(void *);
|
||||
void (*destroy)(void *);
|
||||
} swig_class;
|
||||
|
||||
/* Don't use for expressions have side effect */
|
||||
#ifndef RB_STRING_VALUE
|
||||
#define RB_STRING_VALUE(s) (TYPE(s) == T_STRING ? (s) : (*(volatile VALUE *)&(s) = rb_str_to_str(s)))
|
||||
|
|
@ -111,7 +81,9 @@ typedef struct {
|
|||
#define rb_undef_alloc_func(klass) rb_undef_method(CLASS_OF((klass)), "new")
|
||||
#endif
|
||||
|
||||
/* Contract support */
|
||||
|
||||
#define SWIG_contract_assert(expr, msg) if (!(expr)) { rb_raise(rb_eRuntimeError, (char *) msg ); } else
|
||||
%}
|
||||
|
||||
%runtime "swigrun.swg" /* Common C API type-checking code */
|
||||
%runtime "rubytracking.swg" /* API for tracking C++ classes to Ruby objects */
|
||||
%runtime "rubyrun.swg"
|
||||
%runtime "rubyapi.swg"
|
||||
|
|
@ -1,125 +1,60 @@
|
|||
/* --- Input Values --- */
|
||||
|
||||
%typemap(in) char * "$1 = StringValuePtr($input);";
|
||||
%typemap(in) char [ANY] "$1 = StringValuePtr($input);";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* String & length
|
||||
* utility methods for char strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(in) (int LENGTH, char *STRING) {
|
||||
$1 = ($1_ltype) StringValueLen($input);
|
||||
$2 = ($2_ltype) StringValuePtr($input);
|
||||
}
|
||||
|
||||
%typemap(in) (char *STRING, int LENGTH) {
|
||||
$1 = ($1_ltype) StringValuePtr($input);
|
||||
$2 = ($2_ltype) StringValueLen($input);
|
||||
}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
/* Single char */
|
||||
%typemap(out) char "$result = rb_str_new(&$1,1);";
|
||||
%typemap(out) const char & "$result = rb_str_new($1, 1);";
|
||||
|
||||
/* C string */
|
||||
%typemap(out) char * "$result = rb_str_new2($1);";
|
||||
|
||||
/* Special typemap for character array return values */
|
||||
%typemap(out) char [ANY], const char [ANY] "$result = rb_str_new2($1);";
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
/* A string */
|
||||
#ifdef __cplusplus
|
||||
|
||||
%typemap(varin) char * {
|
||||
char *temp = (char *) StringValuePtr($input);
|
||||
if ($1) delete [] $1;
|
||||
$1 = ($type) new char[strlen(temp)+1];
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
|
||||
char *temp = (char *) StringValuePtr($input);
|
||||
$1 = ($type) new char[strlen(temp)+1];
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
%typemap(varin) char * {
|
||||
char *temp = (char *) StringValuePtr($input);
|
||||
if ($1) free((char*) $1);
|
||||
$1 = ($type) malloc(strlen(temp)+1);
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char * {
|
||||
char *temp = (char *) StringValuePtr($input);
|
||||
$1 = ($type) malloc(strlen(temp)+1);
|
||||
strcpy((char*)$1,temp);
|
||||
}
|
||||
|
||||
#endif /* __cplusplus */
|
||||
|
||||
/* Special case for string array variables */
|
||||
%typemap(varin,
|
||||
warning="462:Unable to set variable of type char []") char[]
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
rb_raise(rb_eTypeError, "C/C++ variable '$name' is read-only.");
|
||||
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) == SWIG_OK) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
if (TYPE(obj) == T_STRING) {
|
||||
char *cstr = rb_string_value_ptr(&(obj));
|
||||
size_t size = RSTRING(obj)->len + 1;
|
||||
if (cptr) {
|
||||
if (alloc) {
|
||||
if (*alloc == SWIG_NEWOBJ) {
|
||||
*cptr = SWIG_new_copy_array(cstr, size, char);
|
||||
} else {
|
||||
*cptr = cstr;
|
||||
*alloc = SWIG_OLDOBJ;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (psize) *psize = size;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(varin) char[ANY] "strncpy($1,StringValuePtr($input),$1_dim0);";
|
||||
|
||||
/* --- Variable Output --- */
|
||||
|
||||
/* Character */
|
||||
%typemap(varout) char "$result = rb_str_new(&$1,1);";
|
||||
|
||||
/* C string */
|
||||
%typemap(varout) char * "$result = rb_str_new2($1);";
|
||||
|
||||
/* Special typemap for character array return values */
|
||||
%typemap(varout) char [ANY], const char [ANY] "$result = rb_str_new2($1);";
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
%typemap(constant) char {
|
||||
char temp = $1;
|
||||
rb_define_const($module,"$symname", rb_str_new(&temp,1));
|
||||
%fragment("SWIG_FromCharPtrAndSize","header") {
|
||||
SWIGINTERNINLINE VALUE
|
||||
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
||||
{
|
||||
if (carray) {
|
||||
if (size > LONG_MAX) {
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,char *), SWIG_TypeQuery("char *"), 0);
|
||||
} else {
|
||||
return rb_str_new(carray, SWIG_numeric_cast(size,long));
|
||||
}
|
||||
} else {
|
||||
return Qnil;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(constant) char *
|
||||
"rb_define_const($module,\"$symname\", rb_str_new2($1));";
|
||||
|
||||
/* directorin typemaps */
|
||||
|
||||
%typemap(directorin) char * "$input = rb_str_new2($1);";
|
||||
|
||||
/* directorout typemaps */
|
||||
|
||||
%typemap(directorout) char * "$result = STR2CSTR($1);";
|
||||
%typemap(directorout) const char * "$result = STR2CSTR($1);";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_CHAR) char {
|
||||
$1 = (TYPE($input) == T_STRING && (RSTRING($input)->len == 1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_STRING) char * {
|
||||
$1 = (TYPE($input) == T_STRING) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* The plain char * handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) char * {
|
||||
rb_raise(rb_eRuntimeError, $1);
|
||||
}
|
||||
|
||||
%include <typemaps/strings.swg>
|
||||
%typemap_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen)
|
||||
|
|
|
|||
|
|
@ -1,162 +0,0 @@
|
|||
/* --- Input typemaps --- */
|
||||
|
||||
%typemap(in) SWIGTYPE *,
|
||||
SWIGTYPE []
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, $disown);"
|
||||
|
||||
%typemap(in) SWIGTYPE *DISOWN
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, SWIG_POINTER_DISOWN);"
|
||||
|
||||
/* Additional check for null references */
|
||||
%typemap(in) SWIGTYPE &
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, $disown); if ($1 == NULL) rb_raise(rb_eTypeError, \"null reference\");"
|
||||
|
||||
/* Object passed by value. Convert to a pointer */
|
||||
%typemap(in) SWIGTYPE {
|
||||
$&1_ltype ptr;
|
||||
SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, $disown);
|
||||
if (ptr) $1 = *ptr;
|
||||
}
|
||||
|
||||
/* Pointer to a class member */
|
||||
%typemap(in) SWIGTYPE (CLASS::*) "SWIG_ConvertPacked($input, (void *) &$1, sizeof($1_type), $1_descriptor, $disown);";
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
%typemap(out) SWIGTYPE*, SWIGTYPE &, SWIGTYPE []
|
||||
"$result = SWIG_NewPointerObj((void *) $1, $1_descriptor,$owner);";
|
||||
|
||||
/* Dynamic casts */
|
||||
|
||||
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
|
||||
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
|
||||
$result = SWIG_NewPointerObj((void *) $1, ty,$owner);
|
||||
}
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(out) SWIGTYPE (CLASS::*) "$result = SWIG_NewPackedObj((void *) &$1, sizeof($1_type), $1_descriptor);";
|
||||
|
||||
/* Primitive types--return by value */
|
||||
%typemap(out) SWIGTYPE
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = new $1_ltype(($1_ltype &)$1);
|
||||
$result = SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1);
|
||||
}
|
||||
#else
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = ($&1_ltype) malloc(sizeof($1_type));
|
||||
memmove(resultptr, &$1, sizeof($1_type));
|
||||
$result = SWIG_NewPointerObj((void *) resultptr, $&1_descriptor, 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --- Variable Input --- */
|
||||
|
||||
%typemap(varin) SWIGTYPE [ANY] {
|
||||
void *temp;
|
||||
int ii;
|
||||
$1_basetype *b = 0;
|
||||
if ((SWIG_ConvertPtr($input,(void **) &temp, $1_descriptor, 0)) == -1) {
|
||||
rb_raise(rb_eTypeError, "C variable '$name ($1_ltype)'");
|
||||
}
|
||||
b = ($1_basetype *) $1;
|
||||
for (ii = 0; ii < $1_size; ii++) b[ii] = *(($1_basetype *) temp + ii);
|
||||
}
|
||||
|
||||
%typemap(varin,warning="462: Unable to set dimensionless array variable") SWIGTYPE [] {
|
||||
rb_raise(rb_eTypeError, "C/C++ variable '$name' is readonly");
|
||||
}
|
||||
|
||||
/* Typemaps for pointers. Note: the SWIG run-time type checker works
|
||||
even if a pointer happens to be mapped to a Ruby class */
|
||||
|
||||
%typemap(varin) SWIGTYPE *
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor, 1);"
|
||||
|
||||
%typemap(varin) SWIGTYPE & {
|
||||
void *temp;
|
||||
SWIG_ConvertPtr($input, (void **) &temp, $1_descriptor, 1);
|
||||
$1 = *($1_ltype) temp;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE {
|
||||
$&1_ltype ptr;
|
||||
SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 1);
|
||||
if (ptr) $1 = *ptr;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE (CLASS::*) {
|
||||
char temp[sizeof($1_type)];
|
||||
SWIG_ConvertPacked($input, (void *) temp, sizeof($1_type), $1_descriptor, 1);
|
||||
memmove((void *) &$1, temp, sizeof($1_type));
|
||||
}
|
||||
|
||||
/* --- Output typemaps --- */
|
||||
|
||||
/* Pointers, references, and arrays */
|
||||
%typemap(varout) SWIGTYPE*, SWIGTYPE []
|
||||
"$result = SWIG_NewPointerObj((void *) $1, $1_descriptor,0);";
|
||||
|
||||
%typemap(varout) SWIGTYPE &
|
||||
"$result = SWIG_NewPointerObj((void *) &$1, $1_descriptor,0);";
|
||||
|
||||
/* Copy by value */
|
||||
%typemap(varout) SWIGTYPE "$result = SWIG_NewPointerObj((void *) &$1, $&1_descriptor, 0);";
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(varout) SWIGTYPE (CLASS::*) "$result = SWIG_NewPackedObj((void *) &$1, sizeof($1_type), $1_descriptor);";
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
%typemap(constant) SWIGTYPE*, SWIGTYPE &, SWIGTYPE []
|
||||
"rb_define_const($module,\"$symname\", SWIG_NewPointerObj((void *) $1, $1_descriptor,0));";
|
||||
|
||||
%typemap(constant) SWIGTYPE "rb_define_const($module,\"$symname\", SWIG_NewPointerObj((void *) &$1, $&1_descriptor, 0));";
|
||||
|
||||
%typemap(constant) SWIGTYPE (CLASS::*) "rb_define_const($module, \"$symname\", SWIG_NewPackedObj((void *) &$1, sizeof($type), $1_descriptor));";
|
||||
|
||||
/* --- directorin typemaps --- */
|
||||
|
||||
%typemap(directorin) SWIGTYPE*
|
||||
"$input = SWIG_NewPointerObj((void *) $1, $1_descriptor,0);";
|
||||
|
||||
%typemap(directorin) SWIGTYPE
|
||||
"$input = SWIG_NewPointerObj((void *) &$1, $1_descriptor,0);";
|
||||
|
||||
%typemap(directorin) SWIGTYPE&
|
||||
"$input = SWIG_NewPointerObj((void *) &$1, $1_descriptor,0);";
|
||||
|
||||
|
||||
/* --- directorout typemaps --- */
|
||||
%typemap(directorout) SWIGTYPE *,
|
||||
SWIGTYPE &,
|
||||
SWIGTYPE []
|
||||
"if ((SWIG_ConvertPtr($input,(void **) &$result, $descriptor,SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, $&1_descriptor, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, $1_descriptor, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling.
|
||||
* Note that in Ruby, we can only raise an exception class and
|
||||
* not some arbitrary object as in Python.
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) SWIGTYPE, SWIGTYPE *, SWIGTYPE [ANY], SWIGTYPE &
|
||||
"(void)$1; rb_raise(rb_eRuntimeError, \"$1_type\");";
|
||||
|
||||
|
|
@ -7,109 +7,120 @@
|
|||
* garbage collector.
|
||||
************************************************************************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
|
||||
/* Global Ruby hash table to store Trackings from C/C++
|
||||
structs to Ruby Objects. */
|
||||
static VALUE swig_ruby_trackings;
|
||||
|
||||
/* Setup a Ruby hash table to store Trackings */
|
||||
static void SWIG_RubyInitializeTrackings() {
|
||||
/* Create a ruby hash table to store Trackings from C++
|
||||
objects to Ruby objects. Also make sure to tell
|
||||
the garabage collector about the hash table. */
|
||||
swig_ruby_trackings = rb_hash_new();
|
||||
rb_gc_register_address(&swig_ruby_trackings);
|
||||
SWIGRUNTIME void SWIG_RubyInitializeTrackings() {
|
||||
/* Create a ruby hash table to store Trackings from C++
|
||||
objects to Ruby objects. Also make sure to tell
|
||||
the garabage collector about the hash table. */
|
||||
swig_ruby_trackings = rb_hash_new();
|
||||
rb_gc_register_address(&swig_ruby_trackings);
|
||||
}
|
||||
|
||||
/* Get a Ruby number to reference a pointer */
|
||||
static VALUE SWIG_RubyPtrToReference(void* ptr) {
|
||||
/* We cast the pointer to an unsigned long
|
||||
and then store a reference to it using
|
||||
a Ruby number object. */
|
||||
SWIGRUNTIME VALUE SWIG_RubyPtrToReference(void* ptr) {
|
||||
/* We cast the pointer to an unsigned long
|
||||
and then store a reference to it using
|
||||
a Ruby number object. */
|
||||
|
||||
/* Convert the pointer to a Ruby number */
|
||||
unsigned long value = (unsigned long) ptr;
|
||||
return LONG2NUM(value);
|
||||
/* Convert the pointer to a Ruby number */
|
||||
unsigned long value = (unsigned long) ptr;
|
||||
return LONG2NUM(value);
|
||||
}
|
||||
|
||||
/* Get a Ruby number to reference an object */
|
||||
static VALUE SWIG_RubyObjectToReference(VALUE object) {
|
||||
/* We cast the object to an unsigned long
|
||||
and then store a reference to it using
|
||||
a Ruby number object. */
|
||||
SWIGRUNTIME VALUE SWIG_RubyObjectToReference(VALUE object) {
|
||||
/* We cast the object to an unsigned long
|
||||
and then store a reference to it using
|
||||
a Ruby number object. */
|
||||
|
||||
/* Convert the Object to a Ruby number */
|
||||
unsigned long value = (unsigned long) object;
|
||||
return LONG2NUM(value);
|
||||
/* Convert the Object to a Ruby number */
|
||||
unsigned long value = (unsigned long) object;
|
||||
return LONG2NUM(value);
|
||||
}
|
||||
|
||||
/* Get a Ruby object from a previously stored reference */
|
||||
static VALUE SWIG_RubyReferenceToObject(VALUE reference) {
|
||||
/* The provided Ruby number object is a reference
|
||||
to the Ruby object we want.*/
|
||||
SWIGRUNTIME VALUE SWIG_RubyReferenceToObject(VALUE reference) {
|
||||
/* The provided Ruby number object is a reference
|
||||
to the Ruby object we want.*/
|
||||
|
||||
/* First convert the Ruby number to a C number */
|
||||
unsigned long value = NUM2LONG(reference);
|
||||
return (VALUE) value;
|
||||
/* First convert the Ruby number to a C number */
|
||||
unsigned long value = NUM2LONG(reference);
|
||||
return (VALUE) value;
|
||||
}
|
||||
|
||||
/* Add a Tracking from a C/C++ struct to a Ruby object */
|
||||
static void SWIG_RubyAddTracking(void* ptr, VALUE object) {
|
||||
/* In a Ruby hash table we store the pointer and
|
||||
the associated Ruby object. The trick here is
|
||||
that we cannot store the Ruby object directly - if
|
||||
we do then it cannot be garbage collected. So
|
||||
instead we typecast it as a unsigned long and
|
||||
convert it to a Ruby number object.*/
|
||||
SWIGRUNTIME void SWIG_RubyAddTracking(void* ptr, VALUE object) {
|
||||
/* In a Ruby hash table we store the pointer and
|
||||
the associated Ruby object. The trick here is
|
||||
that we cannot store the Ruby object directly - if
|
||||
we do then it cannot be garbage collected. So
|
||||
instead we typecast it as a unsigned long and
|
||||
convert it to a Ruby number object.*/
|
||||
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
|
||||
/* Get a reference to the Ruby object as a Ruby number */
|
||||
VALUE value = SWIG_RubyObjectToReference(object);
|
||||
/* Get a reference to the Ruby object as a Ruby number */
|
||||
VALUE value = SWIG_RubyObjectToReference(object);
|
||||
|
||||
/* Store the mapping to the global hash table. */
|
||||
rb_hash_aset(swig_ruby_trackings, key, value);
|
||||
rb_hash_aset(swig_ruby_trackings, key, value);
|
||||
}
|
||||
|
||||
/* Get the Ruby object that owns the specified C/C++ struct */
|
||||
static VALUE SWIG_RubyInstanceFor(void* ptr) {
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
SWIGRUNTIME VALUE SWIG_RubyInstanceFor(void* ptr) {
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
|
||||
/* Now lookup the value stored in the global hash table */
|
||||
VALUE value = rb_hash_aref(swig_ruby_trackings, key);
|
||||
/* Now lookup the value stored in the global hash table */
|
||||
VALUE value = rb_hash_aref(swig_ruby_trackings, key);
|
||||
|
||||
if (value == Qnil) {
|
||||
/* No object exists - return nil. */
|
||||
return Qnil;
|
||||
}
|
||||
else {
|
||||
/* Convert this value to Ruby object */
|
||||
return SWIG_RubyReferenceToObject(value);
|
||||
}
|
||||
if (value == Qnil) {
|
||||
/* No object exists - return nil. */
|
||||
return Qnil;
|
||||
}
|
||||
else {
|
||||
/* Convert this value to Ruby object */
|
||||
return SWIG_RubyReferenceToObject(value);
|
||||
}
|
||||
}
|
||||
|
||||
/* Remove a Tracking from a C/C++ struct to a Ruby object */
|
||||
static void SWIG_RubyRemoveTracking(void* ptr) {
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
SWIGRUNTIME void SWIG_RubyRemoveTracking(void* ptr) {
|
||||
/* Get a reference to the pointer as a Ruby number */
|
||||
VALUE key = SWIG_RubyPtrToReference(ptr);
|
||||
|
||||
/* Define delete method - in C++ this could be marked as
|
||||
static but unfortunately not in C. */
|
||||
VALUE delete_function = rb_intern("delete");
|
||||
/* Define delete method - in C++ this could be marked as
|
||||
static but unfortunately not in C. */
|
||||
VALUE delete_function = rb_intern("delete");
|
||||
|
||||
/* Delete the object from the hash table by calling Ruby's
|
||||
do this we need to call the Hash.delete method.*/
|
||||
rb_funcall(swig_ruby_trackings, delete_function, 1, key);
|
||||
/* Delete the object from the hash table by calling Ruby's
|
||||
do this we need to call the Hash.delete method.*/
|
||||
rb_funcall(swig_ruby_trackings, delete_function, 1, key);
|
||||
}
|
||||
|
||||
/* This is a helper method that unlinks a Ruby object from its
|
||||
underlying C++ object. This is needed if the lifetime of the
|
||||
Ruby object is longer than the C++ object */
|
||||
static void SWIG_RubyUnlinkObjects(void* ptr) {
|
||||
VALUE object = SWIG_RubyInstanceFor(ptr);
|
||||
SWIGRUNTIME void SWIG_RubyUnlinkObjects(void* ptr) {
|
||||
VALUE object = SWIG_RubyInstanceFor(ptr);
|
||||
|
||||
if (object != Qnil) {
|
||||
DATA_PTR(object) = 0;
|
||||
}
|
||||
if (object != Qnil) {
|
||||
DATA_PTR(object) = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
45
Lib/ruby/rubytypemaps.swg
Normal file
45
Lib/ruby/rubytypemaps.swg
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* directors are supported in Python */
|
||||
#ifndef SWIG_DIRECTOR_TYPEMAPS
|
||||
#define SWIG_DIRECTOR_TYPEMAPS
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Basic definitions
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%define_swig_object(VALUE)
|
||||
|
||||
#define SWIG_SetResultObj(obj) $result = obj
|
||||
#define SWIG_AppendResultObj(obj) $result = SWIG_Ruby_AppendResult($result, obj)
|
||||
#define SWIG_SetConstantObj(name, obj) rb_define_const($module, name, obj);
|
||||
#define SWIG_NoneObject() Qnil
|
||||
|
||||
/* error manipulation */
|
||||
#define SWIG_ErrorType(code) SWIG_Ruby_ErrorType(code)
|
||||
#define SWIG_SetErrorObj(code, obj) SWIG_Ruby_SetErrorMsg(SWIG_ErrorType(code),obj)
|
||||
#define SWIG_SetErrorMsg(code, msg) SWIG_Ruby_SetErrorMsg(SWIG_ErrorType(code),msg)
|
||||
#define SWIG_ExceptionObj(d, type, obj) rb_exc_raise(rb_exc_new3(rb_eRuntimeError, rb_obj_as_string(obj)))
|
||||
#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg)
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* All the typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "rubyfragments.swg"
|
||||
|
||||
%include <typemaps/swigtype.swg>
|
||||
%include <typemaps/void.swg>
|
||||
%include <typemaps/valtypes.swg>
|
||||
%include <typemaps/ptrtypes.swg>
|
||||
%include <typemaps/swigobject.swg>
|
||||
%include <typemaps/inoutlist.swg>
|
||||
%include <rubyprimtypes.swg>
|
||||
%include <rubystrings.swg>
|
||||
%include <typemaps/misctypes.swg>
|
||||
%include <typemaps/enumint.swg>
|
||||
|
||||
6
Lib/ruby/rubyuserdir.swg
Normal file
6
Lib/ruby/rubyuserdir.swg
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
#define %alias %feature("alias")
|
||||
#define %freefunc %feature("freefunc")
|
||||
#define %markfunc %feature("markfunc")
|
||||
#define %mixin %feature("mixin")
|
||||
#define %predicate %feature("predicate", "1")
|
||||
#define %trackobjects %feature("trackobjects")
|
||||
|
|
@ -1,33 +0,0 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Void * - Accepts any kind of pointer
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* in */
|
||||
|
||||
%typemap(in) void *
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, 0, SWIG_POINTER_EXCEPTION|$disown);";
|
||||
|
||||
/* out */
|
||||
|
||||
%typemap(out) void "$result = Qnil;";
|
||||
|
||||
/* varin */
|
||||
|
||||
%typemap(varin) void *
|
||||
"SWIG_ConvertPtr($input, (void **) &$1, 0, 1);";
|
||||
|
||||
/* varout */
|
||||
|
||||
%typemap(varout) void "$result = Qnil;";
|
||||
|
||||
/* directorout */
|
||||
|
||||
%typemap(directorout) void * "if ((SWIG_ConvertPtr($input,(void **) &$result, 0, SWIG_POINTER_EXCEPTION | $disown )) == -1) throw Swig::DirectorTypeMismatchException(\"Pointer conversion failed.\");";
|
||||
|
||||
/* typecheck */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
|
||||
void *ptr;
|
||||
$1 = (NIL_P($input) || (TYPE($input) == T_DATA && SWIG_ConvertPtr($input, &ptr, 0, 0) != -1)) ? 1 : 0;
|
||||
}
|
||||
|
||||
74
Lib/ruby/rubywstrings.swg
Normal file
74
Lib/ruby/rubywstrings.swg
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/* ------------------------------------------------------------
|
||||
* utility methods for wchar_t strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/*
|
||||
Ruby doesn't support the wchar_t, so, we need to use an 'opaque' type.
|
||||
*/
|
||||
|
||||
%types(ruby_wchar_array *);
|
||||
|
||||
%fragment("ruby_wchar_array","header",fragment="<wchar.h>") {
|
||||
struct ruby_wchar_array {
|
||||
wchar_t *cptr;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
SWIGINTERN get_ruby_wchar_array_info() {
|
||||
static swig_type_info* ruby_wchar_array_info = 0;
|
||||
if (!ruby_wchar_array_info) ruby_wchar_array_info = SWIG_TypeQuery("ruby_wchar_array *");
|
||||
return ruby_wchar_array_info;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_AsWCharPtrAndSize","header",fragment="ruby_wchar_array") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
|
||||
{
|
||||
static swig_type_info* ptr_wchar_info = 0;
|
||||
wchar_t * vptr = 0;
|
||||
if (!ptr_wchar_info) ptr_wchar_info = SWIG_TypeQuery("wchar_t *");
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, ptr_wchar_info, 0) != SWIG_OK) {
|
||||
if (cptr) *cptr = vptr;
|
||||
if (psize) *psize = vptr ? (wcslen(vptr) + 1) : 0;
|
||||
return SWIG_OK;
|
||||
} else {
|
||||
ruby_wchar_array *vptr = 0;
|
||||
if (SWIG_ConvertPtr(obj, (void**)&vptr, get_ruby_wchar_array_info(), 0) != SWIG_OK) {
|
||||
if (cptr) *cptr = vptr->cptr;
|
||||
if (psize) *psize = vprtr->size;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromWCharPtrAndSize","header",fragment="ruby_wchar_array") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
|
||||
{
|
||||
ruby_wchar_array *vptr = SWIG_new(ruby_wchar_array);
|
||||
vptr->cptr = carray;
|
||||
vptr->size = size;
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,wchar_t *), get_ruby_wchar_array_info(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromWCharPtr","header",fragment="<wchar.h>") {
|
||||
SWIGINTERNINLINE PyObject *
|
||||
SWIG_FromWCharPtr(const wchar_t * carray)
|
||||
{
|
||||
static swig_type_info* wchar_ptr_info = 0;
|
||||
if (!wchar_array_info) wchar_ptr_info = SWIG_TypeQuery("wchar_t *");
|
||||
return SWIG_NewPointerObj(SWIG_const_cast(carray,wchar_t *), wchar_ptr_info, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The plain wchar_t * handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%include <typemaps/strbase.swg>
|
||||
%typemap_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen);
|
||||
|
||||
|
|
@ -1,86 +1,30 @@
|
|||
//
|
||||
// SWIG typemaps for std::string
|
||||
// Luigi Ballabio
|
||||
// Apr 8, 2002
|
||||
// std::string
|
||||
//
|
||||
// Ruby implementation
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::string is typemapped by value
|
||||
// This can prevent exporting methods which return a string
|
||||
// in order for the user to modify it.
|
||||
// However, I think I'll wait until someone asks for it...
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%include exception.i
|
||||
#ifndef SWIG_STD_BASIC_STRING
|
||||
#define SWIG_STD_STRING
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
// Ruby wants class names to start with a capital letter
|
||||
%rename(String) string;
|
||||
class string;
|
||||
|
||||
/* Overloading check */
|
||||
%typemap(typecheck) string = char *;
|
||||
%typemap(typecheck) const string & = char *;
|
||||
|
||||
%typemap(in) string {
|
||||
if (TYPE($input) == T_STRING) {
|
||||
$1 = std::string(StringValuePtr($input));
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "not a string");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in) const string & (std::string temp) {
|
||||
if (TYPE($input) == T_STRING) {
|
||||
temp = std::string(StringValuePtr($input));
|
||||
$1 = &temp;
|
||||
} else {
|
||||
SWIG_exception(SWIG_TypeError, "not a string");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(out) string {
|
||||
$result = rb_str_new2($1.c_str());
|
||||
}
|
||||
|
||||
%typemap(out) const string & {
|
||||
$result = rb_str_new2($1->c_str());
|
||||
}
|
||||
|
||||
%typemap(directorin) string, const string &, string & {
|
||||
$input = rb_str_new2($1_name.c_str());
|
||||
}
|
||||
|
||||
%typemap(directorin) string *, const string * {
|
||||
$input = rb_str_new2($1_name->c_str());
|
||||
}
|
||||
|
||||
%typemap(directorout) string {
|
||||
if (TYPE($input) == T_STRING)
|
||||
$result = std::string(StringValuePtr($input));
|
||||
else
|
||||
throw Swig::DirectorTypeMismatchException("string expected");
|
||||
}
|
||||
|
||||
%typemap(directorout,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const string & {
|
||||
if (TYPE($input) == T_STRING) {
|
||||
static std::string temp = std::string(StringValuePtr($input));
|
||||
$result = &temp;
|
||||
} else {
|
||||
throw Swig::DirectorTypeMismatchException("string expected");
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(throws) string, const string &
|
||||
"rb_raise(rb_eRuntimeError, $1.c_str());";
|
||||
|
||||
%typemap(throws) string *, const string *
|
||||
"rb_raise(rb_eRuntimeError, $1->c_str());";
|
||||
namespace std
|
||||
{
|
||||
class string;
|
||||
}
|
||||
|
||||
%include <typemaps/std_string.swg>
|
||||
%include <rubystrings.swg>
|
||||
|
||||
%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);
|
||||
|
||||
#else
|
||||
|
||||
%include <std/std_string.i>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -1,441 +1 @@
|
|||
//
|
||||
// typemaps for Ruby
|
||||
//
|
||||
// $Header$
|
||||
//
|
||||
// Copyright (C) 2000 Network Applied Communication Laboratory, Inc.
|
||||
// Copyright (C) 2000 Information-technology Promotion Agency, Japan
|
||||
//
|
||||
// Masaki Fukushima
|
||||
//
|
||||
|
||||
/*
|
||||
The SWIG typemap library provides a language independent mechanism for
|
||||
supporting output arguments, input values, and other C function
|
||||
calling mechanisms. The primary use of the library is to provide a
|
||||
better interface to certain C function--especially those involving
|
||||
pointers.
|
||||
*/
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// 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);
|
||||
|
||||
*/
|
||||
|
||||
%define INPUT_TYPEMAP(type, converter)
|
||||
%typemap(in) type *INPUT($*1_ltype temp), type &INPUT($*1_ltype temp)
|
||||
{
|
||||
temp = ($*1_ltype) converter($input);
|
||||
$1 = &temp;
|
||||
}
|
||||
%typemap(typecheck) type *INPUT = type;
|
||||
%typemap(typecheck) type &INPUT = type;
|
||||
%enddef
|
||||
|
||||
INPUT_TYPEMAP(float, NUM2DBL);
|
||||
INPUT_TYPEMAP(double, NUM2DBL);
|
||||
INPUT_TYPEMAP(int, NUM2INT);
|
||||
INPUT_TYPEMAP(short, NUM2SHRT);
|
||||
INPUT_TYPEMAP(long, NUM2LONG);
|
||||
INPUT_TYPEMAP(long long, NUM2LL);
|
||||
INPUT_TYPEMAP(unsigned int, NUM2UINT);
|
||||
INPUT_TYPEMAP(unsigned short, NUM2USHRT);
|
||||
INPUT_TYPEMAP(unsigned long, NUM2ULONG);
|
||||
INPUT_TYPEMAP(unsigned long long, NUM2ULL);
|
||||
INPUT_TYPEMAP(unsigned char, NUM2UINT);
|
||||
INPUT_TYPEMAP(signed char, NUM2INT);
|
||||
INPUT_TYPEMAP(bool, RTEST);
|
||||
|
||||
#undef INPUT_TYPEMAP
|
||||
|
||||
// OUTPUT typemaps. These typemaps are used for parameters that
|
||||
// are output only. The output value is appended to the result as
|
||||
// a array 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 Ruby Array.
|
||||
|
||||
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 Ruby output of the function would be a Array containing both
|
||||
output values.
|
||||
*/
|
||||
|
||||
%include "fragments.i"
|
||||
|
||||
%define OUTPUT_TYPEMAP(type, converter, convtype)
|
||||
%typemap(in,numinputs=0) type *OUTPUT($*1_ltype temp), type &OUTPUT($*1_ltype temp) "$1 = &temp;";
|
||||
%typemap(argout, fragment="output_helper") type *OUTPUT, type &OUTPUT {
|
||||
VALUE o = converter(convtype (*$1));
|
||||
$result = output_helper($result, o);
|
||||
}
|
||||
%enddef
|
||||
|
||||
OUTPUT_TYPEMAP(int, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(short, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(long, INT2NUM, (long));
|
||||
OUTPUT_TYPEMAP(long long, LL2NUM, (long long));
|
||||
OUTPUT_TYPEMAP(unsigned int, UINT2NUM, (unsigned int));
|
||||
OUTPUT_TYPEMAP(unsigned short, UINT2NUM, (unsigned int));
|
||||
OUTPUT_TYPEMAP(unsigned long, UINT2NUM, (unsigned long));
|
||||
OUTPUT_TYPEMAP(unsigned long long, ULL2NUM, (unsigned long long));
|
||||
OUTPUT_TYPEMAP(unsigned char, UINT2NUM, (unsigned int));
|
||||
OUTPUT_TYPEMAP(signed char, INT2NUM, (int));
|
||||
OUTPUT_TYPEMAP(float, rb_float_new, (double));
|
||||
OUTPUT_TYPEMAP(double, rb_float_new, (double));
|
||||
|
||||
#undef OUTPUT_TYPEMAP
|
||||
|
||||
%typemap(in,numinputs=0) bool *OUTPUT(bool temp), bool &OUTPUT(bool temp) "$1 = &temp;";
|
||||
%typemap(argout, fragment="output_helper") bool *OUTPUT, bool &OUTPUT {
|
||||
VALUE o = (*$1) ? Qtrue : Qfalse;
|
||||
$result = output_helper($result, o);
|
||||
}
|
||||
|
||||
// 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 Ruby array.
|
||||
|
||||
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 Ruby). Rather, the modified input value shows
|
||||
up as the return value of the function. Thus, to apply this function
|
||||
to a Ruby 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.
|
||||
|
||||
*/
|
||||
|
||||
%typemap(in) int *INOUT = int *INPUT;
|
||||
%typemap(in) short *INOUT = short *INPUT;
|
||||
%typemap(in) long *INOUT = long *INPUT;
|
||||
%typemap(in) long long *INOUT = long long *INPUT;
|
||||
%typemap(in) unsigned *INOUT = unsigned *INPUT;
|
||||
%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
|
||||
%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
|
||||
%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
|
||||
%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
|
||||
%typemap(in) signed char *INOUT = signed char *INPUT;
|
||||
%typemap(in) bool *INOUT = bool *INPUT;
|
||||
%typemap(in) float *INOUT = float *INPUT;
|
||||
%typemap(in) double *INOUT = double *INPUT;
|
||||
|
||||
%typemap(in) int &INOUT = int &INPUT;
|
||||
%typemap(in) short &INOUT = short &INPUT;
|
||||
%typemap(in) long &INOUT = long &INPUT;
|
||||
%typemap(in) long long &INOUT = long long &INPUT;
|
||||
%typemap(in) unsigned &INOUT = unsigned &INPUT;
|
||||
%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
|
||||
%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
|
||||
%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
|
||||
%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
|
||||
%typemap(in) signed char &INOUT = signed char &INPUT;
|
||||
%typemap(in) bool &INOUT = bool &INPUT;
|
||||
%typemap(in) float &INOUT = float &INPUT;
|
||||
%typemap(in) double &INOUT = double &INPUT;
|
||||
|
||||
%typemap(argout) int *INOUT = int *OUTPUT;
|
||||
%typemap(argout) short *INOUT = short *OUTPUT;
|
||||
%typemap(argout) long *INOUT = long *OUTPUT;
|
||||
%typemap(argout) long long *INOUT = long long *OUTPUT;
|
||||
%typemap(argout) unsigned *INOUT = unsigned *OUTPUT;
|
||||
%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
|
||||
%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
|
||||
%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
|
||||
%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
|
||||
%typemap(argout) signed char *INOUT = signed char *OUTPUT;
|
||||
%typemap(argout) bool *INOUT = bool *OUTPUT;
|
||||
%typemap(argout) float *INOUT = float *OUTPUT;
|
||||
%typemap(argout) double *INOUT = double *OUTPUT;
|
||||
|
||||
%typemap(argout) int &INOUT = int &OUTPUT;
|
||||
%typemap(argout) short &INOUT = short &OUTPUT;
|
||||
%typemap(argout) long &INOUT = long &OUTPUT;
|
||||
%typemap(argout) long long &INOUT = long long &OUTPUT;
|
||||
%typemap(argout) unsigned &INOUT = unsigned &OUTPUT;
|
||||
%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
|
||||
%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
|
||||
%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
|
||||
%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
|
||||
%typemap(argout) signed char &INOUT = signed char &OUTPUT;
|
||||
%typemap(argout) bool &INOUT = bool &OUTPUT;
|
||||
%typemap(argout) float &INOUT = float &OUTPUT;
|
||||
%typemap(argout) double &INOUT = double &OUTPUT;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Special types
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
/*
|
||||
The typemaps.i library also provides the following mappings :
|
||||
|
||||
struct timeval *
|
||||
time_t
|
||||
|
||||
Ruby has builtin class Time. INPUT/OUTPUT typemap for timeval and
|
||||
time_t is provided.
|
||||
|
||||
int PROG_ARGC
|
||||
char **PROG_ARGV
|
||||
|
||||
Some C function receive argc and argv from C main function.
|
||||
This typemap provides ignore typemap which pass Ruby ARGV contents
|
||||
as argc and argv to C function.
|
||||
*/
|
||||
|
||||
|
||||
// struct timeval *
|
||||
%{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef HAVE_SYS_TIME_H
|
||||
# include <sys/time.h>
|
||||
struct timeval rb_time_timeval(VALUE);
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(in) struct timeval *INPUT (struct timeval temp)
|
||||
{
|
||||
if (NIL_P($input))
|
||||
$1 = NULL;
|
||||
else {
|
||||
temp = rb_time_timeval($input);
|
||||
$1 = &temp;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(in,numinputs=0) struct timeval *OUTPUT(struct timeval temp)
|
||||
{
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(argout) struct timeval *OUTPUT
|
||||
{
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_usec);
|
||||
}
|
||||
|
||||
%typemap(out) struct timeval *
|
||||
{
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_usec);
|
||||
}
|
||||
|
||||
%typemap(out) struct timespec *
|
||||
{
|
||||
$result = rb_time_new($1->tv_sec, $1->tv_nsec / 1000);
|
||||
}
|
||||
|
||||
// time_t
|
||||
%typemap(in) time_t
|
||||
{
|
||||
if (NIL_P($input))
|
||||
$1 = (time_t)-1;
|
||||
else
|
||||
$1 = NUM2LONG(rb_funcall($input, rb_intern("tv_sec"), 0));
|
||||
}
|
||||
|
||||
%typemap(out) time_t
|
||||
{
|
||||
$result = rb_time_new($1, 0);
|
||||
}
|
||||
|
||||
// argc and argv
|
||||
%typemap(in,numinputs=0) int PROG_ARGC {
|
||||
$1 = RARRAY(rb_argv)->len + 1;
|
||||
}
|
||||
|
||||
%typemap(in,numinputs=0) char **PROG_ARGV {
|
||||
int i, n;
|
||||
VALUE ary = rb_eval_string("[$0] + ARGV");
|
||||
n = RARRAY(ary)->len;
|
||||
$1 = (char **)malloc(n + 1);
|
||||
for (i = 0; i < n; i++) {
|
||||
VALUE v = rb_obj_as_string(RARRAY(ary)->ptr[i]);
|
||||
$1[i] = (char *)malloc(RSTRING(v)->len + 1);
|
||||
strcpy($1[i], RSTRING(v)->ptr);
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(freearg) char **PROG_ARGV {
|
||||
int i, n = RARRAY(rb_argv)->len + 1;
|
||||
for (i = 0; i < n; i++) free($1[i]);
|
||||
free($1);
|
||||
}
|
||||
|
||||
// FILE *
|
||||
%{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#include "rubyio.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
%}
|
||||
|
||||
%typemap(in) FILE *READ {
|
||||
OpenFile *of;
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_readable(of);
|
||||
$1 = GetReadFile(of);
|
||||
rb_read_check($1);
|
||||
}
|
||||
|
||||
%typemap(in) FILE *READ_NOCHECK {
|
||||
OpenFile *of;
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_readable(of);
|
||||
$1 = GetReadFile(of);
|
||||
}
|
||||
|
||||
%typemap(in) FILE *WRITE {
|
||||
OpenFile *of;
|
||||
GetOpenFile($input, of);
|
||||
rb_io_check_writable(of);
|
||||
$1 = GetWriteFile(of);
|
||||
}
|
||||
|
||||
/* Overloading information */
|
||||
|
||||
%typemap(typecheck) double *INOUT = double;
|
||||
%typemap(typecheck) signed char *INOUT = signed char;
|
||||
%typemap(typecheck) unsigned char *INOUT = unsigned char;
|
||||
%typemap(typecheck) unsigned long *INOUT = unsigned long;
|
||||
%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
|
||||
%typemap(typecheck) unsigned short *INOUT = unsigned short;
|
||||
%typemap(typecheck) unsigned int *INOUT = unsigned int;
|
||||
%typemap(typecheck) long *INOUT = long;
|
||||
%typemap(typecheck) long long *INOUT = long long;
|
||||
%typemap(typecheck) short *INOUT = short;
|
||||
%typemap(typecheck) int *INOUT = int;
|
||||
%typemap(typecheck) float *INOUT = float;
|
||||
|
||||
%typemap(typecheck) double &INOUT = double;
|
||||
%typemap(typecheck) signed char &INOUT = signed char;
|
||||
%typemap(typecheck) unsigned char &INOUT = unsigned char;
|
||||
%typemap(typecheck) unsigned long &INOUT = unsigned long;
|
||||
%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
|
||||
%typemap(typecheck) unsigned short &INOUT = unsigned short;
|
||||
%typemap(typecheck) unsigned int &INOUT = unsigned int;
|
||||
%typemap(typecheck) long &INOUT = long;
|
||||
%typemap(typecheck) long long &INOUT = long long;
|
||||
%typemap(typecheck) short &INOUT = short;
|
||||
%typemap(typecheck) int &INOUT = int;
|
||||
%typemap(typecheck) float &INOUT = float;
|
||||
|
||||
%include <typemaps/typemaps.swg>
|
||||
|
|
|
|||
|
|
@ -142,7 +142,7 @@ namespace swig {
|
|||
template <> struct traits_asval<Type > {
|
||||
typedef Type value_type;
|
||||
static int asval(PyObject *obj, value_type *val) {
|
||||
return SWIG_AsVal(Type)(obj, val);
|
||||
return SWIG_AsVal(Type)(obj, val) == SWIG_OK;
|
||||
}
|
||||
};
|
||||
template <> struct traits_from<Type > {
|
||||
|
|
@ -160,14 +160,12 @@ namespace swig {
|
|||
*/
|
||||
|
||||
%define %typemap_traits(Code,Type...)
|
||||
%typemap_ascheckfrom(SWIG_arg(Code),
|
||||
SWIG_arg(swig::as<Type >),
|
||||
SWIG_arg(swig::check<Type >),
|
||||
SWIG_arg(swig::from),
|
||||
SWIG_arg(SWIG_Traits_frag(Type)),
|
||||
SWIG_arg(SWIG_Traits_frag(Type)),
|
||||
SWIG_arg(SWIG_Traits_frag(Type)),
|
||||
Type);
|
||||
%typemap_asvalfrom(SWIG_arg(Code),
|
||||
SWIG_arg(swig::asval<Type >),
|
||||
SWIG_arg(swig::from),
|
||||
SWIG_arg(SWIG_Traits_frag(Type)),
|
||||
SWIG_arg(SWIG_Traits_frag(Type)),
|
||||
Type);
|
||||
%enddef
|
||||
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -282,7 +282,13 @@ namespace std {
|
|||
|
||||
/* Macro for overload resolution */
|
||||
|
||||
#define %typecheck(_x) %typemap(typecheck, precedence=_x)
|
||||
%define %typecheck(_x, _opt...)
|
||||
#if #_opt != ""
|
||||
%typemap(typecheck, precedence=_x, _opt)
|
||||
#else
|
||||
%typemap(typecheck, precedence=_x)
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
/* Macros for precedence levels */
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,39 @@
|
|||
# define SWIGRUNTIMEINLINE SWIGRUNTIME SWIGINLINE
|
||||
#endif
|
||||
|
||||
/* Generic buffer size */
|
||||
#ifndef SWIG_BUFFER_SIZE
|
||||
# define SWIG_BUFFER_SIZE 1024
|
||||
#endif
|
||||
|
||||
/* Flags for pointer conversions */
|
||||
#define SWIG_POINTER_DISOWN 0x1
|
||||
|
||||
/* Flags for new pointer objects */
|
||||
#define SWIG_POINTER_OWN 0x1
|
||||
|
||||
/* Alloc. memory flags */
|
||||
#define SWIG_OLDOBJ 1
|
||||
#define SWIG_NEWOBJ 2
|
||||
|
||||
/* Error flags */
|
||||
#define SWIG_OK 0
|
||||
#define SWIG_ERROR -1
|
||||
|
||||
#define SWIG_MemoryError 1
|
||||
#define SWIG_IOError 2
|
||||
#define SWIG_RuntimeError 3
|
||||
#define SWIG_IndexError 4
|
||||
#define SWIG_TypeError 5
|
||||
#define SWIG_DivisionByZero 6
|
||||
#define SWIG_OverflowError 7
|
||||
#define SWIG_SyntaxError 8
|
||||
#define SWIG_ValueError 9
|
||||
#define SWIG_SystemError 10
|
||||
#define SWIG_AttributeError 11
|
||||
#define SWIG_UnknownError 99
|
||||
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -74,7 +107,6 @@ typedef struct swig_module_info {
|
|||
void *clientdata; /* Language specific module data */
|
||||
} swig_module_info;
|
||||
|
||||
|
||||
/*
|
||||
Compare two type names skipping the space characters, therefore
|
||||
"char*" == "char *" and "Class<int>" == "Class<int >", etc.
|
||||
|
|
@ -208,6 +240,7 @@ SWIG_TypePrettyName(const swig_type_info *type) {
|
|||
type, separated by vertical-bar characters. We choose
|
||||
to print the last name, as it is often (?) the most
|
||||
specific. */
|
||||
if (!type) return NULL;
|
||||
if (type->str != NULL) {
|
||||
const char *last_name = type->str;
|
||||
const char *s;
|
||||
|
|
@ -318,7 +351,6 @@ SWIG_TypeQueryModule(swig_module_info *start,
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
Pack binary data into a string
|
||||
*/
|
||||
|
|
|
|||
1
Lib/tcl/cdata.i
Normal file
1
Lib/tcl/cdata.i
Normal file
|
|
@ -0,0 +1 @@
|
|||
%include <typemaps/cdata.swg>
|
||||
|
|
@ -10,70 +10,45 @@
|
|||
* some way.
|
||||
*/
|
||||
|
||||
/* %cstring_input_binary(TYPEMAP, SIZE)
|
||||
/*
|
||||
* %cstring_input_binary(TYPEMAP, SIZE)
|
||||
*
|
||||
* Macro makes a function accept binary string data along with
|
||||
* a size.
|
||||
*/
|
||||
|
||||
%define %cstring_input_binary(TYPEMAP, SIZE)
|
||||
%apply (char *STRING, int LENGTH) { (TYPEMAP, SIZE) };
|
||||
%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) {
|
||||
* %cstring_bounded_output(Char *outx, 512);
|
||||
* void foo(Char *outx) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
%define %cstring_bounded_output(TYPEMAP,MAX)
|
||||
%typemap(ignore) TYPEMAP(char temp[MAX+1]) {
|
||||
$1 = ($1_ltype) temp;
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper") TYPEMAP {
|
||||
Tcl_Obj *o;
|
||||
$1[MAX] = 0;
|
||||
o = Tcl_NewStringObj($1,-1);
|
||||
Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp), o);
|
||||
}
|
||||
%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) {
|
||||
* %cstring_chunk_output(Char *outx, 512);
|
||||
* void foo(Char *outx) {
|
||||
* memmove(outx, somedata, 512);
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
%define %cstring_chunk_output(TYPEMAP,SIZE)
|
||||
%typemap(ignore) TYPEMAP(char temp[SIZE]) {
|
||||
$1 = ($1_ltype) temp;
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper") TYPEMAP {
|
||||
Tcl_Obj *o = Tcl_NewStringObj($1,SIZE);
|
||||
Tcl_ListObjAppendElement(interp, Tcl_GetObjResult(interp),o);
|
||||
}
|
||||
%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);
|
||||
* %cstring_bounded_mutable(Char *in, 512);
|
||||
* void foo(in *x) {
|
||||
* while (*x) {
|
||||
* *x = toupper(*x);
|
||||
|
|
@ -83,28 +58,13 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
%define %cstring_bounded_mutable(TYPEMAP,MAX)
|
||||
%typemap(in) TYPEMAP(char temp[MAX+1]) {
|
||||
char *t = Tcl_GetStringFromObj($input,NULL);
|
||||
strncpy(temp,t,MAX);
|
||||
$1 = ($1_ltype) temp;
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper") TYPEMAP {
|
||||
Tcl_Obj *o;
|
||||
$1[MAX] = 0;
|
||||
o = Tcl_NewStringObj($1,-1);
|
||||
Tcl_ListObjAppendElement(interp, Tcl_GetObjResult(interp),o);
|
||||
}
|
||||
%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);
|
||||
* %cstring_mutable(Char *in);
|
||||
* void foo(in *x) {
|
||||
* while (*x) {
|
||||
* *x = toupper(*x);
|
||||
|
|
@ -114,177 +74,64 @@
|
|||
*
|
||||
*/
|
||||
|
||||
%define %cstring_mutable(TYPEMAP,...)
|
||||
%typemap(in) TYPEMAP {
|
||||
int n;
|
||||
char *t = Tcl_GetStringFromObj($input,&n);
|
||||
$1 = ($1_ltype) t;
|
||||
|
||||
#if #__VA_ARGS__ == ""
|
||||
#ifdef __cplusplus
|
||||
$1 = ($1_ltype) new char[n+1];
|
||||
#else
|
||||
$1 = ($1_ltype) malloc(n+1);
|
||||
#endif
|
||||
#else
|
||||
#ifdef __cplusplus
|
||||
$1 = ($1_ltype) new char[n+1+__VA_ARGS__];
|
||||
#else
|
||||
$1 = ($1_ltype) malloc(n+1+__VA_ARGS__);
|
||||
#endif
|
||||
#endif
|
||||
memmove($1,t,n);
|
||||
$1[n] = 0;
|
||||
}
|
||||
|
||||
%typemap(argout,fragment="t_output_helper") TYPEMAP {
|
||||
Tcl_Obj *o;
|
||||
o = Tcl_NewStringObj($1,-1);
|
||||
Tcl_ListObjAppendElement(interp, Tcl_GetObjResult(interp), o);
|
||||
#ifdef __cplusplus
|
||||
delete[] $1;
|
||||
#else
|
||||
free($1);
|
||||
#endif
|
||||
}
|
||||
%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) {
|
||||
* %cstring_output_maxsize(Char *outx, int max) {
|
||||
* void foo(Char *outx, int max) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*/
|
||||
|
||||
%define %cstring_output_maxsize(TYPEMAP, SIZE)
|
||||
%typemap(in) (TYPEMAP, SIZE) {
|
||||
long temp;
|
||||
if (Tcl_GetLongFromObj(interp,$input,&temp) != TCL_OK) {
|
||||
SWIG_fail;
|
||||
}
|
||||
$2 = ($2_ltype) temp;
|
||||
#ifdef __cplusplus
|
||||
$1 = ($1_ltype) new char[$2+1];
|
||||
#else
|
||||
$1 = ($1_ltype) malloc($2+1);
|
||||
#endif
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper") (TYPEMAP,SIZE) {
|
||||
Tcl_Obj *o;
|
||||
o = Tcl_NewStringObj($1,-1);
|
||||
Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
|
||||
#ifdef __cplusplus
|
||||
delete [] $1;
|
||||
#else
|
||||
free($1);
|
||||
#endif
|
||||
}
|
||||
%enddef
|
||||
|
||||
/*
|
||||
* %cstring_output_withsize(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to return character data along with a 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) {
|
||||
* %cstring_output_maxsize(Char *outx, int *max) {
|
||||
* void foo(Char *outx, int *max) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* *max = strlen(outx);
|
||||
* }
|
||||
*/
|
||||
|
||||
%define %cstring_output_withsize(TYPEMAP, SIZE)
|
||||
%typemap(in) (TYPEMAP, SIZE) {
|
||||
long n;
|
||||
if (Tcl_GetLongFromObj(interp,$input,&n) != TCL_OK) {
|
||||
SWIG_fail;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
$1 = ($1_ltype) new char[n+1];
|
||||
$2 = ($2_ltype) new $*1_ltype;
|
||||
#else
|
||||
$1 = ($1_ltype) malloc(n+1);
|
||||
$2 = ($2_ltype) malloc(sizeof($*1_ltype));
|
||||
#endif
|
||||
*$2 = n;
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper") (TYPEMAP,SIZE) {
|
||||
Tcl_Obj *o;
|
||||
o = Tcl_NewStringObj($1,*$2);
|
||||
Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp), o);
|
||||
#ifdef __cplusplus
|
||||
delete [] $1;
|
||||
delete $2;
|
||||
#else
|
||||
free($1);
|
||||
free($2);
|
||||
#endif
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_output_allocate(TYPEMAP, RELEASE)
|
||||
*
|
||||
* This macro is used to return character data that was
|
||||
* 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);
|
||||
* %cstring_output_allocated(Char **outx, free($1));
|
||||
* void foo(Char **outx) {
|
||||
* *outx = (Char *) malloc(512);
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*/
|
||||
|
||||
%define %cstring_output_allocate(TYPEMAP, RELEASE)
|
||||
%typemap(ignore) TYPEMAP($*1_ltype temp = 0) {
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(argout,fragment="t_output_helper") TYPEMAP {
|
||||
if (*$1) {
|
||||
Tcl_Obj *o = Tcl_NewStringObj(*$1,-1);
|
||||
RELEASE;
|
||||
Tcl_ListObjAppendElement(interp, Tcl_GetObjResult(interp), o);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
/*
|
||||
* %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
|
||||
*
|
||||
* This macro is used to return character data that was
|
||||
* 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);
|
||||
* %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 %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
|
||||
%typemap(ignore) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) {
|
||||
$1 = &temp;
|
||||
$2 = &tempn;
|
||||
}
|
||||
|
||||
%typemap(argout,fragment="t_output_helper")(TYPEMAP,SIZE) {
|
||||
if (*$1) {
|
||||
Tcl_Obj *o = Tcl_NewStringObj(*$1,*$2);
|
||||
RELEASE;
|
||||
Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp), o);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
|
||||
|
||||
%include <typemaps/cstring.swg>
|
||||
%include <tclstrings.swg>
|
||||
|
||||
%typemap_cstrings(%cstring,
|
||||
char,
|
||||
SWIG_AsCharPtr,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtr,
|
||||
SWIG_FromCharPtrAndSize);
|
||||
|
||||
|
|
|
|||
137
Lib/tcl/cwstring.i
Normal file
137
Lib/tcl/cwstring.i
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
/*
|
||||
* cstring.i
|
||||
* $Header$
|
||||
*
|
||||
|
||||
* 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_input_binary(TYPEMAP, SIZE)
|
||||
*
|
||||
* Macro makes a function accept binary string data along with
|
||||
* a size.
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_bounded_output(TYPEMAP, MAX)
|
||||
*
|
||||
* This macro is used to return a NULL-terminated output string of
|
||||
* some maximum length. For example:
|
||||
*
|
||||
* %cwstring_bounded_output(wchar_t *outx, 512);
|
||||
* void foo(wchar_t *outx) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_chunk_output(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to return a chunk of binary string data.
|
||||
* Embedded NULLs are okay. For example:
|
||||
*
|
||||
* %cwstring_chunk_output(wchar_t *outx, 512);
|
||||
* void foo(wchar_t *outx) {
|
||||
* memmove(outx, somedata, 512);
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_bounded_mutable(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to wrap a string that's going to mutate.
|
||||
*
|
||||
* %cwstring_bounded_mutable(wchar_t *in, 512);
|
||||
* void foo(in *x) {
|
||||
* while (*x) {
|
||||
* *x = toupper(*x);
|
||||
* x++;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_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.
|
||||
*
|
||||
* %cwstring_mutable(wchar_t *in);
|
||||
* void foo(in *x) {
|
||||
* while (*x) {
|
||||
* *x = toupper(*x);
|
||||
* x++;
|
||||
* }
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_output_maxsize(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro returns data in a string of some user-defined size.
|
||||
*
|
||||
* %cwstring_output_maxsize(wchar_t *outx, int max) {
|
||||
* void foo(wchar_t *outx, int max) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_output_withsize(TYPEMAP, SIZE)
|
||||
*
|
||||
* This macro is used to return wchar_tacter data along with a size
|
||||
* parameter.
|
||||
*
|
||||
* %cwstring_output_maxsize(wchar_t *outx, int *max) {
|
||||
* void foo(wchar_t *outx, int *max) {
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* *max = strlen(outx);
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_output_allocate(TYPEMAP, RELEASE)
|
||||
*
|
||||
* This macro is used to return wchar_tacter data that was
|
||||
* allocated with new or malloc.
|
||||
*
|
||||
* %cwstring_output_allocated(wchar_t **outx, free($1));
|
||||
* void foo(wchar_t **outx) {
|
||||
* *outx = (wchar_t *) malloc(512);
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* }
|
||||
*/
|
||||
|
||||
/*
|
||||
* %cwstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
|
||||
*
|
||||
* This macro is used to return wchar_tacter data that was
|
||||
* allocated with new or malloc.
|
||||
*
|
||||
* %cwstring_output_allocated(wchar_t **outx, int *sz, free($1));
|
||||
* void foo(wchar_t **outx, int *sz) {
|
||||
* *outx = (wchar_t *) malloc(512);
|
||||
* sprintf(outx,"blah blah\n");
|
||||
* *sz = strlen(outx);
|
||||
* }
|
||||
*/
|
||||
|
||||
|
||||
%include <typemaps/cstring.swg>
|
||||
%include <pywstrings.swg>
|
||||
|
||||
%typemap_cstrings(%cwstring,
|
||||
wchar_t,
|
||||
SWIG_AsWCharPtr,
|
||||
SWIG_AsWCharPtrAndSize,
|
||||
SWIG_FromWCharPtr,
|
||||
SWIG_FromWCharArray);
|
||||
|
||||
|
|
@ -1,56 +1,37 @@
|
|||
//
|
||||
// SWIG typemaps for std::string
|
||||
// Luigi Ballabio and Manu ???
|
||||
// Apr 26, 2002
|
||||
// std::string
|
||||
//
|
||||
// Tcl implementation
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// std::string is typemapped by value
|
||||
// This can prevent exporting methods which return a string
|
||||
// in order for the user to modify it.
|
||||
// However, I think I'll wait until someone asks for it...
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
%include exception.i
|
||||
#ifndef SWIG_STD_BASIC_STRING
|
||||
#define SWIG_STD_STRING
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
|
||||
class string;
|
||||
|
||||
/* Overloading check */
|
||||
%typemap(typecheck) string = char *;
|
||||
%typemap(typecheck) const string & = char *;
|
||||
|
||||
%typemap(in) string {
|
||||
$1 = std::string(Tcl_GetStringFromObj($input,NULL));
|
||||
}
|
||||
|
||||
%typemap(in) const string & (std::string temp) {
|
||||
temp = std::string(Tcl_GetStringFromObj($input,NULL));
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(out) string {
|
||||
Tcl_SetStringObj($result,(char*)$1.c_str(),$1.length());
|
||||
}
|
||||
|
||||
%typemap(out) const string & {
|
||||
Tcl_SetStringObj($result,(char*)$1->c_str(),$1->length());
|
||||
}
|
||||
|
||||
%typemap(throws) string {
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj((char*) $1.c_str(), -1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
%typemap(throws) const string & {
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj((char*) $1.c_str(), -1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
namespace std
|
||||
{
|
||||
class string;
|
||||
}
|
||||
|
||||
%include <typemaps/std_string.swg>
|
||||
%include <tclstrings.swg>
|
||||
|
||||
%fragment("Tcl_std_string_asptr","header",fragment="SWIG_AsCharPtrAndSize") {
|
||||
%tcl_asptr_decl(std::string)
|
||||
}
|
||||
%fragment("Tcl_std_string_asval","header",fragment="Tcl_std_string_asptr") {
|
||||
%tcl_asptr_decl(std::string)
|
||||
}
|
||||
|
||||
%std_string_asptr_frag(std::string, char, SWIG_AsCharPtrAndSize, "Tcl_std_string_asptr")
|
||||
%std_string_asval_frag(std::string, "Tcl_std_string_asval")
|
||||
%std_string_from(std::string, SWIG_FromCharPtrAndSize)
|
||||
|
||||
%typemap_asptrfromn(SWIG_CCode(STRING), std::string);
|
||||
|
||||
#else
|
||||
|
||||
%include <std/std_string.i>
|
||||
|
||||
#endif
|
||||
|
|
|
|||
37
Lib/tcl/std_wstring.i
Normal file
37
Lib/tcl/std_wstring.i
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
//
|
||||
// std::wstring
|
||||
//
|
||||
|
||||
#ifndef SWIG_STD_BASIC_STRING
|
||||
#define SWIG_STD_WSTRING
|
||||
|
||||
%{
|
||||
#include <string>
|
||||
%}
|
||||
|
||||
namespace std
|
||||
{
|
||||
class wstring;
|
||||
}
|
||||
|
||||
%include <typemaps/std_string.i>
|
||||
%include <tclwstrings.swg>
|
||||
|
||||
%fragment("Tcl_std_wstring_asptr","header",fragment="SWIG_AsCharPtrAndSize") {
|
||||
%tcl_asptr_decl(std::wstring)
|
||||
}
|
||||
%fragment("Tcl_std_wstring_asval","header",fragment="Tcl_std_wstring_asptr") {
|
||||
%tcl_asptr_decl(std::wstring)
|
||||
}
|
||||
|
||||
%std_string_asptr_frag(std::wstring, wchar_t, SWIG_AsCharPtrAndSize, "Tcl_std_wstring_asptr")
|
||||
%std_string_asval_frag(std::wstring, "Tcl_std_wstring_asval")
|
||||
%std_string_from(std::wstring, SWIG_FromCharPtrAndSize)
|
||||
|
||||
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::wstring);
|
||||
|
||||
#else
|
||||
|
||||
%include <std/std_string.i>
|
||||
|
||||
#endif
|
||||
743
Lib/tcl/tcl8.swg
743
Lib/tcl/tcl8.swg
|
|
@ -1,730 +1,53 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* tcl8.swg
|
||||
* tcl.swg
|
||||
*
|
||||
* Tcl8 configuration module.
|
||||
* Tcl configuration module.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%runtime "swigrun.swg" // Common C API type-checking code
|
||||
%runtime "swigtcl8.swg"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* --- standard typemaps ---
|
||||
* The runtime part
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <tclruntime.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Special user directives
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <tcluserdir.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Inner macros
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <tclmacros.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Error manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* Input arguments */
|
||||
|
||||
/* For primitive types, the Tcl module uses a special function
|
||||
|
||||
SWIG_GetArgs(Tcl_Interp *, int objc, Tcl_Obj *CONST objv[], const char *fmt, ...)
|
||||
|
||||
The fmt field contains special conversion characters i,h,l,b,f,d,c,p, and o
|
||||
that are used to marshal different types. The parse codes below correspond
|
||||
to these special codes */
|
||||
|
||||
%typemap(in,parse="i") int "";
|
||||
%typemap(in,parse="h") short, unsigned short "";
|
||||
%typemap(in,parse="l") long "";
|
||||
%typemap(in,parse="b") signed char, unsigned char "";
|
||||
%typemap(in,parse="f") float "";
|
||||
%typemap(in,parse="d") double "";
|
||||
%typemap(in,parse="c") char "";
|
||||
%typemap(in,parse="s") char *, char [ANY] "";
|
||||
|
||||
/* Pointers */
|
||||
%typemap(in) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
"if ((SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,SWIG_POINTER_EXCEPTION | $disown) != TCL_OK)) SWIG_fail;";
|
||||
|
||||
%typemap(in) void *
|
||||
"if ((SWIG_ConvertPtr($input, (void **) &$1, 0,SWIG_POINTER_EXCEPTION | $disown) != TCL_OK)) SWIG_fail;";
|
||||
|
||||
/* For bools, we first convert to an integer and then to a bool. There
|
||||
is no guarantee that a bool is the same size as an int so we have to do this */
|
||||
|
||||
%typemap(in) bool (int tempb) "if (Tcl_GetIntFromObj(interp,$input,&tempb) == TCL_ERROR) SWIG_fail;
|
||||
$1 = tempb ? true : false;";
|
||||
|
||||
%typemap(in) unsigned int "$1 = ($1_ltype) strtoul(Tcl_GetStringFromObj($input,NULL), 0, 0);";
|
||||
%typemap(in) unsigned long "$1 = ($1_ltype) strtoul(Tcl_GetStringFromObj($input,NULL), 0, 0);";
|
||||
|
||||
/* These will pass an integer as an unsigned long. However, the implementation is crippled due
|
||||
to limited precision in Tcl */
|
||||
|
||||
%typemap(in) long long "$1 = ($1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0);";
|
||||
%typemap(in) unsigned long long "$1 = ($1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL), 0, 0);";
|
||||
|
||||
/* Enum parsing. Note: internally SWIG converts enums to/from integers so it's okay to use
|
||||
the "i" parse code here */
|
||||
|
||||
%typemap(in,parse="i") enum SWIGTYPE "";
|
||||
|
||||
/* Unknown type. We convert from a pointer */
|
||||
%typemap(in) SWIGTYPE ($&1_ltype argp)
|
||||
"if ((SWIG_ConvertPtr($input, (void **) &argp, $&1_descriptor,SWIG_POINTER_EXCEPTION ) != TCL_OK)) SWIG_fail;
|
||||
$1 = *argp; ";
|
||||
|
||||
/* Member pointer */
|
||||
%typemap(in) SWIGTYPE (CLASS::*) "if ((SWIG_ConvertPacked($input, (void *) &$1, sizeof($1_type), $1_descriptor, SWIG_POINTER_EXCEPTION)) != TCL_OK) SWIG_fail;";
|
||||
|
||||
/* Special constant variations. These typemaps can be used to parse objects that are both constants
|
||||
or values. A Hash table lookup will occur. */
|
||||
|
||||
%typemap(in,parse="I") int CONSTANT, unsigned int CONSTANT "";
|
||||
%typemap(in,parse="H") short CONSTANT, unsigned short CONSTANT "";
|
||||
%typemap(in,parse="L") long CONSTANT, unsigned long CONSTANT "";
|
||||
%typemap(in,parse="B") signed char CONSTANT, unsigned char CONSTANT "";
|
||||
%typemap(in,parse="F") float CONSTANT "";
|
||||
%typemap(in,parse="D") double CONSTANT "";
|
||||
%typemap(in,parse="C") char CONSTANT "";
|
||||
%typemap(in,parse="S") char * CONSTANT "";
|
||||
%typemap(in,parse="P") SWIGTYPE *CONSTANT, SWIGTYPE &CONSTANT, SWIGTYPE CONSTANT [] "";
|
||||
%typemap(in,parse="I") enum SWIGTYPE CONSTANT "";
|
||||
|
||||
/* Constant references. Passed by value */
|
||||
/* Const primitive references. Passed by value */
|
||||
|
||||
%typemap(in) const int & ($*1_ltype temp),
|
||||
const short & ($*1_ltype temp),
|
||||
const long & ($*1_ltype temp),
|
||||
const unsigned short & ($*1_ltype temp),
|
||||
const signed char & ($*1_ltype temp),
|
||||
const unsigned char & ($*1_ltype temp),
|
||||
const enum SWIGTYPE & ($*1_ltype temp)
|
||||
{
|
||||
long ltemp;
|
||||
if (Tcl_GetLongFromObj(interp, $input, <emp) != TCL_OK) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = ($*1_ltype) ltemp;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) const unsigned int & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) strtoul(Tcl_GetStringFromObj($input,NULL),0,0);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned long & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) strtoul(Tcl_GetStringFromObj($input,NULL),0,0);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const bool & (bool temp)
|
||||
{
|
||||
long ltemp;
|
||||
if (Tcl_GetLongFromObj(interp, $input, <emp) != TCL_OK) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = ltemp ? true : false;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
|
||||
%typemap(in) const float & (float temp),
|
||||
const double & (double temp)
|
||||
{
|
||||
double dtemp;
|
||||
if (Tcl_GetDoubleFromObj(interp, $input, &dtemp) != TCL_OK) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = ($*1_ltype) dtemp;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) const long long & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const unsigned long long & ($*1_ltype temp)
|
||||
"temp = ($*1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0);
|
||||
$1 = &temp;";
|
||||
|
||||
%typemap(in) const char &(char temp) {
|
||||
char *stemp = Tcl_GetStringFromObj($input,NULL);
|
||||
temp = *stemp;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
/* Output values */
|
||||
|
||||
%typemap(out) bool, int, short, unsigned short, signed char, unsigned char, enum SWIGTYPE
|
||||
"Tcl_SetObjResult(interp,Tcl_NewIntObj((long) $1));";
|
||||
|
||||
%typemap(out) long
|
||||
"Tcl_SetObjResult(interp,Tcl_NewLongObj((long) $1));";
|
||||
|
||||
%typemap(out) unsigned int, unsigned long {
|
||||
char temp[256];
|
||||
sprintf(temp,"%lu", (unsigned long) $1);
|
||||
Tcl_SetObjResult(interp,Tcl_NewStringObj(temp,-1));
|
||||
}
|
||||
|
||||
|
||||
%typemap(out) long long {
|
||||
char temp[256];
|
||||
sprintf(temp,"%lld", (long long) $1);
|
||||
Tcl_SetObjResult(interp,Tcl_NewStringObj(temp,-1));
|
||||
}
|
||||
|
||||
%typemap(out) unsigned long long {
|
||||
char temp[256];
|
||||
sprintf(temp,"%llu", (unsigned long long) $1);
|
||||
Tcl_SetObjResult(interp,Tcl_NewStringObj(temp,-1));
|
||||
}
|
||||
|
||||
%typemap(out) char
|
||||
"Tcl_SetObjResult(interp,Tcl_NewStringObj(&$1,1));";
|
||||
|
||||
%typemap(out) float, double
|
||||
"Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) $1));";
|
||||
|
||||
%typemap(out) char *
|
||||
"Tcl_SetObjResult(interp,Tcl_NewStringObj($1,-1));";
|
||||
|
||||
%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
"Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) $1, $1_descriptor, $owner));";
|
||||
|
||||
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
|
||||
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
|
||||
Tcl_SetObjResult(interp,SWIG_NewPointerObj((void *) $1, ty, $owner));
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE *INSTANCE, SWIGTYPE &INSTANCE, SWIGTYPE INSTANCE[]
|
||||
"Tcl_SetObjResult(interp,SWIG_NewInstanceObj((void *) $1, $1_descriptor, $owner));";
|
||||
|
||||
%typemap(out) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
"Tcl_SetObjResult(interp,SWIG_NewInstanceObj((void *) $1, $1_descriptor, $owner));";
|
||||
|
||||
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
|
||||
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor,(void **) &$1);
|
||||
Tcl_SetObjResult(interp,SWIG_NewInstanceObj((void *) $1, ty, $owner));
|
||||
}
|
||||
|
||||
%typemap(out) SWIGTYPE (CLASS::*)
|
||||
"Tcl_SetObjResult(interp, SWIG_NewPackedObj((void *) &$1, sizeof($1_type), $1_descriptor, $owner));";
|
||||
|
||||
%typemap(out) void "";
|
||||
|
||||
/* Primitive types--return by value */
|
||||
%typemap(out) SWIGTYPE NOINSTANCE
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = new $1_ltype(($1_ltype &) $1);
|
||||
Tcl_SetObjResult(interp,SWIG_NewPointerObj((void*) resultptr, $&1_descriptor, $owner));
|
||||
}
|
||||
#else
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = ($&1_ltype) malloc(sizeof($1_type));
|
||||
memmove(resultptr, &$1, sizeof($1_type));
|
||||
Tcl_SetObjResult(interp,SWIG_NewPointerObj((void*) resultptr, $&1_descriptor, $owner));
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Primitive types--return by value */
|
||||
%typemap(out) SWIGTYPE INSTANCE
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = new $1_ltype(($1_ltype &) $1);
|
||||
Tcl_SetObjResult(interp,SWIG_NewInstanceObj((void*) resultptr, $&1_descriptor,1));
|
||||
}
|
||||
#else
|
||||
{
|
||||
$&1_ltype resultptr;
|
||||
resultptr = ($&1_ltype) malloc(sizeof($1_type));
|
||||
memmove(resultptr, &$1, sizeof($1_type));
|
||||
Tcl_SetObjResult(interp,SWIG_NewInstanceObj((void*) resultptr, $&1_descriptor,1));
|
||||
}
|
||||
#endif
|
||||
|
||||
%typemap(out) SWIGTYPE = SWIGTYPE INSTANCE;
|
||||
|
||||
/* Special typemap for character array returns */
|
||||
%typemap(out) char [ANY] "Tcl_SetObjResult(interp,Tcl_NewStringObj($1,-1));"
|
||||
|
||||
|
||||
/* Primitive references */
|
||||
|
||||
%typemap(out) const int &,
|
||||
const short &, const unsigned short &,
|
||||
const signed char &, const unsigned char &,
|
||||
const bool &,
|
||||
const enum SWIGTYPE &
|
||||
"Tcl_SetObjResult(interp,Tcl_NewIntObj((long) *($1)));";
|
||||
|
||||
%typemap(out) const long &
|
||||
"Tcl_SetObjResult(interp,Tcl_NewLongObj((long) *($1)));";
|
||||
|
||||
%typemap(out) const unsigned int &, const unsigned long &
|
||||
{
|
||||
char temp[256];
|
||||
sprintf(temp,"%lu", (unsigned long)*($1));
|
||||
Tcl_SetObjResult(interp,Tcl_NewStringObj(temp,-1));
|
||||
}
|
||||
|
||||
|
||||
%typemap(out) const float &, const double &
|
||||
"Tcl_SetObjResult(interp,Tcl_NewDoubleObj((double) *($1)));";
|
||||
|
||||
%typemap(out) const long long & {
|
||||
char temp[256];
|
||||
sprintf(temp,"%lld", (long long)*($1));
|
||||
Tcl_SetObjResult(interp,Tcl_NewStringObj(temp,-1));
|
||||
}
|
||||
|
||||
%typemap(out) const unsigned long long &
|
||||
{
|
||||
char temp[256];
|
||||
sprintf(temp,"%llu", (unsigned long long)*($1));
|
||||
Tcl_SetObjResult(interp,Tcl_NewStringObj(temp,-1));
|
||||
}
|
||||
|
||||
%typemap(out) const char &
|
||||
"Tcl_SetObjResult(interp,Tcl_NewStringObj($1,1));";
|
||||
|
||||
|
||||
/* --- Variable output --- */
|
||||
|
||||
%typemap(varout) int, short, unsigned short, signed char, unsigned char, bool, enum SWIGTYPE
|
||||
"$result = Tcl_NewIntObj((long) $1);";
|
||||
|
||||
%typemap(varout) long
|
||||
"$result = Tcl_NewLongObj((long) $1);";
|
||||
|
||||
%typemap(varout) unsigned int, unsigned long {
|
||||
char temp[256];
|
||||
sprintf(temp,"%lu", (unsigned long)$1);
|
||||
$result = Tcl_NewStringObj(temp,-1);
|
||||
}
|
||||
|
||||
%typemap(varout) long long {
|
||||
char temp[256];
|
||||
sprintf(temp,"%lld", (long long)$1);
|
||||
$result = Tcl_NewStringObj(temp,-1);
|
||||
}
|
||||
|
||||
%typemap(varout) unsigned long long {
|
||||
char temp[256];
|
||||
sprintf(temp,"%llu", (unsigned long long)$1);
|
||||
$result = Tcl_NewStringObj(temp,-1);
|
||||
}
|
||||
|
||||
%typemap(varout) double,float "$result = Tcl_NewDoubleObj((double) $1);";
|
||||
%typemap(varout) char * "$result = Tcl_NewStringObj((char*) $1,-1);";
|
||||
%typemap(varout) char [ANY] "$result = Tcl_NewStringObj((char *) $1,-1);";
|
||||
%typemap(varout) char "$result = Tcl_NewStringObj(&$1,1);";
|
||||
%typemap(varout) SWIGTYPE *, SWIGTYPE [] "$result = SWIG_NewPointerObj((void *) $1, $1_descriptor, 0);";
|
||||
%typemap(varout) SWIGTYPE & "$result = SWIG_NewPointerObj((void *) &$1, $1_descriptor, 0);";
|
||||
|
||||
%typemap(varout) SWIGTYPE *INSTANCE, SWIGTYPE INSTANCE[]
|
||||
"$result = SWIG_NewInstanceObj((void *) $1, $1_descriptor, 0);";
|
||||
|
||||
%typemap(varout) SWIGTYPE &INSTANCE
|
||||
"$result = SWIG_NewInstanceObj((void *) &$1, $1_descriptor, 0);";
|
||||
|
||||
%typemap(varout) SWIGTYPE INSTANCE "$result = SWIG_NewInstanceObj((void *) &$1, $&1_descriptor, 0);";
|
||||
%typemap(varout) SWIGTYPE "$result = SWIG_NewInstanceObj((void *) &$1, $&1_descriptor, 0);";
|
||||
%typemap(varout) SWIGTYPE (CLASS::*) "$result = SWIG_NewPackedObj((void *) &$1, sizeof($1_type), $1_descriptor, 0);";
|
||||
|
||||
/* -- Variable input --- */
|
||||
|
||||
%typemap(varin) int, short, unsigned short, long, signed char, unsigned char
|
||||
{
|
||||
long temp;
|
||||
if (Tcl_GetLongFromObj(interp, $input, &temp) != TCL_OK) {
|
||||
return (char*) "Type error. expected an integer";
|
||||
}
|
||||
$1 = ($1_type) temp;
|
||||
}
|
||||
|
||||
%typemap(varin) unsigned int, unsigned long "$1 = ($1_ltype) strtoul(Tcl_GetStringFromObj($input,NULL),0,0);";
|
||||
|
||||
%typemap(varin) enum SWIGTYPE
|
||||
{
|
||||
int temp;
|
||||
if (Tcl_GetIntFromObj(interp, $input, &temp) != TCL_OK) {
|
||||
return (char*) "Type error. expected an integer";
|
||||
}
|
||||
if (sizeof(int) != sizeof($1)) {
|
||||
return (char*) "enum variable '$name' can not be set.";
|
||||
}
|
||||
*(int *)(void *)&($1) = temp;
|
||||
}
|
||||
|
||||
%typemap(varin) bool
|
||||
{
|
||||
long temp;
|
||||
if (Tcl_GetLongFromObj(interp, $input, &temp) != TCL_OK) {
|
||||
return (char*) "Type error. expected an integer";
|
||||
}
|
||||
$1 = temp ? true : false;
|
||||
}
|
||||
|
||||
%typemap(varin) long long "$1 = ($1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0);";
|
||||
%typemap(varin) unsigned long long "$1 = ($1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0);";
|
||||
|
||||
%typemap(varin) double, float {
|
||||
double temp;
|
||||
if (Tcl_GetDoubleFromObj(interp, $input, &temp) != TCL_OK) {
|
||||
return (char*) "Type error. expected a double.";
|
||||
}
|
||||
$1 = ($1_type) temp;
|
||||
}
|
||||
|
||||
%typemap(varin) char *
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
char *temp = Tcl_GetStringFromObj($input,NULL);
|
||||
if ($1) delete [] $1;
|
||||
$1 = ($1_type) new char[strlen(temp)+1];
|
||||
strcpy((char *) $1,temp);
|
||||
}
|
||||
#else
|
||||
{
|
||||
char *temp = Tcl_GetStringFromObj($input,NULL);
|
||||
if ($1) free((char*)$1);
|
||||
$1 = ($1_type) malloc(strlen(temp)+1);
|
||||
strcpy((char *) $1,temp);
|
||||
}
|
||||
#endif
|
||||
|
||||
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char *
|
||||
#ifdef __cplusplus
|
||||
{
|
||||
char *temp = Tcl_GetStringFromObj($input,NULL);
|
||||
$1 = ($1_type) new char[strlen(temp)+1];
|
||||
strcpy((char *) $1,temp);
|
||||
}
|
||||
#else
|
||||
{
|
||||
char *temp = Tcl_GetStringFromObj($input,NULL);
|
||||
$1 = ($1_type) malloc(strlen(temp)+1);
|
||||
strcpy((char *) $1,temp);
|
||||
}
|
||||
#endif
|
||||
|
||||
%typemap(varin) char [ANY] {
|
||||
char *temp = Tcl_GetStringFromObj($input,NULL);
|
||||
strncpy((char*)$1,temp,$1_dim0);
|
||||
}
|
||||
|
||||
%typemap(varin,warning="462: Unable to set variable of type char []") char [] {
|
||||
return (char*)"Variable $symname is read-only.";
|
||||
}
|
||||
|
||||
%typemap(varin) char
|
||||
{
|
||||
char *temp = Tcl_GetStringFromObj($input,NULL);
|
||||
$1 = *temp;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE * {
|
||||
if (SWIG_ConvertPtr($input,(void **)&$1,$1_descriptor, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN) != TCL_OK) {
|
||||
return (char*)"Type error. Expected $1_ltype";
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(varin,warning="462: Unable to set dimensionless array variable") SWIGTYPE [] {
|
||||
return (char*)"Variable $symname is read-only.";
|
||||
}
|
||||
|
||||
%typemap(varin) void * {
|
||||
void *temp;
|
||||
if (SWIG_ConvertPtr($input,&temp,0, SWIG_POINTER_EXCEPTION | SWIG_POINTER_DISOWN) != TCL_OK) {
|
||||
return (char*)"Type error. Expected $1_ltype";
|
||||
}
|
||||
$1 = ($1_type) temp;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE & {
|
||||
void *temp;
|
||||
if (SWIG_ConvertPtr($input,&temp,$1_descriptor, SWIG_POINTER_EXCEPTION) != TCL_OK) {
|
||||
return (char*)"Type error. Expected $1_ltype";
|
||||
}
|
||||
$1 = *($1_ltype) temp;
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE {
|
||||
void *temp;
|
||||
if (SWIG_ConvertPtr($input,&temp,$&1_descriptor, SWIG_POINTER_EXCEPTION) != TCL_OK) {
|
||||
return (char*)"Type error. Expected $&1_ltype";
|
||||
}
|
||||
$1 = *(($&1_type) temp);
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE [ANY] {
|
||||
void *temp;
|
||||
if (SWIG_ConvertPtr($input,&temp,$1_descriptor, SWIG_POINTER_EXCEPTION) != TCL_OK) {
|
||||
return (char *)"Type error. Expected $1_ltype";
|
||||
}
|
||||
memmove((void *) $1,temp,$1_size*sizeof($1_basetype));
|
||||
}
|
||||
|
||||
%typemap(varin) SWIGTYPE (CLASS::*) {
|
||||
char temp[sizeof($1_type)];
|
||||
if (SWIG_ConvertPacked($input, temp, sizeof($1_type), $1_descriptor, SWIG_POINTER_EXCEPTION) != TCL_OK) {
|
||||
return (char *) "Type error. Expected $1_ltype";
|
||||
}
|
||||
memmove((void *) &$1, temp, sizeof($1_type));
|
||||
}
|
||||
|
||||
/* --- Constants --- */
|
||||
|
||||
%typemap(consttab) int, short, unsigned short, unsigned char, signed char, bool, enum SWIGTYPE
|
||||
{ SWIG_TCL_INT, (char *)"$nsname", (long) $value, 0, 0, 0}
|
||||
|
||||
%typemap(consttab) unsigned int, unsigned long
|
||||
{ SWIG_TCL_STRING, (char *) "$nsname", 0, 0, (void *)"$value", 0}
|
||||
|
||||
%typemap(consttab) float, double
|
||||
{ SWIG_TCL_FLOAT, (char*)"$nsname", 0, (double) $value, 0, 0}
|
||||
|
||||
%typemap(consttab) char, char *
|
||||
{ SWIG_TCL_STRING, (char*)"$nsname", 0, 0, (void *)"$value", 0}
|
||||
|
||||
%typemap(consttab) long long, unsigned long long
|
||||
{ SWIG_TCL_STRING, (char *) "$nsname", 0, 0, (void *)"$value", 0}
|
||||
|
||||
%typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
|
||||
{ SWIG_TCL_POINTER, (char*)"$nsname", 0, 0, (void *)$value, &$1_descriptor}
|
||||
|
||||
%typemap(consttab) SWIGTYPE (CLASS::*)
|
||||
{ SWIG_TCL_BINARY, (char *)"$nsname", sizeof($type), 0, (void *)&$value, &$1_descriptor}
|
||||
|
||||
%include <tclerrors.swg>
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Look for user fragments file. If not found, include empty system one.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include "tclfragments.swg"
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
%include <tcltypemaps.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* String & length
|
||||
* Overloaded operator support
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(in) (char *STRING, int LENGTH) {
|
||||
int temp;
|
||||
$1 = ($1_ltype) Tcl_GetStringFromObj($input,&temp);
|
||||
$2 = ($2_ltype) temp;
|
||||
}
|
||||
%include <tclopers.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Typechecking rules
|
||||
* Warnings for Python keywords
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER)
|
||||
int, short, long,
|
||||
unsigned int, unsigned short, unsigned long,
|
||||
signed char, unsigned char,
|
||||
const int &, const short &, const long &,
|
||||
const unsigned int &, const unsigned short &, const unsigned long &,
|
||||
enum SWIGTYPE, const enum SWIGTYPE &,
|
||||
bool, const bool &
|
||||
{
|
||||
long tmp;
|
||||
if (Tcl_GetLongFromObj(NULL,$input,&tmp) == TCL_ERROR) $1 = 0;
|
||||
else $1 = 1;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER)
|
||||
long long, const long long &
|
||||
{
|
||||
int len;
|
||||
char *end = 0;
|
||||
char *str = Tcl_GetStringFromObj($input, &len);
|
||||
strtoll(str, &end, 0);
|
||||
$1 = (end != 0) && (*end != '\0') && (str != end) && (errno == 0);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_INTEGER)
|
||||
unsigned long long, const unsigned long long &
|
||||
{
|
||||
int len;
|
||||
char *end = 0;
|
||||
char *str = Tcl_GetStringFromObj($input, &len);
|
||||
strtoull(str, &end, 0);
|
||||
$1 = (end != 0) && (*end != '\0') && (str != end) && (errno == 0);
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_DOUBLE)
|
||||
float, double,
|
||||
const float &, const double &
|
||||
{
|
||||
double tmp;
|
||||
if (Tcl_GetDoubleFromObj(NULL,$input,&tmp) == TCL_ERROR) $1 = 0;
|
||||
else $1 = 1;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_CHAR) char {
|
||||
char *tmp;
|
||||
int len;
|
||||
tmp = Tcl_GetStringFromObj($input,&len);
|
||||
$1 = (len == 1) ? 1 : 0;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_STRING) char * {
|
||||
$1 = 1;
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
|
||||
void *ptr;
|
||||
if (SWIG_ConvertPtr($input, (void **) &ptr, $1_descriptor, 0) == TCL_ERROR) {
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
|
||||
void *ptr;
|
||||
if (SWIG_ConvertPtr($input, (void **) &ptr, $&1_descriptor, 0) == TCL_ERROR) {
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
|
||||
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
|
||||
void *ptr;
|
||||
if (SWIG_ConvertPtr($input, (void **) &ptr, 0, 0) == TCL_ERROR) {
|
||||
$1 = 0;
|
||||
} else {
|
||||
$1 = 1;
|
||||
}
|
||||
}
|
||||
%include <tclkw.swg>
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Exception handling
|
||||
* The Python initialization function
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%typemap(throws) int,
|
||||
long,
|
||||
short,
|
||||
unsigned int,
|
||||
unsigned long,
|
||||
unsigned short {
|
||||
Tcl_SetObjResult(interp, Tcl_NewIntObj((long) $1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE CLASS {
|
||||
$&1_ltype temp = new $1_ltype($1);
|
||||
Tcl_SetObjResult(interp, SWIG_NewInstanceObj((void *) temp, $&1_descriptor, 1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE {
|
||||
(void)$1;
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj((char*) "$1_type", -1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY] {
|
||||
(void)$1;
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj((char*) "$1_type", -1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
%typemap(throws) enum SWIGTYPE {
|
||||
(void)$1;
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj((char*) "$1_type", -1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
%typemap(throws) char * {
|
||||
Tcl_SetObjResult(interp, Tcl_NewStringObj((char*) $1, -1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* ANSI C typemaps
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%types(size_t);
|
||||
%apply unsigned long { size_t };
|
||||
%apply const unsigned long& { const size_t& };
|
||||
|
||||
%types(ptrdiff_t);
|
||||
%apply long { ptrdiff_t };
|
||||
%apply const long& { const ptrdiff_t& };
|
||||
%include <tclinit.swg>
|
||||
|
||||
|
||||
// Some special reserved words in classes
|
||||
%include "tcl8kw.swg"
|
||||
|
||||
/* C++ overloaded operators.
|
||||
|
||||
These declarations define how SWIG is going to rename C++
|
||||
overloaded operators in Tcl. Since Tcl allows identifiers
|
||||
to be essentially any valid string, we'll just use the
|
||||
normal operator names */
|
||||
|
||||
#ifdef __cplusplus
|
||||
%rename("+") *::operator+;
|
||||
//%rename("u+") *::operator+(); // Unary +
|
||||
//%rename("u+") *::operator+() const; // Unary +
|
||||
%rename("-") *::operator-;
|
||||
//%rename("u-") *::operator-(); // Unary -
|
||||
//%rename("u-") *::operator-() const; // Unary -
|
||||
%rename("*") *::operator*;
|
||||
%rename("/") *::operator/;
|
||||
%rename("<<") *::operator<<;
|
||||
%rename(">>") *::operator>>;
|
||||
%rename("&") *::operator&;
|
||||
%rename("|") *::operator|;
|
||||
%rename("^") *::operator^;
|
||||
%rename("%") *::operator%;
|
||||
%rename("=") *::operator=;
|
||||
#endif
|
||||
|
||||
|
||||
/* This initialization code exports the module initialization function */
|
||||
|
||||
%header %{
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef MAC_TCL
|
||||
#pragma export on
|
||||
#endif
|
||||
SWIGEXPORT int SWIG_init(Tcl_Interp *);
|
||||
#ifdef MAC_TCL
|
||||
#pragma export off
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
/* Start the initialization function */
|
||||
|
||||
%insert(init) "swiginit.swg"
|
||||
|
||||
%init %{
|
||||
SWIGEXPORT int SWIG_init(Tcl_Interp *interp) {
|
||||
int i;
|
||||
if (interp == 0) return TCL_ERROR;
|
||||
#ifdef USE_TCL_STUBS
|
||||
if (Tcl_InitStubs(interp, (char*)"8.1", 0) == NULL) {
|
||||
return TCL_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
Tcl_PkgProvide(interp, (char*)SWIG_name, (char*)SWIG_version);
|
||||
|
||||
#ifdef SWIG_namespace
|
||||
Tcl_Eval(interp, "namespace eval " SWIG_namespace " { }");
|
||||
#endif
|
||||
|
||||
SWIG_InitializeModule((void *) interp);
|
||||
SWIG_PropagateClientData();
|
||||
|
||||
for (i = 0; swig_commands[i].name; i++) {
|
||||
Tcl_CreateObjCommand(interp, (char *) swig_commands[i].name, (swig_wrapper_func) swig_commands[i].wrapper, swig_commands[i].clientdata, NULL);
|
||||
}
|
||||
for (i = 0; swig_variables[i].name; i++) {
|
||||
Tcl_SetVar(interp, (char *) swig_variables[i].name, (char *) "", TCL_GLOBAL_ONLY);
|
||||
Tcl_TraceVar(interp, (char *) swig_variables[i].name, TCL_TRACE_READS | TCL_GLOBAL_ONLY, (Tcl_VarTraceProc *) swig_variables[i].get, (ClientData) swig_variables[i].addr);
|
||||
Tcl_TraceVar(interp, (char *) swig_variables[i].name, TCL_TRACE_WRITES | TCL_GLOBAL_ONLY, (Tcl_VarTraceProc *) swig_variables[i].set, (ClientData) swig_variables[i].addr);
|
||||
}
|
||||
SWIG_InstallConstants(interp, swig_constants);
|
||||
%}
|
||||
|
||||
/* Note: the initialization function is closed after all code is generated */
|
||||
|
|
|
|||
107
Lib/tcl/tclapi.swg
Normal file
107
Lib/tcl/tclapi.swg
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* SWIG API. Portion that goes into the runtime
|
||||
* ----------------------------------------------------------------------------- */
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Constant declarations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* Constant Types */
|
||||
#define SWIG_TCL_POINTER 4
|
||||
#define SWIG_TCL_BINARY 5
|
||||
|
||||
/* Constant information structure */
|
||||
typedef struct swig_const_info {
|
||||
int type;
|
||||
char *name;
|
||||
long lvalue;
|
||||
double dvalue;
|
||||
void *pvalue;
|
||||
swig_type_info **ptype;
|
||||
} swig_const_info;
|
||||
|
||||
typedef int (*swig_wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []);
|
||||
typedef int (*swig_wrapper_func)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []);
|
||||
typedef char *(*swig_variable_func)(ClientData, Tcl_Interp *, char *, char *, int);
|
||||
typedef void (*swig_delete_func)(ClientData);
|
||||
|
||||
typedef struct swig_method {
|
||||
const char *name;
|
||||
swig_wrapper method;
|
||||
} swig_method;
|
||||
|
||||
typedef struct swig_attribute {
|
||||
const char *name;
|
||||
swig_wrapper getmethod;
|
||||
swig_wrapper setmethod;
|
||||
} swig_attribute;
|
||||
|
||||
typedef struct swig_class {
|
||||
const char *name;
|
||||
swig_type_info **type;
|
||||
swig_wrapper constructor;
|
||||
void (*destructor)(void *);
|
||||
swig_method *methods;
|
||||
swig_attribute *attributes;
|
||||
struct swig_class **bases;
|
||||
char **base_names;
|
||||
swig_module_info *module;
|
||||
} swig_class;
|
||||
|
||||
typedef struct swig_instance {
|
||||
Tcl_Obj *thisptr;
|
||||
void *thisvalue;
|
||||
swig_class *classptr;
|
||||
int destroy;
|
||||
Tcl_Command cmdtok;
|
||||
} swig_instance;
|
||||
|
||||
/* Structure for command table */
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int (*wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []);
|
||||
ClientData clientdata;
|
||||
} swig_command_info;
|
||||
|
||||
/* Structure for variable linking table */
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void *addr;
|
||||
char * (*get)(ClientData, Tcl_Interp *, char *, char *, int);
|
||||
char * (*set)(ClientData, Tcl_Interp *, char *, char *, int);
|
||||
} swig_var_info;
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------*
|
||||
* Install a constant object
|
||||
* -----------------------------------------------------------------------------*/
|
||||
|
||||
static Tcl_HashTable swigconstTable;
|
||||
static int swigconstTableinit = 0;
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Tcl_SetConstantObj(Tcl_Interp *interp, const char* name, Tcl_Obj *obj) {
|
||||
int newobj;
|
||||
Tcl_ObjSetVar2(interp,Tcl_NewStringObj(name,-1), NULL, obj, TCL_GLOBAL_ONLY);
|
||||
Tcl_SetHashValue(Tcl_CreateHashEntry(&swigconstTable, name, &newobj), (ClientData) obj);
|
||||
}
|
||||
|
||||
SWIGINTERN Tcl_Obj *
|
||||
SWIG_Tcl_GetConstantObj(const char *key) {
|
||||
Tcl_HashEntry *entryPtr;
|
||||
if (!swigconstTableinit) return 0;
|
||||
entryPtr = Tcl_FindHashEntry(&swigconstTable, key);
|
||||
if (entryPtr) {
|
||||
return (Tcl_Obj *) Tcl_GetHashValue(entryPtr);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
75
Lib/tcl/tclerrors.swg
Normal file
75
Lib/tcl/tclerrors.swg
Normal file
|
|
@ -0,0 +1,75 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* error manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%insert("header") %{
|
||||
|
||||
|
||||
SWIGINTERN const char*
|
||||
SWIG_Tcl_ErrorType(int code) {
|
||||
switch(code) {
|
||||
case SWIG_MemoryError:
|
||||
return "MemoryError";
|
||||
break;
|
||||
case SWIG_IOError:
|
||||
return "IOError";
|
||||
break;
|
||||
case SWIG_RuntimeError:
|
||||
return "RuntimeError";
|
||||
break;
|
||||
case SWIG_IndexError:
|
||||
return "IndexError";
|
||||
break;
|
||||
case SWIG_TypeError:
|
||||
return "TypeError";
|
||||
break;
|
||||
case SWIG_DivisionByZero:
|
||||
return "ZeroDivisionError";
|
||||
break;
|
||||
case SWIG_OverflowError:
|
||||
return "OverflowError";
|
||||
break;
|
||||
case SWIG_SyntaxError:
|
||||
return "SyntaxError";
|
||||
break;
|
||||
case SWIG_ValueError:
|
||||
return "ValueError";
|
||||
break;
|
||||
case SWIG_SystemError:
|
||||
return "SystemError";
|
||||
break;
|
||||
case SWIG_AttributeError:
|
||||
return "AttributeError";
|
||||
break;
|
||||
default:
|
||||
return "RuntimeError";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Tcl_SetErrorObj(Tcl_Interp *interp, const char *ctype, Tcl_Obj *obj)
|
||||
{
|
||||
Tcl_ResetResult(interp);
|
||||
Tcl_SetObjResult(interp, obj);
|
||||
Tcl_SetErrorCode(interp, "SWIG", ctype, NULL);
|
||||
}
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Tcl_SetErrorMsg(Tcl_Interp *interp, const char *ctype, const char *mesg)
|
||||
{
|
||||
Tcl_ResetResult(interp);
|
||||
Tcl_SetErrorCode(interp, "SWIG", ctype, NULL);
|
||||
Tcl_AddErrorInfo(interp, mesg);
|
||||
}
|
||||
|
||||
SWIGINTERNINLINE void
|
||||
SWIG_Tcl_AddErrorMsg(Tcl_Interp *interp, const char* mesg)
|
||||
{
|
||||
Tcl_AddErrorInfo(interp, mesg);
|
||||
}
|
||||
|
||||
|
||||
|
||||
%}
|
||||
23
Lib/tcl/tclfragments.swg
Normal file
23
Lib/tcl/tclfragments.swg
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
|
||||
Create a file with this name, 'fragments.i', in your working
|
||||
directory and add all the %fragments you want to take precedence
|
||||
over the ones defined by default by swig.
|
||||
|
||||
For example, if you add:
|
||||
|
||||
%fragment(SWIG_AsVal_frag(int),"header") {
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_AsVal_dec(int)(TclObject *obj, int *val)
|
||||
{
|
||||
<your code here>;
|
||||
}
|
||||
}
|
||||
|
||||
this will replace the code used to retreive an integer value for all
|
||||
the typemaps that need it, including:
|
||||
|
||||
int, std::vector<int>, std::list<std::pair<int,int> >, etc.
|
||||
|
||||
|
||||
*/
|
||||
106
Lib/tcl/tclinit.swg
Normal file
106
Lib/tcl/tclinit.swg
Normal file
|
|
@ -0,0 +1,106 @@
|
|||
/* ------------------------------------------------------------
|
||||
* The start of the Tcl initialization function
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%insert(init) "swiginit.swg"
|
||||
|
||||
/* This initialization code exports the module initialization function */
|
||||
|
||||
%header %{
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#ifdef MAC_TCL
|
||||
#pragma export on
|
||||
#endif
|
||||
SWIGEXPORT int SWIG_init(Tcl_Interp *);
|
||||
#ifdef MAC_TCL
|
||||
#pragma export off
|
||||
#endif
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
%}
|
||||
|
||||
%init %{
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* constants/methods manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* Install Constants */
|
||||
|
||||
SWIGINTERN void
|
||||
SWIG_Tcl_InstallConstants(Tcl_Interp *interp, swig_const_info constants[]) {
|
||||
int i;
|
||||
Tcl_Obj *obj;
|
||||
|
||||
if (!swigconstTableinit) {
|
||||
Tcl_InitHashTable(&swigconstTable, TCL_STRING_KEYS);
|
||||
swigconstTableinit = 1;
|
||||
}
|
||||
for (i = 0; constants[i].type; i++) {
|
||||
switch(constants[i].type) {
|
||||
case SWIG_TCL_POINTER:
|
||||
obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
|
||||
break;
|
||||
case SWIG_TCL_BINARY:
|
||||
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype),0);
|
||||
break;
|
||||
default:
|
||||
obj = 0;
|
||||
break;
|
||||
}
|
||||
if (obj) {
|
||||
SWIG_Tcl_SetConstantObj(interp, constants[i].name, obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------*
|
||||
* Partial Init method
|
||||
* -----------------------------------------------------------------------------*/
|
||||
|
||||
SWIGEXPORT int SWIG_init(Tcl_Interp *interp) {
|
||||
int i;
|
||||
if (interp == 0) return TCL_ERROR;
|
||||
#ifdef USE_TCL_STUBS
|
||||
if (Tcl_InitStubs(interp, (char*)"8.1", 0) == NULL) {
|
||||
return TCL_ERROR;
|
||||
}
|
||||
#endif
|
||||
Tcl_PkgProvide(interp, (char*)SWIG_name, (char*)SWIG_version);
|
||||
|
||||
#ifdef SWIG_namespace
|
||||
Tcl_Eval(interp, "namespace eval " SWIG_namespace " { }");
|
||||
#endif
|
||||
|
||||
SWIG_InitializeModule((void *) interp);
|
||||
SWIG_PropagateClientData();
|
||||
|
||||
for (i = 0; swig_commands[i].name; i++) {
|
||||
Tcl_CreateObjCommand(interp, (char *) swig_commands[i].name, (swig_wrapper_func) swig_commands[i].wrapper,
|
||||
swig_commands[i].clientdata, NULL);
|
||||
}
|
||||
for (i = 0; swig_variables[i].name; i++) {
|
||||
Tcl_SetVar(interp, (char *) swig_variables[i].name, (char *) "", TCL_GLOBAL_ONLY);
|
||||
Tcl_TraceVar(interp, (char *) swig_variables[i].name, TCL_TRACE_READS | TCL_GLOBAL_ONLY,
|
||||
(Tcl_VarTraceProc *) swig_variables[i].get, (ClientData) swig_variables[i].addr);
|
||||
Tcl_TraceVar(interp, (char *) swig_variables[i].name, TCL_TRACE_WRITES | TCL_GLOBAL_ONLY,
|
||||
(Tcl_VarTraceProc *) swig_variables[i].set, (ClientData) swig_variables[i].addr);
|
||||
}
|
||||
|
||||
SWIG_Tcl_InstallConstants(interp, swig_constants);
|
||||
|
||||
%}
|
||||
|
||||
/* Note: the initialization function is closed after all code is generated */
|
||||
26
Lib/tcl/tclmacros.swg
Normal file
26
Lib/tcl/tclmacros.swg
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
%include <typemaps/swigmacros.swg>
|
||||
|
||||
|
||||
/* aux macros to deal with the interp argument */
|
||||
|
||||
#undef SWIG_As_dec
|
||||
#undef SWIG_AsPtr_dec
|
||||
#undef SWIG_AsVal_dec
|
||||
|
||||
#define SWIG_Tcl_AsVal(Type...) SWIG_Tcl_ ## AsVal ## _ ## #@Type
|
||||
#define SWIG_AsVal_dec(Type...) SWIG_ ## AsVal_dec ## _ ## #@Type
|
||||
|
||||
#define SWIG_Tcl_AsPtr(Type...) SWIG_Tcl_ ## AsPtr ## _ ## #@Type
|
||||
#define SWIG_AsPtr_dec(Type...) SWIG_ ## AsPtr_dec ## _ ## #@Type
|
||||
|
||||
|
||||
%define %tcl_asval_decl(Type...)
|
||||
%#define SWIG_AsVal_dec(Type)(obj,val) SWIG_Tcl_AsVal(Type)(Tcl_Interp *interp, obj, val)
|
||||
%#define SWIG_AsVal(Type)(obj,val) SWIG_Tcl_AsVal(Type)(interp, obj, val)
|
||||
%enddef
|
||||
|
||||
|
||||
%define %tcl_asptr_decl(Type...)
|
||||
%#define SWIG_AsPtr_dec(Type)(obj,ptr) SWIG_Tcl_AsPtr(Type)(Tcl_Interp *interp, obj, ptr)
|
||||
%#define SWIG_AsPtr(Type)(obj,ptr) SWIG_Tcl_AsPtr(Type)(interp, obj, ptr)
|
||||
%enddef
|
||||
24
Lib/tcl/tclopers.swg
Normal file
24
Lib/tcl/tclopers.swg
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* C++ overloaded operators.
|
||||
|
||||
These declarations define how SWIG is going to rename C++
|
||||
overloaded operators in Tcl. Since Tcl allows identifiers
|
||||
to be essentially any valid string, we'll just use the
|
||||
normal operator names */
|
||||
|
||||
#ifdef __cplusplus
|
||||
%rename("+") *::operator+;
|
||||
//%rename("u+") *::operator+(); // Unary +
|
||||
//%rename("u+") *::operator+() const; // Unary +
|
||||
%rename("-") *::operator-;
|
||||
//%rename("u-") *::operator-(); // Unary -
|
||||
//%rename("u-") *::operator-() const; // Unary -
|
||||
%rename("*") *::operator*;
|
||||
%rename("/") *::operator/;
|
||||
%rename("<<") *::operator<<;
|
||||
%rename(">>") *::operator>>;
|
||||
%rename("&") *::operator&;
|
||||
%rename("|") *::operator|;
|
||||
%rename("^") *::operator^;
|
||||
%rename("%") *::operator%;
|
||||
%rename("=") *::operator=;
|
||||
#endif
|
||||
308
Lib/tcl/tclprimtypes.swg
Normal file
308
Lib/tcl/tclprimtypes.swg
Normal file
|
|
@ -0,0 +1,308 @@
|
|||
%include <typemaps/primtypes.swg>
|
||||
|
||||
/* Macro for 'signed long' derived types */
|
||||
|
||||
%define %type_slong(Type, Frag, Min, Max)
|
||||
%derived_type_from(long, Type)
|
||||
%fragment("Tcl_asval_"{Type},"header",fragment=Frag) %{
|
||||
%tcl_asval_decl(Type)
|
||||
%}
|
||||
%signed_derived_type_asval(long, Type, "Tcl_asval_"{Type} , Min, Max)
|
||||
%enddef
|
||||
|
||||
/* Macro for 'unsigned long' derived types */
|
||||
|
||||
%define %type_ulong(Type, Frag, Max)
|
||||
%derived_type_from(unsigned long, Type)
|
||||
%fragment("Tcl_asval_"{Type},"header",fragment=Frag) %{
|
||||
%tcl_asval_decl(Type)
|
||||
%}
|
||||
%unsigned_derived_type_asval(unsigned long, Type, "Tcl_asval_"{Type}, Max)
|
||||
%enddef
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Primitive Types
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
/* boolean */
|
||||
|
||||
%fragment(SWIG_From_frag(bool),"header") {
|
||||
SWIG_define(SWIG_From_dec(bool), Tcl_NewBooleanObj)
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(bool),"header") {
|
||||
%tcl_asval_decl(bool)
|
||||
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(bool)(Tcl_Obj *obj, bool *val)
|
||||
{
|
||||
int v;
|
||||
if (Tcl_GetBooleanFromObj(0, obj, &v) == TCL_OK) {
|
||||
if (val) *val = v ? true : false;
|
||||
return SWIG_OK;
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* signed/unsigned char */
|
||||
|
||||
%type_slong(signed char, "<limits.h>", SCHAR_MIN, SCHAR_MAX)
|
||||
%type_ulong(unsigned char, "<limits.h>", UCHAR_MAX)
|
||||
|
||||
/* short/unsigned short */
|
||||
|
||||
%type_slong(short, "<limits.h>", SHRT_MIN, SHRT_MAX)
|
||||
%type_ulong(unsigned short, "<limits.h>", USHRT_MAX)
|
||||
|
||||
/* int/unsigned int */
|
||||
|
||||
%type_slong(int, "<limits.h>", INT_MIN, INT_MAX)
|
||||
%type_ulong(unsigned int, "<limits.h>", UINT_MAX)
|
||||
|
||||
/* 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
|
||||
|
||||
|
||||
/* long */
|
||||
|
||||
%fragment(SWIG_From_frag(long),"header",
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE Tcl_Obj*
|
||||
SWIG_From_dec(long)(long value)
|
||||
{
|
||||
if (((long) INT_MIN <= value) && (value <= (long) INT_MAX)) {
|
||||
return Tcl_NewIntObj(SWIG_numeric_cast(value,int));
|
||||
} else {
|
||||
return Tcl_NewLongObj(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long),"header") {
|
||||
%tcl_asval_decl(long)
|
||||
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long)(Tcl_Obj *obj, long* val)
|
||||
{
|
||||
long v;
|
||||
if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) {
|
||||
if (val) *val = (long) v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long),"header",
|
||||
fragment=SWIG_From_frag(long)) {
|
||||
SWIGINTERNINLINE Tcl_Obj*
|
||||
SWIG_From_dec(unsigned long)(unsigned long value)
|
||||
{
|
||||
if (value < (unsigned long) LONG_MAX) {
|
||||
return SWIG_From(long)(SWIG_numeric_cast(value, long));
|
||||
} else {
|
||||
char temp[256];
|
||||
snprintf(temp, sizeof(temp),"%lu", value);
|
||||
return Tcl_NewStringObj(temp,-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long),"header") {
|
||||
%tcl_asval_decl(unsigned long)
|
||||
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long)(Tcl_Obj *obj, unsigned long *val) {
|
||||
int len = 0;
|
||||
const char *nptr = Tcl_GetStringFromObj(obj, &len);
|
||||
if (nptr && len > 0) {
|
||||
char *endptr;
|
||||
unsigned long v = strtoul(nptr, &endptr,0);
|
||||
if (errno == ERANGE) {
|
||||
errno = 0;
|
||||
return SWIG_OverflowError;
|
||||
} else {
|
||||
if (*endptr == '\0') {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* long long */
|
||||
|
||||
%fragment(SWIG_From_frag(long long),"header",
|
||||
fragment=SWIG_From_frag(long),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE Tcl_Obj*
|
||||
SWIG_From_dec(long long)(long long value)
|
||||
{
|
||||
if (((long long) LONG_MIN <= value) && (value <= (long long) LONG_MAX)) {
|
||||
return SWIG_From(long)(SWIG_numeric_cast(value,long));
|
||||
} else {
|
||||
char temp[256];
|
||||
snprintf(temp, sizeof(temp),"%lld", value);
|
||||
return Tcl_NewStringObj(temp,-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(long long),"header") {
|
||||
%tcl_asval_decl(long long)
|
||||
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val)
|
||||
{
|
||||
int len = 0;
|
||||
const char *nptr = Tcl_GetStringFromObj(obj, &len);
|
||||
if (nptr && len > 0) {
|
||||
char *endptr;
|
||||
long long v = strtoll(nptr, &endptr,0);
|
||||
if (errno == ERANGE) {
|
||||
errno = 0;
|
||||
return SWIG_OverflowError;
|
||||
} else {
|
||||
if (*endptr == '\0') {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* unsigned long long */
|
||||
|
||||
%fragment(SWIG_From_frag(unsigned long long),"header",
|
||||
fragment=SWIG_From_frag(long long),
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE Tcl_Obj*
|
||||
SWIG_From_dec(unsigned long long)(unsigned long long value)
|
||||
{
|
||||
if (value < (unsigned long long) LONG_MAX) {
|
||||
return SWIG_From(long long)(SWIG_numeric_cast(value, long long));
|
||||
} else {
|
||||
char temp[256];
|
||||
snprintf(temp, sizeof(temp),"%llu", value);
|
||||
return Tcl_NewStringObj(temp,-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
|
||||
fragment=SWIG_AsVal_frag(unsigned long)) {
|
||||
%tcl_asval_decl(unsigned long long)
|
||||
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(unsigned long long)(Tcl_Obj *obj, unsigned long long *val)
|
||||
{
|
||||
int len = 0;
|
||||
const char *nptr = Tcl_GetStringFromObj(obj, &len);
|
||||
if (nptr && len > 0) {
|
||||
char *endptr;
|
||||
unsigned long long v = strtoull(nptr, &endptr,0);
|
||||
if (errno == ERANGE) {
|
||||
errno = 0;
|
||||
return SWIG_OverflowError;
|
||||
} else {
|
||||
if (*endptr == '\0') {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
}
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* float */
|
||||
|
||||
%derived_type_from(double, float)
|
||||
%fragment("Tcl_asval_float","header",fragment="<float.h>") {
|
||||
%tcl_asval_decl(float)
|
||||
}
|
||||
%signed_derived_type_asval(double, float, "Tcl_asval_float", -FLT_MAX, FLT_MAX)
|
||||
|
||||
/* double */
|
||||
|
||||
%fragment(SWIG_From_frag(double),"header") {
|
||||
SWIG_define(SWIG_From_dec(double), Tcl_NewDoubleObj)
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(double),"header") {
|
||||
%tcl_asval_decl(double)
|
||||
|
||||
SWIGINTERN int
|
||||
SWIG_AsVal_dec(double)(Tcl_Obj *obj, double *val)
|
||||
{
|
||||
double v;
|
||||
if (Tcl_GetDoubleFromObj(0, obj, &v) == TCL_OK) {
|
||||
if (val) *val = v;
|
||||
return SWIG_OK;
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* char */
|
||||
|
||||
%fragment(SWIG_From_frag(char),"header") {
|
||||
SWIGINTERNINLINE Tcl_Obj*
|
||||
SWIG_From_dec(char)(char c)
|
||||
{
|
||||
return Tcl_NewStringObj(&c,1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(char),"header",
|
||||
fragment="SWIG_AsCharArray",
|
||||
fragment=SWIG_AsVal_frag(signed char)) {
|
||||
%tcl_asval_decl(char)
|
||||
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_AsVal_dec(char)(Tcl_Obj *obj, char *val)
|
||||
{
|
||||
return SWIG_AsCharArray(obj, val, 1) == SWIG_OK ? SWIG_OK : SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* wchar_t */
|
||||
|
||||
%fragment(SWIG_From_frag(wchar_t),"header") {
|
||||
SWIGINTERNINLINE Tcl_Obj*
|
||||
SWIG_From_dec(wchar_t)(wchar_t c)
|
||||
{
|
||||
return Tcl_NewUnicodeObj(&c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
%fragment(SWIG_AsVal_frag(wchar_t),"header",
|
||||
fragment="SWIG_AsWCharArray",
|
||||
fragment="<wchar.h>",
|
||||
fragment=SWIG_AsVal_frag(long)) {
|
||||
%tcl_asval_decl(wchar_t)
|
||||
|
||||
SWIGINTERNINLINE int
|
||||
SWIG_AsVal_dec(wchar_t)(Tcl_Obj *obj, wchar_t *val)
|
||||
{
|
||||
return (SWIG_AsWCharArray(obj, val, 1) == SWIG_OK) ? SWIG_OK : SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* Apply the primitive typemap for all the types with checkcode
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%apply_checkctypes(%typemap_primitive)
|
||||
|
|
@ -1,139 +1,96 @@
|
|||
/*
|
||||
* $Header$
|
||||
*
|
||||
* swigtcl8.swg
|
||||
*/
|
||||
/***********************************************************************
|
||||
* tclrun.swg
|
||||
*
|
||||
* This file contains the runtime support for Tcl modules
|
||||
* and includes code for managing global variables and pointer
|
||||
* type checking.
|
||||
*
|
||||
************************************************************************/
|
||||
|
||||
#include <tcl.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
/* Common SWIG API */
|
||||
|
||||
/* for raw pointers */
|
||||
#define SWIG_ConvertPtr(oc, ptr, ty, flags) SWIG_Tcl_ConvertPtr(interp, oc, ptr, ty, flags)
|
||||
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Tcl_NewPointerObj(ptr, type, flags)
|
||||
|
||||
/* for raw packed data */
|
||||
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Tcl_ConvertPacked(interp, obj, ptr, sz, ty, flags)
|
||||
#define SWIG_NewPackedObj(ptr, sz, type, flags) SWIG_Tcl_NewPackedObj(ptr, sz, type, flags)
|
||||
|
||||
/* for class or struct pointers */
|
||||
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_Tcl_ConvertPtr(interp, obj, pptr, type, flags)
|
||||
#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_Tcl_NewInstanceObj(interp, thisvalue, type, flags)
|
||||
|
||||
/* for C or C++ function pointers */
|
||||
#define SWIG_ConvertFunctionPtr(obj, pptr, type, flags) SWIG_Tcl_ConvertPtr(interp, obj, pptr, type, flags)
|
||||
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Tcl_NewPointerObj(ptr, type, 0)
|
||||
|
||||
/* for C++ member pointers, ie, member methods */
|
||||
#define SWIG_ConvertMember(obj, ptr, sz, ty, flags) SWIG_Tcl_ConvertPacked(interp,obj, ptr, sz, ty, flags)
|
||||
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Tcl_NewPackedObj(ptr, sz, type, 0)
|
||||
|
||||
/* Runtime API */
|
||||
#define SWIG_GetModule(clientdata) SWIG_Tcl_GetModule((Tcl_Interp *) (clientdata))
|
||||
#define SWIG_SetModule(clientdata, pointer) SWIG_Tcl_SetModule((Tcl_Interp *) (clientdata), pointer)
|
||||
|
||||
/* Tcl-specific SWIG API */
|
||||
#define SWIG_Acquire(ptr) SWIG_Tcl_Acquire(ptr)
|
||||
#define SWIG_MethodCommand SWIG_Tcl_MethodCommand
|
||||
#define SWIG_Disown(ptr) SWIG_Tcl_Disown(ptr)
|
||||
#define SWIG_ConvertPtrFromString(c, ptr, ty, flags) SWIG_Tcl_ConvertPtrFromString(interp, c, ptr, ty, flags)
|
||||
#define SWIG_MakePtr(c, ptr, ty, flags) SWIG_Tcl_MakePtr(c, ptr, ty, flags)
|
||||
#define SWIG_PointerTypeFromString(c) SWIG_Tcl_PointerTypeFromString(c)
|
||||
#define SWIG_GetArgs SWIG_Tcl_GetArgs
|
||||
#define SWIG_GetConstantObj(key) SWIG_Tcl_GetConstantObj(key)
|
||||
#define SWIG_ObjectConstructor SWIG_Tcl_ObjectConstructor
|
||||
#define SWIG_Thisown(ptr) SWIG_Tcl_Thisown(ptr)
|
||||
#define SWIG_ObjectDelete SWIG_Tcl_ObjectDelete
|
||||
|
||||
/* Error manipulation */
|
||||
#define SWIG_fail goto fail
|
||||
#define SWIG_var_fail return "$name"
|
||||
#define SWIG_exception(code, msg) do { SWIG_Tcl_SetErrorMsg(interp, SWIG_Tcl_ErrorType(code), msg); SWIG_fail; } while (0)
|
||||
#define SWIG_contract_assert(expr, msg) if (!(expr)) { SWIG_Tcl_SetErrorMsg(interp, 0, msg); SWIG_fail; } else
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Constant table */
|
||||
|
||||
#define SWIG_TCL_INT 1
|
||||
#define SWIG_TCL_FLOAT 2
|
||||
#define SWIG_TCL_STRING 3
|
||||
#define SWIG_TCL_POINTER 4
|
||||
#define SWIG_TCL_BINARY 5
|
||||
|
||||
/* Flags for pointer conversion */
|
||||
#define SWIG_POINTER_EXCEPTION 0x1
|
||||
#define SWIG_POINTER_DISOWN 0x2
|
||||
|
||||
/* Swig fail macro */
|
||||
|
||||
#define SWIG_fail goto fail
|
||||
|
||||
/* Constant information structure */
|
||||
typedef struct swig_const_info {
|
||||
int type;
|
||||
char *name;
|
||||
long lvalue;
|
||||
double dvalue;
|
||||
void *pvalue;
|
||||
swig_type_info **ptype;
|
||||
} swig_const_info;
|
||||
|
||||
typedef int (*swig_wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []);
|
||||
typedef int (*swig_wrapper_func)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []);
|
||||
typedef char *(*swig_variable_func)(ClientData, Tcl_Interp *, char *, char *, int);
|
||||
typedef void (*swig_delete_func)(ClientData);
|
||||
|
||||
typedef struct swig_method {
|
||||
const char *name;
|
||||
swig_wrapper method;
|
||||
} swig_method;
|
||||
|
||||
typedef struct swig_attribute {
|
||||
const char *name;
|
||||
swig_wrapper getmethod;
|
||||
swig_wrapper setmethod;
|
||||
} swig_attribute;
|
||||
|
||||
typedef struct swig_class {
|
||||
const char *name;
|
||||
swig_type_info **type;
|
||||
swig_wrapper constructor;
|
||||
void (*destructor)(void *);
|
||||
swig_method *methods;
|
||||
swig_attribute *attributes;
|
||||
struct swig_class **bases;
|
||||
char **base_names;
|
||||
swig_module_info *module;
|
||||
} swig_class;
|
||||
|
||||
typedef struct swig_instance {
|
||||
Tcl_Obj *thisptr;
|
||||
void *thisvalue;
|
||||
swig_class *classptr;
|
||||
int destroy;
|
||||
Tcl_Command cmdtok;
|
||||
} swig_instance;
|
||||
|
||||
#define SWIG_NewPointerObj(ptr, type, flags) \
|
||||
SWIG_Tcl_NewPointerObj(ptr, type, flags)
|
||||
#define SWIG_ConvertPtr(oc, ptr, ty, flags) \
|
||||
SWIG_Tcl_ConvertPtr(interp, oc, ptr, ty, flags)
|
||||
#define SWIG_ConvertPtrFromString(c, ptr, ty, flags) \
|
||||
SWIG_Tcl_ConvertPtrFromString(interp, c, ptr, ty, flags)
|
||||
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) \
|
||||
SWIG_Tcl_ConvertPacked(interp, obj, ptr, sz, ty, flags)
|
||||
#define SWIG_MakePtr(c, ptr, ty, flags) \
|
||||
SWIG_Tcl_MakePtr(c, ptr, ty, flags)
|
||||
#define SWIG_NewPackedObj(ptr, sz, type, flags) \
|
||||
SWIG_Tcl_NewPackedObj(ptr, sz, type, flags)
|
||||
#define SWIG_GetArgs SWIG_Tcl_GetArgs
|
||||
#define SWIG_PointerTypeFromString(c) \
|
||||
SWIG_Tcl_PointerTypeFromString(c)
|
||||
#define SWIG_Acquire(ptr) \
|
||||
SWIG_Tcl_Acquire(ptr)
|
||||
#define SWIG_Disown(ptr) \
|
||||
SWIG_Tcl_Disown(ptr)
|
||||
#define SWIG_Thisown(ptr) \
|
||||
SWIG_Tcl_Thisown(ptr)
|
||||
#define SWIG_InstallConstants(interp, constants) \
|
||||
SWIG_Tcl_InstallConstants(interp, constants)
|
||||
#define SWIG_GetConstant(key) \
|
||||
SWIG_Tcl_GetConstant(key)
|
||||
#define SWIG_NewInstanceObj(thisvalue, type, flags) \
|
||||
SWIG_Tcl_NewInstanceObj(interp, thisvalue, type, flags)
|
||||
#define SWIG_ObjectConstructor SWIG_Tcl_ObjectConstructor
|
||||
#define SWIG_MethodCommand SWIG_Tcl_MethodCommand
|
||||
#define SWIG_ObjectDelete SWIG_Tcl_ObjectDelete
|
||||
|
||||
/* Runtime API */
|
||||
#define SWIG_GetModule(clientdata) SWIG_Tcl_GetModule((Tcl_Interp *) (clientdata))
|
||||
#define SWIG_SetModule(clientdata, pointer) SWIG_Tcl_SetModule((Tcl_Interp *) (clientdata), pointer)
|
||||
#define SWIG_MODULE_CLIENTDATA_TYPE Tcl_Interp *
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* pointers/data manipulation
|
||||
* ----------------------------------------------------------------------------- */
|
||||
/* Object support */
|
||||
static Tcl_HashTable swigobjectTable;
|
||||
static int swigobjectTableinit = 0;
|
||||
|
||||
/* Acquire ownership of a pointer */
|
||||
static void
|
||||
SWIG_Tcl_Acquire(void *ptr) {
|
||||
Tcl_HashEntry *entryPtr;
|
||||
int newobj;
|
||||
SWIGRUNTIME Tcl_HashTable*
|
||||
SWIG_Tcl_ObjectTable() {
|
||||
static Tcl_HashTable swigobjectTable;
|
||||
static int swigobjectTableinit = 0;
|
||||
if (!swigobjectTableinit) {
|
||||
Tcl_InitHashTable(&swigobjectTable, TCL_ONE_WORD_KEYS);
|
||||
swigobjectTableinit = 1;
|
||||
}
|
||||
entryPtr = Tcl_CreateHashEntry(&swigobjectTable, (char *) ptr, &newobj);
|
||||
return &swigobjectTable;
|
||||
}
|
||||
|
||||
/* Acquire ownership of a pointer */
|
||||
SWIGRUNTIME void
|
||||
SWIG_Tcl_Acquire(void *ptr) {
|
||||
int newobj;
|
||||
Tcl_CreateHashEntry(SWIG_Tcl_ObjectTable(), (char *) ptr, &newobj);
|
||||
}
|
||||
|
||||
SWIGRUNTIME int
|
||||
SWIG_Tcl_Thisown(void *ptr) {
|
||||
if (Tcl_FindHashEntry(SWIG_Tcl_ObjectTable(), (char *) ptr)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Disown a pointer. Returns 1 if we owned it to begin with */
|
||||
static int
|
||||
SWIGRUNTIME int
|
||||
SWIG_Tcl_Disown(void *ptr) {
|
||||
Tcl_HashEntry *entryPtr;
|
||||
if (!swigobjectTableinit) return 0;
|
||||
entryPtr = Tcl_FindHashEntry(&swigobjectTable, (char *) ptr);
|
||||
Tcl_HashEntry *entryPtr = Tcl_FindHashEntry(SWIG_Tcl_ObjectTable(), (char *) ptr);
|
||||
if (entryPtr) {
|
||||
Tcl_DeleteHashEntry(entryPtr);
|
||||
return 1;
|
||||
|
|
@ -141,23 +98,14 @@ SWIG_Tcl_Disown(void *ptr) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
SWIG_Tcl_Thisown(void *ptr) {
|
||||
if (!swigobjectTableinit) return 0;
|
||||
if (Tcl_FindHashEntry(&swigobjectTable, (char *) ptr)) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
static int
|
||||
SWIGRUNTIME int
|
||||
SWIG_Tcl_ConvertPtrFromString(Tcl_Interp *interp, const char *c, void **ptr, swig_type_info *ty, int flags) {
|
||||
swig_cast_info *tc;
|
||||
/* Pointer values must start with leading underscore */
|
||||
while (*c != '_') {
|
||||
*ptr = (void *) 0;
|
||||
if (strcmp(c,"NULL") == 0) return TCL_OK;
|
||||
if (strcmp(c,"NULL") == 0) return SWIG_OK;
|
||||
/* Hmmm. It could be an object name. */
|
||||
if (Tcl_VarEval(interp,c," cget -this", (char *) NULL) == TCL_OK) {
|
||||
Tcl_Obj *result = Tcl_GetObjResult(interp);
|
||||
|
|
@ -165,38 +113,32 @@ SWIG_Tcl_ConvertPtrFromString(Tcl_Interp *interp, const char *c, void **ptr, swi
|
|||
continue;
|
||||
}
|
||||
Tcl_ResetResult(interp);
|
||||
if (flags & SWIG_POINTER_EXCEPTION)
|
||||
Tcl_SetResult(interp, (char *) "Type error. Expected a pointer", TCL_STATIC);
|
||||
return TCL_ERROR;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
c++;
|
||||
c = SWIG_UnpackData(c,ptr,sizeof(void *));
|
||||
if (ty) {
|
||||
tc = SWIG_TypeCheck(c,ty);
|
||||
if ((!tc) && (flags & SWIG_POINTER_EXCEPTION)) {
|
||||
Tcl_SetResult(interp, (char *) "Type error. Expected ", TCL_STATIC);
|
||||
Tcl_AppendElement(interp, (char *) ty->name);
|
||||
return TCL_ERROR;
|
||||
} else if (!tc) {
|
||||
if (!tc) {
|
||||
Tcl_ResetResult(interp);
|
||||
return TCL_ERROR;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
if (flags & SWIG_POINTER_DISOWN) {
|
||||
SWIG_Disown((void *) *ptr);
|
||||
}
|
||||
*ptr = SWIG_TypeCast(tc,(void *) *ptr);
|
||||
}
|
||||
return TCL_OK;
|
||||
return SWIG_OK;
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
static SWIGINLINE int
|
||||
SWIGRUNTIMEINLINE int
|
||||
SWIG_Tcl_ConvertPtr(Tcl_Interp *interp, Tcl_Obj *oc, void **ptr, swig_type_info *ty, int flags) {
|
||||
return SWIG_Tcl_ConvertPtrFromString(interp, Tcl_GetStringFromObj(oc,NULL), ptr, ty, flags);
|
||||
}
|
||||
|
||||
/* Convert a pointer value */
|
||||
static char *
|
||||
SWIGRUNTIME char *
|
||||
SWIG_Tcl_PointerTypeFromString(char *c) {
|
||||
char d;
|
||||
/* Pointer values must start with leading underscore. NULL has no type */
|
||||
|
|
@ -213,7 +155,7 @@ SWIG_Tcl_PointerTypeFromString(char *c) {
|
|||
}
|
||||
|
||||
/* Convert a packed value value */
|
||||
static int
|
||||
SWIGRUNTIME int
|
||||
SWIG_Tcl_ConvertPacked(Tcl_Interp *interp, Tcl_Obj *obj, void *ptr, int sz, swig_type_info *ty, int flags) {
|
||||
swig_cast_info *tc;
|
||||
const char *c;
|
||||
|
|
@ -228,7 +170,7 @@ SWIG_Tcl_ConvertPacked(Tcl_Interp *interp, Tcl_Obj *obj, void *ptr, int sz, swig
|
|||
tc = SWIG_TypeCheck(c,ty);
|
||||
if (!tc) goto type_error;
|
||||
}
|
||||
return TCL_OK;
|
||||
return SWIG_OK;
|
||||
|
||||
type_error:
|
||||
|
||||
|
|
@ -236,18 +178,18 @@ type_error:
|
|||
if (ty) {
|
||||
Tcl_SetResult(interp, (char *) "Type error. Expected ", TCL_STATIC);
|
||||
Tcl_AppendElement(interp, (char *) ty->name);
|
||||
return TCL_ERROR;
|
||||
return SWIG_ERROR;
|
||||
} else {
|
||||
Tcl_SetResult(interp, (char *) "Expected packed data.", TCL_STATIC);
|
||||
return TCL_ERROR;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
}
|
||||
return TCL_ERROR;
|
||||
return SWIG_ERROR;
|
||||
}
|
||||
|
||||
|
||||
/* Take a pointer and convert it to a string */
|
||||
static void
|
||||
SWIGRUNTIME void
|
||||
SWIG_Tcl_MakePtr(char *c, void *ptr, swig_type_info *ty, int flags) {
|
||||
if (ptr) {
|
||||
*(c++) = '_';
|
||||
|
|
@ -260,16 +202,16 @@ SWIG_Tcl_MakePtr(char *c, void *ptr, swig_type_info *ty, int flags) {
|
|||
}
|
||||
|
||||
/* Create a new pointer object */
|
||||
static SWIGINLINE Tcl_Obj *
|
||||
SWIGRUNTIMEINLINE Tcl_Obj *
|
||||
SWIG_Tcl_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
|
||||
Tcl_Obj *robj;
|
||||
char result[512];
|
||||
char result[SWIG_BUFFER_SIZE];
|
||||
SWIG_MakePtr(result,ptr,type,flags);
|
||||
robj = Tcl_NewStringObj(result,-1);
|
||||
return robj;
|
||||
}
|
||||
|
||||
static Tcl_Obj *
|
||||
SWIGRUNTIME Tcl_Obj *
|
||||
SWIG_Tcl_NewPackedObj(void *ptr, int sz, swig_type_info *type, int flags) {
|
||||
char result[1024];
|
||||
char *r = result;
|
||||
|
|
@ -281,160 +223,42 @@ SWIG_Tcl_NewPackedObj(void *ptr, int sz, swig_type_info *type, int flags) {
|
|||
return Tcl_NewStringObj(result,-1);
|
||||
}
|
||||
|
||||
static Tcl_HashTable swigconstTable;
|
||||
static int swigconstTableinit = 0;
|
||||
/* -----------------------------------------------------------------------------*
|
||||
* Get type list
|
||||
* -----------------------------------------------------------------------------*/
|
||||
|
||||
/* Install Constants */
|
||||
static void
|
||||
SWIG_Tcl_InstallConstants(Tcl_Interp *interp, swig_const_info constants[]) {
|
||||
int i;
|
||||
Tcl_Obj *obj;
|
||||
Tcl_HashEntry *entryPtr;
|
||||
int newobj;
|
||||
SWIGRUNTIME swig_module_info *
|
||||
SWIG_Tcl_GetModule(Tcl_Interp *interp) {
|
||||
char *data;
|
||||
swig_module_info *ret = 0;
|
||||
|
||||
/* first check if pointer already created */
|
||||
data = (char *) Tcl_GetVar(interp, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME,
|
||||
TCL_GLOBAL_ONLY);
|
||||
if (data) {
|
||||
SWIG_UnpackData(data, &ret, sizeof(swig_type_info **));
|
||||
}
|
||||
|
||||
if (!swigconstTableinit) {
|
||||
Tcl_InitHashTable(&swigconstTable, TCL_STRING_KEYS);
|
||||
swigconstTableinit = 1;
|
||||
}
|
||||
for (i = 0; constants[i].type; i++) {
|
||||
switch(constants[i].type) {
|
||||
case SWIG_TCL_INT:
|
||||
obj = Tcl_NewIntObj(constants[i].lvalue);
|
||||
break;
|
||||
case SWIG_TCL_FLOAT:
|
||||
obj = Tcl_NewDoubleObj(constants[i].dvalue);
|
||||
break;
|
||||
case SWIG_TCL_STRING:
|
||||
obj = Tcl_NewStringObj((char *) constants[i].pvalue,-1);
|
||||
break;
|
||||
case SWIG_TCL_POINTER:
|
||||
obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
|
||||
break;
|
||||
case SWIG_TCL_BINARY:
|
||||
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype),0);
|
||||
break;
|
||||
default:
|
||||
obj = 0;
|
||||
break;
|
||||
}
|
||||
if (obj) {
|
||||
Tcl_ObjSetVar2(interp,Tcl_NewStringObj(constants[i].name,-1), NULL, obj, TCL_GLOBAL_ONLY);
|
||||
entryPtr = Tcl_CreateHashEntry(&swigconstTable, constants[i].name, &newobj);
|
||||
Tcl_SetHashValue(entryPtr, (ClientData) obj);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static Tcl_Obj *
|
||||
SWIG_Tcl_GetConstant(const char *key) {
|
||||
Tcl_HashEntry *entryPtr;
|
||||
if (!swigconstTableinit) return 0;
|
||||
entryPtr = Tcl_FindHashEntry(&swigconstTable, key);
|
||||
if (entryPtr) {
|
||||
return (Tcl_Obj *) Tcl_GetHashValue(entryPtr);
|
||||
}
|
||||
return 0;
|
||||
SWIGRUNTIME void
|
||||
SWIG_Tcl_SetModule(Tcl_Interp *interp, swig_module_info *module) {
|
||||
char buf[SWIG_BUFFER_SIZE];
|
||||
char *data;
|
||||
|
||||
/* create a new pointer */
|
||||
data = SWIG_PackData(buf, &module, sizeof(swig_type_info **));
|
||||
*data = 0;
|
||||
Tcl_SetVar(interp, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, buf, 0);
|
||||
}
|
||||
|
||||
/* Get arguments */
|
||||
static int
|
||||
SWIG_Tcl_GetArgs(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], const char *fmt, ...) {
|
||||
int argno = 0, opt = 0;
|
||||
long tempi;
|
||||
double tempd;
|
||||
const char *c;
|
||||
va_list ap;
|
||||
void *vptr;
|
||||
Tcl_Obj *obj = 0;
|
||||
swig_type_info *ty;
|
||||
/* -----------------------------------------------------------------------------*
|
||||
* Object auxiliars
|
||||
* -----------------------------------------------------------------------------*/
|
||||
|
||||
va_start(ap,fmt);
|
||||
for (c = fmt; (*c && (*c != ':') && (*c != ';')); c++,argno++) {
|
||||
if (*c == '|') {
|
||||
opt = 1;
|
||||
c++;
|
||||
}
|
||||
if (argno >= (objc-1)) {
|
||||
if (!opt) {
|
||||
Tcl_SetResult(interp, (char *) "Wrong # args. ", TCL_STATIC);
|
||||
goto argerror;
|
||||
} else {
|
||||
va_end(ap);
|
||||
return TCL_OK;
|
||||
}
|
||||
}
|
||||
|
||||
vptr = va_arg(ap,void *);
|
||||
if (vptr) {
|
||||
if (isupper(*c)) {
|
||||
obj = SWIG_GetConstant(Tcl_GetStringFromObj(objv[argno+1],0));
|
||||
if (!obj) obj = objv[argno+1];
|
||||
} else {
|
||||
obj = objv[argno+1];
|
||||
}
|
||||
switch(*c) {
|
||||
case 'i': case 'I':
|
||||
case 'l': case 'L':
|
||||
case 'h': case 'H':
|
||||
case 'b': case 'B':
|
||||
if (Tcl_GetLongFromObj(interp,obj,&tempi) != TCL_OK) goto argerror;
|
||||
if ((*c == 'i') || (*c == 'I')) *((int *)vptr) = (int)tempi;
|
||||
else if ((*c == 'l') || (*c == 'L')) *((long *)vptr) = (long)tempi;
|
||||
else if ((*c == 'h') || (*c == 'H')) *((short*)vptr) = (short)tempi;
|
||||
else if ((*c == 'b') || (*c == 'B')) *((unsigned char *)vptr) = (unsigned char)tempi;
|
||||
break;
|
||||
case 'f': case 'F':
|
||||
case 'd': case 'D':
|
||||
if (Tcl_GetDoubleFromObj(interp,obj,&tempd) != TCL_OK) goto argerror;
|
||||
if ((*c == 'f') || (*c == 'F')) *((float *) vptr) = (float)tempd;
|
||||
else if ((*c == 'd') || (*c == 'D')) *((double*) vptr) = tempd;
|
||||
break;
|
||||
case 's': case 'S':
|
||||
if (*(c+1) == '#') {
|
||||
int *vlptr = (int *) va_arg(ap, void *);
|
||||
*((char **) vptr) = Tcl_GetStringFromObj(obj, vlptr);
|
||||
c++;
|
||||
} else {
|
||||
*((char **)vptr) = Tcl_GetStringFromObj(obj,NULL);
|
||||
}
|
||||
break;
|
||||
case 'c': case 'C':
|
||||
*((char *)vptr) = *(Tcl_GetStringFromObj(obj,NULL));
|
||||
break;
|
||||
case 'p': case 'P':
|
||||
ty = (swig_type_info *) va_arg(ap, void *);
|
||||
if (SWIG_Tcl_ConvertPtr(interp, obj, (void **) vptr, ty, SWIG_POINTER_EXCEPTION) == TCL_ERROR) goto argerror;
|
||||
break;
|
||||
case 'o': case 'O':
|
||||
*((Tcl_Obj **)vptr) = objv[argno+1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((*c != ';') && ((objc-1) > argno)) {
|
||||
Tcl_SetResult(interp, (char *) "Wrong # args.", TCL_STATIC);
|
||||
goto argerror;
|
||||
}
|
||||
va_end(ap);
|
||||
return TCL_OK;
|
||||
|
||||
argerror:
|
||||
{
|
||||
char temp[32];
|
||||
sprintf(temp,"%d", argno+1);
|
||||
c = strchr(fmt,':');
|
||||
if (!c) c = strchr(fmt,';');
|
||||
if (!c) c = (char *)"";
|
||||
Tcl_AppendResult(interp,c," argument ", temp, NULL);
|
||||
va_end(ap);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SWIGRUNTIME void
|
||||
SWIG_Tcl_ObjectDelete(ClientData clientData) {
|
||||
swig_instance *si = (swig_instance *) clientData;
|
||||
if ((si) && (si->destroy) && (SWIG_Disown(si->thisvalue))) {
|
||||
|
|
@ -447,7 +271,7 @@ SWIG_Tcl_ObjectDelete(ClientData clientData) {
|
|||
}
|
||||
|
||||
/* Function to invoke object methods given an instance */
|
||||
static int
|
||||
SWIGRUNTIME int
|
||||
SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST _objv[]) {
|
||||
char *method, *attrname;
|
||||
swig_instance *inst = (swig_instance *) clientData;
|
||||
|
|
@ -598,7 +422,6 @@ SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_
|
|||
Tcl_SetResult(interp,(char *) "Invalid attribute name.", TCL_STATIC);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
Tcl_SetResult(interp, (char *) "Invalid method. Must be one of: configure cget -acquire -disown -delete", TCL_STATIC);
|
||||
cls = inst->classptr;
|
||||
bi = 0;
|
||||
|
|
@ -628,8 +451,33 @@ SWIG_Tcl_MethodCommand(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_
|
|||
return TCL_ERROR;
|
||||
}
|
||||
|
||||
/* This function takes the current result and turns it into an object command */
|
||||
SWIGRUNTIME Tcl_Obj *
|
||||
SWIG_Tcl_NewInstanceObj(Tcl_Interp *interp, void *thisvalue, swig_type_info *type, int flags) {
|
||||
Tcl_Obj *robj = SWIG_NewPointerObj(thisvalue, type,0);
|
||||
/* Check to see if this pointer belongs to a class or not */
|
||||
if ((type->clientdata) && (interp)) {
|
||||
Tcl_CmdInfo ci;
|
||||
char *name;
|
||||
name = Tcl_GetStringFromObj(robj,NULL);
|
||||
if (!Tcl_GetCommandInfo(interp,name, &ci) || (flags)) {
|
||||
swig_instance *newinst = (swig_instance *) malloc(sizeof(swig_instance));
|
||||
newinst->thisptr = Tcl_DuplicateObj(robj);
|
||||
Tcl_IncrRefCount(newinst->thisptr);
|
||||
newinst->thisvalue = thisvalue;
|
||||
newinst->classptr = (swig_class *) type->clientdata;
|
||||
newinst->destroy = flags;
|
||||
newinst->cmdtok = Tcl_CreateObjCommand(interp, Tcl_GetStringFromObj(robj,NULL), (swig_wrapper_func) SWIG_MethodCommand, (ClientData) newinst, (swig_delete_func) SWIG_ObjectDelete);
|
||||
if (flags) {
|
||||
SWIG_Acquire(thisvalue);
|
||||
}
|
||||
}
|
||||
}
|
||||
return robj;
|
||||
}
|
||||
|
||||
/* Function to create objects */
|
||||
static int
|
||||
SWIGRUNTIME int
|
||||
SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) {
|
||||
Tcl_Obj *newObj = 0;
|
||||
void *thisvalue = 0;
|
||||
|
|
@ -689,7 +537,7 @@ SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc,
|
|||
Tcl_SetResult(interp, (char *) "No constructor available.", TCL_STATIC);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if (SWIG_Tcl_ConvertPtr(interp,newObj, (void **) &thisvalue, *(classptr->type), SWIG_POINTER_EXCEPTION) == TCL_ERROR) {
|
||||
if (SWIG_Tcl_ConvertPtr(interp,newObj, (void **) &thisvalue, *(classptr->type), 0) != SWIG_OK) {
|
||||
Tcl_DecrRefCount(newObj);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
|
|
@ -706,81 +554,106 @@ SWIG_Tcl_ObjectConstructor(ClientData clientData, Tcl_Interp *interp, int objc,
|
|||
return TCL_OK;
|
||||
}
|
||||
|
||||
/* -----------------------------------------------------------------------------*
|
||||
* Get arguments
|
||||
* -----------------------------------------------------------------------------*/
|
||||
SWIGRUNTIME int
|
||||
SWIG_Tcl_GetArgs(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], const char *fmt, ...) {
|
||||
int argno = 0, opt = 0;
|
||||
long tempi;
|
||||
double tempd;
|
||||
const char *c;
|
||||
va_list ap;
|
||||
void *vptr;
|
||||
Tcl_Obj *obj = 0;
|
||||
swig_type_info *ty;
|
||||
|
||||
/* This function takes the current result and turns it into an object command */
|
||||
static Tcl_Obj *
|
||||
SWIG_Tcl_NewInstanceObj(Tcl_Interp *interp, void *thisvalue, swig_type_info *type, int flags) {
|
||||
Tcl_Obj *robj = SWIG_NewPointerObj(thisvalue, type,0);
|
||||
/* Check to see if this pointer belongs to a class or not */
|
||||
if ((type->clientdata) && (interp)) {
|
||||
Tcl_CmdInfo ci;
|
||||
char *name;
|
||||
name = Tcl_GetStringFromObj(robj,NULL);
|
||||
if (!Tcl_GetCommandInfo(interp,name, &ci) || (flags)) {
|
||||
swig_instance *newinst = (swig_instance *) malloc(sizeof(swig_instance));
|
||||
newinst->thisptr = Tcl_DuplicateObj(robj);
|
||||
Tcl_IncrRefCount(newinst->thisptr);
|
||||
newinst->thisvalue = thisvalue;
|
||||
newinst->classptr = (swig_class *) type->clientdata;
|
||||
newinst->destroy = flags;
|
||||
newinst->cmdtok = Tcl_CreateObjCommand(interp, Tcl_GetStringFromObj(robj,NULL), (swig_wrapper_func) SWIG_MethodCommand, (ClientData) newinst, (swig_delete_func) SWIG_ObjectDelete);
|
||||
if (flags) {
|
||||
SWIG_Acquire(thisvalue);
|
||||
va_start(ap,fmt);
|
||||
for (c = fmt; (*c && (*c != ':') && (*c != ';')); c++,argno++) {
|
||||
if (*c == '|') {
|
||||
opt = 1;
|
||||
c++;
|
||||
}
|
||||
if (argno >= (objc-1)) {
|
||||
if (!opt) {
|
||||
Tcl_SetResult(interp, (char *) "Wrong number of arguments ", TCL_STATIC);
|
||||
goto argerror;
|
||||
} else {
|
||||
va_end(ap);
|
||||
return TCL_OK;
|
||||
}
|
||||
}
|
||||
|
||||
vptr = va_arg(ap,void *);
|
||||
if (vptr) {
|
||||
if (isupper(*c)) {
|
||||
obj = SWIG_Tcl_GetConstantObj(Tcl_GetStringFromObj(objv[argno+1],0));
|
||||
if (!obj) obj = objv[argno+1];
|
||||
} else {
|
||||
obj = objv[argno+1];
|
||||
}
|
||||
switch(*c) {
|
||||
case 'i': case 'I':
|
||||
case 'l': case 'L':
|
||||
case 'h': case 'H':
|
||||
case 'b': case 'B':
|
||||
if (Tcl_GetLongFromObj(interp,obj,&tempi) != TCL_OK) goto argerror;
|
||||
if ((*c == 'i') || (*c == 'I')) *((int *)vptr) = (int)tempi;
|
||||
else if ((*c == 'l') || (*c == 'L')) *((long *)vptr) = (long)tempi;
|
||||
else if ((*c == 'h') || (*c == 'H')) *((short*)vptr) = (short)tempi;
|
||||
else if ((*c == 'b') || (*c == 'B')) *((unsigned char *)vptr) = (unsigned char)tempi;
|
||||
break;
|
||||
case 'f': case 'F':
|
||||
case 'd': case 'D':
|
||||
if (Tcl_GetDoubleFromObj(interp,obj,&tempd) != TCL_OK) goto argerror;
|
||||
if ((*c == 'f') || (*c == 'F')) *((float *) vptr) = (float)tempd;
|
||||
else if ((*c == 'd') || (*c == 'D')) *((double*) vptr) = tempd;
|
||||
break;
|
||||
case 's': case 'S':
|
||||
if (*(c+1) == '#') {
|
||||
int *vlptr = (int *) va_arg(ap, void *);
|
||||
*((char **) vptr) = Tcl_GetStringFromObj(obj, vlptr);
|
||||
c++;
|
||||
} else {
|
||||
*((char **)vptr) = Tcl_GetStringFromObj(obj,NULL);
|
||||
}
|
||||
break;
|
||||
case 'c': case 'C':
|
||||
*((char *)vptr) = *(Tcl_GetStringFromObj(obj,NULL));
|
||||
break;
|
||||
case 'p': case 'P':
|
||||
ty = (swig_type_info *) va_arg(ap, void *);
|
||||
if (SWIG_Tcl_ConvertPtr(interp, obj, (void **) vptr, ty, 0) != SWIG_OK) goto argerror;
|
||||
break;
|
||||
case 'o': case 'O':
|
||||
*((Tcl_Obj **)vptr) = objv[argno+1];
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return robj;
|
||||
}
|
||||
|
||||
/* Structure for command table */
|
||||
typedef struct {
|
||||
const char *name;
|
||||
int (*wrapper)(ClientData, Tcl_Interp *, int, Tcl_Obj *CONST []);
|
||||
ClientData clientdata;
|
||||
} swig_command_info;
|
||||
|
||||
/* Structure for variable linking table */
|
||||
typedef struct {
|
||||
const char *name;
|
||||
void *addr;
|
||||
char * (*get)(ClientData, Tcl_Interp *, char *, char *, int);
|
||||
char * (*set)(ClientData, Tcl_Interp *, char *, char *, int);
|
||||
} swig_var_info;
|
||||
|
||||
|
||||
/* Contract support */
|
||||
|
||||
#define SWIG_contract_assert(expr, msg) if (!(expr)) { Tcl_SetResult(interp, (char *) msg, TCL_STATIC ); goto fail; } else
|
||||
|
||||
static swig_module_info *
|
||||
SWIG_Tcl_GetModule(Tcl_Interp *interp) {
|
||||
char *data;
|
||||
swig_module_info *ret = 0;
|
||||
|
||||
/* first check if pointer already created */
|
||||
data = (char *) Tcl_GetVar(interp, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TCL_GLOBAL_ONLY);
|
||||
if (data) {
|
||||
SWIG_UnpackData(data, &ret, sizeof(swig_type_info **));
|
||||
if ((*c != ';') && ((objc-1) > argno)) {
|
||||
Tcl_SetResult(interp, (char *) "Wrong # args.", TCL_STATIC);
|
||||
goto argerror;
|
||||
}
|
||||
va_end(ap);
|
||||
return TCL_OK;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void
|
||||
SWIG_Tcl_SetModule(Tcl_Interp *interp, swig_module_info *module) {
|
||||
char buf[512];
|
||||
char *data;
|
||||
|
||||
/* create a new pointer */
|
||||
data = SWIG_PackData(buf, &module, sizeof(swig_type_info **));
|
||||
*data = 0;
|
||||
Tcl_SetVar(interp, "swig_runtime_data_type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, buf, 0);
|
||||
argerror:
|
||||
{
|
||||
char temp[32];
|
||||
sprintf(temp,"%d", argno+1);
|
||||
c = strchr(fmt,':');
|
||||
if (!c) c = strchr(fmt,';');
|
||||
if (!c) c = (char *)"";
|
||||
Tcl_AppendResult(interp,c," argument ", temp, NULL);
|
||||
va_end(ap);
|
||||
return TCL_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
13
Lib/tcl/tclruntime.swg
Normal file
13
Lib/tcl/tclruntime.swg
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/* tcl.h has to appear first */
|
||||
%insert(runtime) %{
|
||||
#include <stdio.h>
|
||||
#include <tcl.h>
|
||||
#include <errno.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
%}
|
||||
|
||||
%insert(runtime) "swigrun.swg"; /* Common C API type-checking code */
|
||||
%insert(runtime) "tclapi.swg"; /* SWIG/Tcl API */
|
||||
%insert(runtime) "tclrun.swg"; /* Tcl run-time code */
|
||||
36
Lib/tcl/tclstrings.swg
Normal file
36
Lib/tcl/tclstrings.swg
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ------------------------------------------------------------
|
||||
* utility methods for char strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsCharPtrAndSize(Tcl_Obj *obj, char** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
int len = 0;
|
||||
char *cstr = Tcl_GetStringFromObj(obj, &len);
|
||||
if (cstr) {
|
||||
if (cptr) *cptr = cstr;
|
||||
if (psize) *psize = len + 1;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%fragment("SWIG_FromCharPtrAndSize","header",
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE Tcl_Obj *
|
||||
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
|
||||
{
|
||||
return (size < INT_MAX) ? Tcl_NewStringObj(carray, SWIG_numeric_cast(size,int)) : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The plain char * handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%include <typemaps/strings.swg>
|
||||
%typemap_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen)
|
||||
13
Lib/tcl/tclswigtype.swg
Normal file
13
Lib/tcl/tclswigtype.swg
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
%include <typemaps/swigtype.swg>
|
||||
|
||||
%typemap(out) SWIGTYPE = SWIGTYPE INSTANCE;
|
||||
%typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE;
|
||||
%typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE;
|
||||
%typemap(out) SWIGTYPE [] = SWIGTYPE INSTANCE[];
|
||||
%typemap(varout) SWIGTYPE = SWIGTYPE INSTANCE;
|
||||
|
||||
%typemap(throws,noblock=1) SWIGTYPE CLASS {
|
||||
SWIG_set_result(SWIG_NewInstanceObj(SWIG_as_voidptr(SWIG_new_copy($1, $1_ltype)), $&1_descriptor, 1));
|
||||
SWIG_fail;
|
||||
}
|
||||
|
||||
42
Lib/tcl/tcltypemaps.swg
Normal file
42
Lib/tcl/tcltypemaps.swg
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/* no director supported in Tcl */
|
||||
#ifdef SWIG_DIRECTOR_TYPEMAPS
|
||||
#undef SWIG_DIRECTOR_TYPEMAPS
|
||||
#endif
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Basic definitions
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%define_swig_object(Tcl_Obj *)
|
||||
|
||||
#define SWIG_SetResultObj(obj) $result = obj
|
||||
#define SWIG_AppendResultObj(obj) $result = (Tcl_ListObjAppendElement(NULL,$result,obj) == TCL_OK) ? $result : NULL;
|
||||
#define SWIG_SetConstantObj(name, obj) SWIG_Tcl_SetConstantObj(interp, name, obj)
|
||||
#define SWIG_NoneObject() NULL
|
||||
|
||||
/* error manipulation */
|
||||
#define SWIG_ErrorType(code) SWIG_Tcl_ErrorType(code)
|
||||
#define SWIG_SetErrorObj(code,obj) SWIG_Tcl_SetErrorObj(interp,SWIG_ErrorType(code),obj)
|
||||
#define SWIG_SetErrorMsg(code,msg) SWIG_Tcl_SetErrorMsg(interp,SWIG_ErrorType(code),msg)
|
||||
#define SWIG_ExceptionObj(d,type,obj) SWIG_Tcl_SetErrorObj(interp,type,obj)
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* All the typemaps
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%include "tclfragments.swg"
|
||||
|
||||
%include <tclswigtype.swg>
|
||||
%include <typemaps/void.swg>
|
||||
%include <typemaps/valtypes.swg>
|
||||
%include <typemaps/ptrtypes.swg>
|
||||
%include <typemaps/swigobject.swg>
|
||||
%include <typemaps/inoutlist.swg>
|
||||
%include <tclprimtypes.swg>
|
||||
%include <tclstrings.swg>
|
||||
%include <typemaps/misctypes.swg>
|
||||
%include <typemaps/enumint.swg>
|
||||
5
Lib/tcl/tcluserdir.swg
Normal file
5
Lib/tcl/tcluserdir.swg
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Special user directives
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
|
||||
36
Lib/tcl/tclwstrings.swg
Normal file
36
Lib/tcl/tclwstrings.swg
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/* ------------------------------------------------------------
|
||||
* utility methods for wchar strings
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%fragment("SWIG_AsCharPtrAndSize","header") {
|
||||
SWIGINTERN int
|
||||
SWIG_AsWCharPtrAndSize(Tcl_Obj *obj, wchar_t** cptr, size_t* psize, int *alloc)
|
||||
{
|
||||
int len = 0;
|
||||
wchar_t *cstr = Tcl_GetUnicodeFromObj(obj, &len);
|
||||
if (cstr) {
|
||||
if (cptr) *cptr = cstr;
|
||||
if (psize) *psize = len + 1;
|
||||
if (alloc) *alloc = SWIG_OLDOBJ;
|
||||
return SWIG_OK;
|
||||
}
|
||||
return SWIG_TypeError;
|
||||
}
|
||||
}
|
||||
|
||||
%fragment("SWIG_FromWCharPtrAndSize","header",
|
||||
fragment="<limits.h>") {
|
||||
SWIGINTERNINLINE Tcl_Obj *
|
||||
SWIG_FromWCharPtrAndSize(const wchar_t* carray, size_t size)
|
||||
{
|
||||
return (size < INT_MAX) ? Tcl_NewUnicodeObj(carray, SWIG_numeric_cast(size,int)) : NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------
|
||||
* The plain char * handling
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%include <typemaps/strings.swg>
|
||||
%typemap_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen)
|
||||
|
|
@ -1,507 +1 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* typemaps.i
|
||||
*
|
||||
* Swig typemap library for Tcl8. This file contains various sorts
|
||||
* of typemaps for modifying Swig's code generation.
|
||||
*
|
||||
* Author: David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
/*
|
||||
The SWIG typemap library provides a language independent mechanism for
|
||||
supporting output arguments, input values, and other C function
|
||||
calling mechanisms. The primary use of the library is to provide a
|
||||
better interface to certain C function--especially those involving
|
||||
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);
|
||||
|
||||
*/
|
||||
|
||||
%typemap(in) double *INPUT(double temp), double &INPUT(double temp)
|
||||
{
|
||||
if (Tcl_GetDoubleFromObj(interp,$input,&temp) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) float *INPUT(double dvalue, float temp), float &INPUT(double dvalue, float temp)
|
||||
{
|
||||
if (Tcl_GetDoubleFromObj(interp,$input,&dvalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = (float) dvalue;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) int *INPUT(int temp), int &INPUT(int temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&temp) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) short *INPUT(int ivalue, short temp), short &INPUT(int ivalue, short temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = (short) ivalue;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) long *INPUT(int ivalue, long temp), long &INPUT(int ivalue, long temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = (long) ivalue;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) unsigned int *INPUT(int ivalue, unsigned int temp),
|
||||
unsigned int &INPUT(int ivalue, unsigned int temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = (unsigned int) ivalue;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) unsigned short *INPUT(int ivalue, unsigned short temp),
|
||||
unsigned short &INPUT(int ivalue, unsigned short temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = (unsigned short) ivalue;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) unsigned long *INPUT(int ivalue, unsigned long temp),
|
||||
unsigned long &INPUT(int ivalue, unsigned long temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = (unsigned long) ivalue;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) unsigned char *INPUT(int ivalue, unsigned char temp),
|
||||
unsigned char &INPUT(int ivalue, unsigned char temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = (unsigned char) ivalue;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) signed char *INPUT(int ivalue, signed char temp),
|
||||
signed char &INPUT(int ivalue, signed char temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = (signed char) ivalue;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) bool *INPUT(int ivalue, bool temp),
|
||||
bool &INPUT(int ivalue, bool temp)
|
||||
{
|
||||
if (Tcl_GetIntFromObj(interp,$input,&ivalue) == TCL_ERROR) {
|
||||
SWIG_fail;
|
||||
}
|
||||
temp = ivalue ? true : false;
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) long long *INPUT($*1_ltype temp),
|
||||
long long &INPUT($*1_ltype temp)
|
||||
{
|
||||
temp = ($*1_ltype) strtoll(Tcl_GetStringFromObj($input,NULL),0,0);
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
%typemap(in) unsigned long long *INPUT($*1_ltype temp),
|
||||
unsigned long long &INPUT($*1_ltype temp)
|
||||
{
|
||||
temp = ($*1_ltype) strtoull(Tcl_GetStringFromObj($input,NULL),0,0);
|
||||
$1 = &temp;
|
||||
}
|
||||
|
||||
// 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 Tcl list.
|
||||
|
||||
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 Tcl output of the function would be a list containing both
|
||||
output values.
|
||||
|
||||
*/
|
||||
|
||||
%typemap(in,numinputs=0) int *OUTPUT(int temp),
|
||||
short *OUTPUT(short temp),
|
||||
long *OUTPUT(long temp),
|
||||
unsigned int *OUTPUT(unsigned int temp),
|
||||
unsigned short *OUTPUT(unsigned short temp),
|
||||
unsigned long *OUTPUT(unsigned long temp),
|
||||
unsigned char *OUTPUT(unsigned char temp),
|
||||
signed char *OUTPUT(signed char temp),
|
||||
bool *OUTPUT(bool temp),
|
||||
float *OUTPUT(float temp),
|
||||
double *OUTPUT(double temp),
|
||||
long long *OUTPUT($*1_ltype temp),
|
||||
unsigned long long *OUTPUT($*1_ltype temp),
|
||||
int &OUTPUT(int temp),
|
||||
short &OUTPUT(short temp),
|
||||
long &OUTPUT(long temp),
|
||||
unsigned int &OUTPUT(unsigned int temp),
|
||||
unsigned short &OUTPUT(unsigned short temp),
|
||||
unsigned long &OUTPUT(unsigned long temp),
|
||||
signed char &OUTPUT(signed char temp),
|
||||
bool &OUTPUT(bool temp),
|
||||
unsigned char &OUTPUT(unsigned char temp),
|
||||
float &OUTPUT(float temp),
|
||||
double &OUTPUT(double temp),
|
||||
long long &OUTPUT($*1_ltype temp),
|
||||
unsigned long long &OUTPUT($*1_ltype temp)
|
||||
"$1 = &temp;";
|
||||
|
||||
%typemap(argout) int *OUTPUT, int &OUTPUT,
|
||||
short *OUTPUT, short &OUTPUT,
|
||||
long *OUTPUT, long &OUTPUT,
|
||||
unsigned int *OUTPUT, unsigned int &OUTPUT,
|
||||
unsigned short *OUTPUT, unsigned short &OUTPUT,
|
||||
unsigned long *OUTPUT, unsigned long &OUTPUT,
|
||||
unsigned char *OUTPUT, unsigned char &OUTPUT,
|
||||
signed char *OUTPUT, signed char &OUTPUT,
|
||||
bool *OUTPUT, bool &OUTPUT
|
||||
{
|
||||
Tcl_Obj *o;
|
||||
o = Tcl_NewIntObj((int) *($1));
|
||||
Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
|
||||
}
|
||||
|
||||
%typemap(argout) float *OUTPUT, float &OUTPUT,
|
||||
double *OUTPUT, double &OUTPUT
|
||||
{
|
||||
Tcl_Obj *o;
|
||||
o = Tcl_NewDoubleObj((double) *($1));
|
||||
Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
|
||||
}
|
||||
|
||||
%typemap(argout) long long *OUTPUT, long long &OUTPUT
|
||||
{
|
||||
char temp[256];
|
||||
Tcl_Obj *o;
|
||||
sprintf(temp,"%lld",(long long)*($1));
|
||||
o = Tcl_NewStringObj(temp,-1);
|
||||
Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
|
||||
}
|
||||
|
||||
%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT
|
||||
{
|
||||
char temp[256];
|
||||
Tcl_Obj *o;
|
||||
sprintf(temp,"%llu",(unsigned long long)*($1));
|
||||
o = Tcl_NewStringObj(temp,-1);
|
||||
Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),o);
|
||||
}
|
||||
|
||||
// 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 Tcl list.
|
||||
|
||||
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 Tcl). Rather, the modified input value shows
|
||||
up as the return value of the function. Thus, to apply this function
|
||||
to a Tcl variable you might do this :
|
||||
|
||||
set x [neg $x]
|
||||
|
||||
*/
|
||||
|
||||
|
||||
%typemap(in) int *INOUT = int *INPUT;
|
||||
%typemap(in) short *INOUT = short *INPUT;
|
||||
%typemap(in) long *INOUT = long *INPUT;
|
||||
%typemap(in) unsigned int *INOUT = unsigned int *INPUT;
|
||||
%typemap(in) unsigned short *INOUT = unsigned short *INPUT;
|
||||
%typemap(in) unsigned long *INOUT = unsigned long *INPUT;
|
||||
%typemap(in) unsigned char *INOUT = unsigned char *INPUT;
|
||||
%typemap(in) signed char *INOUT = signed char *INPUT;
|
||||
%typemap(in) bool *INOUT = bool *INPUT;
|
||||
%typemap(in) float *INOUT = float *INPUT;
|
||||
%typemap(in) double *INOUT = double *INPUT;
|
||||
%typemap(in) long long *INOUT = long long *INPUT;
|
||||
%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
|
||||
|
||||
%typemap(in) int &INOUT = int &INPUT;
|
||||
%typemap(in) short &INOUT = short &INPUT;
|
||||
%typemap(in) long &INOUT = long &INPUT;
|
||||
%typemap(in) unsigned int &INOUT = unsigned int &INPUT;
|
||||
%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
|
||||
%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
|
||||
%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
|
||||
%typemap(in) signed char &INOUT = signed char &INPUT;
|
||||
%typemap(in) bool &INOUT = bool &INPUT;
|
||||
%typemap(in) float &INOUT = float &INPUT;
|
||||
%typemap(in) double &INOUT = double &INPUT;
|
||||
%typemap(in) long long &INOUT = long long &INPUT;
|
||||
%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
|
||||
|
||||
%typemap(argout) int *INOUT = int *OUTPUT;
|
||||
%typemap(argout) short *INOUT = short *OUTPUT;
|
||||
%typemap(argout) long *INOUT = long *OUTPUT;
|
||||
%typemap(argout) unsigned int *INOUT = unsigned int *OUTPUT;
|
||||
%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
|
||||
%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
|
||||
%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
|
||||
%typemap(argout) signed char *INOUT = signed char *OUTPUT;
|
||||
%typemap(argout) bool *INOUT = bool *OUTPUT;
|
||||
%typemap(argout) float *INOUT = float *OUTPUT;
|
||||
%typemap(argout) double *INOUT = double *OUTPUT;
|
||||
%typemap(argout) long long *INOUT = long long *OUTPUT;
|
||||
%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
|
||||
|
||||
%typemap(argout) int &INOUT = int &OUTPUT;
|
||||
%typemap(argout) short &INOUT = short &OUTPUT;
|
||||
%typemap(argout) long &INOUT = long &OUTPUT;
|
||||
%typemap(argout) unsigned int &INOUT = unsigned int &OUTPUT;
|
||||
%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
|
||||
%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
|
||||
%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
|
||||
%typemap(argout) signed char &INOUT = signed char &OUTPUT;
|
||||
%typemap(argout) bool &INOUT = bool &OUTPUT;
|
||||
%typemap(argout) float &INOUT = float &OUTPUT;
|
||||
%typemap(argout) double &INOUT = double &OUTPUT;
|
||||
%typemap(argout) long long &INOUT = long long &OUTPUT;
|
||||
%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
// Special types
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
// If interp * appears as a function argument, we ignore it and get
|
||||
// it from the wrapper function.
|
||||
|
||||
/*
|
||||
The typemaps.i library also provides the following mappings :
|
||||
|
||||
Tcl_Interp *interp
|
||||
|
||||
Passes the current Tcl_Interp value directly to a C function.
|
||||
This can be used to work with existing wrapper functions or
|
||||
if you just need the interp value for some reason. When used,
|
||||
the 'interp' parameter becomes hidden in the Tcl interface--that
|
||||
is, you don't specify it explicitly. SWIG fills in its value
|
||||
automatically.
|
||||
|
||||
int Tcl_Result
|
||||
|
||||
Makes the integer return code of a function the return value
|
||||
of a SWIG generated wrapper function. For example :
|
||||
|
||||
int foo() {
|
||||
... do stuff ...
|
||||
return TCL_OK;
|
||||
}
|
||||
|
||||
could be wrapped as follows :
|
||||
|
||||
%include typemaps.i
|
||||
%apply int Tcl_Result { int foo };
|
||||
int foo();
|
||||
|
||||
*/
|
||||
|
||||
%typemap(in,numinputs=0) Tcl_Interp *interp {
|
||||
$1 = interp;
|
||||
}
|
||||
|
||||
// If return code is a Tcl_Result, simply pass it on
|
||||
|
||||
%typemap(out) int Tcl_Result {
|
||||
return $1;
|
||||
}
|
||||
|
||||
/* Overloading information */
|
||||
|
||||
%typemap(typecheck) double *INPUT = double;
|
||||
%typemap(typecheck) bool *INPUT = bool;
|
||||
%typemap(typecheck) signed char *INPUT = signed char;
|
||||
%typemap(typecheck) unsigned char *INPUT = unsigned char;
|
||||
%typemap(typecheck) unsigned long *INPUT = unsigned long;
|
||||
%typemap(typecheck) unsigned short *INPUT = unsigned short;
|
||||
%typemap(typecheck) unsigned int *INPUT = unsigned int;
|
||||
%typemap(typecheck) long *INPUT = long;
|
||||
%typemap(typecheck) short *INPUT = short;
|
||||
%typemap(typecheck) int *INPUT = int;
|
||||
%typemap(typecheck) float *INPUT = float;
|
||||
%typemap(typecheck) long long *INPUT = long long;
|
||||
%typemap(typecheck) unsigned long long *INPUT = unsigned long long;
|
||||
|
||||
%typemap(typecheck) double &INPUT = double;
|
||||
%typemap(typecheck) bool &INPUT = bool;
|
||||
%typemap(typecheck) signed char &INPUT = signed char;
|
||||
%typemap(typecheck) unsigned char &INPUT = unsigned char;
|
||||
%typemap(typecheck) unsigned long &INPUT = unsigned long;
|
||||
%typemap(typecheck) unsigned short &INPUT = unsigned short;
|
||||
%typemap(typecheck) unsigned int &INPUT = unsigned int;
|
||||
%typemap(typecheck) long &INPUT = long;
|
||||
%typemap(typecheck) short &INPUT = short;
|
||||
%typemap(typecheck) int &INPUT = int;
|
||||
%typemap(typecheck) float &INPUT = float;
|
||||
%typemap(typecheck) long long &INPUT = long long;
|
||||
%typemap(typecheck) unsigned long long &INPUT = unsigned long long;
|
||||
|
||||
%typemap(typecheck) double *INOUT = double;
|
||||
%typemap(typecheck) bool *INOUT = bool;
|
||||
%typemap(typecheck) signed char *INOUT = signed char;
|
||||
%typemap(typecheck) unsigned char *INOUT = unsigned char;
|
||||
%typemap(typecheck) unsigned long *INOUT = unsigned long;
|
||||
%typemap(typecheck) unsigned short *INOUT = unsigned short;
|
||||
%typemap(typecheck) unsigned int *INOUT = unsigned int;
|
||||
%typemap(typecheck) long *INOUT = long;
|
||||
%typemap(typecheck) short *INOUT = short;
|
||||
%typemap(typecheck) int *INOUT = int;
|
||||
%typemap(typecheck) float *INOUT = float;
|
||||
%typemap(typecheck) long long *INOUT = long long;
|
||||
%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
|
||||
|
||||
%typemap(typecheck) double &INOUT = double;
|
||||
%typemap(typecheck) bool &INOUT = bool;
|
||||
%typemap(typecheck) signed char &INOUT = signed char;
|
||||
%typemap(typecheck) unsigned char &INOUT = unsigned char;
|
||||
%typemap(typecheck) unsigned long &INOUT = unsigned long;
|
||||
%typemap(typecheck) unsigned short &INOUT = unsigned short;
|
||||
%typemap(typecheck) unsigned int &INOUT = unsigned int;
|
||||
%typemap(typecheck) long &INOUT = long;
|
||||
%typemap(typecheck) short &INOUT = short;
|
||||
%typemap(typecheck) int &INOUT = int;
|
||||
%typemap(typecheck) float &INOUT = float;
|
||||
%typemap(typecheck) long long &INOUT = long long;
|
||||
%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
%include <typemaps/typemaps.swg>
|
||||
|
|
|
|||
16
Lib/typemaps/README
Normal file
16
Lib/typemaps/README
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* Internal typemap specializations
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
enumint.swg enum especializations as int types
|
||||
inoutlist.swg return the OUTPUT types in a list
|
||||
misctypes.swg Miscellaneos types (size_t, ptrdiff_t, etc)
|
||||
primtypes.swg Macros to manage primitive types (shot,int,double,etc)
|
||||
ptrtypes.swg Typemaps for types with a 'ptr' behavior
|
||||
strings.swg String base typemaps
|
||||
cstring.swg Various forms of C character string handling
|
||||
swigobject.swg Language object, such as PyObject, Tcl_Obj, etc
|
||||
swigtype.swg SWIGTYPE
|
||||
valtypes.swg Typemaps for types with a 'by value' behavior
|
||||
void.swg void * typemaps
|
||||
implicit.swg Allow the use of implicit C++ constructors
|
||||
79
Lib/typemaps/cdata.swg
Normal file
79
Lib/typemaps/cdata.swg
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/* -----------------------------------------------------------------------------
|
||||
* cdata.i
|
||||
*
|
||||
* Author(s): David Beazley (beazley@cs.uchicago.edu)
|
||||
*
|
||||
* This library file contains macros for manipulating raw C data as strings.
|
||||
*
|
||||
* $Header$
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%{
|
||||
typedef struct SWIGCDATA {
|
||||
char *data;
|
||||
size_t len;
|
||||
} SWIGCDATA;
|
||||
%}
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* Typemaps for returning binary data
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%typemap(out,noblock=1,fragment="SWIG_FromCharPtrAndSize") SWIGCDATA {
|
||||
$result = SWIG_FromCharPtrAndSize($1.data,$1.len);
|
||||
}
|
||||
%typemap(in) (const void *indata, int inlen) = (char *STRING, int SIZE);
|
||||
|
||||
|
||||
/* -----------------------------------------------------------------------------
|
||||
* %cdata(TYPE [, NAME])
|
||||
*
|
||||
* Convert raw C data to a binary string.
|
||||
* ----------------------------------------------------------------------------- */
|
||||
|
||||
%define %cdata(TYPE,NAME...)
|
||||
|
||||
%insert("header") {
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if #NAME == ""
|
||||
static SWIGCDATA cdata_##TYPE(TYPE *ptr, size_t nelements)
|
||||
#else
|
||||
static SWIGCDATA cdata_##NAME(TYPE *ptr, size_t nelements)
|
||||
#endif
|
||||
{
|
||||
SWIGCDATA d;
|
||||
d.data = (char *) ptr;
|
||||
#if #TYPE != "void"
|
||||
d.len = nelements*sizeof(TYPE);
|
||||
#else
|
||||
d.len = nelements;
|
||||
#endif
|
||||
return d;
|
||||
}
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
#if #NAME == ""
|
||||
SWIGCDATA cdata_##TYPE(TYPE *ptr, size_t nelements = 1);
|
||||
#else
|
||||
SWIGCDATA cdata_##NAME(TYPE *ptr, size_t nelements = 1);
|
||||
#endif
|
||||
%enddef
|
||||
|
||||
%rename(cdata) ::cdata_void(void *ptr, size_t nelements = 1);
|
||||
|
||||
%cdata(void);
|
||||
|
||||
/* Memory move function */
|
||||
void memmove(void *data, const void *indata, size_t inlen);
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -10,13 +10,11 @@
|
|||
* some way.
|
||||
*/
|
||||
|
||||
%include <pytuplehlp.swg>
|
||||
|
||||
%define %typemap_cstrings(Name, Char,
|
||||
SWIG_AsCharPtr,
|
||||
SWIG_AsCharPtrAndSize,
|
||||
SWIG_FromCharPtr,
|
||||
SWIG_FromCharArray)
|
||||
SWIG_FromCharPtrAndSize)
|
||||
|
||||
/* %cstring_input_binary(TYPEMAP, SIZE)
|
||||
*
|
||||
|
|
@ -30,14 +28,17 @@
|
|||
*/
|
||||
|
||||
%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;
|
||||
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) (TYPEMAP, SIZE)
|
||||
(Char *buf, size_t size, int alloc) {
|
||||
if (SWIG_AsCharPtrAndSize($input, &buf, &size, &alloc) != SWIG_OK) {
|
||||
SWIG_arg_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
|
||||
}
|
||||
$1 = ($1_ltype) buf;
|
||||
$2 = ($2_ltype) size - 1;
|
||||
}
|
||||
%typemap(freearg) (TYPEMAP, SIZE) {
|
||||
if (alloc$argnum == SWIG_NEWOBJ) SWIG_delete_array(buf$argnum);
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
|
|
@ -55,11 +56,14 @@
|
|||
*/
|
||||
|
||||
%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));";
|
||||
%typemap(in,noblock=1,numinputs=0) TYPEMAP (Char temp[MAX+1]) {
|
||||
$1 = ($1_ltype) temp;
|
||||
}
|
||||
%typemap(freearg) TYPEMAP "";
|
||||
%typemap(argout,noblock=1,fragment= #SWIG_FromCharPtr ) TYPEMAP {
|
||||
$1[MAX] = 0;
|
||||
SWIG_append_result(SWIG_FromCharPtr($1));
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
|
|
@ -77,11 +81,13 @@
|
|||
*/
|
||||
|
||||
%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));";
|
||||
%typemap(in,noblock=1,numinputs=0) TYPEMAP(Char temp[SIZE]) {
|
||||
$1 = ($1_ltype) temp;
|
||||
}
|
||||
%typemap(freearg) TYPEMAP "";
|
||||
%typemap(argout,noblock=1,fragment= #SWIG_FromCharPtrAndSize) TYPEMAP {
|
||||
SWIG_append_result(SWIG_FromCharPtrAndSize($1,SIZE));
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
|
|
@ -102,17 +108,21 @@
|
|||
|
||||
|
||||
%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;
|
||||
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP (Char temp[MAX+1], Char *t, size_t n, int alloc) {
|
||||
if (SWIG_AsCharPtrAndSize($input, &t, &n, &alloc) != SWIG_OK) {
|
||||
SWIG_arg_fail(SWIG_TypeError, "TYPEMAP", $argnum);
|
||||
}
|
||||
if ( n > (size_t) MAX ) n = (size_t) MAX;
|
||||
memcpy(temp, t, sizeof(Char)*n);
|
||||
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(t);
|
||||
temp[n - 1] = 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));";
|
||||
}
|
||||
%typemap(freearg) TYPEMAP "";
|
||||
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
|
||||
$1[MAX] = 0;
|
||||
SWIG_append_result(SWIG_FromCharPtr($1));
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
|
|
@ -133,22 +143,21 @@
|
|||
*/
|
||||
|
||||
%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;
|
||||
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP (Char* t, size_t n, int alloc, size_t expansion = 0) {
|
||||
#if #EXP != ""
|
||||
expansion += EXP;
|
||||
#endif
|
||||
Char* t = 0; size_t n = 0;
|
||||
SWIG_AsCharPtrAndSize($input, &t, &n);
|
||||
if (SWIG_arg_fail($argnum)) SWIG_fail;
|
||||
if (SWIG_AsCharPtrAndSize($input, &t, &n, &alloc) != SWIG_OK) {
|
||||
SWIG_arg_fail(SWIG_TypeError, "TYPEMAP", $argnum);
|
||||
}
|
||||
$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));
|
||||
memcpy($1,t,sizeof(Char)*n);
|
||||
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(t);
|
||||
$1[n-1] = 0;
|
||||
}
|
||||
%typemap(freearg) TYPEMAP "";
|
||||
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
|
||||
SWIG_append_result(SWIG_FromCharPtr($1));
|
||||
SWIG_delete_array($1);
|
||||
}
|
||||
%enddef
|
||||
|
|
@ -165,19 +174,19 @@
|
|||
*/
|
||||
|
||||
%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(in,noblock=1,fragment=SWIG_AsVal_frag(unsigned long)) (TYPEMAP, SIZE) (unsigned long size) {
|
||||
if (SWIG_AsVal(unsigned long)($input, &size) != SWIG_OK) {
|
||||
SWIG_arg_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
|
||||
}
|
||||
$2 = SWIG_numeric_cast(size, $2_ltype);
|
||||
$1 = SWIG_new_array(size+1, $*1_ltype);
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharPtr) (TYPEMAP,SIZE) {
|
||||
$result = t_output_helper($result,SWIG_FromCharPtr($1));
|
||||
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) (TYPEMAP,SIZE) {
|
||||
SWIG_append_result(SWIG_FromCharPtr($1));
|
||||
SWIG_delete_array($1);
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* %cstring_output_withsize(TYPEMAP, SIZE)
|
||||
*
|
||||
|
|
@ -192,15 +201,16 @@
|
|||
*/
|
||||
|
||||
%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;
|
||||
%typemap(in,noblock=1,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) (unsigned long n) {
|
||||
if (SWIG_AsVal(unsigned long)($input, &n) != SWIG_OK) {
|
||||
SWIG_arg_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
|
||||
}
|
||||
$1 = SWIG_new_array(n+1, $*1_ltype);
|
||||
$2 = SWIG_new($*2_ltype);
|
||||
*$2 = n;
|
||||
$2 = SWIG_new($*2_ltype);
|
||||
*$2 = SWIG_numeric_cast(n, $*2_ltype);
|
||||
}
|
||||
%typemap(argout,fragment="t_output_helper," #SWIG_FromCharArray) (TYPEMAP,SIZE) {
|
||||
$result = t_output_helper($result, SWIG_FromCharArray($1,*$2));
|
||||
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize) (TYPEMAP,SIZE) {
|
||||
SWIG_append_result(SWIG_FromCharPtrAndSize($1,*$2));
|
||||
SWIG_delete_array($1);
|
||||
SWIG_delete($2);
|
||||
}
|
||||
|
|
@ -221,14 +231,14 @@
|
|||
*/
|
||||
|
||||
%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));
|
||||
%typemap(in,noblock=1,numinputs=0) TYPEMAP($*1_ltype temp = 0) {
|
||||
$1 = &temp;
|
||||
}
|
||||
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
|
||||
if (*$1) {
|
||||
SWIG_append_result(SWIG_FromCharPtr(*$1));
|
||||
RELEASE;
|
||||
}
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
|
|
@ -247,16 +257,16 @@
|
|||
* }
|
||||
*/
|
||||
|
||||
%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;
|
||||
}
|
||||
}
|
||||
%define Name ## _output_allocate_size(TYPEMAP, SIZE, RELEASE)
|
||||
%typemap(in,noblock=1,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) {
|
||||
$1 = &temp; $2 = &tempn;
|
||||
}
|
||||
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize)(TYPEMAP,SIZE) {
|
||||
if (*$1) {
|
||||
SWIG_append_result(SWIG_FromCharPtrAndSize(*$1,*$2));
|
||||
RELEASE;
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
%enddef
|
||||
64
Lib/typemaps/enumint.swg
Normal file
64
Lib/typemaps/enumint.swg
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
/* ------------------------------------------------------------
|
||||
* Enums mapped as integer values
|
||||
* ------------------------------------------------------------ */
|
||||
|
||||
%apply int { enum SWIGTYPE };
|
||||
%apply const int& { const enum SWIGTYPE& };
|
||||
|
||||
%typemap(in,fragment=SWIG_AsVal_frag(int),noblock=1) const enum SWIGTYPE& (int val, int ecode, $basetype temp) {
|
||||
ecode = SWIG_AsVal(int)($input, &val);
|
||||
if (ecode != SWIG_OK) {
|
||||
SWIG_arg_fail(ecode, "$basetype", $argnum);
|
||||
} else {
|
||||
temp = SWIG_static_cast(val,$basetype);
|
||||
$1 = &temp;
|
||||
}
|
||||
}
|
||||
|
||||
%typemap(varin,fragment=SWIG_AsVal_frag(int),noblock=1) enum SWIGTYPE {
|
||||
if (sizeof(int) != sizeof($1)) {
|
||||
SWIG_var_fail(SWIG_AttributeError,"$type", "$name");
|
||||
} else {
|
||||
int ecode = SWIG_AsVal(int)($input, SWIG_reinterpret_cast(&$1,int*));
|
||||
if (ecode != SWIG_OK) {
|
||||
SWIG_var_fail(ecode, "$type", "$name");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
typemaps needed due to unnamed enums
|
||||
*/
|
||||
%define SWIG_ENUM_OUT_TYPEMAPS(from_meth,frag)
|
||||
%typemap(out,noblock=1,fragment=frag) enum SWIGTYPE {
|
||||
$result = from_meth(($1));
|
||||
}
|
||||
%typemap(out,noblock=1,fragment=frag) const enum SWIGTYPE& {
|
||||
$result = from_meth((*$1));
|
||||
}
|
||||
%typemap(varout,noblock=1,fragment=frag) enum SWIGTYPE, const enum SWIGTYPE& {
|
||||
$result = from_meth($1);
|
||||
}
|
||||
%typemap(constcode,noblock=1,fragment=frag) enum SWIGTYPE {
|
||||
SWIG_set_constant("$symname", from_meth($value));
|
||||
}
|
||||
%typemap(directorin,noblock=1,fragment=frag) enum SWIGTYPE *DIRECTORIN {
|
||||
$input = from_meth(*$1_name);
|
||||
}
|
||||
%typemap(directorin,noblock=1,fragment=frag) enum SWIGTYPE, const enum SWIGTYPE& {
|
||||
$input = from_meth($1_name);
|
||||
}
|
||||
%typemap(throws,noblock=1,fragment=frag) enum SWIGTYPE {
|
||||
SWIG_exception_obj(0,"$type", from_meth($1));
|
||||
}
|
||||
%enddef
|
||||
|
||||
SWIG_ENUM_OUT_TYPEMAPS(SWIG_From(int),SWIG_From_frag(int));
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
204
Lib/typemaps/implicit.swg
Normal file
204
Lib/typemaps/implicit.swg
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
/*
|
||||
The %implict macro allows a SwigType (Class) to be accepted
|
||||
as an input parameter and use its implicit constructors when needed.
|
||||
|
||||
For example:
|
||||
|
||||
|
||||
%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/or the SWIG_arg macro.
|
||||
|
||||
*/
|
||||
|
||||
%check_swig_object()
|
||||
|
||||
%define %implicit_type(Type...)
|
||||
%traits_swigtype(Type);
|
||||
%enddef
|
||||
|
||||
%define %implicit_frag(Type...) ,fragment=SWIG_Traits_frag(Type) %enddef
|
||||
|
||||
%define %implicit_code(Type...)
|
||||
if (swig::asval<Type>(obj, 0)) {
|
||||
Type _v;
|
||||
swig::asval<Type>(obj, &_v);
|
||||
if (val) *val = new value_type(_v);
|
||||
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(SWIG_Object obj, value_type **val) {
|
||||
Type *vptr;
|
||||
static swig_type_info* desc = SWIG_TypeQuery("Type *");
|
||||
if ((SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0) == SWIG_OK)) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
%formacro_1(%implicit_code,__VA_ARGS__)
|
||||
}
|
||||
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(SWIG_Object obj, value_type **val) {
|
||||
Type *vptr;
|
||||
static swig_type_info* desc = SWIG_TypeQuery("Type *");
|
||||
if ((SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0) == SWIG_OK)) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
%implicit_code(Imp1);
|
||||
}
|
||||
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(SWIG_Object obj, value_type **val) {
|
||||
Type *vptr;
|
||||
static swig_type_info* desc = SWIG_TypeQuery("Type *");
|
||||
if ((SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0) == SWIG_OK)) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
%implicit_code(Imp1);
|
||||
%implicit_code(Imp2);
|
||||
}
|
||||
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(SWIG_Object obj, value_type **val) {
|
||||
Type *vptr;
|
||||
static swig_type_info* desc = SWIG_TypeQuery("Type *");
|
||||
if ((SWIG_ConvertPtr(obj, (void **)&vptr, desc, 0) == SWIG_OK)) {
|
||||
if (val) *val = vptr;
|
||||
return SWIG_OLDOBJ;
|
||||
} else {
|
||||
%implicit_code(Imp1);
|
||||
%implicit_code(Imp2);
|
||||
%implicit_code(Imp3);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
%}
|
||||
|
||||
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
|
||||
%enddef
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue