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:
Marcelo Matus 2005-10-18 13:24:15 +00:00
parent 5bbd841acc
commit 7e5e4fd1f9
144 changed files with 6378 additions and 7248 deletions

View File

@ -1,11 +1,67 @@
Version 1.3.27 (October 15, 2005)
=================================
07/15/2005: wsfulton
10/18/2005: mmatus
Unifying the typemaps for
python, ruby, tcl
and in the process, fix several problems in three
languages to work in the "canonical" way now stablished in
the typemap library
SWIG/Lib/typempas
The current status of the unification is that everything
compiles and runs inside the test-suite and examples
directories. And for the first type we have three
languages than pass the primitive_types.i case.
Also, we have uniform way to treat the errors, for example
if you do something like
>>> from primitive_types import *
>>> print val_uchar(10)
10
>>> print val_uchar(1000)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
OverflowError: in argument 1 of type 'unsigned char'
you get the same exception in all the three languages.
And well, many more good things will come from this
unification, as proper support of the STL/STD classes
for all the languages, and hopefully, we can keep
adding other languages.
The hardest part, writting a common typemap library
that suites the three different languages, is done,
and adding another language it is easy now.
Still the global unification is not complete, the STL/STD
part is next, and probably adding one or two more
languages.
If you are curious, look at the python, ruby and/or tcl
directories to see what is needed to support the new
common typemaps library. Still, the final way to
integrate a new language could change as we move to
integrate the STD/STL.
*** POTENTIAL INCOMPATIBILITY ***
Some missing typemaps could start working, and change
the old expected behavior, specially in ruby and tcl.
10/15/2005: wsfulton
[Java] Fix for typesafe enum wrapping so that it is possible to
overload a method with 2 different enum types.
07/15/2005: wsfulton
10/15/2005: wsfulton
Fix for %feature("immutable","0") attempting to generate setters
for constants.

View File

@ -1,5 +1,5 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = example
INTERFACE = example.i

View File

@ -1,5 +1,5 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SRCS =
TARGET = example
INTERFACE = example.i

View File

@ -1,5 +1,5 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
CXXSRCS = example.cxx
TARGET = example
INTERFACE = example.i

View File

@ -1,5 +1,5 @@
TOP = ../..
SWIG = $(TOP)/../swig
SWIG = $(TOP)/../preinst-swig
SRCS = example.c
TARGET = my_tclsh
DLTARGET = example

View File

@ -16,16 +16,16 @@ public:
}
};
class quat;
class Quat;
class matrix4;
class tacka3;
class quat {
class Quat {
public:
quat::quat(void){}
quat::quat(float in_w, float x, float y, float z){}
quat::quat(const tacka3& axis, float angle){}
quat::quat(const matrix4& m){}
Quat::Quat(void){}
Quat::Quat(float in_w, float x, float y, float z){}
Quat::Quat(const tacka3& axis, float angle){}
Quat::Quat(const matrix4& m){}
};
%}

View File

@ -346,6 +346,7 @@ C_TEST_CASES += \
sizeof_pointer \
sneaky1 \
struct_rename \
typedef_struct \
typemap_subst \
unions

View File

@ -0,0 +1,49 @@
%module(directors="1") director_wstring;
%include stl.i
%include std_vector.i
%include std_wstring.i
// Using thread unsafe wrapping
%warnfilter(470) A;
%{
#include <vector>
#include <string>
%}
%feature("director") A;
%inline %{
struct A
{
A(const std::wstring& first)
: m_strings(1, first)
{}
virtual ~A() {}
virtual const std::wstring& get_first() const
{ return get(0); }
virtual const std::wstring& get(int n) const
{ return m_strings[n]; }
virtual const std::wstring& call_get_first() const
{ return get_first(); }
virtual const std::wstring& call_get(int n) const
{ return get(n); }
std::vector<std::wstring> m_strings;
virtual void process_text(const char *text)
{
}
void call_process_func() { process_text("hello"); }
};
%}
%template(StringVector) std::vector<std::wstring>;

View File

@ -63,6 +63,7 @@ struct SpeedClass {
enum speed { slow=10, medium=20, fast=30, lightning };
typedef enum speed speedtd1;
int speedTest0(int s) { return s; }
speed speedTest1(speed s) { return s; }
enum speed speedTest2(enum speed s) { return s; }
const speed speedTest3(const speed s) { return s; }
@ -77,6 +78,7 @@ struct SpeedClass {
SpeedClass() : myColour2(red), mySpeedtd1(slow) { }
};
int speedTest0(int s) { return s; }
SpeedClass::speed speedTest1(SpeedClass::speed s) { return s; }
enum SpeedClass::speed speedTest2(enum SpeedClass::speed s) { return s; }
const SpeedClass::speed speedTest3(const SpeedClass::speed s) { return s; }

View File

@ -19,8 +19,10 @@ SWIGEXPORT extern int externexport(int);
extern int SWIGSTDCALL externstdcall(int);
%{
// externimport ought to be using MYDLLIMPORT and compiled into another dll, but that is
// a bit tricky to do in the test framework
/*
externimport ought to be using MYDLLIMPORT and compiled into another dll, but that is
a bit tricky to do in the test framework
*/
SWIGEXPORT extern int externimport(int i) { return i; }
SWIGEXPORT extern int externexport(int i) { return i; }
extern int SWIGSTDCALL externstdcall(int i) { return i; }

View File

@ -1,4 +1,4 @@
%module implicittest
%module li_implicit
%include implicit.i
%inline

View File

@ -1,6 +1,9 @@
// Massive primitive datatype test.
%module(directors="1") primitive_types
// Ruby constant names
#pragma SWIG nowarn=801
// Using thread unsafe wrapping
#pragma SWIG nowarn=470
/*
@ -217,8 +220,8 @@ macro(long, pfx, long)
macro(unsigned long, pfx, ulong)
macro(long long, pfx, llong)
macro(unsigned long long, pfx, ullong)
//macro(float, pfx, float)
//macro(double, pfx, double)
macro(float, pfx, float)
macro(double, pfx, double)
macro(char, pfx, char)
%enddef
@ -345,9 +348,7 @@ macro(size_t, pfx, sizet)
%enddef
#ifdef SWIGPYTHON
%apply (char *STRING, int LENGTH) { (const char *str, size_t len) }
#endif
%inline {
struct Foo

View File

@ -18,14 +18,15 @@ CPP_TEST_CASES += \
complextest \
director_stl \
director_thread \
director_wstring \
file_test \
implicittest \
inout \
input \
inplaceadd \
kwargs \
li_cstring \
li_cwstring \
li_implicit \
li_std_except \
li_std_vectora \
li_std_map \

View File

@ -6,6 +6,7 @@ if mainc(largs) != 3:
targs=('hi','hola')
if mainv(targs,1) != 'hola':
print mainv(targs,1)
raise RuntimeError, "bad main typemap"
targs=('hi', 'hola')

View File

@ -0,0 +1 @@
import empty

View File

@ -32,6 +32,10 @@
p->second += 1;
}
inline void AddOne1r(double& a) {
a += 1;
}
%}
%template() std::pair<double, double>;
@ -41,3 +45,4 @@ void AddOne3(double* INOUT, double* INOUT, double* INOUT);
void AddOne1p(std::pair<double, double>* INOUT);
void AddOne2p(std::pair<double, double>* INOUT, double* INOUT);
void AddOne3p(double* INOUT, std::pair<double, double>* INOUT, double* INOUT);
void AddOne1r(double& INOUT);

View File

@ -11,9 +11,11 @@ if test2() != " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_
raise RuntimeError
if test3("hello") != "hello-suffix":
print test3("hello")
raise RuntimeError
if test4("hello") != "hello-suffix":
print test4("hello")
raise RuntimeError
if test5(4) != 'xxxx':

View File

@ -1,4 +1,4 @@
from implicittest import *
from li_implicit import *
b = B()
ai = A(1)
ad = A(2.0)

View File

@ -11,6 +11,7 @@ if li_std_string.test_cvalue(x) != x:
raise RuntimeError, "bad string mapping"
if li_std_string.test_value(x) != x:
print x, li_std_string.test_value(x)
raise RuntimeError, "bad string mapping"
if li_std_string.test_const_reference(x) != x:

View File

@ -3,6 +3,7 @@ import li_std_wstring
x=u"h"
if li_std_wstring.test_wcvalue(x) != x:
print li_std_wstring.test_wcvalue(x)
raise RuntimeError, "bad string mapping"
x=u"hello"

View File

@ -14,8 +14,8 @@ cvar.var_long = sct_long
cvar.var_ulong = sct_ulong
cvar.var_llong = sct_llong
cvar.var_ullong = sct_ullong
#cvar.var_float = sct_float
#cvar.var_double = sct_double
cvar.var_float = sct_float
cvar.var_double = sct_double
cvar.var_char = sct_char
cvar.var_pchar = sct_pchar
cvar.var_pcharc = sct_pcharc
@ -46,8 +46,8 @@ if cvar.var_long != cct_long: pyerror("long", cvar.var_long, cct_long)
if cvar.var_ulong != cct_ulong: pyerror("ulong", cvar.var_ulong, cct_ulong)
if cvar.var_llong != cct_llong: pyerror("llong", cvar.var_llong, cct_llong)
if cvar.var_ullong != cct_ullong: pyerror("ullong", cvar.var_ullong, cct_ullong)
#if cvar.var_float != cct_float: pyerror("float", cvar.var_float, cct_float)
#if cvar.var_double != cct_double: pyerror("double", cvar.var_double, cct_double)
if cvar.var_float != cct_float: pyerror("float", cvar.var_float, cct_float)
if cvar.var_double != cct_double: pyerror("double", cvar.var_double, cct_double)
if cvar.var_char != cct_char: pyerror("char", cvar.var_char, cct_char)
if cvar.var_pchar != cct_pchar: pyerror("pchar", cvar.var_pchar, cct_pchar)
if cvar.var_pcharc != cct_pcharc: pyerror("pchar", cvar.var_pcharc, cct_pcharc)
@ -128,8 +128,8 @@ p.var_long = p.stc_long
p.var_ulong = p.stc_ulong
p.var_llong = p.stc_llong
p.var_ullong = p.stc_ullong
#p.var_float = p.stc_float
#p.var_double = p.stc_double
p.var_float = p.stc_float
p.var_double = p.stc_double
p.var_char = p.stc_char
p.var_pchar = sct_pchar
p.var_pcharc = sct_pcharc
@ -156,8 +156,8 @@ t.var_long = t.stc_long
t.var_ulong = t.stc_ulong
t.var_llong = t.stc_llong
t.var_ullong = t.stc_ullong
#t.var_float = t.stc_float
#t.var_double = t.stc_double
t.var_float = t.stc_float
t.var_double = t.stc_double
t.var_char = t.stc_char
t.var_pchar = sct_pchar
t.var_pcharc = sct_pcharc
@ -215,6 +215,7 @@ if cvar.var_char != '\0':
cvar.var_namet = '\0'
#if cvar.var_namet != '\0\0\0\0\0':
if cvar.var_namet != '':
print 'hola', '', cvar.var_namet
raise RuntimeError, "bad char '\0' case"
cvar.var_namet = ''
@ -301,7 +302,7 @@ try:
a = t.var_uint
t.var_uint = -1
error = 1
except TypeError:
except OverflowError:
if a != t.var_uint:
error = 1
pass

View File

@ -33,7 +33,7 @@ if (Bools.value(Bools.const_pbool) != Bools.bool1)
exit 1
end
if (Bools.value(Bools.const_rbool) != Bools.bool2)
if (Bools.const_rbool != Bools.bool2)
print "Runtime test 7 failed\n"
exit 1
end
@ -59,7 +59,7 @@ if (Bools.value(Bools.pbo(Bools.pbool)) != Bools.value(Bools.pbool))
exit 1
end
if (Bools.const_rbo(Bools.value(Bools.const_rbool)) != Bools.value(Bools.const_rbool))
if (Bools.const_rbo(Bools.const_rbool) != Bools.const_rbool)
print "Runtime test 12 failed\n"
exit 1
end

View File

@ -14,6 +14,12 @@ class MyFoo2 < Foo
end
end
class MyFoo3 < Foo
def ping
5 # error: should return a string
end
end
ok = false
a = MyFoo.new
@ -38,5 +44,16 @@ rescue TypeError
ok = true
end
a = MyFoo3.new
b = launder(a)
begin
b.pong
rescue TypeError
ok = true
end
raise RuntimeError unless ok

View File

@ -0,0 +1,43 @@
require 'primitive_types'
include Primitive_types
raise RuntimeError if val_uchar(255) != 255
raise RuntimeError if val_double(255.5) != 255.5
fail = 0
begin
val_uchar(-1)
rescue RangeError
fail = 1
end
fail = 0
begin
val_uchar(256)
rescue RangeError
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_uchar(256.0)
rescue TypeError
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_uchar("caca")
rescue TypeError
fail = 1
end
raise RuntimeError if fail != 1

View File

@ -9,6 +9,9 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
CPP_TEST_CASES += \
primitive_types \
include $(srcdir)/../common.mk
# Overridden variables here
@ -39,6 +42,6 @@ run_testcase = \
# Clean
%.clean:
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile tcl_clean

View File

@ -35,7 +35,7 @@ if { [ value $const_pbool ] != $bool1} {
exit 1
}
if { [ value $const_rbool ] != $bool2} {
if { $const_rbool != $bool2} {
puts stderr "Runtime test 7 failed"
exit 1
}
@ -61,7 +61,7 @@ if { [ value [ pbo $pbool ] ] != [ value $pbool ]} {
exit 1
}
if { [ const_rbo [ value $const_rbool ] ] != [ value $const_rbool ]} {
if { [ const_rbo $const_rbool ] != $const_rbool } {
puts stderr "Runtime test 12 failed"
exit 1
}

View File

@ -3,6 +3,7 @@ if [ catch { load ./enum_thorough[info sharedlibextension] enum_thorough} err_ms
puts stderr "Could not load shared object:\n$err_msg"
}
if { [speedTest0 $SpeedClass_slow] != $SpeedClass_slow } { puts stderr "speedTest0 failed" }
if { [speedTest4 $SpeedClass_slow] != $SpeedClass_slow } { puts stderr "speedTest4 failed" }
if { [speedTest5 $SpeedClass_slow] != $SpeedClass_slow } { puts stderr "speedTest5 failed" }

View File

@ -9,7 +9,7 @@ set v [malloc_void 32]
set x [foo 3]
if {$x != "foo:int"} {
puts stderr "foo(int) test failed"
puts stderr "foo(int) test failed $x"
exit 1
}

View File

@ -0,0 +1,21 @@
if [ catch { load ./primitive_types[info sharedlibextension] primitive_types} err_msg ] {
puts stderr "Could not load shared object:\n$err_msg"
}
if {[val_int 10] != 10 } { error "bad int map" }
if {[val_schar 10] != 10 } { error "bad char map" }
if {[val_short 10] != 10 } { error "bad schar map" }
if [catch { val_schar 10000 } ] {} else { error "bad schar map" }
if [catch { val_uint -100 } ] {} else { error "bad uint map" }
if [catch { val_uchar -100 } ] {} else { error "bad uchar map" }
if {[val_uint 10] != 10 } { error "bad uint map" }
if {[val_uchar 10] != 10 } { error "bad uchar map" }
if {[val_ushort 10] != 10 } { error "bad ushort map" }

View File

@ -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);

View File

@ -84,7 +84,6 @@ extern "C" {
func = C_SCHEME_FALSE; \
}
#define SWIG_POINTER_DISOWN 1
enum {
SWIG_BARF1_BAD_ARGUMENT_TYPE /* 1 arg */,

View File

@ -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
%{

View File

@ -92,7 +92,7 @@
%typemap(in,checkfn="lua_isuserdata") SWIGTYPE
{
$&ltype 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 ******************************/

View File

@ -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 ******************************/

View File

@ -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

View File

@ -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

View File

@ -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);
}
}

View File

@ -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
View File

@ -0,0 +1 @@
%include <typemaps/cdata.swg>

View File

@ -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);

View File

@ -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);

View File

@ -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);
}

View File

@ -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*);

View 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>

View File

@ -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
}

View File

@ -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;
}
}

View File

@ -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
}
};
}
%}
}

View File

@ -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
View 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);
}
}
%}

View File

@ -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

View File

@ -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 */

View File

@ -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>

View File

@ -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;";

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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") %{

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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 {
$&ltype argp;
SWIG_Python_ConvertPtr($input, (void **)&argp, $&descriptor, SWIG_POINTER_EXCEPTION);
if (SWIG_arg_fail($argnum)) SWIG_fail;
if (argp == NULL) {
SWIG_null_ref("$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
{
$&ltype 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
{
$&ltype resultptr;
resultptr = ($&ltype) 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 {
$&ltype 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 ($&ltype 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 {
$&ltype 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;
}

View File

@ -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

View File

@ -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
View 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>

View File

@ -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

View File

@ -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

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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());
}
}

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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
View File

@ -0,0 +1 @@
%include <typemaps/cdata.swg>

137
Lib/ruby/cstring.i Normal file
View 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);

View File

@ -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__

View File

@ -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;
}
%}

View File

@ -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
View 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

View File

@ -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

View File

@ -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
View 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);
}
%}

View 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
View File

@ -0,0 +1 @@
%insert(initbeforefunc) "swiginit.swg"

1
Lib/ruby/rubymacros.swg Normal file
View File

@ -0,0 +1 @@
%include <typemaps/swigmacros.swg>

View File

@ -1,6 +0,0 @@
/* ------------------------------------------------------------
* --- ANSI/Posix C/C++ types ---
* ------------------------------------------------------------ */
%apply unsigned long { size_t };

View File

@ -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);";

View File

@ -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
View 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

View File

@ -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"

View File

@ -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)

View File

@ -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\");";

View File

@ -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
View 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
View 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")

View File

@ -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
View 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);

View File

@ -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

View File

@ -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>

View File

@ -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
/*

Some files were not shown because too many files have changed in this diff Show More