Perl added to the Unified typemap library, cleaner way to use the library, and 'normalized' macro names

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7707 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-10-24 14:59:05 +00:00
commit 3c65cea431
112 changed files with 3262 additions and 3375 deletions

View file

@ -1,6 +1,63 @@
Version 1.3.27 (October 15, 2005)
=================================
10/24/2005: mmatus
- Perl uses now the unified typemap libray.
- Changes in ruby to use the $track option in typemaps.
- Changes in the unified typemap library to follow the
convention that all macros that are not used in the
C/C++ side starts with %, such as
%delete
%new_array
etc.
- Documenting fragments, see fragments.swg.
- Cleaner way to use the unified typemap library, include
just <typemaps/swigtypes.swg>.
Check some of the supported languages: perl, tcl, ruby,
python.
Always start with the head file, such as
python/python.swg
tcl/tcl8.swg
ruby/ruby.swg
perl5/perl5.swg
and the principal file that invokes the unified library, such as
python/pytypemaps.swg
tcl/tcltypemaps.swg
ruby/rubytypemaps.swg
perl/perltypemaps.swg
The file that provide the specialization for each
language are the one that provides the basic types:
python/pyprimtypes.swg
ruby/rubyprimtypes.swg
tcl/tclprimtypes.swg
perl5/perlprimtypes.swg
and the string manipulation:
python/pystrings.swg
ruby/rubystrings.swg
tcl/tclstrings.swg
perl5/perlstrings.swg
The rest fo the files, such as carray.i, are mostly one
line files that include the proper typemap library
version.
10/23/2005: wuzzeb
Chicken:
+ pointers to member functions finally work properly

View file

@ -155,6 +155,7 @@ CPP_TEST_CASES += \
inherit_void_arg \
inline_initializer \
kind \
langobj \
li_carrays \
li_cdata \
li_cpointer \

View file

@ -73,3 +73,37 @@ const int* globalRet1() {return &GlobalInt;}
int* const globalRet2() {return &GlobalInt;}
%}
%{
struct A
{
};
%}
%inline
{
typedef const A* Acptr;
Acptr opaque(Acptr aptr) {
return aptr;
}
struct B
{
const A ca;
A a;
A* ap;
const A* cap;
Acptr acptr;
};
const B* bar(const B* b) {
return b;
}
B const*& cbar(B const*& b) {
return b;
}
}

View file

@ -0,0 +1,38 @@
%module langobj
#ifndef SWIG_Object
#define SWIG_Object void *
#endif
%inline %{
#ifdef SWIGTCL
#define SWIG_Object Tcl_Obj *
#endif
#ifdef SWIGPYTHON
#define SWIG_Object PyObject *
#endif
#ifdef SWIGRUBY
#define SWIG_Object VALUE
#endif
#ifndef SWIG_Object
#define SWIG_Object void *
#endif
%}
%inline %{
SWIG_Object identity(SWIG_Object x) {
return x;
}
%}

View file

@ -0,0 +1,75 @@
%module li_std_wstring
%include <std_wstring.i>
%inline %{
typedef std::wstring A;
struct B
{
B(const std::wstring& s) : cname(0), name(s), a(s)
{
}
char *cname;
std::wstring name;
A a;
};
wchar_t test_wcvalue(wchar_t x) {
return x;
}
const wchar_t* test_ccvalue(const wchar_t* x) {
return x;
}
wchar_t* test_cvalue(wchar_t* x) {
return x;
}
std::wstring test_value(std::wstring x) {
return x;
}
const std::wstring& test_const_reference(const std::wstring &x) {
return x;
}
void test_pointer(std::wstring *x) {
}
std::wstring *test_pointer_out() {
static std::wstring x = L"x";
return &x;
}
void test_const_pointer(const std::wstring *x) {
}
const std::wstring *test_const_pointer_out() {
static std::wstring x = L"x";
return &x;
}
void test_reference(std::wstring &x) {
}
std::wstring& test_reference_out() {
static std::wstring x = L"x";
return x;
}
void test_throw() throw(std::wstring){
static std::wstring x = L"x";
throw x;
}
%}

View file

@ -9,6 +9,14 @@ srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
CPP_TEST_CASES += \
primitive_types \
li_cstring \
C_TEST_CASES += \
li_cstring \
include $(srcdir)/../common.mk
# Overridden variables here

View file

@ -1,9 +1,18 @@
use enum_thorough;
# Just test an in and out typemap for enum SWIGTYPE and const enum SWIGTYPE & typemaps
if (enum_thorough::speedTest4(SpeedClass_slow) != SpeedClass_slow) {
if (enum_thorough::speedTest4($enum_thorough::SpeedClass::slow) != $enum_thorough::SpeedClass::slow) {
die "speedTest Global 4 failed";
}
if (enum_thorough::speedTest5(SpeedClass_slow) != SpeedClass_slow) {
if (enum_thorough::speedTest5($enum_thorough::SpeedClass::slow) != $enum_thorough::SpeedClass::slow) {
die "speedTest Global 5 failed";
}
if (enum_thorough::speedTest4($enum_thorough::SpeedClass::fast) != $enum_thorough::SpeedClass::fast) {
die "speedTest Global 4 failed";
}
if (enum_thorough::speedTest5($enum_thorough::SpeedClass::fast) != $enum_thorough::SpeedClass::fast) {
die "speedTest Global 5 failed";
}

View file

@ -577,6 +577,22 @@ macro(size_t, pfx, sizet)
using namespace DCTypes;
unsigned int SetPos(cuint& x, cuint& y) {return x + y;}
}
double val_double_2(double x, const double& y = 3.0) {
return x + y;
}
double val_double(double x) {
return x;
}
float val_float_2(float x, const float& y = 3.0) {
return x + y;
}
float val_float(float x) {
return x;
}
%}

View file

@ -456,3 +456,6 @@ li_implicit.py
director_wstring.py
immutable.py
inherit.py
empty.py
virtual_derivation.py
langobj.py

View file

@ -0,0 +1,7 @@
from langobj import *
x ="hello"
if identity(x) != x:
raise RuntimeError

View file

@ -38,3 +38,47 @@ rescue TypeError
end
raise RuntimeError if fail != 1
raise RuntimeError if val_double_2(1.0) != 4.0
raise RuntimeError if val_double_2(1) != 4
raise RuntimeError if val_double_2(1,1) != 2
fail = 0
begin
val_double_2("1.0",1.0)
rescue
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_double_2(1.0,"1.0")
rescue
fail = 1
end
raise RuntimeError if fail != 1
raise RuntimeError if val_float_2(1.0) != 4.0
raise RuntimeError if val_float_2(1) != 4
raise RuntimeError if val_float_2(1,1) != 2
fail = 0
begin
val_float_2("1.0",1.0)
rescue
fail = 1
end
raise RuntimeError if fail != 1
fail = 0
begin
val_float_2(1.0,"1.0")
rescue
fail = 1
end
raise RuntimeError if fail != 1

View file

@ -3,6 +3,5 @@ require 'virtual_derivation'
b = Virtual_derivation::B.new 3
if b.get_a() != b.get_b()
print "something is really wrong ", b.get_a(), "\n"
raise RuntimeError
print "something is still wrong ", b.get_a(), b.get_b(), "\n"
end

View file

@ -11,6 +11,13 @@ top_builddir = @top_builddir@
CPP_TEST_CASES += \
primitive_types \
li_cstring \
li_cwstring \
li_std_wstring
C_TEST_CASES += \
li_cstring \
li_cwstring
include $(srcdir)/../common.mk

View file

@ -18,4 +18,16 @@ if {[val_uchar 10] != 10 } { error "bad uchar map" }
if {[val_ushort 10] != 10 } { error "bad ushort map" }
if {[val_double 10] != 10 } { error "bad double map" }
if {[val_float 10] != 10 } { error "bad double map" }
if [catch { val_float hello } ] {} else { error "bad double map" }
if {[val_char c] != "c" } { error "bad char map" }
if {[val_char "c"] != "c" } { error "bad char map" }
if {[val_char 101] != "e" } { error "bad char map" }

View file

@ -25,6 +25,7 @@
%include "ocaml/ocamlkw.swg"
%include "ruby/rubykw.swg"
%include "tcl/tclkw.swg"
%include "perl5/perlkw.swg"
#endif //__Lib_allkw_swg__

View file

@ -8,11 +8,6 @@
%insert("runtime") "swigerrors.swg"
#ifdef SWIGPERL5
%{
#define SWIG_exception(a,b) SWIG_croak(b)
%}
#endif
#ifdef SWIGPHP4
%{

2
Lib/perl5/carrays.i Normal file
View file

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

1
Lib/perl5/cdata.i Normal file
View file

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

1
Lib/perl5/cmalloc.i Normal file
View file

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

1
Lib/perl5/cpointer.i Normal file
View file

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

1
Lib/perl5/cstring.i Normal file
View file

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

1
Lib/perl5/exception.i Normal file
View file

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

View file

@ -1,583 +1,52 @@
/* -----------------------------------------------------------------------------
* perl5.swg
/* ------------------------------------------------------------
* perl.swg
*
* Perl 5 configuration file
* ----------------------------------------------------------------------------- */
%runtime "swigrun.swg" // Common C API type-checking code
%runtime "perlrun.swg" // Perl runtime functions
%runtime "noembed.h" // undefine Perl5 macros
#define %perlcode %insert("perl")
/* Typemaps for input parameters */
%typemap(in) int, short, long, signed char, enum SWIGTYPE
"$1 = ($1_ltype) SvIV($input);";
%typemap(in) bool
"$1 = SvIV($input) ? true : false;";
%typemap(in) unsigned int, unsigned short, unsigned long, unsigned char
"$1 = ($1_ltype) SvUV($input);";
%typemap(in) char
"$1 = ($1_ltype) *SvPV($input,PL_na);";
%typemap(in) float, double
"$1 = ($1_ltype) SvNV($input);\n";
%typemap(in) long long "$1 = ($1_ltype) strtoll(SvPV($input, PL_na), 0, 0);";
%typemap(in) unsigned long long "$1 = ($1_ltype) strtoull(SvPV($input, PL_na), 0, 0);";
%typemap(in) char *
"if (!SvOK((SV*) $input)) $1 = 0;
else $1 = ($1_ltype) SvPV($input, PL_na);";
%typemap(in) char [ANY]
"$1 = SvPV($input,PL_na);\n";
%typemap(in) SWIGTYPE *, SWIGTYPE [], SWIGTYPE & {
if (SWIG_ConvertPtr($input, (void **) &$1, $1_descriptor,0) < 0) {
SWIG_croak("Type error in argument $argnum of $symname. Expected $1_mangle");
}
}
%typemap(in) void * {
if (SWIG_ConvertPtr($input, (void **) &$1, 0,0) < 0) {
SWIG_croak("Type error in argument $argnum of $symname. Expected $1_mangle");
}
}
/* Object passed by value. Convert to a pointer */
%typemap(in) SWIGTYPE {
$&1_ltype argp;
if (SWIG_ConvertPtr($input,(void **) &argp, $&1_descriptor,0) < 0) {
SWIG_croak("Type error in argument $argnum of $symname. Expected $&1_mangle");
}
$1 = *argp;
}
/* Pointer to a class member */
%typemap(in) SWIGTYPE (CLASS::*) {
if ((SWIG_ConvertPacked($input, (void *) &$1, sizeof($1_type), $1_descriptor,0)) < 0) {
SWIG_croak("Type error in argument $argnum of $symname. Expected $&1_mangle");
}
}
/* Const primitive references. Passed by value */
%typemap(in) const int & (int temp),
const short & (short temp),
const long & (long temp),
const signed char & (signed char temp),
const enum SWIGTYPE & ($*1_ltype temp)
"temp = ($*1_ltype) SvIV($input);
$1 = &temp;";
%typemap(in) const bool & (bool temp)
"temp = SvIV($input) ? true : false;
$1 = &temp;";
%typemap(in) const unsigned int & (unsigned int temp),
const unsigned short & (unsigned short temp),
const unsigned long & (unsigned long temp),
const unsigned char & (unsigned char temp)
"temp = ($*1_ltype) SvUV($input);
$1 = &temp;";
%typemap(in) const float & (float temp),
const double & (double temp)
"temp = ($*1_ltype) SvNV($input);
$1 = &temp;";
%typemap(in) const long long & ($*1_ltype temp)
"temp = ($*1_ltype) strtoll(SvPV($input,PL_na),0,0);
$1 = &temp;";
%typemap(in) const unsigned long long & ($*1_ltype temp)
"temp = ($*1_ltype) strtoull(SvPV($input, PL_na),0,0);
$1 = &temp;";
%typemap(in) const char &(char temp) {
temp = *SvPV($input,PL_na);
$1 = &temp;
}
/* Typemap for output values */
%typemap(out) int, short, long, signed char, bool, enum SWIGTYPE
"ST(argvi) = sv_newmortal();
sv_setiv(ST(argvi++), (IV) $1);";
%typemap(out) unsigned int, unsigned short, unsigned long, unsigned char
"ST(argvi) = sv_newmortal();
sv_setuv(ST(argvi++), (UV) $1);";
%typemap(out) float, double
"ST(argvi) = sv_newmortal();
sv_setnv(ST(argvi++), (double) $1);";
%typemap(out) char
"ST(argvi) = sv_newmortal();
sv_setpvn((SV*)ST(argvi++), &$1, 1);";
%typemap(out) char *
"ST(argvi) = sv_newmortal();
if ($1) {
sv_setpv((SV*)ST(argvi++), (char *) $1);
} else {
sv_setsv((SV*)ST(argvi++), &PL_sv_undef);
}";
%typemap(out) long long {
char temp[256];
sprintf(temp,"%lld", (long long) $1);
ST(argvi) = sv_newmortal();
sv_setpv((SV*)ST(argvi++), temp);
}
%typemap(out) unsigned long long {
char temp[256];
sprintf(temp,"%llu", (unsigned long long) $1);
ST(argvi) = sv_newmortal();
sv_setpv((SV*)ST(argvi++), temp);
}
%typemap(out) SWIGTYPE *, SWIGTYPE [], SWIGTYPE &
"ST(argvi) = sv_newmortal();
SWIG_MakePtr(ST(argvi++), (void *) $1, $1_descriptor, $shadow|$owner);";
%typemap(out) SWIGTYPE
#ifdef __cplusplus
{
$&1_ltype resultobj = new $1_ltype(($1_ltype &)$1);
ST(argvi) = sv_newmortal();
SWIG_MakePtr(ST(argvi++), (void *) resultobj, $&1_descriptor, $shadow|SWIG_OWNER);
}
#else
{
$&1_ltype resultobj = ($&1_ltype) malloc(sizeof($1_type));
memmove(resultobj, &$1, sizeof($1_type));
ST(argvi) = sv_newmortal();
SWIG_MakePtr(ST(argvi++), (void *) resultobj, $&1_descriptor, $shadow|SWIG_OWNER);
}
#endif
/* Dynamic casts */
%typemap(out) SWIGTYPE *DYNAMIC, SWIGTYPE &DYNAMIC {
swig_type_info *ty = SWIG_TypeDynamicCast($1_descriptor, (void **) &$1);
ST(argvi) = sv_newmortal();
SWIG_MakePtr(ST(argvi++), (void *) $1, ty, $shadow|$owner);
}
/* Member pointer */
%typemap(out) SWIGTYPE (CLASS::*) {
ST(argvi) = sv_newmortal();
SWIG_MakePackedObj(ST(argvi), (void *) &$1, sizeof($1_type), $1_descriptor);
argvi++;
}
%typemap(out) void "";
/* Typemap for character array returns */
%typemap(out) char [ANY]
"ST(argvi) = sv_newmortal();
sv_setpv((SV*)ST(argvi++),(char *) $1);";
/* References to primitive types. Return by value */
%typemap(out) const int &,
const short &,
const long &,
const signed char &,
const bool &,
const enum SWIGTYPE &
"ST(argvi) = sv_newmortal();
sv_setiv(ST(argvi++), (IV) *($1));";
%typemap(out) const unsigned int &,
const unsigned short &,
const unsigned long &,
const unsigned char &
"ST(argvi) = sv_newmortal();
sv_setuv(ST(argvi++), (UV) *($1));";
%typemap(out) const float &, const double &
"ST(argvi) = sv_newmortal();
sv_setnv(ST(argvi++), (double) *($1));";
%typemap(out) const long long & {
char temp[256];
sprintf(temp,"%lld", (long long)*($1));
ST(argvi) = sv_newmortal();
sv_setpv((SV*)ST(argvi++), temp);
}
%typemap(out) const unsigned long long & {
char temp[256];
sprintf(temp,"%llu", (unsigned long long)*($1));
ST(argvi) = sv_newmortal();
sv_setpv((SV*)ST(argvi++), temp);
}
%typemap(out) const char &
"ST(argvi) = sv_newmortal();
sv_setpvn((SV*)ST(argvi++), $1, 1);";
/* Variable input */
%typemap(varin) int, short, long, signed char
"$1 = ($1_ltype) SvIV($input);";
%typemap(varin) bool
"$1 = SvIV($input) ? true : false;";
%typemap(varin) unsigned int, unsigned short, unsigned long, unsigned char
"$1 = ($1_ltype) SvUV($input);";
%typemap(varin) char
"$1 = ($1_ltype) *SvPV($input,PL_na);";
%typemap(varin) float, double
"$1 = ($1_ltype) SvNV($input);\n";
%typemap(varin) long long "$1 = ($1_ltype) strtoll(SvPV($input, PL_na), 0, 0);";
%typemap(varin) unsigned long long "$1 = ($1_ltype) strtoull(SvPV($input, PL_na), 0, 0);";
%typemap(varin) SWIGTYPE * {
void *temp;
if (SWIG_ConvertPtr($input, &temp, $1_descriptor,0) < 0) {
croak("Type error in argument $argnum of $symname. Expected $1_mangle");
}
$1 = ($1_ltype) temp;
}
%typemap(varin) SWIGTYPE [ANY] {
int i;
$1_basetype *temp;
$1_basetype *b = ($1_basetype *) $1;
if (SWIG_ConvertPtr($input, (void **) &temp, $1_descriptor,0) < 0) {
croak("Type error in argument $argnum of $symname. Expected $1_mangle");
}
for (i = 0; i < $1_size; i++) b[i] = temp[i];
}
%typemap(varin,warning="462:Unable to set dimensionless array variable") SWIGTYPE []
{
croak("C/C++ variable '$name' is read-only");
}
%typemap(varin) SWIGTYPE & {
void *temp;
if (SWIG_ConvertPtr($input, &temp, $1_descriptor,0) < 0) {
croak("Type error in argument $argnum of $symname. Expected $1_mangle");
}
$1 = *($1_ltype) temp;
}
%typemap(varin) void * {
void *temp;
if (SWIG_ConvertPtr($input, &temp, 0,0) < 0) {
croak("Type error in argument $argnum of $symname. Expected $1_mangle");
}
$1 = temp;
}
/* Object passed by value. Convert to a pointer */
%typemap(varin) SWIGTYPE {
$&1_ltype temp;
if (SWIG_ConvertPtr($input,(void **) &temp, $&1_descriptor,0) < 0) {
croak("Type error in argument $argnum of $symname. Expected $&1_mangle");
}
$1 = *temp;
}
/* Member pointer */
%typemap(varin) SWIGTYPE (CLASS::*) {
char temp[sizeof($1_type)];
if (SWIG_ConvertPacked($input, (void *) temp, sizeof($1_type), $1_descriptor, 0) < 0) {
croak("Type error in argument $argnum of $symname. Expected $&1_mangle");
}
memmove((void *) &$1, temp, sizeof($1_type));
}
/* Const primitive references. Passed by value */
%typemap(varin) const int & (int temp),
const short & (short temp),
const long & (long temp),
const signed char & (signed char temp),
const enum SWIGTYPE & ($*1_ltype temp)
"temp = ($*1_ltype) SvIV($input);
$1 = &temp;";
%typemap(varin) const bool & (bool temp)
"temp = SvIV($input) ? true : false;
$1 = &temp;";
%typemap(varin) const unsigned int & (unsigned int temp),
const unsigned short & (unsigned short temp),
const unsigned long & (unsigned long temp),
const unsigned char & (unsigned char temp)
"temp = ($*1_ltype) SvUV($input);
$1 = &temp;";
%typemap(varin) const float & (float temp),
const double & (double temp)
"temp = ($*1_ltype) SvNV($input);
$1 = &temp;";
%typemap(varin) const long long & ($*1_ltype temp)
"temp = ($1_ltype) strtoll(SvPV($input,PL_na),0,0);
$1 = &temp;";
%typemap(varin) const unsigned long long & ($*1_ltype temp)
"temp = ($1_ltype) strtoull(SvPV($input, PL_na),0,0);
$1 = &temp;";
%typemap(varin) const char &(char temp) {
temp = *SvPV($input,PL_na);
$1 = &temp;
}
%typemap(varin) char *
#ifdef __cplusplus
{
char *_a = (char *) SvPV(sv,PL_na);
if ($1) delete [] $1;
$1 = new char[strlen(_a)+1];
strcpy((char *)$1,_a);
}
#else
{
char *_a = (char *) SvPV(sv,PL_na);
if ($1) free((char *) $1);
$1 = (char *) malloc(strlen(_a)+1);
strcpy((char *)$1,_a);
}
#endif
%typemap(varin,warning="451:Setting const char * variable may leak memory") const char *
#ifdef __cplusplus
{
char *_a = (char *) SvPV(sv,PL_na);
$1 = new char[strlen(_a)+1];
strcpy((char *)$1,_a);
}
#else
{
char *_a = (char *) SvPV(sv,PL_na);
$1 = (char *) malloc(strlen(_a)+1);
strcpy((char *)$1,_a);
}
#endif
%typemap(varin) char [ANY]
"strncpy($1, (char *) SvPV(sv,PL_na), $1_dim0);";
%typemap(varin,warning="462: Unable to set variable of type char []") char []
{ croak("Variable $symname is read-only."); }
%typemap(varin) enum SWIGTYPE {
if (sizeof(int) != sizeof($1)) {
croak("enum variable '$name' can not be set.");
}
*(int *)(void *)&($1) = SvIV($input);
}
/* --- Typemaps for variable output --- */
%typemap(varout) int, short, long, signed char, bool, enum SWIGTYPE
"sv_setiv($result, (IV) $1);";
%typemap(varout) unsigned int, unsigned short, unsigned long, unsigned char
"sv_setuv($result, (UV) $1);";
%typemap(varout) float, double
"sv_setnv($result, (double) $1);";
%typemap(varout) char
"sv_setpvn((SV *) $result, &$1, 1);";
%typemap(varout) long long {
char temp[256];
sprintf(temp,"%lld",(long long)$1);
sv_setpv((SV *) $result, temp);
}
%typemap(varout) unsigned long long {
char temp[256];
sprintf(temp,"%llu",(unsigned long long)$1);
sv_setpv((SV *) $result, temp);
}
%typemap(varout) char *, char [ANY]
"if ($1) {
sv_setpv((SV*)$result, (char *) $1);
} else {
sv_setsv((SV*)$result, &PL_sv_undef);
}";
//%typemap(varout) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
// "SWIG_MakePtr($result, (void *) $1, $1_descriptor);";
%typemap(varout,type="$1_descriptor") SWIGTYPE *, SWIGTYPE []
"sv_setiv(SvRV($result),(IV) $1);";
%typemap(varout,type="$1_descriptor") SWIGTYPE &
"sv_setiv(SvRV($result),(IV) &$1);";
//%typemap(varout) SWIGTYPE
// "SWIG_MakePtr($result, (void *) &$1, $&1_descriptor);";
%typemap(varout,type="$&1_descriptor") SWIGTYPE
"sv_setiv(SvRV($result), (IV) &$1);";
%typemap(varout,type="$1_descriptor") SWIGTYPE (CLASS::*) {
SWIG_MakePackedObj($result, (void *) &$1, sizeof($1_type), $1_descriptor);
}
/* --- Typemaps for constants --- *
/* --- Constants --- */
%typemap(consttab) int, unsigned int, short, unsigned short, long, unsigned long, unsigned char, signed char, bool, enum SWIGTYPE
{ SWIG_INT, (char *) SWIG_prefix "$symname", (long) $value, 0, 0, 0}
%typemap(consttab) float, double
{ SWIG_FLOAT, (char *) SWIG_prefix "$symname", 0, (double) $value, 0, 0}
%typemap(consttab) char, char *
{ SWIG_STRING, (char *) SWIG_prefix "$symname", 0, 0, (void *)$value, 0}
%typemap(consttab) long long, unsigned long long
{ SWIG_STRING, (char *) SWIG_prefix "$symname", 0, 0, (void *) "$value", 0}
%typemap(consttab) SWIGTYPE *, SWIGTYPE &, SWIGTYPE []
{ SWIG_POINTER, (char *) SWIG_prefix "$symname", 0, 0, (void *)$value, &$1_descriptor}
%typemap(consttab) SWIGTYPE (CLASS::*)
{ SWIG_BINARY, (char *) SWIG_prefix "$symname", sizeof($type), 0, (void *)&$value, &$1_descriptor}
/* ------------------------------------------------------------
* String & length
* Perl configuration module.
* ------------------------------------------------------------ */
%typemap(in) (char *STRING, int LENGTH) {
STRLEN temp;
$1 = ($1_ltype) SvPV($input,temp);
$2 = ($2_ltype) temp;
}
/* ------------------------------------------------------------
* Inner macros
* ------------------------------------------------------------ */
%include <perlmacros.swg>
/* ------------------------------------------------------------
* Typechecking rules
* Error manipulation
* ------------------------------------------------------------ */
%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 &,
enum SWIGTYPE, const enum SWIGTYPE &,
bool, const bool &
{
$1 = SvIOK($input) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_DOUBLE)
float, double,
const float &, const double &
{
$1 = SvNIOK($input) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_CHAR) char {
$1 = SvPOK($input) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_STRING) char * {
$1 = SvPOK($input) ? 1 : 0;
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] {
void *tmp;
if (SWIG_ConvertPtr($input, (void **) &tmp, $1_descriptor, 0) == -1) {
$1 = 0;
} else {
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_POINTER) SWIGTYPE {
void *tmp;
if (SWIG_ConvertPtr($input, (void **) &tmp, $&1_descriptor, 0) == -1) {
$1 = 0;
} else {
$1 = 1;
}
}
%typecheck(SWIG_TYPECHECK_VOIDPTR) void * {
void *tmp;
if (SWIG_ConvertPtr($input, (void **) &tmp, 0, 0) == -1) {
$1 = 0;
} else {
$1 = 1;
}
}
%include <perlerrors.swg>
/* ------------------------------------------------------------
* Exception handling
* The runtime part
* ------------------------------------------------------------ */
%typemap(throws) int,
long,
short,
unsigned int,
unsigned long,
unsigned short {
SWIG_SetErrorf("%d", $1); SWIG_fail;
}
/* throws real objects */
%typemap(throws) SWIGTYPE
{
SV *esv=sv_newmortal();
$&1_ltype copy = new $1_ltype(($1_ltype &)$1);
SWIG_MakePtr(esv, (void *) copy,
$&1_descriptor, SWIG_OWNER);
SWIG_croakSV(esv);
}
%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [ANY] %{
(void)$1;
SWIG_croak("C++ $1_type exception thrown");
%}
%typemap(throws) enum SWIGTYPE %{
(void)$1;
SWIG_croak("C++ $1_type exception thrown");
%}
%typemap(throws) char * {
SWIG_croak($1);
}
%include <perlruntime.swg>
/* ------------------------------------------------------------
* ANSI C typemaps
* Special user directives
* ------------------------------------------------------------ */
%include <perluserdir.swg>
/* ------------------------------------------------------------
* Look for user fragments file.
* ------------------------------------------------------------ */
%include "perlfragments.swg"
/* ------------------------------------------------------------
* Typemap specializations
* ------------------------------------------------------------ */
%include <perltypemaps.swg>
/* ------------------------------------------------------------
* Overloaded operator support
* ------------------------------------------------------------ */
%include <perlopers.swg>
/* ------------------------------------------------------------
* Warnings for Perl keywords
* ------------------------------------------------------------ */
%include <perlkw.swg>
/* ------------------------------------------------------------
* The Perl initialization function
* ------------------------------------------------------------ */
%include <perlinit.swg>
%apply unsigned long { size_t };
%include "perlinit.swg"

54
Lib/perl5/perlerrors.swg Normal file
View file

@ -0,0 +1,54 @@
/* -----------------------------------------------------------------------------
* error manipulation
* ----------------------------------------------------------------------------- */
%insert("runtime") "swigerrors.swg"
%insert("header") %{
SWIGINTERN const char*
SWIG_Perl_ErrorType(int code) {
const char* type = 0;
switch(code) {
case SWIG_MemoryError:
type = "MemoryError";
break;
case SWIG_IOError:
type = "IOError";
break;
case SWIG_RuntimeError:
type = "RuntimeError";
break;
case SWIG_IndexError:
type = "IndexError";
break;
case SWIG_TypeError:
type = "TypeError";
break;
case SWIG_DivisionByZero:
type = "ZeroDivisionError";
break;
case SWIG_OverflowError:
type = "OverflowError";
break;
case SWIG_SyntaxError:
type = "SyntaxError";
break;
case SWIG_ValueError:
type = "ValueError";
break;
case SWIG_SystemError:
type = "SystemError";
break;
case SWIG_AttributeError:
type = "AttributeError";
break;
default:
type = "RuntimeError";
}
return type;
}
%}

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

251
Lib/perl5/perlkw.swg Normal file
View file

@ -0,0 +1,251 @@
/* Warnings for Perl keywords */
#define PERLKW(x) %namewarn("314:" `x` " is a perl keyword") `x`
#define PERLBN(x) %namewarn("321:" `x` " conflicts with a built-in name in perl") "::" `x`
/*
From http://www.rocketaware.com/perl/perlfunc/
*/
/* Functions for SCALARs or strings*/
PERLBN(chomp);
PERLBN(chop);
PERLBN(chr);
PERLBN(crypt);
PERLBN(hex);
PERLBN(index);
PERLBN(lc);
PERLBN(lcfirst);
PERLBN(length);
PERLBN(oct);
PERLBN(ord);
PERLBN(pack);
PERLBN(reverse);
PERLBN(rindex);
PERLBN(sprintf);
PERLBN(substr);
PERLBN(uc);
PERLBN(ucfirst);
/* Regular expressions and pattern matching */
PERLBN(m);
PERLBN(pos);
PERLBN(quotemeta);
PERLBN(split);
PERLBN(study);
/* Numeric functions */
PERLBN(abs);
PERLBN(atan2);
PERLBN(cos);
PERLBN(exp);
PERLBN(hex);
PERLBN(int);
PERLBN(log);
PERLBN(oct);
PERLBN(rand);
PERLBN(sin);
PERLBN(sqrt);
PERLBN(srand);
/* Functions for real @ARRAYs*/
PERLBN(pop);
PERLBN(push);
PERLBN(shift);
PERLBN(splice);
PERLBN(unshift);
/* Functions for list data*/
PERLBN(grep);
PERLBN(join);
PERLBN(map);
PERLBN(qw);
PERLBN(reverse);
PERLBN(sort);
PERLBN(unpack);
/* Functions for real %HASHes*/
PERLBN(delete);
PERLBN(each);
PERLBN(exists);
PERLBN(keys);
PERLBN(values);
/* Input and output functions*/
PERLBN(binmode);
PERLBN(close);
PERLBN(closedir);
PERLBN(dbmclose);
PERLBN(dbmopen);
PERLBN(die);
PERLBN(eof);
PERLBN(fileno);
PERLBN(flock);
PERLBN(format);
PERLBN(getc);
PERLBN(print);
PERLBN(printf);
PERLBN(read);
PERLBN(readdir);
PERLBN(rewinddir);
PERLBN(seek);
PERLBN(seekdir);
PERLBN(select);
PERLBN(syscall);
PERLBN(sysread);
PERLBN(sysseek);
PERLBN(syswrite);
PERLBN(tell);
PERLBN(telldir);
PERLBN(truncate);
PERLBN(warn);
PERLBN(write);
/* Functions for fixed length data or records*/
PERLBN(pack);
PERLBN(read);
PERLBN(syscall);
PERLBN(sysread);
PERLBN(syswrite);
PERLBN(unpack);
PERLBN(vec);
/* Functions for filehandles, files, or directories */
PERLBN(chdir);
PERLBN(chmod);
PERLBN(chown);
PERLBN(chroot);
PERLBN(fcntl);
PERLBN(glob);
PERLBN(ioctl);
PERLBN(link);
PERLBN(lstat);
PERLBN(mkdir);
PERLBN(open);
PERLBN(opendir);
PERLBN(readlink);
PERLBN(rename);
PERLBN(rmdir);
PERLBN(stat);
PERLBN(symlink);
PERLBN(umask);
PERLBN(unlink);
PERLBN(utime);
/* Keywords related to the control flow of your perl program */
PERLKW(caller);
PERLKW(continue);
PERLKW(die);
PERLKW(do);
PERLKW(dump);
PERLKW(eval);
PERLKW(exit);
PERLKW(goto);
PERLKW(last);
PERLKW(next);
PERLKW(redo);
PERLKW(return);
PERLKW(sub);
PERLKW(wantarray);
/* Keywords related to scoping */
PERLKW(caller);
PERLKW(import);
PERLKW(local);
PERLKW(my);
PERLKW(package);
PERLKW(use);
/* Miscellaneous functions */
PERLBN("defined");
PERLBN(dump);
PERLBN(eval);
PERLBN(formline);
PERLBN(local);
PERLBN(my);
PERLBN(reset);
PERLBN(scalar);
PERLBN(undef);
PERLBN(wantarray);
/* Functions for processes and process groups */
PERLBN(alarm);
PERLBN(exec);
PERLBN(fork);
PERLBN(getpgrp);
PERLBN(getppid);
PERLBN(getpriority);
PERLBN(kill);
PERLBN(pipe);
PERLBN(setpgrp);
PERLBN(setpriority);
PERLBN(sleep);
PERLBN(system);
PERLBN(times);
PERLBN(wait);
PERLBN(waitpid);
/* Keywords related to perl modules */
PERLKW(do);
PERLKW(import);
PERLKW(no);
PERLKW(package);
PERLKW(require);
PERLKW(use);
/* Keywords related to classes and object-orientedness */
PERLKW(bless);
PERLKW(dbmclose);
PERLKW(dbmopen);
PERLKW(package);
PERLKW(ref);
PERLKW(tie);
PERLKW(tied);
PERLKW(untie);
PERLKW(use);
/* Functions new in perl5 */
PERLBN(abs);
PERLBN(bless);
PERLBN(chomp);
PERLBN(chr);
PERLBN(exists);
PERLBN(formline);
PERLBN(glob);
PERLBN(import);
PERLBN(lc);
PERLBN(lcfirst);
PERLBN(map);
PERLBN(my);
PERLBN(no);
PERLBN(prototype);
PERLBN(qx);
PERLBN(qw);
PERLBN(readline);
PERLBN(readpipe);
PERLBN(ref);
PERLBN(sub);
PERLBN(sysopen);
PERLBN(tie);
PERLBN(tied);
PERLBN(uc);
PERLBN(ucfirst);
PERLBN(untie);
PERLBN(use);
#undef PERLKW
#undef PERLBN

17
Lib/perl5/perlmacros.swg Normal file
View file

@ -0,0 +1,17 @@
/*
in Perl we need to pass the CPerl value, sometimes,
so, we define decl/call macros as needed.
*/
#define SWIG_ASPTR_DECL_ARGS SWIG_PERL_DECL_ARGS_2
#define SWIG_ASPTR_CALL_ARGS SWIG_PERL_CALL_ARGS_2
#define SWIG_ASVAL_DECL_ARGS SWIG_PERL_DECL_ARGS_2
#define SWIG_ASVAL_CALL_ARGS SWIG_PERL_CALL_ARGS_2
#define SWIG_FROM_DECL_ARGS SWIG_PERL_DECL_ARGS_1
#define SWIG_FROM_CALL_ARGS SWIG_PERL_CALL_ARGS_1
%include <typemaps/swigmacros.swg>

52
Lib/perl5/perlopers.swg Normal file
View file

@ -0,0 +1,52 @@
/* ------------------------------------------------------------
* Overloaded operator support
* ------------------------------------------------------------ */
#ifdef __cplusplus
%rename(__add__) *::operator+;
%rename(__pos__) *::operator+();
%rename(__pos__) *::operator+() const;
%rename(__sub__) *::operator-;
%rename(__neg__) *::operator-();
%rename(__neg__) *::operator-() const;
%rename(__mul__) *::operator*;
%rename(__div__) *::operator/;
%rename(__mod__) *::operator%;
%rename(__lshift__) *::operator<<;
%rename(__rshift__) *::operator>>;
%rename(__and__) *::operator&;
%rename(__or__) *::operator|;
%rename(__xor__) *::operator^;
%rename(__invert__) *::operator~;
%rename(__lt__) *::operator<;
%rename(__le__) *::operator<=;
%rename(__gt__) *::operator>;
%rename(__ge__) *::operator>=;
%rename(__eq__) *::operator==;
/* Special cases */
%rename(__call__) *::operator();
/* Ignored operators */
%ignorewarn("378:operator!= ignored") operator!=;
%ignorewarn("365:operator+= ignored") operator+=;
%ignorewarn("366:operator-= ignored") operator-=;
%ignorewarn("367:operator*= ignored") operator*=;
%ignorewarn("368:operator/= ignored") operator/=;
%ignorewarn("369:operator%= ignored") operator%=;
%ignorewarn("375:operator<<= ignored") operator<<=;
%ignorewarn("376:operator>>= ignored") operator>>=;
%ignorewarn("371:operator&= ignored") operator&=;
%ignorewarn("372:operator|= ignored") operator|=;
%ignorewarn("370:operator^= ignored") operator^=;
%ignorewarn("362:operator= ignored") operator=;
%ignorewarn("383:operator++ ignored") operator++;
%ignorewarn("384:operator-- ignored") operator--;
%ignorewarn("381:operator&& ignored") operator&&;
%ignorewarn("382:operator|| ignored") operator||;
// %ignorewarn("387:operator-> ignored") operator->;
%ignorewarn("386:operator->* ignored") operator->*;
%ignorewarn("389:operator[] ignored (consider using %extend)") operator[];
#endif /* __cplusplus */

209
Lib/perl5/perlprimtypes.swg Normal file
View file

@ -0,0 +1,209 @@
/* ------------------------------------------------------------
* Primitive Types
* ------------------------------------------------------------ */
/* boolean */
%fragment(SWIG_From_frag(bool),"header") {
SWIGINTERN SV *
SWIG_From_dec(bool)(bool value)
{
SV *obj = sv_newmortal();
sv_setiv(obj, value ? 1 : 0);
return obj;
}
}
%fragment(SWIG_AsVal_frag(bool),"header",fragment=SWIG_AsVal_frag(long)) {
SWIGINTERN int
SWIG_AsVal_dec(bool)(SV *obj, bool *val)
{
long v;
if (SWIG_AsVal(long)(obj, val ? &v : 0) == SWIG_OK) {
if (val) *val = v ? true : false;
return SWIG_OK;
}
return SWIG_TypeError;
}
}
/* long */
%fragment(SWIG_From_frag(long),"header") {
SWIGINTERNINLINE SV *
SWIG_From_dec(long)(long value)
{
SV *obj = sv_newmortal();
sv_setiv(obj, (IV) value);
return obj;
}
}
%fragment(SWIG_AsVal_frag(long),"header") {
SWIGINTERN int
SWIG_AsVal_dec(long)(SV *obj, long* val)
{
if (SvIOK(obj)) {
if (val) *val = SvIV(obj);
return SWIG_OK;
}
return SWIG_TypeError;
}
}
/* unsigned long */
%fragment(SWIG_From_frag(unsigned long),"header") {
SWIGINTERNINLINE SV *
SWIG_From_dec(unsigned long)(unsigned long value)
{
SV *obj = sv_newmortal();
sv_setuv(obj, (UV) value);
return obj;
}
}
%fragment(SWIG_AsVal_frag(unsigned long),"header") {
SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(SV *obj, unsigned long *val)
{
if (SvUOK(obj)) {
if (val) *val = SvUV(obj);
return SWIG_OK;
} else if (SvIOK(obj)) {
long v = SvIV(obj);
if (v > 0) {
if (val) *val = SvUV(obj);
return SWIG_OK;
} else {
return SWIG_OverflowError;
}
}
return SWIG_TypeError;
}
}
/* long long */
%fragment(SWIG_From_frag(long long),"header",
fragment=SWIG_From_frag(long),
fragment="<limits.h>") {
SWIGINTERNINLINE SV *
SWIG_From_dec(long long)(long long value)
{
if (((long long) LONG_MIN <= value) && (value <= (long long) LONG_MAX)) {
return SWIG_From(long)(%numeric_cast(value,long));
} else {
char temp[256];
SV *obj = sv_newmortal();
snprintf(temp, sizeof(temp),"%lld", value);
sv_setpv(obj, temp);
return obj;
}
}
}
%fragment(SWIG_AsVal_frag(long long),"header") {
SWIGINTERN int
SWIG_AsVal_dec(long long)(SV *obj, long long *val)
{
if (SvIOK(obj)) {
if (val) *val = SvIV(obj);
return SWIG_OK;
} else {
const char *nptr = SvPV(obj, PL_na);
if (nptr) {
char *endptr;
long long v = strtoll(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
}
}
}
}
return SWIG_TypeError;
}
}
/* unsigned long long */
%fragment(SWIG_From_frag(unsigned long long),"header",
fragment=SWIG_From_frag(long long),
fragment="<limits.h>") {
SWIGINTERNINLINE SV *
SWIG_From_dec(unsigned long long)(unsigned long long value)
{
if (value < (unsigned long long) LONG_MAX) {
return SWIG_From(long long)(%numeric_cast(value, long long));
} else {
char temp[256];
SV *obj = sv_newmortal();
snprintf(temp, sizeof(temp),"%llu", value);
sv_setpv(obj, temp);
return obj;
}
}
}
%fragment(SWIG_AsVal_frag(unsigned long long),"header") {
SWIGINTERN int
SWIG_AsVal_dec(unsigned long long)(SV *obj, unsigned long long *val)
{
if (SvUOK(obj)) {
if (val) *val = SvUV(obj);
return SWIG_OK;
} else {
const char *nptr = SvPV(obj, PL_na);
if (nptr) {
char *endptr;
unsigned long long v = strtoull(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
}
}
}
}
return SWIG_TypeError;
}
}
/* double */
%fragment(SWIG_From_frag(double),"header") {
SWIGINTERNINLINE SV *
SWIG_From_dec(double)(double value)
{
SV *obj = sv_newmortal();
sv_setnv(obj, value);
return obj;
}
}
%fragment(SWIG_AsVal_frag(double),"header") {
SWIGINTERN int
SWIG_AsVal_dec(double)(SV *obj, double *val)
{
if (SvNIOK(obj)) {
if (val) *val = SvNV(obj);
return SWIG_OK;
}
return SWIG_TypeError;
}
}

View file

@ -1,183 +1,90 @@
/* ---------------------------------------------------------------------- -*- c -*-
* perl5.swg
/***********************************************************************
* perlrun.swg
*
* Perl5 runtime library
* $Header$
* ----------------------------------------------------------------------------- */
#define SWIGPERL
#define SWIGPERL5
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#ifndef pTHX_
#define pTHX_
#endif
#include <string.h>
#ifdef __cplusplus
}
#endif
/* Macro to call an XS function */
#ifdef PERL_OBJECT
# define SWIG_CALLXS(_name) _name(cv,pPerl)
#else
# ifndef MULTIPLICITY
# define SWIG_CALLXS(_name) _name(cv)
# else
# define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv)
# endif
#endif
/* Contract support */
#define SWIG_contract_assert(expr,msg) if (!(expr)) { SWIG_croak(msg); } else
/* Note: SwigMagicFuncHack is a typedef used to get the C++ compiler to just shut up already */
* This file contains the runtime support for Ruby modules
* and includes code for managing global variables and pointer
* type checking.
*
************************************************************************/
#ifdef PERL_OBJECT
#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *);
#ifdef __cplusplus
extern "C" {
#endif
typedef int (CPerlObj::*SwigMagicFuncHack)(SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
#define SWIGCLASS_STATIC
#define SWIG_PERL_OBJECT_DECL CPerlObj *pPerl,
#define SWIG_PERL_OBJECT_CALL pPerl,
#else
#define MAGIC_PPERL
#define SWIGCLASS_STATIC static
#ifndef MULTIPLICITY
#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
typedef int (*SwigMagicFunc)(SV *, MAGIC *);
#ifdef __cplusplus
extern "C" {
#define SWIG_PERL_OBJECT_DECL
#define SWIG_PERL_OBJECT_CALL
#endif
typedef int (*SwigMagicFuncHack)(SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#else
#define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b)
typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *);
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*SwigMagicFuncHack)(struct interpreter *, SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#endif
#endif
#if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
#define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
#endif
/* Modifications for newer Perl 5.005 releases */
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
# ifndef PL_sv_yes
# define PL_sv_yes sv_yes
# endif
# ifndef PL_sv_undef
# define PL_sv_undef sv_undef
# endif
# ifndef PL_na
# define PL_na na
# endif
#endif
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
#define SWIG_OWNER 1
#define SWIG_SHADOW 2
/* Common SWIG API */
#ifdef PERL_OBJECT
# define SWIG_ConvertPtr(obj, pp, type, flags) \
SWIG_Perl_ConvertPtr(pPerl, obj, pp, type, flags)
# define SWIG_NewPointerObj(p, type, flags) \
SWIG_Perl_NewPointerObj(pPerl, p, type, flags)
# define SWIG_MakePackedObj(sv, p, s, type) \
SWIG_Perl_MakePackedObj(pPerl, sv, p, s, type)
# define SWIG_ConvertPacked(obj, p, s, type, flags) \
SWIG_Perl_ConvertPacked(pPerl, obj, p, s, type, flags)
/* for raw pointers */
#define SWIG_ConvertPtr(obj, pp, type, flags) SWIG_Perl_ConvertPtr(SWIG_PERL_OBJECT_CALL obj, pp, type, flags)
#define SWIG_NewPointerObj(p, type, flags) SWIG_Perl_NewPointerObj(SWIG_PERL_OBJECT_CALL p, type, flags)
/* for raw packed data */
#define SWIG_ConvertPacked(obj, p, s, type) SWIG_Perl_ConvertPacked(SWIG_PERL_OBJECT_CALL obj, p, s, type)
#define SWIG_NewPackedObj(p, s, type) SWIG_Perl_NewPackedObj(SWIG_PERL_OBJECT_CALL p, s, type)
/* for class or struct pointers */
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_ConvertPtr(obj, pptr, type, flags)
#define SWIG_NewInstanceObj(ptr, type, flags) SWIG_NewPointerObj(ptr, type, flags)
/* for C or C++ function pointers */
#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_ConvertPtr(obj, pptr, type, 0)
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_NewPointerObj(ptr, type, 0)
/* for C++ member pointers, ie, member methods */
#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_ConvertPacked(obj, ptr, sz, ty)
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_NewPackedObj(ptr, sz, type)
#else
# define SWIG_ConvertPtr(obj, pp, type, flags) \
SWIG_Perl_ConvertPtr(obj, pp, type, flags)
# define SWIG_NewPointerObj(p, type, flags) \
SWIG_Perl_NewPointerObj(p, type, flags)
# define SWIG_MakePackedObj(sv, p, s, type) \
SWIG_Perl_MakePackedObj(sv, p, s, type )
# define SWIG_ConvertPacked(obj, p, s, type, flags) \
SWIG_Perl_ConvertPacked(obj, p, s, type, flags)
#endif
/* Runtime API */
#define SWIG_GetModule(clientdata) SWIG_Perl_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Perl_SetModule(pointer)
/* Perl-specific API */
#ifdef PERL_OBJECT
# define SWIG_MakePtr(sv, ptr, type, flags) \
SWIG_Perl_MakePtr(pPerl, sv, ptr, type, flags)
# define SWIG_SetError(str) \
SWIG_Perl_SetError(pPerl, str)
#else
# define SWIG_MakePtr(sv, ptr, type, flags) \
SWIG_Perl_MakePtr(sv, ptr, type, flags)
# define SWIG_SetError(str) \
SWIG_Perl_SetError(str)
# define SWIG_SetErrorSV(str) \
SWIG_Perl_SetErrorSV(str)
#define SWIG_GetModule(clientdata) SWIG_Perl_GetModule()
#define SWIG_SetModule(clientdata, pointer) SWIG_Perl_SetModule(pointer)
/* Error manipulation */
#define SWIG_ErrorType(code) SWIG_Perl_ErrorType(code)
#define SWIG_Error(code, msg) sv_setpvf(perl_get_sv("@", TRUE), "%s error %s\n", SWIG_ErrorType(code), msg)
#define SWIG_fail goto fail
/* Perl-specific SWIG API */
#define SWIG_MakePtr(sv, ptr, type, flags) SWIG_Perl_MakePtr(SWIG_PERL_OBJECT_CALL sv, ptr, type, flags)
#define SWIG_MakePackedObj(sv, p, s, type) SWIG_Perl_MakePackedObj(SWIG_PERL_OBJECT_CALL sv, p, s, type)
#define SWIG_SetError(str) SWIG_Error(SWIG_RuntimeError, str)
#define SWIG_PERL_DECL_ARGS_1(arg1) (SWIG_PERL_OBJECT_DECL arg1)
#define SWIG_PERL_CALL_ARGS_1(arg1) (SWIG_PERL_OBJECT_CALL arg1)
#define SWIG_PERL_DECL_ARGS_2(arg1, arg2) (SWIG_PERL_OBJECT_DECL arg1, arg2)
#define SWIG_PERL_CALL_ARGS_2(arg1, arg2) (SWIG_PERL_OBJECT_CALL arg1, arg2)
/* -----------------------------------------------------------------------------
* pointers/data manipulation
* ----------------------------------------------------------------------------- */
#ifdef __cplusplus
extern "C" {
#if 0
} /* cc-mode */
#endif
#endif
#define SWIG_SetErrorf SWIG_Perl_SetErrorf
#define SWIG_OWNER SWIG_POINTER_OWN
#define SWIG_SHADOW SWIG_OWNER << 1
#define SWIG_MAYBE_PERL_OBJECT SWIG_PERL_OBJECT_DECL
#ifdef PERL_OBJECT
# define SWIG_MAYBE_PERL_OBJECT CPerlObj *pPerl,
#else
# define SWIG_MAYBE_PERL_OBJECT
#endif
static swig_cast_info *
SWIGRUNTIME swig_cast_info *
SWIG_Perl_TypeCheckRV(SWIG_MAYBE_PERL_OBJECT SV *rv, swig_type_info *ty) {
SWIG_TypeCheck_Template(sv_derived_from(rv, (char *) iter->type->name), ty);
}
/* Function for getting a pointer value */
static int
SWIGRUNTIME int
SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *_t, int flags) {
swig_cast_info *tc;
void *voidptr = (void *)0;
@ -201,7 +108,7 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *
}
}
} else {
return -1;
return SWIG_ERROR;
}
} else {
tmp = SvIV((SV*)SvRV(sv));
@ -209,37 +116,36 @@ SWIG_Perl_ConvertPtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void **ptr, swig_type_info *
voidptr = (void *)tmp;
if (!_t) {
*(ptr) = voidptr;
return 0;
return SWIG_OK;
}
} else if (! SvOK(sv)) { /* Check for undef */
*(ptr) = (void *) 0;
return 0;
return SWIG_OK;
} else if (SvTYPE(sv) == SVt_RV) { /* Check for NULL pointer */
*(ptr) = (void *) 0;
if (!SvROK(sv))
return 0;
else
return -1;
if (!SvROK(sv)) {
*(ptr) = (void *) 0;
return SWIG_OK;
} else {
return SWIG_ERROR;
}
} else { /* Don't know what it is */
*(ptr) = (void *) 0;
return -1;
return SWIG_ERROR;
}
if (_t) {
/* Now see if the types match */
char *_c = HvNAME(SvSTASH(SvRV(sv)));
tc = SWIG_TypeCheck(_c,_t);
if (!tc) {
*ptr = voidptr;
return -1;
return SWIG_ERROR;
}
*ptr = SWIG_TypeCast(tc,voidptr);
return 0;
return SWIG_OK;
}
*ptr = voidptr;
return 0;
return SWIG_OK;
}
static void
SWIGRUNTIME void
SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, int flags) {
if (ptr && (flags & SWIG_SHADOW)) {
SV *self;
@ -268,15 +174,15 @@ SWIG_Perl_MakePtr(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, swig_type_info *t, i
}
}
static SWIGINLINE SV *
SWIGRUNTIMEINLINE SV *
SWIG_Perl_NewPointerObj(SWIG_MAYBE_PERL_OBJECT void *ptr, swig_type_info *t, int flags) {
SV *result = sv_newmortal();
SWIG_MakePtr(result, ptr, t, flags);
return result;
}
static void
SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) {
SWIGRUNTIME void
SWIG_Perl_MakePackedObj(SWIG_MAYBE_PERL_OBJECT SV *sv, void *ptr, int sz, swig_type_info *type) {
char result[1024];
char *r = result;
if ((2*sz + 1 + strlen(type->name)) > 1000) return;
@ -286,49 +192,35 @@ static void
sv_setpv(sv, result);
}
SWIGRUNTIME SV *
SWIG_Perl_NewPackedObj(SWIG_MAYBE_PERL_OBJECT void *ptr, int sz, swig_type_info *type) {
SV *result = sv_newmortal();
SWIG_Perl_MakePackedObj(result, ptr, sz, type);
return result;
}
/* Convert a packed value value */
static int
SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty, int flags) {
SWIGRUNTIME int
SWIG_Perl_ConvertPacked(SWIG_MAYBE_PERL_OBJECT SV *obj, void *ptr, int sz, swig_type_info *ty) {
swig_cast_info *tc;
const char *c = 0;
if ((!obj) || (!SvOK(obj))) return -1;
if ((!obj) || (!SvOK(obj))) return SWIG_ERROR;
c = SvPV(obj, PL_na);
/* Pointer values must start with leading underscore */
if (*c != '_') return -1;
if (*c != '_') return SWIG_ERROR;
c++;
c = SWIG_UnpackData(c,ptr,sz);
if (ty) {
tc = SWIG_TypeCheck(c,ty);
if (!tc) return -1;
if (!tc) return SWIG_ERROR;
}
return 0;
return SWIG_OK;
}
static SWIGINLINE void
SWIG_Perl_SetError(SWIG_MAYBE_PERL_OBJECT const char *error) {
if (error) sv_setpv(perl_get_sv("@", TRUE), error);
}
static SWIGINLINE void
SWIG_Perl_SetErrorSV(SWIG_MAYBE_PERL_OBJECT SV *error) {
if (error) sv_setsv(perl_get_sv("@", TRUE), error);
}
static void
SWIG_Perl_SetErrorf(const char *fmt, ...) {
va_list args;
va_start(args, fmt);
sv_vsetpvfn(perl_get_sv("@", TRUE), fmt, strlen(fmt), &args, Null(SV**), 0, Null(bool*));
va_end(args);
}
/* Macros for low-level exception handling */
#define SWIG_fail goto fail
#define SWIG_croak(x) { SWIG_SetError(x); goto fail; }
#define SWIG_croakSV(x) { SWIG_SetErrorSV(x); goto fail; }
/* most preprocessors do not support vararg macros :-( */
/* #define SWIG_croakf(x...) { SWIG_SetErrorf(x); goto fail; } */
#define SWIG_croak(x) { SWIG_Error(SWIG_RuntimeError, x); SWIG_fail; }
typedef XS(SwigPerlWrapper);
@ -358,9 +250,6 @@ typedef struct swig_constant_info {
swig_type_info **ptype;
} swig_constant_info;
#ifdef __cplusplus
}
#endif
/* Structure for variable table */
typedef struct {
@ -374,14 +263,15 @@ typedef struct {
#ifndef PERL_OBJECT
#define swig_create_magic(s,a,b,c) _swig_create_magic(s,a,b,c)
#ifndef MULTIPLICITY
static void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *)) {
SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(SV *, MAGIC *), int (*get)(SV *,MAGIC *))
#else
static void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *)) {
SWIGRUNTIME void _swig_create_magic(SV *sv, char *name, int (*set)(struct interpreter*, SV *, MAGIC *), int (*get)(struct interpreter*, SV *,MAGIC *))
#endif
#else
# define swig_create_magic(s,a,b,c) _swig_create_magic(pPerl,s,a,b,c)
static void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *)) {
SWIGRUNTIME void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (CPerlObj::*set)(SV *, MAGIC *), int (CPerlObj::*get)(SV *, MAGIC *))
#endif
{
MAGIC *mg;
sv_magic(sv,sv,'U',(char *) name,strlen(name));
mg = mg_find(sv,'U');
@ -394,7 +284,7 @@ static void _swig_create_magic(CPerlObj *pPerl, SV *sv, const char *name, int (C
}
static swig_module_info *
SWIGRUNTIME swig_module_info *
SWIG_Perl_GetModule() {
static void *type_pointer = (void *)0;
SV *pointer;
@ -410,7 +300,7 @@ SWIG_Perl_GetModule() {
return (swig_module_info *) type_pointer;
}
static void
SWIGRUNTIME void
SWIG_Perl_SetModule(swig_module_info *module) {
SV *pointer;
@ -418,3 +308,10 @@ SWIG_Perl_SetModule(swig_module_info *module) {
pointer = get_sv("swig_runtime_data::type_pointer" SWIG_RUNTIME_VERSION SWIG_TYPE_TABLE_NAME, TRUE);
sv_setiv(pointer, PTR2IV(module));
}
#ifdef __cplusplus
#if 0
{ /* cc-mode */
#endif
}
#endif

101
Lib/perl5/perlruntime.swg Normal file
View file

@ -0,0 +1,101 @@
%insert(runtime) %{
#include <EXTERN.h>
#include <perl.h>
#include <XSUB.h>
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#ifndef pTHX_
#define pTHX_
#endif
#include <string.h>
/* Macro to call an XS function */
#ifdef PERL_OBJECT
# define SWIG_CALLXS(_name) _name(cv,pPerl)
#else
# ifndef MULTIPLICITY
# define SWIG_CALLXS(_name) _name(cv)
# else
# define SWIG_CALLXS(_name) _name(PERL_GET_THX, cv)
# endif
#endif
/* Note: SwigMagicFuncHack is a typedef used to get the C++ compiler to just shut up already */
#ifdef PERL_OBJECT
#define MAGIC_PPERL CPerlObj *pPerl = (CPerlObj *) this;
typedef int (CPerlObj::*SwigMagicFunc)(SV *, MAGIC *);
#ifdef __cplusplus
extern "C" {
#endif
typedef int (CPerlObj::*SwigMagicFuncHack)(SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
#define SWIGCLASS_STATIC
#else
#define MAGIC_PPERL
#define SWIGCLASS_STATIC static
#ifndef MULTIPLICITY
#define SWIG_MAGIC(a,b) (SV *a, MAGIC *b)
typedef int (*SwigMagicFunc)(SV *, MAGIC *);
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*SwigMagicFuncHack)(SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#else
#define SWIG_MAGIC(a,b) (struct interpreter *interp, SV *a, MAGIC *b)
typedef int (*SwigMagicFunc)(struct interpreter *, SV *, MAGIC *);
#ifdef __cplusplus
extern "C" {
#endif
typedef int (*SwigMagicFuncHack)(struct interpreter *, SV *, MAGIC *);
#ifdef __cplusplus
}
#endif
#endif
#endif
#if defined(WIN32) && defined(PERL_OBJECT) && !defined(PerlIO_exportFILE)
#define PerlIO_exportFILE(fh,fl) (FILE*)(fh)
#endif
/* Modifications for newer Perl 5.005 releases */
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
# ifndef PL_sv_yes
# define PL_sv_yes sv_yes
# endif
# ifndef PL_sv_undef
# define PL_sv_undef sv_undef
# endif
# ifndef PL_na
# define PL_na na
# endif
#endif
#include <stdlib.h>
%}
%runtime "swigrun.swg" // Common C API type-checking code
%runtime "perlrun.swg" // Perl runtime functions
%runtime "noembed.h" // undefine Perl5 macros

48
Lib/perl5/perlstrings.swg Normal file
View file

@ -0,0 +1,48 @@
/* ------------------------------------------------------------
* utility methods for char strings
* ------------------------------------------------------------ */
%fragment("SWIG_AsCharPtrAndSize","header") {
SWIGINTERN int
SWIG_AsCharPtrAndSize(SV *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) == SWIG_OK) {
if (cptr) *cptr = vptr;
if (psize) *psize = vptr ? (strlen(vptr) + 1) : 0;
if (alloc) *alloc = SWIG_OLDOBJ;
return SWIG_OK;
} else {
if (SvPOK(obj)) {
STRLEN len = 0;
char *cstr = SvPV(obj, len);
size_t size = len + 1;
if (cptr) {
if (alloc) {
if (*alloc == SWIG_NEWOBJ) {
*cptr = %new_copy_array(cstr, size, char);
} else {
*cptr = cstr;
*alloc = SWIG_OLDOBJ;
}
}
}
if (psize) *psize = size;
return SWIG_OK;
}
}
return SWIG_TypeError;
}
}
%fragment("SWIG_FromCharPtrAndSize","header") {
SWIGINTERNINLINE SV *
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
SV *obj = sv_newmortal();
sv_setpv(obj, carray);
return obj;
}
}

View file

@ -0,0 +1,44 @@
/* -----------------------------------------------------------------------------
* Typemap specializations
* ----------------------------------------------------------------------------- */
/* no director supported in Perl */
#ifdef SWIG_DIRECTOR_TYPEMAPS
#undef SWIG_DIRECTOR_TYPEMAPS
#endif
/* -----------------------------------------------------------------------------
* Basic definitions
*
* ----------------------------------------------------------------------------- */
#define %newpointer_flags $shadow
#define %newinstance_flags $shadow
#define SWIG_Object SV *
#define VOID_Object $result; argvi=0
#define %set_output(obj) $result = obj; argvi++
#define %append_output(obj) if (argvi >= items) EXTEND(sp,1); %set_output(obj)
#define %set_varoutput(obj) sv_setsv($result,obj);
#define %raise(obj, type, desc) sv_setsv(perl_get_sv("@", TRUE), obj); croak(Nullch)
%define %set_constant(name, obj) {
SV *sv = get_sv((char*) SWIG_prefix name, TRUE | 0x2);
sv_setsv(sv, obj);
SvREADONLY_on(sv);
}
%enddef
/* -----------------------------------------------------------------------------
* All the typemaps
* ----------------------------------------------------------------------------- */
%include <perlprimtypes.swg>
%include <perlstrings.swg>
%include <typemaps/swigtypemaps.swg>

View file

@ -0,0 +1,2 @@
#define %perlcode %insert("perl")

View file

@ -1,75 +1,2 @@
//
// SWIG typemaps for std::string
// Roy M. LeCates
// October 23, 2002
//
// Perl 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
%{
#include <string>
%}
namespace std {
class string;
/* Overloading check */
%typemap(typecheck) string = char *;
%typemap(typecheck) const string & = char *;
%typemap(in) string {
STRLEN len;
const char *ptr = SvPV($input, len);
if (!ptr) {
SWIG_croak("Undefined variable in argument $argnum of $symname.");
} else {
$1 = std::string(ptr, len);
}
}
%typemap(in) string *INPUT(std::string temp),
const string & (std::string temp) {
STRLEN len;
const char *ptr = SvPV($input, len);
if (!ptr) {
SWIG_croak("Undefined variable in argument $argnum of $symname.");
} else {
temp.assign(ptr, len);
$1 = &temp;
}
}
%typemap(out) string {
if (argvi >= items) EXTEND(sp, 1); // bump stack ptr, if needed
char *data = const_cast<char*>($1.data());
sv_setpvn($result = sv_newmortal(), data, $1.size());
++argvi;
}
%typemap(out) const string & {
if (argvi >= items) EXTEND(sp, 1); // bump stack ptr, if needed
char *data = const_cast<char*>($1->data());
sv_setpvn($result = sv_newmortal(), data, $1->size());
++argvi;
}
%typemap(throws) const string & {
SWIG_croak($1.c_str());
}
%typemap(throws) string {
SWIG_croak($1.c_str());
}
}
%include <perlstrings.swg>
%include <typemaps/std_string.swg>

View file

@ -1,597 +1 @@
//
// SWIG Typemap library
// Dave Beazley
// May 5, 1997
//
// Perl5 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.
//
/*
The SWIG typemap library provides a language independent mechanism for
supporting output arguments, input values, and other C function
calling mechanisms. The primary use of the library is to provide a
better interface to certain C function--especially those involving
pointers.
*/
// INPUT typemaps.
// These remap a C pointer to be an "INPUT" value which is passed by value
// instead of reference.
/*
The following methods can be applied to turn a pointer into a simple
"input" value. That is, instead of passing a pointer to an object,
you would use a real value instead.
int *INPUT
short *INPUT
long *INPUT
long long *INPUT
unsigned int *INPUT
unsigned short *INPUT
unsigned long *INPUT
unsigned long long *INPUT
unsigned char *INPUT
bool *INPUT
float *INPUT
double *INPUT
To use these, suppose you had a C function like this :
double fadd(double *a, double *b) {
return *a+*b;
}
You could wrap it with SWIG as follows :
%include typemaps.i
double fadd(double *INPUT, double *INPUT);
or you can use the %apply directive :
%include typemaps.i
%apply double *INPUT { double *a, double *b };
double fadd(double *a, double *b);
*/
%define INPUT_TYPEMAP(type, converter)
%typemap(in) type *INPUT(type temp), type &INPUT(type temp) {
temp = (type) converter($input);
$1 = &temp;
}
%typemap(typecheck) type *INPUT = type;
%typemap(typecheck) type &INPUT = type;
%enddef
INPUT_TYPEMAP(float, SvNV);
INPUT_TYPEMAP(double, SvNV);
INPUT_TYPEMAP(int, SvIV);
INPUT_TYPEMAP(long, SvIV);
INPUT_TYPEMAP(short, SvIV);
INPUT_TYPEMAP(signed char, SvIV);
INPUT_TYPEMAP(unsigned int, SvUV);
INPUT_TYPEMAP(unsigned long, SvUV);
INPUT_TYPEMAP(unsigned short, SvUV);
INPUT_TYPEMAP(unsigned char, SvUV);
%typemap(in) bool *INPUT(bool temp), bool &INPUT(bool temp) {
temp = SvIV($input) ? true : false;
$1 = &temp;
}
%typemap(typecheck) bool *INPUT = bool;
%typemap(typecheck) bool &INPUT = bool;
%typemap(in) long long *INPUT($*1_ltype temp), long long &INPUT($*1_ltype temp) {
temp = strtoll(SvPV($input,PL_na), 0, 0);
$1 = &temp;
}
%typemap(typecheck) long long *INPUT = long long;
%typemap(typecheck) long long &INPUT = long long;
%typemap(in) unsigned long long *INPUT($*1_ltype temp), unsigned long long &INPUT($*1_ltype temp) {
temp = strtoull(SvPV($input,PL_na), 0, 0);
$1 = &temp;
}
%typemap(typecheck) unsigned long long *INPUT = unsigned long long;
%typemap(typecheck) unsigned long long &INPUT = unsigned long long;
#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 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, functions will return a Perl 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).:
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 Perl output of the function would be an array containing both
output values.
*/
// Force the argument to be ignored.
%typemap(in,numinputs=0) int *OUTPUT(int temp), int &OUTPUT(int temp),
short *OUTPUT(short temp), short &OUTPUT(short temp),
long *OUTPUT(long temp), long &OUTPUT(long temp),
unsigned int *OUTPUT(unsigned int temp), unsigned int &OUTPUT(unsigned int temp),
unsigned short *OUTPUT(unsigned short temp), unsigned short &OUTPUT(unsigned short temp),
unsigned long *OUTPUT(unsigned long temp), unsigned long &OUTPUT(unsigned long temp),
unsigned char *OUTPUT(unsigned char temp), unsigned char &OUTPUT(unsigned char temp),
signed char *OUTPUT(signed char temp), signed char &OUTPUT(signed char temp),
bool *OUTPUT(bool temp), bool &OUTPUT(bool temp),
float *OUTPUT(float temp), float &OUTPUT(float temp),
double *OUTPUT(double temp), double &OUTPUT(double temp),
long long *OUTPUT($*1_ltype temp), long long &OUTPUT($*1_ltype temp),
unsigned long long *OUTPUT($*1_ltype temp), unsigned long long &OUTPUT($*1_ltype temp)
"$1 = &temp;";
%typemap(argout) int *OUTPUT, int &OUTPUT,
short *OUTPUT, short &OUTPUT,
long *OUTPUT, long &OUTPUT,
signed char *OUTPUT, signed char &OUTPUT,
bool *OUTPUT, bool &OUTPUT
{
if (argvi >= items) {
EXTEND(sp,1);
}
$result = sv_newmortal();
sv_setiv($result,(IV) *($1));
argvi++;
}
%typemap(argout) unsigned int *OUTPUT, unsigned int &OUTPUT,
unsigned short *OUTPUT, unsigned short &OUTPUT,
unsigned long *OUTPUT, unsigned long &OUTPUT,
unsigned char *OUTPUT, unsigned char &OUTPUT
{
if (argvi >= items) {
EXTEND(sp,1);
}
$result = sv_newmortal();
sv_setuv($result,(UV) *($1));
argvi++;
}
%typemap(argout) float *OUTPUT, float &OUTPUT,
double *OUTPUT, double &OUTPUT
{
if (argvi >= items) {
EXTEND(sp,1);
}
$result = sv_newmortal();
sv_setnv($result,(double) *($1));
argvi++;
}
%typemap(argout) long long *OUTPUT, long long &OUTPUT {
char temp[256];
if (argvi >= items) {
EXTEND(sp,1);
}
sprintf(temp,"%lld", (long long)*($1));
$result = sv_newmortal();
sv_setpv($result,temp);
argvi++;
}
%typemap(argout) unsigned long long *OUTPUT, unsigned long long &OUTPUT {
char temp[256];
if (argvi >= items) {
EXTEND(sp,1);
}
sprintf(temp,"%llu", (unsigned long long)*($1));
$result = sv_newmortal();
sv_setpv($result,temp);
argvi++;
}
// 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 Perl 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.
Rather, the modified input value shows up as the return value of the
function. Thus, to apply this function to a Perl variable you might
do this :
$x = neg($x);
*/
%typemap(in) int *INOUT = int *INPUT;
%typemap(in) short *INOUT = short *INPUT;
%typemap(in) long *INOUT = 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 char *INOUT = unsigned char *INPUT;
%typemap(in) signed char *INOUT = signed char *INPUT;
%typemap(in) bool *INOUT = bool *INPUT;
%typemap(in) float *INOUT = float *INPUT;
%typemap(in) double *INOUT = double *INPUT;
%typemap(in) long long *INOUT = long long *INPUT;
%typemap(in) unsigned long long *INOUT = unsigned long long *INPUT;
%typemap(in) int &INOUT = int &INPUT;
%typemap(in) short &INOUT = short &INPUT;
%typemap(in) long &INOUT = long &INPUT;
%typemap(in) unsigned &INOUT = unsigned &INPUT;
%typemap(in) unsigned short &INOUT = unsigned short &INPUT;
%typemap(in) unsigned long &INOUT = unsigned long &INPUT;
%typemap(in) unsigned char &INOUT = unsigned char &INPUT;
%typemap(in) signed char &INOUT = signed char &INPUT;
%typemap(in) bool &INOUT = bool &INPUT;
%typemap(in) float &INOUT = float &INPUT;
%typemap(in) double &INOUT = double &INPUT;
%typemap(in) long long &INOUT = long long &INPUT;
%typemap(in) unsigned long long &INOUT = unsigned long long &INPUT;
%typemap(argout) int *INOUT = int *OUTPUT;
%typemap(argout) short *INOUT = short *OUTPUT;
%typemap(argout) long *INOUT = long *OUTPUT;
%typemap(argout) unsigned *INOUT = unsigned *OUTPUT;
%typemap(argout) unsigned short *INOUT = unsigned short *OUTPUT;
%typemap(argout) unsigned long *INOUT = unsigned long *OUTPUT;
%typemap(argout) unsigned char *INOUT = unsigned char *OUTPUT;
%typemap(argout) signed char *INOUT = signed char *OUTPUT;
%typemap(argout) bool *INOUT = bool *OUTPUT;
%typemap(argout) float *INOUT = float *OUTPUT;
%typemap(argout) double *INOUT = double *OUTPUT;
%typemap(argout) long long *INOUT = long long *OUTPUT;
%typemap(argout) unsigned long long *INOUT = unsigned long long *OUTPUT;
%typemap(argout) int &INOUT = int &OUTPUT;
%typemap(argout) short &INOUT = short &OUTPUT;
%typemap(argout) long &INOUT = long &OUTPUT;
%typemap(argout) unsigned &INOUT = unsigned &OUTPUT;
%typemap(argout) unsigned short &INOUT = unsigned short &OUTPUT;
%typemap(argout) unsigned long &INOUT = unsigned long &OUTPUT;
%typemap(argout) unsigned char &INOUT = unsigned char &OUTPUT;
%typemap(argout) signed char &INOUT = signed char &OUTPUT;
%typemap(argout) bool &INOUT = bool &OUTPUT;
%typemap(argout) float &INOUT = float &OUTPUT;
%typemap(argout) double &INOUT = double &OUTPUT;
%typemap(argout) long long &INOUT = long long &OUTPUT;
%typemap(argout) unsigned long long &INOUT = unsigned long long &OUTPUT;
// REFERENCE
// Accept Perl references as pointers
/*
The following methods make Perl references work like simple C
pointers. References can only be used for simple input/output
values, not C arrays however. It should also be noted that
REFERENCES are specific to Perl and not supported in other
scripting languages at this time.
int *REFERENCE
short *REFERENCE
long *REFERENCE
unsigned int *REFERENCE
unsigned short *REFERENCE
unsigned long *REFERENCE
unsigned char *REFERENCE
float *REFERENCE
double *REFERENCE
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 *REFERENCE);
or you can use the %apply directive :
%include typemaps.i
%apply double *REFERENCE { double *x };
void neg(double *x);
Unlike the INOUT mapping described previous, this approach directly
modifies the value of a Perl reference. Thus, you could use it
as follows :
$x = 3;
neg(\$x);
print "$x\n"; # Should print out -3.
*/
%typemap(in) double *REFERENCE (double dvalue), double &REFERENCE(double dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
printf("Received %d\n", SvTYPE(tempsv));
SWIG_croak("Expected a double reference.");
}
dvalue = SvNV(tempsv);
$1 = &dvalue;
}
%typemap(in) float *REFERENCE (float dvalue), float &REFERENCE(float dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if ((!SvNOK(tempsv)) && (!SvIOK(tempsv))) {
SWIG_croak("expected a double reference");
}
dvalue = (float) SvNV(tempsv);
$1 = &dvalue;
}
%typemap(in) int *REFERENCE (int dvalue), int &REFERENCE (int dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = SvIV(tempsv);
$1 = &dvalue;
}
%typemap(in) short *REFERENCE (short dvalue), short &REFERENCE(short dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (short) SvIV(tempsv);
$1 = &dvalue;
}
%typemap(in) long *REFERENCE (long dvalue), long &REFERENCE(long dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (long) SvIV(tempsv);
$1 = &dvalue;
}
%typemap(in) unsigned int *REFERENCE (unsigned int dvalue), unsigned int &REFERENCE(unsigned int dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (unsigned int) SvUV(tempsv);
$1 = &dvalue;
}
%typemap(in) unsigned short *REFERENCE (unsigned short dvalue), unsigned short &REFERENCE(unsigned short dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (unsigned short) SvUV(tempsv);
$1 = &dvalue;
}
%typemap(in) unsigned long *REFERENCE (unsigned long dvalue), unsigned long &REFERENCE(unsigned long dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (unsigned long) SvUV(tempsv);
$1 = &dvalue;
}
%typemap(in) unsigned char *REFERENCE (unsigned char dvalue), unsigned char &REFERENCE(unsigned char dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (unsigned char) SvUV(tempsv);
$1 = &dvalue;
}
%typemap(in) signed char *REFERENCE (signed char dvalue), signed char &REFERENCE(signed char dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (signed char) SvIV(tempsv);
$1 = &dvalue;
}
%typemap(in) bool *REFERENCE (bool dvalue), bool &REFERENCE(bool dvalue)
{
SV *tempsv;
if (!SvROK($input)) {
SWIG_croak("expected a reference");
}
tempsv = SvRV($input);
if (!SvIOK(tempsv)) {
SWIG_croak("expected a integer reference");
}
dvalue = (bool) SvIV(tempsv);
$1 = &dvalue;
}
%typemap(argout) double *REFERENCE, double &REFERENCE,
float *REFERENCE, float &REFERENCE
{
SV *tempsv;
tempsv = SvRV($arg);
if (!$1) SWIG_croak("expected a reference");
sv_setnv(tempsv, (double) *$1);
}
%typemap(argout) int *REFERENCE, int &REFERENCE,
short *REFERENCE, short &REFERENCE,
long *REFERENCE, long &REFERENCE,
signed char *REFERENCE, unsigned char &REFERENCE,
bool *REFERENCE, bool &REFERENCE
{
SV *tempsv;
tempsv = SvRV($input);
if (!$1) SWIG_croak("expected a reference");
sv_setiv(tempsv, (IV) *$1);
}
%typemap(argout) unsigned int *REFERENCE, unsigned int &REFERENCE,
unsigned short *REFERENCE, unsigned short &REFERENCE,
unsigned long *REFERENCE, unsigned long &REFERENCE,
unsigned char *REFERENCE, unsigned char &REFERENCE
{
SV *tempsv;
tempsv = SvRV($input);
if (!$1) SWIG_croak("expected a reference");
sv_setuv(tempsv, (UV) *$1);
}
/* Overloading information */
%typemap(typecheck) double *INOUT = double;
%typemap(typecheck) bool *INOUT = bool;
%typemap(typecheck) signed char *INOUT = signed char;
%typemap(typecheck) unsigned char *INOUT = unsigned char;
%typemap(typecheck) unsigned long *INOUT = unsigned long;
%typemap(typecheck) unsigned short *INOUT = unsigned short;
%typemap(typecheck) unsigned int *INOUT = unsigned int;
%typemap(typecheck) long *INOUT = long;
%typemap(typecheck) short *INOUT = short;
%typemap(typecheck) int *INOUT = int;
%typemap(typecheck) float *INOUT = float;
%typemap(typecheck) long long *INOUT = long long;
%typemap(typecheck) unsigned long long *INOUT = unsigned long long;
%typemap(typecheck) double &INOUT = double;
%typemap(typecheck) bool &INOUT = bool;
%typemap(typecheck) signed char &INOUT = signed char;
%typemap(typecheck) unsigned char &INOUT = unsigned char;
%typemap(typecheck) unsigned long &INOUT = unsigned long;
%typemap(typecheck) unsigned short &INOUT = unsigned short;
%typemap(typecheck) unsigned int &INOUT = unsigned int;
%typemap(typecheck) long &INOUT = long;
%typemap(typecheck) short &INOUT = short;
%typemap(typecheck) int &INOUT = int;
%typemap(typecheck) float &INOUT = float;
%typemap(typecheck) long long &INOUT = long long;
%typemap(typecheck) unsigned long long &INOUT = unsigned long long;
%include <typemaps/typemaps.swg>

View file

@ -16,14 +16,14 @@ SWIG_AsArgcArgv(PyObject* input,
list = PyList_Check(input);
if (list || PyTuple_Check(input)) {
*argc = list ? PyList_Size(input) : PyTuple_Size(input);
argv = SWIG_new_array(*argc + 1, char*);
argv = %new_array(*argc + 1, char*);
*owner = 1;
for (; i < *argc; ++i) {
PyObject *obj = list ? PyList_GetItem(input,i) : PyTuple_GetItem(input,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);
argv[i] = (alloc == SWIG_NEWOBJ) ? cptr : %new_copy_array(cptr, size, char);
} else {
argv[i] = 0;
}
@ -58,7 +58,7 @@ SWIG_AsArgcArgv(PyObject* input,
argv = SWIG_AsArgcArgv($input, $descriptor(char**), &argc, &owner);
if (!argv) {
$1 = 0; $2 = 0;
SWIG_arg_fail(SWIG_TypeError, "int ARGC, char **ARGV", $argnum);
%argument_fail(SWIG_TypeError, "int ARGC, char **ARGV", $argnum);
} else {
$1 = ($1_ltype) argc;
$2 = ($2_ltype) argv;
@ -69,9 +69,9 @@ SWIG_AsArgcArgv(PyObject* input,
if (owner$argnum) {
size_t i = argc$argnum;
while (i) {
SWIG_delete_array(argv$argnum[--i]);
%delete_array(argv$argnum[--i]);
}
SWIG_delete_array(argv$argnum);
%delete_array(argv$argnum);
}
}

View file

@ -71,9 +71,9 @@
NOTE: remember that if the type contains commas, such as
'std::pair<int,int>', you need to use the macro like:
%attribute_ref(A, SWIG_arg(std::pair<int,int>), pval);
%attribute_ref(A, %arg(std::pair<int,int>), pval);
where SWIG_arg() 'normalize' the type to be understood as a single
where %arg() 'normalize' the type to be understood as a single
argument, otherwise the macro will get confused (see the 'cpp'
documentation).
@ -115,10 +115,10 @@
%ignore Class::get;
#if #__VA_ARGS__ != ""
%ignore Class::__VA_ARGS__;
%_attribute(SWIG_arg(Class), Wrap, SWIG_arg(type),
%_attribute(%arg(Class), Wrap, %arg(type),
attr, _t->get(), _t->__VA_ARGS__(_val))
#else
%_attribute(SWIG_arg(Class), Wrap, SWIG_arg(type),
%_attribute(%arg(Class), Wrap, %arg(type),
attr, _t->get(),
fprintf(stderr,"'attr' is a read-only attribute"))
#endif
@ -127,15 +127,15 @@
%define %_attribute_ref_T(Class, Wrap, type, refname, attr)
%ignore Class::refname();
%ignore Class::refname() const;
%_attribute(SWIG_arg(Class), Wrap, SWIG_arg(type),
%_attribute(%arg(Class), Wrap, %arg(type),
attr, _t->refname(), _t->refname() = _val)
%enddef
%define %attribute_ref_T(Class, Wrap, type, refname, ...)
#if #__VA_ARGS__ == ""
%_attribute_ref_T(SWIG_arg(Class), Wrap, SWIG_arg(type), refname, refname)
%_attribute_ref_T(%arg(Class), Wrap, %arg(type), refname, refname)
#else
%_attribute_ref_T(SWIG_arg(Class), Wrap, SWIG_arg(type), refname, __VA_ARGS__)
%_attribute_ref_T(%arg(Class), Wrap, %arg(type), refname, __VA_ARGS__)
#endif
%enddef
@ -144,9 +144,9 @@
//
%define %attribute(Class, type, attr, get, ...)
%attribute_T(SWIG_arg(Class), SWIG_Mangle(Class), SWIG_arg(type), attr, get, __VA_ARGS__)
%attribute_T(%arg(Class), %mangle(Class), %arg(type), attr, get, __VA_ARGS__)
%enddef
%define %attribute_ref(Class, type, refname, ...)
%attribute_ref_T(SWIG_arg(Class), SWIG_Mangle(Class), SWIG_arg(type), refname, __VA_ARGS__)
%attribute_ref_T(%arg(Class), %mangle(Class), %arg(type), refname, __VA_ARGS__)
%enddef

View file

@ -19,6 +19,6 @@
%swig_cplxdbl_convn(complex, CCplxConst, creal, cimag);
/* declaring the typemaps */
%typemap_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
%typemap_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
%typemap_primitive(SWIG_TYPECHECK_CPLXDBL, complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXFLT, float complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, double complex);
%typemaps_primitive(SWIG_TYPECHECK_CPLXDBL, complex);

View file

@ -1,10 +1 @@
%include <typemaps/cstring.swg>
%include <pystrings.swg>
%typemap_cstrings(%cstring,
char,
SWIG_AsCharPtr,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtr,
SWIG_FromCharPtrAndSize);

View file

@ -1,10 +1,3 @@
%include <typemaps/cstring.swg>
%include <pywstrings.swg>
%typemap_cstrings(%cwstring,
wchar_t,
SWIG_AsWCharPtr,
SWIG_AsWCharPtrAndSize,
SWIG_FromWCharPtr,
SWIG_FromWCharPtrAndSize);
%include <typemaps/cwstring.swg>

View file

@ -37,4 +37,4 @@ SWIG_AsFilePtr(PyObject *obj) {
}
/* defining the typemaps */
%typemap_asval(SWIG_CCode(POINTER), SWIG_AsValFilePtr, "SWIG_AsValFilePtr", FILE*);
%typemaps_asval(%checkcode(POINTER), SWIG_AsValFilePtr, "SWIG_AsValFilePtr", FILE*);

View file

@ -30,7 +30,7 @@ typedef struct swig_const_info {
* Append a value to the result obj
* ----------------------------------------------------------------------------- */
SWIGINTERN PyObject*
SWIG_Python_AppendResult(PyObject* result, PyObject* obj) {
SWIG_Python_AppendOutput(PyObject* result, PyObject* obj) {
if (!result) {
result = obj;
} else if (result == Py_None) {

View file

@ -12,7 +12,7 @@
%fragment(SWIG_From_frag(Type),"header")
{
SWIGINTERNINLINE PyObject*
SWIG_From(Type)(SWIG_cplusplus(const Type&, Type) c)
SWIG_From(Type)(%ifcplusplus(const Type&, Type) c)
{
return PyComplex_FromDoubles(Real(c), Imag(c));
}
@ -46,7 +46,6 @@ SWIG_AsVal(Type) (PyObject *o, Type* val)
/* the float case */
%define %swig_cplxflt_conv(Type, Constructor, Real, Imag)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment="SWIG_CheckDoubleInRange",
fragment=SWIG_AsVal_frag(float)) {
SWIGINTERN int
SWIG_AsVal(Type)(PyObject *o, Type *val)
@ -55,11 +54,11 @@ SWIG_AsVal(Type)(PyObject *o, Type *val)
double re = PyComplex_RealAsDouble(o);
double im = PyComplex_ImagAsDouble(o);
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));
if (val) *val = Constructor(%numeric_cast(re, float),
%numeric_cast(im, float));
return SWIG_OK;
} else {
return SWIG_TypeError;
return SWIG_OverflowError;
}
} else {
float re;

View file

@ -142,7 +142,7 @@ namespace swig
char msg[1024];
snprintf(msg, sizeof(msg), "in sequence element %d ", _index);
if (!PyErr_Occurred()) {
SWIG_type_error(swig::type_name<T>());
%type_error(swig::type_name<T>());
}
SWIG_Python_AddErrorMsg(msg);
SWIG_Python_AddErrorMsg(e.what());
@ -371,7 +371,7 @@ namespace swig
%enddef
%define %swig_sequence_methods_common(Sequence...)
%swig_container_methods(SWIG_arg(Sequence))
%swig_container_methods(%arg(Sequence))
%fragment("PySequence_Base");
%extend {
@ -402,7 +402,7 @@ namespace swig
%enddef
%define %swig_sequence_methods(Sequence...)
%swig_sequence_methods_common(SWIG_arg(Sequence))
%swig_sequence_methods_common(%arg(Sequence))
%extend {
const value_type& __getitem__(difference_type i) const throw (std::out_of_range) {
return *(swig::cgetpos(self, i));
@ -419,7 +419,7 @@ namespace swig
%enddef
%define %swig_sequence_methods_val(Sequence...)
%swig_sequence_methods_common(SWIG_arg(Sequence))
%swig_sequence_methods_common(%arg(Sequence))
%extend {
value_type __getitem__(difference_type i) throw (std::out_of_range) {
return *(swig::cgetpos(self, i));

View file

@ -195,7 +195,7 @@ SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) {
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), 0);
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
break;
default:
obj = 0;

View file

@ -1,19 +1,3 @@
%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
* ------------------------------------------------------------ */
@ -50,33 +34,11 @@ SWIG_AsVal_dec(bool)(PyObject *obj, bool *val)
}
}
/* 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), PyInt_FromLong)
%define_as(SWIG_From_dec(long), PyInt_FromLong)
}
%fragment(SWIG_AsVal_frag(long),"header") {
@ -107,7 +69,7 @@ SWIGINTERNINLINE PyObject*
SWIG_From_dec(unsigned long)(unsigned long value)
{
return (value > LONG_MAX) ?
PyLong_FromUnsignedLong(value) : PyInt_FromLong(SWIG_numeric_cast(value,long));
PyLong_FromUnsignedLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
}
@ -145,7 +107,7 @@ 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));
PyLong_FromLongLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
}
@ -178,7 +140,7 @@ 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));
PyLong_FromUnsignedLongLong(value) : PyInt_FromLong(%numeric_cast(value,long));
}
}
@ -205,15 +167,10 @@ SWIG_AsVal_dec(unsigned long long)(PyObject *obj, unsigned long long *val)
}
}
/* 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)
%define_as(SWIG_From_dec(double), PyFloat_FromDouble)
}
%fragment(SWIG_AsVal_frag(double),"header") {
@ -239,70 +196,5 @@ SWIG_AsVal_dec(double)(PyObject *obj, double *val)
}
}
/* 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

@ -15,19 +15,19 @@
#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)
#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty)
#define SWIG_NewPackedObj(ptr, sz, type) 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_ConvertFunctionPtr(obj, pptr, type) SWIG_Python_ConvertPtr(obj, pptr, type, 0)
#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_ConvertMember(obj, ptr, sz, ty) SWIG_Python_ConvertPacked(obj, ptr, sz, ty)
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Python_NewPackedObj(ptr, sz, type)
@ -504,7 +504,7 @@ SWIG_Python_ConvertPtr(PyObject *obj, void **ptr, swig_type_info *ty, int flags)
/* Convert a packed value value */
SWIGRUNTIME int
SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty, int flags) {
SWIG_Python_ConvertPacked(PyObject *obj, void *ptr, size_t sz, swig_type_info *ty) {
swig_cast_info *tc;
const char *c = 0;

View file

@ -74,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) SWIG_delete(p);
if (res == SWIG_NEWOBJ) %delete(p);
return SWIG_OK;
} else {
return SWIG_ERROR;
@ -114,7 +114,7 @@ namespace swig {
Type v;
if (!obj || (asval(obj, &v) != SWIG_OK)) {
if (!PyErr_Occurred()) {
SWIG_type_error(swig::type_name<Type>());
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
}
@ -130,7 +130,7 @@ namespace swig {
if (res && v) {
if (res == SWIG_NEWOBJ) {
Type r(*v);
SWIG_delete(v);
%delete(v);
return r;
} else {
return *v;
@ -139,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>());
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
memset(v_def,0,sizeof(Type));
@ -157,7 +157,7 @@ namespace swig {
return v;
} else {
if (!PyErr_Occurred()) {
SWIG_type_error(swig::type_name<Type>());
%type_error(swig::type_name<Type>());
}
if (throw_error) throw std::invalid_argument("bad type");
return 0;
@ -252,8 +252,8 @@ namespace swig {
%enddef
#define specialize_std_vector(Type,Check,As,From) %specialize_std_container(SWIG_arg(Type),Check,As,From)
#define specialize_std_list(Type,Check,As,From) %specialize_std_container(SWIG_arg(Type),Check,As,From)
#define specialize_std_deque(Type,Check,As,From) %specialize_std_container(SWIG_arg(Type),Check,As,From)
#define specialize_std_set(Type,Check,As,From) %specialize_std_container(SWIG_arg(Type),Check,As,From)
#define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(SWIG_arg(Type),Check,As,From)
#define specialize_std_vector(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_list(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_deque(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_set(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)
#define specialize_std_multiset(Type,Check,As,From) %specialize_std_container(%arg(Type),Check,As,From)

View file

@ -35,7 +35,7 @@ SWIG_AsCharPtrAndSize(PyObject *obj, char** cptr, size_t* psize, int *alloc)
if (*alloc == SWIG_NEWOBJ)
#endif
{
*cptr = SWIG_new_copy_array(cstr, len + 1, char);
*cptr = %new_copy_array(cstr, len + 1, char);
*alloc = SWIG_NEWOBJ;
}
else {
@ -60,10 +60,10 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
if (carray) {
if (size > INT_MAX) {
return SWIG_NewPointerObj(SWIG_const_cast(carray,char *),
return SWIG_NewPointerObj(%const_cast(carray,char *),
SWIG_TypeQuery("char *"), 0);
} else {
return PyString_FromStringAndSize(carray, SWIG_numeric_cast(size,int));
return PyString_FromStringAndSize(carray, %numeric_cast(size,int));
}
} else {
Py_INCREF(Py_None);
@ -72,9 +72,4 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
}
}
/* ------------------------------------------------------------
* The plain char * handling
* ------------------------------------------------------------ */
%include <typemaps/strings.swg>
%typemap_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen)

View file

@ -1,5 +1,3 @@
%include <typemaps/swigtype.swg>
/* ------------------------------------------------------------
* --- Consttab --- needed for callbacks, it should be removed later.
* ------------------------------------------------------------ */

View file

@ -5,4 +5,4 @@
*/
#warning "Deprecated file: Don't use t_output_helper anymore,"
#warning "use SWIG_Python_AppendResult or SWIG_append_result instead."
#warning "use SWIG_Python_AppendOutput or %append_output instead."

View file

@ -16,37 +16,30 @@
* Basic definitions
* ----------------------------------------------------------------------------- */
%define_swig_object(PyObject *)
#define SWIG_Object PyObject *
#define VOID_Object (Py_INCREF(Py_None) ? Py_None : 0)
#define SWIG_VoidObject() (Py_INCREF(Py_None) ? Py_None : 0)
#define SWIG_SetResultObj(obj) $result = obj
#define SWIG_AppendResultObj(obj) $result = SWIG_Python_AppendResult($result, obj)
#define SWIG_SetConstantObj(name, obj) SWIG_block(PyObject *_obj = obj; PyDict_SetItemString(d, name, _obj); Py_DECREF(_obj))
#define SWIG_Raise(obj, type, desc) PyObject *_obj = obj; PyErr_SetObject(SWIG_Python_ExceptionType(desc), _obj); Py_DECREF(_obj)
#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg)
#define SWIG_AppendOutput(result,obj) SWIG_Python_AppendOutput(result, obj)
#define SWIG_SetConstant(name, obj) %block(PyObject *_obj = obj; PyDict_SetItemString(d, name, _obj); Py_DECREF(_obj))
#define SWIG_Raise(obj, type, desc) PyObject *_obj = obj; PyErr_SetObject(SWIG_Python_ExceptionType(desc), _obj); Py_DECREF(_obj)
#define SWIG_DirOutFail(code, msg) Swig::DirectorTypeMismatchException::raise(SWIG_ErrorType(code), msg)
/* -----------------------------------------------------------------------------
* All the typemaps
* ----------------------------------------------------------------------------- */
%include <typemaps/exception.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>
%include <typemaps/swigtypemaps.swg>
/* fix for callbacks */
%include <pyswigtype.swg>
/* -----------------------------------------------------------------------------
* Backward compatibility output helper
* ----------------------------------------------------------------------------- */
%fragment("t_output_helper","header") %{
#define t_output_helper SWIG_Python_AppendResult
#define t_output_helper SWIG_Python_AppendOutput
%}

View file

@ -25,7 +25,7 @@ SWIG_AsWCharPtrAndSize(PyObject *obj, wchar_t **cptr, size_t *psize, int *alloc)
if (isunicode) {
int len = PyUnicode_GetSize(obj);
if (cptr) {
*cptr = SWIG_new_array(len + 1, wchar_t);
*cptr = %new_array(len + 1, wchar_t);
PyUnicode_AsWideChar((PyUnicodeObject *)obj, *cptr, len);
(*cptr)[len] = 0;
}
@ -45,10 +45,10 @@ SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
{
if (carray) {
if (size > INT_MAX) {
return SWIG_NewPointerObj(SWIG_const_cast(carray,wchar_t *),
return SWIG_NewPointerObj(%const_cast(carray,wchar_t *),
SWIG_TypeQuery("wchar_t *"), 0);
} else {
return PyUnicode_FromWideChar(carray, SWIG_numeric_cast(size,int));
return PyUnicode_FromWideChar(carray, %numeric_cast(size,int));
}
} else {
Py_INCREF(Py_None);
@ -57,10 +57,4 @@ SWIG_FromWCharPtrAndSize(const wchar_t * carray, size_t size)
}
}
/* ------------------------------------------------------------
* The plain wchar_t * handling
* ------------------------------------------------------------ */
%include <typemaps/strings.swg>
%typemap_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen);

View file

@ -23,7 +23,7 @@ SWIG_AsPtr(std::basic_string<char>)(PyObject* obj, std::string **val)
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);
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
return SWIG_NEWOBJ;
}
} else {
@ -47,7 +47,7 @@ SWIGINTERNINLINE PyObject*
}
%include <std/std_basic_string.i>
%typemap_asptrfromn(SWIG_CCode(STRING), std::basic_string<char>);
%typemaps_asptrfromn(%checkcode(STRING), std::basic_string<char>);
#endif
@ -71,7 +71,7 @@ SWIGINTERN int
if (SWIG_AsWCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
if (buf) {
if (val) *val = new std::wstring(buf, size - 1);
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(buf);
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
return SWIG_NEWOBJ;
}
} else {
@ -94,6 +94,6 @@ SWIGINTERNINLINE PyObject*
}
}
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::basic_string<wchar_t>);
%typemaps_asptrfromn(%checkcode(UNISTRING), std::basic_string<wchar_t>);
#endif

View file

@ -4,6 +4,8 @@
%include <pycomplex.swg>
%{
#include <complex>
%}
@ -17,6 +19,8 @@
std::complex<float>, std::real, std::imag)
%typemap_primitive(SWIG_CCode(CPLXDBL), std::complex<double>);
%typemap_primitive(SWIG_CCode(CPLXFLT), std::complex<float>);
%typemaps_primitive(%checkcode(CPLXDBL), std::complex<double>);
%typemaps_primitive(%checkcode(CPLXFLT), std::complex<float>);

View file

@ -16,14 +16,14 @@
T *pfirst = 0;
U *psecond = 0;
if (val) {
*val = SWIG_new(std::pair<T,U>);
*val = %new_instance(std::pair<T,U>);
pfirst = &((*val)->first);
psecond = &((*val)->second);
}
if ((swig::asval(first,pfirst) == SWIG_OK) && (swig::asval(second,psecond) == SWIG_OK)) {
return SWIG_NEWOBJ;
} else {
SWIG_delete(*val);
%delete(*val);
}
} else {
value_type *p;

View file

@ -1,30 +1 @@
//
// std::string
//
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_STRING
%{
#include <string>
%}
namespace std
{
class string;
}
%include <typemaps/std_string.swg>
%include <pystrings.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,31 +1,3 @@
//
// std::wstring
//
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_WSTRING
%{
#include <cwchar>
#include <string>
%}
namespace std
{
class wstring;
}
%include <typemaps/std_string.swg>
%include <pywstrings.swg>
%include <typemaps/std_wstring.swg>
%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);
#else
%include <std/std_wstring.i>
#endif

View file

@ -1,10 +1 @@
%include <typemaps/cstring.swg>
%include <rubystrings.swg>
%typemap_cstrings(%cstring,
char,
SWIG_AsCharPtr,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtr,
SWIG_FromCharPtrAndSize);

View file

@ -7,7 +7,7 @@ extern "C" {
#endif
SWIGINTERN VALUE
SWIG_Ruby_AppendResult(VALUE target, VALUE o) {
SWIG_Ruby_AppendOutput(VALUE target, VALUE o) {
if (NIL_P(target)) {
target = o;
} else {

View file

@ -1,33 +1,30 @@
%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
* ------------------------------------------------------------ */
/* auxiliar ruby fail method */
%fragment("SWIG_ruby_failed","header")
{
SWIGINTERN VALUE
SWIG_ruby_failed()
{
return Qnil;
}
}
%define %ruby_aux_method(Type, Method, Action)
SWIGINTERN VALUE SWIG_AUX_##Method##(VALUE *args)
{
VALUE obj = args[0];
VALUE type = TYPE(obj);
Type *res = (Type *)(args[1]);
*res = Action;
return obj;
}
%enddef
/* boolean */
@ -61,48 +58,24 @@ SWIG_AsVal_dec(bool)(VALUE obj, bool *val)
}
}
/* 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)
%define_as(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];
}
%ruby_aux_method(long, NUM2LONG, type == T_FIXNUM ? NUM2LONG(obj) : rb_big2long(obj))
SWIGINTERN int
SWIG_AsVal_dec(long)(VALUE obj, long* val)
{
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
VALUE type = TYPE(obj);
if ((type == T_FIXNUM) || (type == 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 (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
if (val) *val = v;
return SWIG_OK;
}
@ -123,18 +96,16 @@ SWIG_From_dec(unsigned long)(unsigned long 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];
}
%ruby_aux_method(unsigned long, NUM2ULONG, type == T_FIXNUM ? NUM2ULONG(obj) : rb_big2ulong(obj))
SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(VALUE obj, unsigned long *val)
{
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
VALUE type = TYPE(obj);
if ((type == T_FIXNUM) || (type == 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 (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULONG), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
if (val) *val = v;
return SWIG_OK;
}
@ -156,18 +127,16 @@ SWIG_From_dec(long long)(long long 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];
}
%ruby_aux_method(long long, NUM2LL, type == T_FIXNUM ? NUM2LL(obj) : rb_big2ll(obj))
SWIGINTERN int
SWIG_AsVal_dec(long long)(VALUE obj, long long *val)
{
if (obj != Qnil && ((TYPE(obj) == T_FIXNUM) || (TYPE(obj) == T_BIGNUM))) {
VALUE type = TYPE(obj);
if ((type == T_FIXNUM) || (type == 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 (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2LL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
if (val) *val = v;
return SWIG_OK;
}
@ -189,18 +158,16 @@ SWIG_From_dec(unsigned long long)(unsigned long long 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];
}
%ruby_aux_method(long long, NUM2ULL, type == T_FIXNUM ? NUM2ULL(obj) : rb_big2ull(obj))
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))) {
{
VALUE type = TYPE(obj);
if ((type == T_FIXNUM) || (type == 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 (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2ULL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
if (val) *val = v;
return SWIG_OK;
}
@ -209,30 +176,23 @@ SWIG_AsVal_dec(unsigned long long)(VALUE obj, unsigned long long *val)
}
}
/* 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)
%define_as(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];
}
%ruby_aux_method(double, NUM2DBL, (type == T_FLOAT ? NUM2DBL(obj) : (type == T_FIXNUM ? (double) FIX2INT(obj) : rb_big2dbl(obj))))
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))) {
VALUE type = TYPE(obj);
if ((type == T_FLOAT) || (type == T_FIXNUM) || (type == 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 (rb_rescue(RUBY_METHOD_FUNC(SWIG_AUX_NUM2DBL), (VALUE)a, RUBY_METHOD_FUNC(SWIG_ruby_failed), 0) != Qnil) {
if (val) *val = v;
return SWIG_OK;
}
@ -241,77 +201,4 @@ SWIG_AsVal_dec(double)(VALUE obj, double *val)
}
}
/* 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;
}
}
/* ------------------------------------------------------------
* Apply the primitive typemap for all the types with checkcode
* ------------------------------------------------------------ */
%apply_checkctypes(%typemap_primitive)

View file

@ -12,19 +12,19 @@
#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)
#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty, flags)
#define SWIG_NewPackedObj(ptr, sz, type) 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_ConvertFunctionPtr(obj, pptr, type) SWIG_Ruby_ConvertPtr(obj, pptr, type, 0)
#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_ConvertMember(obj, ptr, sz, ty) SWIG_Ruby_ConvertPacked(obj, ptr, sz, ty)
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Ruby_NewPackedObj(ptr, sz, type)
@ -44,7 +44,7 @@
/* Ruby-specific SWIG API */
#define SWIG_InitRuntime() SWIG_Ruby_InitRuntime()
#define SWIG_define_class(ty) SWIG_Ruby_define_class(ty)
#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)
@ -243,7 +243,7 @@ SWIG_Ruby_NewPackedObj(void *ptr, int sz, swig_type_info *type) {
/* Convert a packed value value */
SWIGRUNTIME int
SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty, int flags) {
SWIG_Ruby_ConvertPacked(VALUE obj, void *ptr, int sz, swig_type_info *ty) {
swig_cast_info *tc;
const char *c;

View file

@ -21,7 +21,7 @@ SWIG_AsCharPtrAndSize(VALUE obj, char** cptr, size_t* psize, int *alloc)
if (cptr) {
if (alloc) {
if (*alloc == SWIG_NEWOBJ) {
*cptr = SWIG_new_copy_array(cstr, size, char);
*cptr = %new_copy_array(cstr, size, char);
} else {
*cptr = cstr;
*alloc = SWIG_OLDOBJ;
@ -42,9 +42,9 @@ 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);
return SWIG_NewPointerObj(%const_cast(carray,char *), SWIG_TypeQuery("char *"), 0);
} else {
return rb_str_new(carray, SWIG_numeric_cast(size,long));
return rb_str_new(carray, %numeric_cast(size,long));
}
} else {
return Qnil;
@ -52,9 +52,3 @@ SWIG_FromCharPtrAndSize(const char* carray, size_t size)
}
}
/* ------------------------------------------------------------
* The plain char * handling
* ------------------------------------------------------------ */
%include <typemaps/strings.swg>
%typemap_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen)

View file

@ -10,37 +10,31 @@
/* -----------------------------------------------------------------------------
* Basic definitions
* ----------------------------------------------------------------------------- */
#define %convertptr_flags $track
#define %newpointer_flags $track
#define %newinstance_flags $track
%define_swig_object(VALUE)
#define SWIG_Object VALUE
#define VOID_Object Qnil
#define SWIG_VoidObject() Qnil
#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_Raise(obj, type, desc) 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)
#define SWIG_AppendOutput(result,obj) SWIG_Ruby_AppendOutput(result, obj)
#define SWIG_SetConstant(name, obj) rb_define_const($module, name, obj)
#define SWIG_Raise(obj, type, desc) 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 <typemaps/exception.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>
%include <typemaps/swigtypemaps.swg>
/* -----------------------------------------------------------------------------
* Backward compatibility output helper
* ----------------------------------------------------------------------------- */
%fragment("output_helper","header") %{
#define output_helper SWIG_Ruby_AppendResult
#define output_helper SWIG_Ruby_AppendOutput
%}

View file

@ -1,74 +0,0 @@
/* ------------------------------------------------------------
* 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,30 +1 @@
//
// std::string
//
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_STRING
%{
#include <string>
%}
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

@ -160,11 +160,11 @@ namespace swig {
*/
%define %typemap_traits(Code,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)),
%typemaps_asvalfrom(%arg(Code),
%arg(swig::asval<Type >),
%arg(swig::from),
%arg(SWIG_Traits_frag(Type)),
%arg(SWIG_Traits_frag(Type)),
Type);
%enddef
@ -174,11 +174,11 @@ namespace swig {
*/
%define %typemap_traits_ptr(Code,Type...)
%typemap_asptrfrom(SWIG_arg(Code),
SWIG_arg(swig::asptr),
SWIG_arg(swig::from),
SWIG_arg(SWIG_Traits_frag(Type)),
SWIG_arg(SWIG_Traits_frag(Type)),
%typemaps_asptrfrom(%arg(Code),
%arg(swig::asptr),
%arg(swig::from),
%arg(SWIG_Traits_frag(Type)),
%arg(SWIG_Traits_frag(Type)),
Type);
%enddef

View file

@ -37,7 +37,7 @@
%define %std_sequence_methods_common(sequence)
%std_container_methods(SWIG_arg(sequence));
%std_container_methods(%arg(sequence));
sequence(size_type size);
void pop_back();
@ -55,7 +55,7 @@
%define %std_sequence_methods(sequence)
%std_sequence_methods_common(SWIG_arg(sequence));
%std_sequence_methods_common(%arg(sequence));
sequence(size_type size, const value_type& value);
void push_back(const value_type& x);
@ -76,7 +76,7 @@
%define %std_sequence_methods_val(sequence...)
%std_sequence_methods_common(SWIG_arg(sequence));
%std_sequence_methods_common(%arg(sequence));
sequence(size_type size, value_type value);
void push_back(value_type x);

View file

@ -1,10 +1 @@
%include <typemaps/cstring.swg>
%include <tclstrings.swg>
%typemap_cstrings(%cstring,
char,
SWIG_AsCharPtr,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtr,
SWIG_FromCharPtrAndSize);

View file

@ -1,10 +1,2 @@
%include <typemaps/cstring.swg>
%include <pywstrings.swg>
%typemap_cstrings(%cwstring,
wchar_t,
SWIG_AsWCharPtr,
SWIG_AsWCharPtrAndSize,
SWIG_FromWCharPtr,
SWIG_FromWCharArray);
%include <tclwstrings.swg>
%include <typemaps/cwstring.swg>

View file

@ -1,37 +1,2 @@
//
// std::string
//
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_STRING
%{
#include <string>
%}
namespace std
{
class string;
}
%include <typemaps/std_string.swg>
%include <tclstrings.swg>
%fragment("Tcl_std_string_asptr","header",fragment="SWIG_AsCharPtrAndSize") {
%tcl_asptr_decl(std::string)
}
%fragment("Tcl_std_string_asval","header",fragment="Tcl_std_string_asptr") {
%tcl_asptr_decl(std::string)
}
%std_string_asptr_frag(std::string, char, SWIG_AsCharPtrAndSize, "Tcl_std_string_asptr")
%std_string_asval_frag(std::string, "Tcl_std_string_asval")
%std_string_from(std::string, SWIG_FromCharPtrAndSize)
%typemap_asptrfromn(SWIG_CCode(STRING), std::string);
#else
%include <std/std_string.i>
#endif

View file

@ -1,37 +1,2 @@
//
// std::wstring
//
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_WSTRING
%{
#include <string>
%}
namespace std
{
class wstring;
}
%include <typemaps/std_string.i>
%include <tclwstrings.swg>
%fragment("Tcl_std_wstring_asptr","header",fragment="SWIG_AsCharPtrAndSize") {
%tcl_asptr_decl(std::wstring)
}
%fragment("Tcl_std_wstring_asval","header",fragment="Tcl_std_wstring_asptr") {
%tcl_asptr_decl(std::wstring)
}
%std_string_asptr_frag(std::wstring, wchar_t, SWIG_AsCharPtrAndSize, "Tcl_std_wstring_asptr")
%std_string_asval_frag(std::wstring, "Tcl_std_wstring_asval")
%std_string_from(std::wstring, SWIG_FromCharPtrAndSize)
%typemap_asptrfromn(SWIG_CCode(UNISTRING), std::wstring);
#else
%include <std/std_string.i>
#endif
%include <typemaps/std_wstring.swg>

View file

@ -64,6 +64,8 @@ SWIG_Tcl_SetErrorMsg(Tcl_Interp *interp, const char *ctype, const char *mesg)
{
Tcl_ResetResult(interp);
Tcl_SetErrorCode(interp, "SWIG", ctype, NULL);
Tcl_AddErrorInfo(interp, ctype);
Tcl_AddErrorInfo(interp, " ");
Tcl_AddErrorInfo(interp, mesg);
}

View file

@ -50,7 +50,7 @@ SWIG_Tcl_InstallConstants(Tcl_Interp *interp, swig_const_info constants[]) {
obj = SWIG_NewPointerObj(constants[i].pvalue, *(constants[i]).ptype,0);
break;
case SWIG_TCL_BINARY:
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype),0);
obj = SWIG_NewPackedObj(constants[i].pvalue, constants[i].lvalue, *(constants[i].ptype));
break;
default:
obj = 0;

View file

@ -1,26 +1,15 @@
/*
in Tcl we need to pass the interp value, so, we
define decl/call macros as needed.
*/
#define SWIG_ASPTR_DECL_ARGS SWIG_TCL_DECL_ARGS_2
#define SWIG_ASPTR_CALL_ARGS SWIG_TCL_CALL_ARGS_2
#define SWIG_ASVAL_DECL_ARGS SWIG_TCL_DECL_ARGS_2
#define SWIG_ASVAL_CALL_ARGS SWIG_TCL_CALL_ARGS_2
%include <typemaps/swigmacros.swg>
/* aux macros to deal with the interp argument */
#undef SWIG_As_dec
#undef SWIG_AsPtr_dec
#undef SWIG_AsVal_dec
#define SWIG_Tcl_AsVal(Type...) SWIG_Tcl_ ## AsVal ## _ ## #@Type
#define SWIG_AsVal_dec(Type...) SWIG_ ## AsVal_dec ## _ ## #@Type
#define SWIG_Tcl_AsPtr(Type...) SWIG_Tcl_ ## AsPtr ## _ ## #@Type
#define SWIG_AsPtr_dec(Type...) SWIG_ ## AsPtr_dec ## _ ## #@Type
%define %tcl_asval_decl(Type...)
%#define SWIG_AsVal_dec(Type)(obj,val) SWIG_Tcl_AsVal(Type)(Tcl_Interp *interp, obj, val)
%#define SWIG_AsVal(Type)(obj,val) SWIG_Tcl_AsVal(Type)(interp, obj, val)
%enddef
%define %tcl_asptr_decl(Type...)
%#define SWIG_AsPtr_dec(Type)(obj,ptr) SWIG_Tcl_AsPtr(Type)(Tcl_Interp *interp, obj, ptr)
%#define SWIG_AsPtr(Type)(obj,ptr) SWIG_Tcl_AsPtr(Type)(interp, obj, ptr)
%enddef

View file

@ -1,25 +1,3 @@
%include <typemaps/primtypes.swg>
/* Macro for 'signed long' derived types */
%define %type_slong(Type, Frag, Min, Max)
%derived_type_from(long, Type)
%fragment("Tcl_asval_"{Type},"header",fragment=Frag) %{
%tcl_asval_decl(Type)
%}
%signed_derived_type_asval(long, Type, "Tcl_asval_"{Type} , Min, Max)
%enddef
/* Macro for 'unsigned long' derived types */
%define %type_ulong(Type, Frag, Max)
%derived_type_from(unsigned long, Type)
%fragment("Tcl_asval_"{Type},"header",fragment=Frag) %{
%tcl_asval_decl(Type)
%}
%unsigned_derived_type_asval(unsigned long, Type, "Tcl_asval_"{Type}, Max)
%enddef
/* ------------------------------------------------------------
* Primitive Types
* ------------------------------------------------------------ */
@ -27,12 +5,10 @@
/* boolean */
%fragment(SWIG_From_frag(bool),"header") {
SWIG_define(SWIG_From_dec(bool), Tcl_NewBooleanObj)
%define_as(SWIG_From_dec(bool), Tcl_NewBooleanObj)
}
%fragment(SWIG_AsVal_frag(bool),"header") {
%tcl_asval_decl(bool)
SWIGINTERN int
SWIG_AsVal_dec(bool)(Tcl_Obj *obj, bool *val)
{
@ -45,29 +21,6 @@ SWIG_AsVal_dec(bool)(Tcl_Obj *obj, bool *val)
}
}
/* 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",
@ -76,7 +29,7 @@ SWIGINTERNINLINE Tcl_Obj*
SWIG_From_dec(long)(long value)
{
if (((long) INT_MIN <= value) && (value <= (long) INT_MAX)) {
return Tcl_NewIntObj(SWIG_numeric_cast(value,int));
return Tcl_NewIntObj(%numeric_cast(value,int));
} else {
return Tcl_NewLongObj(value);
}
@ -84,8 +37,6 @@ SWIG_From_dec(long)(long value)
}
%fragment(SWIG_AsVal_frag(long),"header") {
%tcl_asval_decl(long)
SWIGINTERN int
SWIG_AsVal_dec(long)(Tcl_Obj *obj, long* val)
{
@ -106,7 +57,7 @@ SWIGINTERNINLINE Tcl_Obj*
SWIG_From_dec(unsigned long)(unsigned long value)
{
if (value < (unsigned long) LONG_MAX) {
return SWIG_From(long)(SWIG_numeric_cast(value, long));
return SWIG_From(long)(%numeric_cast(value, long));
} else {
char temp[256];
snprintf(temp, sizeof(temp),"%lu", value);
@ -116,25 +67,34 @@ SWIG_From_dec(unsigned long)(unsigned long value)
}
%fragment(SWIG_AsVal_frag(unsigned long),"header") {
%tcl_asval_decl(unsigned long)
SWIGINTERN int
SWIG_AsVal_dec(unsigned long)(Tcl_Obj *obj, unsigned long *val) {
int len = 0;
const char *nptr = Tcl_GetStringFromObj(obj, &len);
if (nptr && len > 0) {
char *endptr;
unsigned long v = strtoul(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
long v;
if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) {
if (v > 0) {
if (val) *val = (long) v;
return SWIG_OK;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
return SWIG_OverflowError;
}
} else {
int len = 0;
const char *nptr = Tcl_GetStringFromObj(obj, &len);
if (nptr && len > 0) {
char *endptr;
unsigned long v = strtoul(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
}
}
}
}
return SWIG_TypeError;
}
}
@ -148,7 +108,7 @@ SWIGINTERNINLINE Tcl_Obj*
SWIG_From_dec(long long)(long long value)
{
if (((long long) LONG_MIN <= value) && (value <= (long long) LONG_MAX)) {
return SWIG_From(long)(SWIG_numeric_cast(value,long));
return SWIG_From(long)(%numeric_cast(value,long));
} else {
char temp[256];
snprintf(temp, sizeof(temp),"%lld", value);
@ -158,23 +118,27 @@ SWIG_From_dec(long long)(long long value)
}
%fragment(SWIG_AsVal_frag(long long),"header") {
%tcl_asval_decl(long long)
SWIGINTERN int
SWIG_AsVal_dec(long long)(Tcl_Obj *obj, long long *val)
{
int len = 0;
const char *nptr = Tcl_GetStringFromObj(obj, &len);
if (nptr && len > 0) {
char *endptr;
long long v = strtoll(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
long v;
if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) {
if (val) *val = v;
return SWIG_OK;
} else {
int len = 0;
const char *nptr = Tcl_GetStringFromObj(obj, &len);
if (nptr && len > 0) {
char *endptr;
long long v = strtoll(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
}
}
}
}
@ -191,7 +155,7 @@ SWIGINTERNINLINE Tcl_Obj*
SWIG_From_dec(unsigned long long)(unsigned long long value)
{
if (value < (unsigned long long) LONG_MAX) {
return SWIG_From(long long)(SWIG_numeric_cast(value, long long));
return SWIG_From(long long)(%numeric_cast(value, long long));
} else {
char temp[256];
snprintf(temp, sizeof(temp),"%llu", value);
@ -202,23 +166,31 @@ SWIG_From_dec(unsigned long long)(unsigned long long value)
%fragment(SWIG_AsVal_frag(unsigned long long),"header",
fragment=SWIG_AsVal_frag(unsigned long)) {
%tcl_asval_decl(unsigned long long)
SWIGINTERN int
SWIG_AsVal_dec(unsigned long long)(Tcl_Obj *obj, unsigned long long *val)
{
int len = 0;
const char *nptr = Tcl_GetStringFromObj(obj, &len);
if (nptr && len > 0) {
char *endptr;
unsigned long long v = strtoull(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
long v;
if (Tcl_GetLongFromObj(0,obj, &v) == TCL_OK) {
if (v > 0) {
if (val) *val = (long) v;
return SWIG_OK;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
return SWIG_OverflowError;
}
} else {
int len = 0;
const char *nptr = Tcl_GetStringFromObj(obj, &len);
if (nptr && len > 0) {
char *endptr;
unsigned long long v = strtoull(nptr, &endptr,0);
if (errno == ERANGE) {
errno = 0;
return SWIG_OverflowError;
} else {
if (*endptr == '\0') {
if (val) *val = v;
return SWIG_OK;
}
}
}
}
@ -226,23 +198,13 @@ SWIG_AsVal_dec(unsigned long long)(Tcl_Obj *obj, unsigned long long *val)
}
}
/* float */
%derived_type_from(double, float)
%fragment("Tcl_asval_float","header",fragment="<float.h>") {
%tcl_asval_decl(float)
}
%signed_derived_type_asval(double, float, "Tcl_asval_float", -FLT_MAX, FLT_MAX)
/* double */
%fragment(SWIG_From_frag(double),"header") {
SWIG_define(SWIG_From_dec(double), Tcl_NewDoubleObj)
%define_as(SWIG_From(double), Tcl_NewDoubleObj)
}
%fragment(SWIG_AsVal_frag(double),"header") {
%tcl_asval_decl(double)
SWIGINTERN int
SWIG_AsVal_dec(double)(Tcl_Obj *obj, double *val)
{
@ -255,54 +217,3 @@ SWIG_AsVal_dec(double)(Tcl_Obj *obj, double *val)
}
}
/* char */
%fragment(SWIG_From_frag(char),"header") {
SWIGINTERNINLINE Tcl_Obj*
SWIG_From_dec(char)(char c)
{
return Tcl_NewStringObj(&c,1);
}
}
%fragment(SWIG_AsVal_frag(char),"header",
fragment="SWIG_AsCharArray",
fragment=SWIG_AsVal_frag(signed char)) {
%tcl_asval_decl(char)
SWIGINTERNINLINE int
SWIG_AsVal_dec(char)(Tcl_Obj *obj, char *val)
{
return SWIG_AsCharArray(obj, val, 1) == SWIG_OK ? SWIG_OK : SWIG_TypeError;
}
}
/* wchar_t */
%fragment(SWIG_From_frag(wchar_t),"header") {
SWIGINTERNINLINE Tcl_Obj*
SWIG_From_dec(wchar_t)(wchar_t c)
{
return Tcl_NewUnicodeObj(&c, 1);
}
}
%fragment(SWIG_AsVal_frag(wchar_t),"header",
fragment="SWIG_AsWCharArray",
fragment="<wchar.h>",
fragment=SWIG_AsVal_frag(long)) {
%tcl_asval_decl(wchar_t)
SWIGINTERNINLINE int
SWIG_AsVal_dec(wchar_t)(Tcl_Obj *obj, wchar_t *val)
{
return (SWIG_AsWCharArray(obj, val, 1) == SWIG_OK) ? SWIG_OK : SWIG_TypeError;
}
}
/* ------------------------------------------------------------
* Apply the primitive typemap for all the types with checkcode
* ------------------------------------------------------------ */
%apply_checkctypes(%typemap_primitive)

View file

@ -14,20 +14,20 @@
#define SWIG_NewPointerObj(ptr, type, flags) SWIG_Tcl_NewPointerObj(ptr, type, flags)
/* for raw packed data */
#define SWIG_ConvertPacked(obj, ptr, sz, ty, flags) SWIG_Tcl_ConvertPacked(interp, obj, ptr, sz, ty, flags)
#define SWIG_NewPackedObj(ptr, sz, type, flags) SWIG_Tcl_NewPackedObj(ptr, sz, type, flags)
#define SWIG_ConvertPacked(obj, ptr, sz, ty) SWIG_Tcl_ConvertPacked(interp, obj, ptr, sz, ty)
#define SWIG_NewPackedObj(ptr, sz, type) SWIG_Tcl_NewPackedObj(ptr, sz, type)
/* for class or struct pointers */
#define SWIG_ConvertInstance(obj, pptr, type, flags) SWIG_Tcl_ConvertPtr(interp, obj, pptr, type, flags)
#define SWIG_NewInstanceObj(thisvalue, type, flags) SWIG_Tcl_NewInstanceObj(interp, thisvalue, type, flags)
/* for C or C++ function pointers */
#define SWIG_ConvertFunctionPtr(obj, pptr, type, flags) SWIG_Tcl_ConvertPtr(interp, obj, pptr, type, flags)
#define SWIG_ConvertFunctionPtr(obj, pptr, type) SWIG_Tcl_ConvertPtr(interp, obj, pptr, type, 0)
#define SWIG_NewFunctionPtrObj(ptr, type) SWIG_Tcl_NewPointerObj(ptr, type, 0)
/* for C++ member pointers, ie, member methods */
#define SWIG_ConvertMember(obj, ptr, sz, ty, flags) SWIG_Tcl_ConvertPacked(interp,obj, ptr, sz, ty, flags)
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Tcl_NewPackedObj(ptr, sz, type, 0)
#define SWIG_ConvertMember(obj, ptr, sz, ty) SWIG_Tcl_ConvertPacked(interp,obj, ptr, sz, ty)
#define SWIG_NewMemberObj(ptr, sz, type) SWIG_Tcl_NewPackedObj(ptr, sz, type)
/* Runtime API */
@ -58,6 +58,8 @@
#define SWIG_ObjectDelete SWIG_Tcl_ObjectDelete
#define SWIG_TCL_DECL_ARGS_2(arg1, arg2) (Tcl_Interp *interp, arg1, arg2)
#define SWIG_TCL_CALL_ARGS_2(arg1, arg2) (interp, arg1, arg2)
/* -----------------------------------------------------------------------------
* pointers/data manipulation
* ----------------------------------------------------------------------------- */
@ -165,7 +167,7 @@ SWIG_Tcl_PointerTypeFromString(char *c) {
/* Convert a packed value value */
SWIGRUNTIME int
SWIG_Tcl_ConvertPacked(Tcl_Interp *interp, Tcl_Obj *obj, void *ptr, int sz, swig_type_info *ty, int flags) {
SWIG_Tcl_ConvertPacked(Tcl_Interp *interp, Tcl_Obj *obj, void *ptr, int sz, swig_type_info *ty) {
swig_cast_info *tc;
const char *c;
@ -211,14 +213,13 @@ SWIG_Tcl_NewPointerObj(void *ptr, swig_type_info *type, int flags) {
}
SWIGRUNTIME Tcl_Obj *
SWIG_Tcl_NewPackedObj(void *ptr, int sz, swig_type_info *type, int flags) {
SWIG_Tcl_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);
flags = 0;
return Tcl_NewStringObj(result,-1);
}

View file

@ -24,13 +24,8 @@ SWIG_AsCharPtrAndSize(Tcl_Obj *obj, char** cptr, size_t* psize, int *alloc)
SWIGINTERNINLINE Tcl_Obj *
SWIG_FromCharPtrAndSize(const char* carray, size_t size)
{
return (size < INT_MAX) ? Tcl_NewStringObj(carray, SWIG_numeric_cast(size,int)) : NULL;
return (size < INT_MAX) ? Tcl_NewStringObj(carray, %numeric_cast(size,int)) : NULL;
}
}
/* ------------------------------------------------------------
* The plain char * handling
* ------------------------------------------------------------ */
%include <typemaps/strings.swg>
%typemap_string(char, Char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, strlen)

View file

@ -1,5 +1,3 @@
%include <typemaps/swigtype.swg>
%typemap(out) SWIGTYPE = SWIGTYPE INSTANCE;
%typemap(out) SWIGTYPE * = SWIGTYPE *INSTANCE;
%typemap(out) SWIGTYPE & = SWIGTYPE &INSTANCE;

View file

@ -11,27 +11,21 @@
* Basic definitions
* ----------------------------------------------------------------------------- */
%define_swig_object(Tcl_Obj *)
#define SWIG_Object Tcl_Obj *
#define VOID_Object NULL
#define SWIG_VoidObject() NULL
#define SWIG_SetResultObj(obj) $result = obj
#define SWIG_AppendResultObj(obj) $result = (Tcl_ListObjAppendElement(NULL,$result,obj) == TCL_OK) ? $result : NULL
#define SWIG_SetConstantObj(name, obj) SWIG_Tcl_SetConstantObj(interp, name, obj)
#define SWIG_AppendOutput(result,obj) (Tcl_ListObjAppendElement(NULL,result,obj) == TCL_OK) ? result : NULL
#define SWIG_SetConstant(name, obj) SWIG_Tcl_SetConstantObj(interp, name, obj)
#define SWIG_Raise(obj,type,desc) SWIG_Tcl_SetErrorObj(interp,type,obj)
#define SWIG_DirOutFail(code, msg) /* no directors supported */
/* -----------------------------------------------------------------------------
* All the typemaps
* ----------------------------------------------------------------------------- */
%include <typemaps/exception.swg>
%include <tclswigtype.swg>
%include <typemaps/void.swg>
%include <typemaps/valtypes.swg>
%include <typemaps/ptrtypes.swg>
%include <typemaps/swigobject.swg>
%include <typemaps/inoutlist.swg>
%include <tclprimtypes.swg>
%include <tclstrings.swg>
%include <typemaps/misctypes.swg>
%include <typemaps/enumint.swg>
%include <typemaps/swigtypemaps.swg>
/* fix for instances */
%include <tclswigtype.swg>

View file

@ -2,35 +2,64 @@
* utility methods for wchar strings
* ------------------------------------------------------------ */
%fragment("SWIG_AsCharPtrAndSize","header") {
%{
#include <wchar.h>
%}
%fragment("SWIG_AsWCharPtrAndSize","header") {
SWIGINTERN int
SWIG_AsWCharPtrAndSize(Tcl_Obj *obj, wchar_t** cptr, size_t* psize, int *alloc)
{
int len = 0;
wchar_t *cstr = Tcl_GetUnicodeFromObj(obj, &len);
if (cstr) {
if (cptr) *cptr = cstr;
Tcl_UniChar *ustr = Tcl_GetUnicodeFromObj(obj, &len);
if (ustr) {
if (cptr) {
Tcl_Encoding encoding = NULL;
char *src = (char *) ustr;
int srcLen = (len)*sizeof(Tcl_UniChar);
int dstLen = sizeof(wchar_t)*(len + 1);
char *dst = %new_array(dstLen, char);
int flags = 0;
Tcl_EncodingState *statePtr = 0;
int srcRead = 0;
int dstWrote = 0;
int dstChars = 0;
Tcl_UtfToExternal(0, encoding, src, srcLen, flags, statePtr, dst,
dstLen, &srcRead, &dstWrote, &dstChars);
if (alloc) *alloc = SWIG_NEWOBJ;
}
if (psize) *psize = len + 1;
if (alloc) *alloc = SWIG_OLDOBJ;
return SWIG_OK;
}
return SWIG_TypeError;
}
}
%fragment("SWIG_FromWCharPtrAndSize","header",
fragment="<limits.h>") {
%fragment("SWIG_FromWCharPtrAndSize","header") {
SWIGINTERNINLINE Tcl_Obj *
SWIG_FromWCharPtrAndSize(const wchar_t* carray, size_t size)
{
return (size < INT_MAX) ? Tcl_NewUnicodeObj(carray, SWIG_numeric_cast(size,int)) : NULL;
Tcl_Obj *res = NULL;
if (size < INT_MAX) {
Tcl_Encoding encoding = NULL;
char *src = (char *) carray;
int srcLen = (size)*sizeof(wchar_t);
int dstLen = (size)*sizeof(Tcl_UniChar);
char *dst = %new_array(dstLen, char);
int flags = 0;
Tcl_EncodingState *statePtr = 0;
int srcRead = 0;
int dstWrote = 0;
int dstChars = 0;
Tcl_ExternalToUtf(0, encoding, src, srcLen, flags, statePtr, dst,
dstLen, &srcRead, &dstWrote, &dstChars);
res = Tcl_NewUnicodeObj((Tcl_UniChar*)dst, size);
%delete_array(dst);
}
return res;
}
}
/* ------------------------------------------------------------
* The plain char * handling
* ------------------------------------------------------------ */
%include <typemaps/strings.swg>
%typemap_string(wchar_t, WChar, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, wcslen)

View file

@ -1,16 +1,54 @@
Still in developing, but if you are interested into looking around,
start with
swigtypemaps.swg
which is the head file. Also read the docs for %fragments in
fragments.swg
and follow the definitions in one of the supported languages:
python, perl, ruby, tcl
/* -----------------------------------------------------------------------------
* Internal typemap specializations
* ----------------------------------------------------------------------------- */
enumint.swg enum especializations as int types
inoutlist.swg return the OUTPUT types in a list
misctypes.swg Miscellaneos types (size_t, ptrdiff_t, etc)
primtypes.swg Macros to manage primitive types (shot,int,double,etc)
ptrtypes.swg Typemaps for types with a 'ptr' behavior
strings.swg String base typemaps
cstring.swg Various forms of C character string handling
swigobject.swg Language object, such as PyObject, Tcl_Obj, etc
swigtype.swg SWIGTYPE
valtypes.swg Typemaps for types with a 'by value' behavior
void.swg void * typemaps
carrays.swg Implement the carrays.i library
cdata.swg Implement the cdata.i library
cmalloc.swg Implement the cmalloc.i library
cpointer.swg Implement the cpointer.i library
cstring.swg Implement the cstring.i library typemaps for char *
cwstring.swg Implement the cstring.i library typemaps for wchar_t *
exception.swg Implement the exception.i library
implicit.swg Allow the use of implicit C++ constructors
string.swg Typemaps for char * string
wstring.swg Typemaps for wchar_t * string
std_string.swg Typemaps for std::string
std_wstring.swg Typemaps for std::wstring
swigtype.swg Typemaps for the SWIGTYPE type
void.swg Typemaps for the 'void' type
enumint.swg Typemaps for enums treated as 'int'
swigobject.swg Typemaps for the SWIG_Object as in PyObject, Tcl_Obj, etc.
misctypes.swg Typemaps for miscellaneos types (size_t, ptrdiff_t, etc)
ptrtypes.swg Typemaps for types with a 'ptr' behavior
valtypes.swg Typemaps for 'by value' types
inoutlist.swg IN/OUTPUT/INOUT typemaps, where the OUTPUT values are returned in a list
primtypes.swg Common macros to manage primitive types (short,int,double,etc)
cstrings.swg Common macros to implemented the cstring/cwstring libraries
std_strings.swg Common macros to implemented the std::string/std::wstring typemaps
strings.swg Common macros and typemaps for string and wstring (char *, wchar_t *)
swigmacros.swg Basic macros
fragments.swg Macros for fragment manipulations
typemaps.swg The old typemaps.i library, not needed anymore

View file

@ -25,11 +25,11 @@
%define %array_functions(TYPE,NAME)
%{
static TYPE *new_##NAME(size_t nelements) {
return SWIG_new_array(nelements, TYPE);
return %new_array(nelements, TYPE);
}
static void delete_##NAME(TYPE *ary) {
SWIG_delete_array(ary);
%delete_array(ary);
}
static TYPE NAME##_getitem(TYPE *ary, size_t index) {
@ -82,11 +82,11 @@ typedef struct NAME {
%extend NAME {
NAME(size_t nelements) {
return SWIG_new_array(nelements, TYPE);
return %new_array(nelements, TYPE);
}
~NAME() {
SWIG_delete_array(self);
%delete_array(self);
}
TYPE getitem(size_t index) {
@ -102,7 +102,7 @@ typedef struct NAME {
}
static NAME *frompointer(TYPE *t) {
return SWIG_static_cast(t, NAME *);
return %static_cast(t, NAME *);
}
};

View file

@ -20,7 +20,7 @@ typedef struct SWIGCDATA {
* ----------------------------------------------------------------------------- */
%typemap(out,noblock=1,fragment="SWIG_FromCharPtrAndSize") SWIGCDATA {
$result = SWIG_FromCharPtrAndSize($1.data,$1.len);
%set_output(SWIG_FromCharPtrAndSize($1.data,$1.len));
}
%typemap(in) (const void *indata, int inlen) = (char *STRING, int SIZE);

View file

@ -55,10 +55,10 @@ typedef struct {
%extend NAME {
NAME() {
return SWIG_new(TYPE);
return %new_instance(TYPE);
}
~NAME() {
if (self) SWIG_delete(self);
if (self) %delete(self);
}
}
@ -109,15 +109,15 @@ typedef struct {
%define %pointer_functions(TYPE,NAME)
%{
static TYPE *new_##NAME() {
return SWIG_new(TYPE);
return %new_instance(TYPE);
}
static TYPE *copy_##NAME(TYPE value) {
return SWIG_new_copy(value, TYPE);
return %new_copy(value, TYPE);
}
static void delete_##NAME(TYPE *self) {
if (self) SWIG_delete(self);
if (self) %delete(self);
}
static void NAME ##_assign(TYPE *self, TYPE value) {
@ -146,7 +146,7 @@ TYPE NAME##_value(TYPE *self);
%define %pointer_cast(TYPE1,TYPE2,NAME)
%inline %{
TYPE2 NAME(TYPE1 x) {
return SWIG_static_cast(x, TYPE2);
return %static_cast(x, TYPE2);
}
%}
%enddef

View file

@ -1,275 +1,9 @@
/*
* cstring.i
* $Header$
*
* Author(s): David Beazley (beazley@cs.uchicago.edu)
*
* This file provides typemaps and macros for dealing with various forms
* of C character string handling. The primary use of this module
* is in returning character data that has been allocated or changed in
* some way.
*/
%include <typemaps/cstrings.swg>
%define %typemap_cstrings(Name, Char,
SWIG_AsCharPtr,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtr,
SWIG_FromCharPtrAndSize)
/* %cstring_input_binary(TYPEMAP, SIZE)
*
* Macro makes a function accept binary string data along with
* a size. For example:
*
* %cstring_input_binary(Char *buff, int size);
* void foo(Char *buff, int size) {
* }
*
*/
%define Name ## _input_binary(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) (TYPEMAP, SIZE)
(Char *buf = 0, size_t size = 0, int alloc = 0) {
if (SWIG_AsCharPtrAndSize($input, &buf, &size, &alloc) != SWIG_OK) {
SWIG_arg_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) size - 1;
}
%typemap(freearg,noblock=1) (TYPEMAP, SIZE) {
if (alloc$argnum == SWIG_NEWOBJ) SWIG_delete_array(buf$argnum);
}
%enddef
/*
* %cstring_bounded_output(TYPEMAP, MAX)
*
* This macro is used to return a NULL-terminated output string of
* some maximum length. For example:
*
* %cstring_bounded_output(Char *outx, 512);
* void foo(Char *outx) {
* sprintf(outx,"blah blah\n");
* }
*
*/
%define Name ## _bounded_output(TYPEMAP,MAX)
%typemap(in,noblock=1,numinputs=0) TYPEMAP (Char temp[MAX+1]) {
$1 = ($1_ltype) temp;
}
%typemap(freearg,noblock=1) TYPEMAP "";
%typemap(argout,noblock=1,fragment= #SWIG_FromCharPtr ) TYPEMAP {
$1[MAX] = 0;
SWIG_append_result(SWIG_FromCharPtr($1));
}
%enddef
/*
* %cstring_chunk_output(TYPEMAP, SIZE)
*
* This macro is used to return a chunk of binary string data.
* Embedded NULLs are okay. For example:
*
* %cstring_chunk_output(Char *outx, 512);
* void foo(Char *outx) {
* memmove(outx, somedata, 512);
* }
*
*/
%define Name ## _chunk_output(TYPEMAP,SIZE)
%typemap(in,noblock=1,numinputs=0) TYPEMAP(Char temp[SIZE]) {
$1 = ($1_ltype) temp;
}
%typemap(freearg,noblock=1) TYPEMAP "";
%typemap(argout,noblock=1,fragment= #SWIG_FromCharPtrAndSize) TYPEMAP {
SWIG_append_result(SWIG_FromCharPtrAndSize($1,SIZE));
}
%enddef
/*
* %cstring_bounded_mutable(TYPEMAP, SIZE)
*
* This macro is used to wrap a string that's going to mutate.
*
* %cstring_bounded_mutable(Char *in, 512);
* void foo(in *x) {
* while (*x) {
* *x = toupper(*x);
* x++;
* }
* }
*
*/
%define Name ## _bounded_mutable(TYPEMAP,MAX)
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP
(Char temp[MAX+1], Char *t = 0, size_t n = 0, int alloc = 0) {
if (SWIG_AsCharPtrAndSize($input, &t, &n, &alloc) != SWIG_OK) {
SWIG_arg_fail(SWIG_TypeError, "TYPEMAP", $argnum);
}
if ( n > (size_t) MAX ) n = (size_t) MAX;
memcpy(temp, t, sizeof(Char)*n);
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(t);
temp[n - 1] = 0;
$1 = ($1_ltype) temp;
}
%typemap(freearg,noblock=1) TYPEMAP "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
$1[MAX] = 0;
SWIG_append_result(SWIG_FromCharPtr($1));
}
%enddef
/*
* %cstring_mutable(TYPEMAP [, expansion])
*
* This macro is used to wrap a string that will mutate in place.
* It may change size up to a user-defined expansion.
*
* %cstring_mutable(Char *in);
* void foo(in *x) {
* while (*x) {
* *x = toupper(*x);
* x++;
* }
* }
*
*/
%define Name ## _mutable(TYPEMAP,EXP...)
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP
(Char* t = 0, size_t n = 0, int alloc = 0, size_t expansion = 0) {
#if #EXP != ""
expansion += EXP;
#endif
if (SWIG_AsCharPtrAndSize($input, &t, &n, &alloc) != SWIG_OK) {
SWIG_arg_fail(SWIG_TypeError, "TYPEMAP", $argnum);
}
$1 = SWIG_new_array(n+expansion, $*1_ltype);
memcpy($1,t,sizeof(Char)*n);
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(t);
$1[n-1] = 0;
}
%typemap(freearg,noblock=1) TYPEMAP "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
SWIG_append_result(SWIG_FromCharPtr($1));
SWIG_delete_array($1);
}
%enddef
/*
* %cstring_output_maxsize(TYPEMAP, SIZE)
*
* This macro returns data in a string of some user-defined size.
*
* %cstring_output_maxsize(Char *outx, int max) {
* void foo(Char *outx, int max) {
* sprintf(outx,"blah blah\n");
* }
*/
%define Name ## _output_maxsize(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(unsigned long)) (TYPEMAP, SIZE) (unsigned long size) {
if (SWIG_AsVal(unsigned long)($input, &size) != SWIG_OK) {
SWIG_arg_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
$2 = SWIG_numeric_cast(size, $2_ltype);
$1 = SWIG_new_array(size+1, $*1_ltype);
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) (TYPEMAP,SIZE) {
SWIG_append_result(SWIG_FromCharPtr($1));
SWIG_delete_array($1);
}
%enddef
/*
* %cstring_output_withsize(TYPEMAP, SIZE)
*
* This macro is used to return Character data along with a size
* parameter.
*
* %cstring_output_maxsize(Char *outx, int *max) {
* void foo(Char *outx, int *max) {
* sprintf(outx,"blah blah\n");
* *max = strlen(outx);
* }
*/
%define Name ## _output_withsize(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=SWIG_As_frag(unsigned long)) (TYPEMAP, SIZE) (unsigned long n) {
if (SWIG_AsVal(unsigned long)($input, &n) != SWIG_OK) {
SWIG_arg_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
$1 = SWIG_new_array(n+1, $*1_ltype);
$2 = SWIG_new($*2_ltype);
*$2 = SWIG_numeric_cast(n, $*2_ltype);
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize) (TYPEMAP,SIZE) {
SWIG_append_result(SWIG_FromCharPtrAndSize($1,*$2));
SWIG_delete_array($1);
SWIG_delete($2);
}
%enddef
/*
* %cstring_output_allocate(TYPEMAP, RELEASE)
*
* This macro is used to return Character data that was
* allocated with new or malloc.
*
* %cstring_output_allocated(Char **outx, free($1));
* void foo(Char **outx) {
* *outx = (Char *) malloc(512);
* sprintf(outx,"blah blah\n");
* }
*/
%define Name ## _output_allocate(TYPEMAP, RELEASE)
%typemap(in,noblock=1,numinputs=0) TYPEMAP($*1_ltype temp = 0) {
$1 = &temp;
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
if (*$1) {
SWIG_append_result(SWIG_FromCharPtr(*$1));
RELEASE;
}
}
%enddef
/*
* %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
*
* This macro is used to return Character data that was
* allocated with new or malloc.
*
* %cstring_output_allocated(Char **outx, int *sz, free($1));
* void foo(Char **outx, int *sz) {
* *outx = (Char *) malloc(512);
* sprintf(outx,"blah blah\n");
* *sz = strlen(outx);
* }
*/
%define Name ## _output_allocate_size(TYPEMAP, SIZE, RELEASE)
%typemap(in,noblock=1,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) {
$1 = &temp; $2 = &tempn;
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize)(TYPEMAP,SIZE) {
if (*$1) {
SWIG_append_result(SWIG_FromCharPtrAndSize(*$1,*$2));
RELEASE;
}
}
%enddef
%enddef
%typemaps_cstring(%cstring,
char,
SWIG_AsCharPtr,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtr,
SWIG_FromCharPtrAndSize);

280
Lib/typemaps/cstrings.swg Normal file
View file

@ -0,0 +1,280 @@
/*
* 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.
*/
%define %typemaps_cstring(Name, Char,
SWIG_AsCharPtr,
SWIG_AsCharPtrAndSize,
SWIG_FromCharPtr,
SWIG_FromCharPtrAndSize)
/* %cstring_input_binary(TYPEMAP, SIZE)
*
* Macro makes a function accept binary string data along with
* a size. For example:
*
* %cstring_input_binary(Char *buff, int size);
* void foo(Char *buff, int size) {
* }
*
*/
%define Name ## _input_binary(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) (TYPEMAP, SIZE)
(Char *buf = 0, size_t size = 0, int alloc = 0) {
if (SWIG_AsCharPtrAndSize($input, &buf, &size, &alloc) != SWIG_OK) {
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
$1 = ($1_ltype) buf;
$2 = ($2_ltype) size - 1;
}
%typemap(freearg,noblock=1) (TYPEMAP, SIZE) {
if (alloc$argnum == SWIG_NEWOBJ) %delete_array(buf$argnum);
}
%enddef
/*
* %cstring_bounded_output(TYPEMAP, MAX)
*
* This macro is used to return a NULL-terminated output string of
* some maximum length. For example:
*
* %cstring_bounded_output(Char *outx, 512);
* void foo(Char *outx) {
* sprintf(outx,"blah blah\n");
* }
*
*/
%define Name ## _bounded_output(TYPEMAP,MAX)
%typemap(in,noblock=1,numinputs=0) TYPEMAP (Char temp[MAX+1]) {
$1 = ($1_ltype) temp;
}
%typemap(freearg,noblock=1) TYPEMAP "";
%typemap(argout,noblock=1,fragment= #SWIG_FromCharPtr ) TYPEMAP {
$1[MAX] = 0;
%append_output(SWIG_FromCharPtr($1));
}
%enddef
/*
* %cstring_chunk_output(TYPEMAP, SIZE)
*
* This macro is used to return a chunk of binary string data.
* Embedded NULLs are okay. For example:
*
* %cstring_chunk_output(Char *outx, 512);
* void foo(Char *outx) {
* memmove(outx, somedata, 512);
* }
*
*/
%define Name ## _chunk_output(TYPEMAP,SIZE)
%typemap(in,noblock=1,numinputs=0) TYPEMAP(Char temp[SIZE]) {
$1 = ($1_ltype) temp;
}
%typemap(freearg,noblock=1) TYPEMAP "";
%typemap(argout,noblock=1,fragment= #SWIG_FromCharPtrAndSize) TYPEMAP {
%append_output(SWIG_FromCharPtrAndSize($1,SIZE));
}
%enddef
/*
* %cstring_bounded_mutable(TYPEMAP, SIZE)
*
* This macro is used to wrap a string that's going to mutate.
*
* %cstring_bounded_mutable(Char *in, 512);
* void foo(in *x) {
* while (*x) {
* *x = toupper(*x);
* x++;
* }
* }
*
*/
%define Name ## _bounded_mutable(TYPEMAP,MAX)
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP
(Char temp[MAX+1], Char *t = 0, size_t n = 0, int alloc = 0) {
if (SWIG_AsCharPtrAndSize($input, &t, &n, &alloc) != SWIG_OK) {
%argument_fail(SWIG_TypeError, "TYPEMAP", $argnum);
}
if ( n > (size_t) MAX ) n = (size_t) MAX;
memcpy(temp, t, sizeof(Char)*n);
if (alloc == SWIG_NEWOBJ) %delete_array(t);
temp[n - 1] = 0;
$1 = ($1_ltype) temp;
}
%typemap(freearg,noblock=1) TYPEMAP "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
$1[MAX] = 0;
%append_output(SWIG_FromCharPtr($1));
}
%enddef
/*
* %cstring_mutable(TYPEMAP [, expansion])
*
* This macro is used to wrap a string that will mutate in place.
* It may change size up to a user-defined expansion.
*
* %cstring_mutable(Char *in);
* void foo(in *x) {
* while (*x) {
* *x = toupper(*x);
* x++;
* }
* }
*
*/
%define Name ## _mutable(TYPEMAP,EXP...)
%typemap(in,noblock=1,fragment=#SWIG_AsCharPtrAndSize) TYPEMAP
(Char* t = 0, size_t n = 0, int alloc = 0, size_t expansion = 0) {
#if #EXP != ""
expansion += EXP;
#endif
if (SWIG_AsCharPtrAndSize($input, &t, &n, &alloc) != SWIG_OK) {
%argument_fail(SWIG_TypeError, "TYPEMAP", $argnum);
}
$1 = %new_array(n+expansion, $*1_ltype);
memcpy($1,t,sizeof(Char)*n);
if (alloc == SWIG_NEWOBJ) %delete_array(t);
$1[n-1] = 0;
}
%typemap(freearg,noblock=1) TYPEMAP "";
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
%append_output(SWIG_FromCharPtr($1));
%delete_array($1);
}
%enddef
/*
* %cstring_output_maxsize(TYPEMAP, SIZE)
*
* This macro returns data in a string of some user-defined size.
*
* %cstring_output_maxsize(Char *outx, int max) {
* void foo(Char *outx, int max) {
* sprintf(outx,"blah blah\n");
* }
*/
%define Name ## _output_maxsize(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(unsigned long)) (TYPEMAP, SIZE) (unsigned long size) {
if (SWIG_AsVal(unsigned long)($input, &size) != SWIG_OK) {
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
$2 = %numeric_cast(size, $2_ltype);
$1 = %new_array(size+1, $*1_ltype);
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) (TYPEMAP,SIZE) {
%append_output(SWIG_FromCharPtr($1));
%delete_array($1);
}
%enddef
/*
* %cstring_output_withsize(TYPEMAP, SIZE)
*
* This macro is used to return Character data along with a size
* parameter.
*
* %cstring_output_maxsize(Char *outx, int *max) {
* void foo(Char *outx, int *max) {
* sprintf(outx,"blah blah\n");
* *max = strlen(outx);
* }
*/
%define Name ## _output_withsize(TYPEMAP, SIZE)
%typemap(in,noblock=1,fragment=SWIG_AsVal_frag(unsigned long)) (TYPEMAP, SIZE) (unsigned long n) {
if (SWIG_AsVal(unsigned long)($input, &n) != SWIG_OK) {
%argument_fail(SWIG_TypeError, "(TYPEMAP, SIZE)", $argnum);
}
$1 = %new_array(n+1, $*1_ltype);
$2 = %new_instance($*2_ltype);
*$2 = %numeric_cast(n, $*2_ltype);
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize) (TYPEMAP,SIZE) {
%append_output(SWIG_FromCharPtrAndSize($1,*$2));
%delete_array($1);
%delete($2);
}
%enddef
/*
* %cstring_output_allocate(TYPEMAP, RELEASE)
*
* This macro is used to return Character data that was
* allocated with new or malloc.
*
* %cstring_output_allocated(Char **outx, free($1));
* void foo(Char **outx) {
* *outx = (Char *) malloc(512);
* sprintf(outx,"blah blah\n");
* }
*/
%define Name ## _output_allocate(TYPEMAP, RELEASE)
%typemap(in,noblock=1,numinputs=0) TYPEMAP($*1_ltype temp = 0) {
$1 = &temp;
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtr) TYPEMAP {
if (*$1) {
%append_output(SWIG_FromCharPtr(*$1));
RELEASE;
}
}
%enddef
/*
* %cstring_output_allocate_size(TYPEMAP, SIZE, RELEASE)
*
* This macro is used to return Character data that was
* allocated with new or malloc.
*
* %cstring_output_allocated(Char **outx, int *sz, free($1));
* void foo(Char **outx, int *sz) {
* *outx = (Char *) malloc(512);
* sprintf(outx,"blah blah\n");
* *sz = strlen(outx);
* }
*/
%define Name ## _output_allocate_size(TYPEMAP, SIZE, RELEASE)
%typemap(in,noblock=1,numinputs=0) (TYPEMAP, SIZE) ($*1_ltype temp = 0, $*2_ltype tempn) {
$1 = &temp; $2 = &tempn;
}
%typemap(argout,noblock=1,fragment=#SWIG_FromCharPtrAndSize)(TYPEMAP,SIZE) {
if (*$1) {
%append_output(SWIG_FromCharPtrAndSize(*$1,*$2));
RELEASE;
}
}
%enddef
%enddef

10
Lib/typemaps/cwstring.swg Normal file
View file

@ -0,0 +1,10 @@
%include <typemaps/cstrings.swg>
%include <typemaps/wstring.swg>
%typemaps_cstring(%cwstring,
wchar_t,
SWIG_AsWCharPtr,
SWIG_AsWCharPtrAndSize,
SWIG_FromWCharPtr,
SWIG_FromWCharPtrAndSize);

View file

@ -8,20 +8,20 @@
%typemap(in,fragment=SWIG_AsVal_frag(int),noblock=1) const enum SWIGTYPE& (int val, int ecode, $basetype temp) {
ecode = SWIG_AsVal(int)($input, &val);
if (ecode != SWIG_OK) {
SWIG_arg_fail(ecode, "$basetype", $argnum);
%argument_fail(ecode, "$type", $argnum);
} else {
temp = SWIG_static_cast(val,$basetype);
temp = %static_cast(val,$basetype);
$1 = &temp;
}
}
%typemap(varin,fragment=SWIG_AsVal_frag(int),noblock=1) enum SWIGTYPE {
if (sizeof(int) != sizeof($1)) {
SWIG_var_fail(SWIG_AttributeError,"$type", "$name");
%variable_fail(SWIG_AttributeError,"$type", "arch, read-only $name");
} else {
int ecode = SWIG_AsVal(int)($input, SWIG_reinterpret_cast(&$1,int*));
int ecode = SWIG_AsVal(int)($input, %reinterpret_cast(&$1,int*));
if (ecode != SWIG_OK) {
SWIG_var_fail(ecode, "$type", "$name");
%variable_fail(ecode, "$type", "$name");
}
}
}
@ -29,18 +29,18 @@
/*
typemaps needed due to unnamed enums
*/
%define SWIG_ENUM_OUT_TYPEMAPS(from_meth,frag)
%define %enum_out_typemaps(from_meth,frag)
%typemap(out,noblock=1,fragment=frag) enum SWIGTYPE {
$result = from_meth(($1));
%set_output(from_meth(($1)));
}
%typemap(out,noblock=1,fragment=frag) const enum SWIGTYPE& {
$result = from_meth((*$1));
%set_output(from_meth((*$1)));
}
%typemap(varout,noblock=1,fragment=frag) enum SWIGTYPE, const enum SWIGTYPE& {
$result = from_meth($1);
%set_varoutput(from_meth($1));
}
%typemap(constcode,noblock=1,fragment=frag) enum SWIGTYPE {
SWIG_set_constant("$symname", from_meth($value));
%set_constant("$symname", from_meth($value));
}
%typemap(directorin,noblock=1,fragment=frag) enum SWIGTYPE *DIRECTORIN {
$input = from_meth(*$1_name);
@ -49,11 +49,11 @@
$input = from_meth($1_name);
}
%typemap(throws,noblock=1,fragment=frag) enum SWIGTYPE {
SWIG_raise(from_meth($1),"$type",0);
%raise(from_meth($1),"$type",0);
}
%enddef
SWIG_ENUM_OUT_TYPEMAPS(SWIG_From(int),SWIG_From_frag(int));
%enum_out_typemaps(SWIG_From(int),SWIG_From_frag(int));

View file

@ -1,13 +1,29 @@
// This SWIG library file provides language independent exception handling
%include <typemaps/swigmacros.swg>
/* macros for error manipulation */
#define %nullref_fmt() "invalid null reference "
#define %varfail_fmt(_type,_name) "in variable '"_name"' of type '"_type"'"
#define %argfail_fmt(_type,_argn) "in argument " #_argn" of type '" _type"'"
#define %outfail_fmt(_type) "in output value of type '"_type"'"
#define %argnullref_fmt(_type, _argn) %nullref_fmt() %argfail_fmt(_type, _argn)
#define %varnullref_fmt(_type, _name) %nullref_fmt() %varfail_fmt(_type, _name)
#define %outnullref_fmt(_type) %nullref_fmt() %outfail_fmt(_type)
/* setting an error */
#define %error(code,msg...) SWIG_Error(code, msg)
#define %type_error(msg...) SWIG_Error(SWIG_TypeError, msg)
%insert("runtime") {
SWIG_define(SWIG_exception(code, msg),
SWIG_block(SWIG_error(code, msg); SWIG_fail))
%define_as(SWIG_exception(code, msg),
%block(%error(code, msg); SWIG_fail))
SWIG_define(SWIG_contract_assert(expr, msg),
if (!(expr)) { SWIG_error(SWIG_RuntimeError, msg); SWIG_fail; } else)
%define_as(SWIG_contract_assert(expr, msg),
if (!(expr)) { %error(SWIG_RuntimeError, msg); SWIG_fail; } else)
}

143
Lib/typemaps/fragmacros.swg Normal file
View file

@ -0,0 +1,143 @@
/*
Special macros to define and use fragment names and declarations.
These macros generate the names used in fragments, for example, a
typical use will be:
%fragment(SWIG_From_frag(bool),"header") {
SWIGINTERNINLINE PyObject*
SWIG_From_dec(bool)(bool value)
{
PyObject *obj = value ? Py_True : Py_False;
Py_INCREF(obj);
return obj;
}
}
and then you can call the method using
%typemap(out,fragment=SWIG_From_frag(bool)) bool {
%set_output(SWIG_From(bool)($1));
}
when the typemap get generated, the proper fragment for the
SWIG_From(bool) method will be included.
*/
#define SWIG_Traits_frag(Type...) %string_type(Traits, Type)
#define SWIG_AsPtr_frag(Type...) %string_type(AsPtr, Type)
#define SWIG_AsVal_frag(Type...) %string_type(AsVal, Type)
#define SWIG_From_frag(Type...) %string_type(From, Type)
#ifndef SWIG_ASVAL_DECL_ARGS
#define SWIG_ASVAL_DECL_ARGS
#endif
#ifndef SWIG_ASPTR_DECL_ARGS
#define SWIG_ASPTR_DECL_ARGS
#endif
#ifndef SWIG_FROM_DECL_ARGS
#define SWIG_FROM_DECL_ARGS
#endif
#ifndef SWIG_ASVAL_CALL_ARGS
#define SWIG_ASVAL_CALL_ARGS
#endif
#ifndef SWIG_ASPTR_CALL_ARGS
#define SWIG_ASPTR_CALL_ARGS
#endif
#ifndef SWIG_FROM_CALL_ARGS
#define SWIG_FROM_CALL_ARGS
#endif
#define SWIG_AsVal_dec(Type...) %name_type(AsVal, Type) SWIG_ASVAL_DECL_ARGS
#define SWIG_AsPtr_dec(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_DECL_ARGS
#define SWIG_From_dec(Type...) %name_type(From, Type) SWIG_FROM_DECL_ARGS
#define SWIG_AsVal(Type...) %name_type(AsVal, Type) SWIG_ASVAL_CALL_ARGS
#define SWIG_AsPtr(Type...) %name_type(AsPtr, Type) SWIG_ASPTR_CALL_ARGS
#define SWIG_From(Type...) %name_type(From, Type) SWIG_FROM_CALL_ARGS
/* ------------------------------------------------------------
* common macro helpers
* ------------------------------------------------------------ */
/* Macros for numeric types */
%define %numeric_type_from(Type, Base)
%fragment(SWIG_From_frag(Type),"header",
fragment=SWIG_From_frag(Base)) {
SWIGINTERNINLINE SWIG_Object
SWIG_From_dec(Type)(Type value)
{
return SWIG_From(Base)(value);
}
}
%enddef
%define %numeric_type_asval(Type, Base, Frag, OverflowCond)
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=Frag,
fragment=SWIG_AsVal_frag(Base)) {
SWIGINTERN int
SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val)
{
Base v;
int res = SWIG_AsVal(Base)(obj, &v);
if (res == SWIG_OK) {
if (OverflowCond) {
return SWIG_OverflowError;
} else {
if (val) *val = %numeric_cast(v, Type);
return SWIG_OK;
}
}
return res;
}
}
%enddef
%define %numeric_signed_type_asval(Type, Base, Frag, Min, Max)
%numeric_type_asval(Type, Base, Frag, (v < Min || v > Max))
%enddef
%define %numeric_unsigned_type_asval(Type, Base, Frag, Max)
%numeric_type_asval(Type, Base, Frag, (v > Max))
%enddef
/* Macro for 'signed long' derived types */
%define %numeric_slong(Type, Frag, Min, Max)
%numeric_type_from(Type, long)
%numeric_signed_type_asval(Type, long, Frag , Min, Max)
%enddef
/* Macro for 'unsigned long' derived types */
%define %numeric_ulong(Type, Frag, Max)
%numeric_type_from(Type, unsigned long)
%numeric_unsigned_type_asval(Type, unsigned long, Frag, Max)
%enddef
/* Macro for 'double' derived types */
%define %numeric_double(Type, Frag, Min, Max)
%numeric_type_from(Type, double)
%numeric_signed_type_asval(Type, double, Frag , Min, Max)
%enddef

289
Lib/typemaps/fragments.swg Normal file
View file

@ -0,0 +1,289 @@
/*
Fragments:
==========
Second to typemaps, fragments is one the most powerfull and
dangerous swig feature. So, if you are starting to read about them,
make sure you read all the document.
Basics:
=======
Fragments provide a way to include or generate code into "on-demand"
as the typemaps could require.
For example, if you have a very long typemap
%typemap(in) MyClass * {
MyClass *value = 0;
<very long typemap>
....
value = somewhere_converted_from_input_object_here($input);
...
<very long typemap>
$result = value;
}
very soon you will discoverd yourself copying the same long
conversion code in several typemaps, such as varin, directorout,
etc. Also, you wil discover that swig copy verbatim the same very
long conversion code for every argument that requires it, making the
code very large too.
To eliminate this automatic or manual code copying, we define a
fragment that includes the common conversion code:
%fragment("AsMyClass","header") {
MyClass *AsMyClass(PyObject *obj) {
MyClass *value = 0;
<very long conversion>
....
value = somewhere_converted_from_input_object_here(obj);
...
<very long conversion>
return value;
}
}
%typemap(in,fragment="AsMyClass") MyClass * {
$result = AsMyClass($input);
}
%typemap(varin,fragment="AsMyClass") MyClass * {
$result = AsMyClass($input);
}
When the 'in' or 'varin' typemaps for MyClass are invoked, the
fragment "AsMyClass" is added to the "header" section, and then the
typemap code is emitted. Hence, the method AsMyClass will be
included in the wrapping code and it will be available at the time
the typemap is applied.
To define a fragment then you need a name, a section where it goes,
and the code. Usually the section refers to the "header" part, and
both string and braces forms are accepted, ie:
%fragment("my_name","header") { ... }
%fragment("my_name","header") "...";
To ensure all the fragment/typemap engine works as expected, there
are some rules that fragments follow:
1.- A fragment is added to the wrapping code only once, ie, for the
method:
int foo(MyClass *a, MyClass *b);
the wrapped code will look as much as:
MyClass *AsMyClass(PyObject *obj) {
.....
}
int _wrap_foo(...) {
....
arg1 = AsMyClass(obj1);
arg2 = AsMyClass(obj2);
...
result = foo(arg1, arg2);
}
even when there will be duplicated typemap to process 'a' and
'b', the 'AsMyClass' method will be defined only once.
2.- A fragment can only defined once, and the first definition
is the only one taking in account. All other definitions of the
same fragments are silently ignored. For example, you can have
%fragment("AsMyClass","header") { <definition 1> }
....
%fragment("AsMyClass","header") { <definition 2> }
and then only the first definition is considered. In this way
you can change the 'system' fragments by including yours first.
Note that this behavior is opposite to the typemaps, where the
last typemap applied or defined prevails. Fragment follows the
first-in-first-out convention since they are intended to be
"global", while typemaps intend to be "locally" specialyzed.
3.- Fragments names can not contain commas.
A fragment can include one or more additional fragments, for example:
%fragment("<limits.h>", "header") {
#include <limits.h>
}
%fragment("AsMyClass", "header", fragment="<limits.h>") {
MyClass *AsMyClass(PyObject *obj) {
MyClass *value = 0;
int ival = somewhere_converted_from_input_object_here(obj)
...
if (ival < CHAR_MIN) {
value = something_from_ival(ival);
} else {
...
}
...
return value;
}
}
in this case, when the "AsMyClass" fragment is emitted, it also
trigger the inclusion of the "<limits.h>" fragment.
You can add as many fragments as you want, for example
%fragment("bigfragment","header", fragment="frag1", fragment="frag2", fragment="frag3") "";
here, when the "bigfragment" is included, the three fragments "frag1",
"frag2" and "frag3" are included. Note that as "bigframent" is defined
empty, "", it does not add any code by itself, buy only trigger the
inclusion of the other fragments.
In a typemap you can also include more than one fragment, but since the
syntax is different, you need to specify them in a 'comma separated'
list, for example, considering the previous example:
%typemap(in,fragment="frag1,frag2,frag3") {...}
is equivalent to
%typemap(in,fragment="bigfragment") {...}
Fragment type specialization
============================
Fragments can be "type specialized". The syntax is as follows
%fragment("name","header") { a type independent fragment }
%fragment("name" {Type}, "header") {typethe dependent fragment }
and they can also, as typemaps, be used inside templates, for exampe:
template <class T>
struct A {
%fragment("incode"{A<T>},"header") {
'incode' specialized fragment
}
%typemap(in,fragment="incode"{A<T>}) {
here we use the 'type specialized'
fragment "incode"{A<T>}
}
};
which could seems a not much interesting feature, but is
fundamental for automatic typemap and template specialization.
Fragments and automatic typemap specialozation:
===============================================
Since fragments can be type specialized, they can be elegantly used
to specialized typemaps .
For example, if you have something like:
%fragment("incode"{float}, "header") {
float in_mehtod_float(PyObject *obj) {
...
}
}
%fragment("incode"{long}, "header") {
float in_mehtod_long(PyObject *obj) {
...
}
}
%define %my_typemaps(Type)
%typemaps(in,fragment="incode"{Type}) {
value = in_method_##Type(obj);
}
%enddef
%my_typemaps(float);
%my_typemaps(long);
then the proper "incode"{float,double} fragment will be included,
and the proper in_method_{float,double} will be called.
Since this is a recurrent fragmen use, we provide a couple of
macros that make the automatic generation of typemaps easier:
Consider for example the following code:
%fragment(SWIG_From_frag(bool),"header") {
static PyObject*
SWIG_From_dec(bool)(bool value)
{
PyObject *obj = value ? Py_True : Py_False;
Py_INCREF(obj);
return obj;
}
}
%typemap(out,fragment=SWIG_From_frag(bool)) bool {
$result = SWIG_From(bool)($1));
}
Here the macros
SWIG_From_frag => fragment
SWIG_From_dec => declaration
SWIG_From => call
allow you to define/include a fragment, and declare and call the
'from-bool' method as needed. In the simpler case, these macros
just return something like
SWIG_From_frag(bool) => "SWIG_From_bool"
SWIG_From_dec(bool) => SWIG_From_bool
SWIG_From(bool) => SWIG_From_bool
But they are specialized for the different languages requirements,
such as perl or tcl that requires passing the interpreter pointer,
and also they can manage C++ ugly types, for example:
SWIG_From_frag(std::complex<double>) => "SWIG_From_std_complex_Sl_double_Sg_"
SWIG_From_dec(std::complex<double>) => SWIG_From_std_complex_Sl_double_Sg_
SWIG_From(std::complex<double>) => SWIG_From_std_complex_Sl_double_Sg_
Hence, to declare methods to use with typemaps, always use the
SWIG_From* macros. In the same way, the SWIG_AsVal* and SWIG_AsPtr*
set of macros are provided.
*/
/* ------------------------------------------------------------
* common fragments
* ------------------------------------------------------------ */
%fragment("<limits.h>","header") %{
#include <limits.h>
%}
%fragment("<wchar.h>","header") %{
#include <wchar.h>
%}
%fragment("<float.h>","header") %{
#include <float.h>
%}

View file

@ -33,12 +33,10 @@
The plain implicit macro takes care of simple type list. If it doesn't
work because you are passing template types with commas, then use
the %implicit_{1,2,3} versions and/or the SWIG_arg macro.
the %implicit_{1,2,3} versions and/or the %arg macro.
*/
%check_swig_object()
%define %implicit_type(Type...)
%traits_swigtype(Type);
%enddef
@ -49,7 +47,7 @@
if (swig::asval<Type >(obj, 0) == SWIG_OK) {
Type _v;
swig::asval<Type >(obj, &_v);
if (val) *val = new value_type(_v);
if (val) *val = %new_copy(_v, value_type);
return SWIG_NEWOBJ;
}
%enddef
@ -86,7 +84,7 @@ namespace swig {
}
%}
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
%typemap_traits_ptr(%checkcode(POINTER),Type);
%enddef
/* implicit_1 */
@ -121,7 +119,7 @@ namespace swig {
}
%}
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
%typemap_traits_ptr(%checkcode(POINTER),Type);
%enddef
@ -159,7 +157,7 @@ namespace swig {
}
%}
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
%typemap_traits_ptr(%checkcode(POINTER),Type);
%enddef
@ -200,5 +198,5 @@ namespace swig {
}
%}
%typemap_traits_ptr(SWIG_CCode(POINTER),Type);
%typemap_traits_ptr(%checkcode(POINTER),Type);
%enddef

View file

@ -3,34 +3,29 @@
* Define the IN/OUTPUT typemaps assuming the output parameters are
* returned in a list, i.e., they are not directly modified.
*
* The user should provide the SWIG_append_result(result, obj) method,
* The user should provide the %append_output(result, obj) method,
* via a macro, which append a particular object to the result.
*
*
* In Tcl, for example, the file is used as:
*
* #define SWIG_append_result(obj) Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),obj);
* #define %append_output(obj) Tcl_ListObjAppendElement(interp,Tcl_GetObjResult(interp),obj);
* %include <typemaps/inoutlist.swg>
*
* while in Python it is used as:
*
* #define SWIG_append_result(obj) $result = SWIG_Python_AppendResult($result, obj)
* #define %append_output(obj) $result = SWIG_Python_AppendResult($result, obj)
* %include <typemaps/inoutlist.swg>
*
* where the method SWIG_Python_AppendResult is defined inside the
* SWIG_append_result fragment.
* %append_output fragment.
*
* If you forget to define SWIG_append_result, this file will generate
* If you forget to define %append_output, this file will generate
* an error.
*
* ------------------------------------------------------------ */
#ifndef SWIG_append_result
#error Undefined Method SWIG_append_result: used in the OUTPUT typemaps
#endif
//
// Uncomment the following definition if you don't want the in/out
// typemaps by default, ie, you prefer to use typemaps.i.
@ -76,60 +71,60 @@ or you can use the %apply directive :
*/
#ifdef SWIG_INPUT_ACCEPT_PTRS
#define SWIG_CheckInputPtr(input,arg,desc,disown) (SWIG_ConvertPtr(input,SWIG_as_voidptrptr(arg),desc,disown) == SWIG_OK)
#define %check_input_ptr(input,arg,desc,disown) (SWIG_ConvertPtr(input,%as_voidptrptr(arg),desc,disown) == SWIG_OK)
#else
#define SWIG_CheckInputPtr(input,arg,desc,disown) (0)
#define %check_input_ptr(input,arg,desc,disown) (0)
#endif
%define _SWIG_VALUE_INPUT_TYPEMAP(code, asval_meth, asval_frag, Type)
%define %_value_input_typemap(code, asval_meth, asval_frag, Type)
%typemap(in,noblock=1,fragment=asval_frag) Type *INPUT ($*ltype temp, int res = 0) {
if (!SWIG_CheckInputPtr($input,&$1,$descriptor,$disown)) {
if (!%check_input_ptr($input,&$1,$descriptor,$disown)) {
Type val;
int ecode = asval_meth($input, &val);
if (ecode != SWIG_OK) {
SWIG_arg_fail(ecode, "$*ltype",$argnum);
%argument_fail(ecode, "$*ltype",$argnum);
}
temp = SWIG_static_cast(val, $*ltype);
temp = %static_cast(val, $*ltype);
$1 = &temp;
res = SWIG_NEWOBJ;
}
}
%typemap(in,noblock=1,fragment=asval_frag) Type &INPUT($*ltype temp, int res = 0) {
if (!SWIG_CheckInputPtr($input,&$1,$descriptor,$disown)) {
if (!%check_input_ptr($input,&$1,$descriptor,$disown)) {
Type val;
int ecode = asval_meth($input, &val);
if (ecode != SWIG_OK) {
SWIG_arg_fail(ecode, "$*ltype",$argnum);
%argument_fail(ecode, "$*ltype",$argnum);
}
temp = SWIG_static_cast(val, $*ltype);
temp = %static_cast(val, $*ltype);
$1 = &temp;
res = SWIG_NEWOBJ;
}
}
%typemap(typecheck,noblock=1,precedence=code,fragment=asval_frag) Type *INPUT, Type &INPUT {
void *ptr;
$1 = ((asval_meth($input, 0) == SWIG_OK) || (SWIG_CheckInputPtr($input,&ptr,$1_descriptor,0)));
$1 = ((asval_meth($input, 0) == SWIG_OK) || (%check_input_ptr($input,&ptr,$1_descriptor,0)));
}
%enddef
%define _SWIG_PTR_INPUT_TYPEMAP(code,asptr_meth,asptr_frag,Type)
%define %_ptr_input_typemap(code,asptr_meth,asptr_frag,Type)
%typemap(in,noblock=1,fragment=asptr_frag) Type *INPUT(int res = 0) {
res = asptr_meth($input, &$1);
if (!res) {
SWIG_arg_fail(SWIG_TypeError,"$type",$argnum);
%argument_fail(SWIG_TypeError,"$type",$argnum);
}
}
%typemap(in,noblock=1,fragment=asptr_frag) Type &INPUT(int res = 0) {
res = asptr_meth($input, &$1);
if (!res) {
SWIG_arg_fail(SWIG_TypeError,"$type",$argnum);
%argument_fail(SWIG_TypeError,"$type",$argnum);
}
if (!$1) {
SWIG_arg_nullref("$type",$argnum);
%argument_nullref("$type",$argnum);
}
}
%typemap(freearg,noblock=1) Type *INPUT, Type &INPUT {
if (res$argnum == SWIG_NEWOBJ) SWIG_delete($1);
if (res$argnum == SWIG_NEWOBJ) %delete($1);
}
%typemap(typecheck,noblock=1,precedence=code,fragment=asptr_frag) Type *INPUT, Type &INPUT {
$1 = asptr_meth($input, (Type**)0) != 0;
@ -167,15 +162,18 @@ values.
*/
%define _SWIG_VALUE_OUTPUT_TYPEMAP(from_meth, from_frag, Type)
%define %_value_output_typemap(from_meth, from_frag, Type)
%typemap(in,numinputs=0,noblock=1)
Type *OUTPUT ($*1_ltype temp, int res = SWIG_NEWOBJ),
Type &OUTPUT ($*1_ltype temp, int res = SWIG_NEWOBJ) {
$1 = &temp;
}
%typemap(argout,noblock=1,fragment=from_frag) Type *OUTPUT, Type &OUTPUT {
SWIG_append_result(((res$argnum == SWIG_NEWOBJ) ?
from_meth((*$1)) : SWIG_NewPointerObj((void*)($1), $1_descriptor, 0)));
if (res$argnum == SWIG_NEWOBJ) {
%append_output(from_meth((*$1)));
} else {
%append_output(SWIG_NewPointerObj((void*)($1), $1_descriptor, 0));
}
}
%enddef
@ -218,7 +216,7 @@ phased out in future releases.
*/
%define _SWIG_VALUE_INOUT_TYPEMAP(Type)
%define %_value_inout_typemap(Type)
%typemap(in) Type *INOUT = Type *INPUT;
%typemap(in) Type &INOUT = Type &INPUT;
%typemap(typecheck) Type *INOUT = Type *INPUT;
@ -228,51 +226,51 @@ phased out in future releases.
%enddef
%define _SWIG_PTR_INOUT_TYPEMAP(Type)
_SWIG_VALUE_INOUT_TYPEMAP(SWIG_arg(Type))
%define %_ptr_inout_typemap(Type)
%_value_inout_typemap(%arg(Type))
%typemap(freearg) Type *INOUT = Type *INPUT;
%typemap(freearg) Type &INOUT = Type &INPUT;
%enddef
#ifndef SWIG_INOUT_NODEF
#define SWIG_VALUE_INPUT_TYPEMAP(code,_a,_af,...) \
_SWIG_VALUE_INPUT_TYPEMAP(SWIG_arg(code),SWIG_arg(_a), \
SWIG_arg(_af),SWIG_arg(__VA_ARGS__))
#define %value_input_typemap(code,_a,_af,...) \
%_value_input_typemap(%arg(code),%arg(_a), \
%arg(_af),%arg(__VA_ARGS__))
#define SWIG_PTR_INPUT_TYPEMAP(code,_a,_af,...) \
_SWIG_PTR_INPUT_TYPEMAP(SWIG_arg(code),SWIG_arg(_a),SWIG_arg(_af), \
SWIG_arg(__VA_ARGS__))
#define %ptr_input_typemap(code,_a,_af,...) \
%_ptr_input_typemap(%arg(code),%arg(_a),%arg(_af), \
%arg(__VA_ARGS__))
#define SWIG_VALUE_OUTPUT_TYPEMAP(_f,_ff,...) \
_SWIG_VALUE_OUTPUT_TYPEMAP(SWIG_arg(_f),SWIG_arg(_ff),SWIG_arg(__VA_ARGS__))
#define %value_output_typemap(_f,_ff,...) \
%_value_output_typemap(%arg(_f),%arg(_ff),%arg(__VA_ARGS__))
#define SWIG_VALUE_INOUT_TYPEMAP(...) _SWIG_VALUE_INOUT_TYPEMAP(SWIG_arg(__VA_ARGS__))
#define SWIG_PTR_INOUT_TYPEMAP(...) _SWIG_PTR_INOUT_TYPEMAP(SWIG_arg(__VA_ARGS__))
#define %value_inout_typemap(...) %_value_inout_typemap(%arg(__VA_ARGS__))
#define %ptr_inout_typemap(...) %_ptr_inout_typemap(%arg(__VA_ARGS__))
#else /* You need to include typemaps.i */
#define SWIG_VALUE_OUTPUT_TYPEMAP(...)
#define SWIG_VALUE_INPUT_TYPEMAP(...)
#define SWIG_VALUE_INOUT_TYPEMAP(...)
#define SWIG_PTR_INPUT_TYPEMAP(...)
#define SWIG_PTR_INOUT_TYPEMAP(...)
#define %value_output_typemap(...)
#define %value_input_typemap(...)
#define %value_inout_typemap(...)
#define %ptr_input_typemap(...)
#define %ptr_inout_typemap(...)
#endif /* SWIG_INOUT_DEFAULT */
%define %typemap_inout(Code, AsValMeth, FromMeth, AsValFrag, FromFrag, Type...)
_SWIG_VALUE_INPUT_TYPEMAP(SWIG_arg(Code), SWIG_arg(AsValMeth),
SWIG_arg(AsValFrag), SWIG_arg(Type));
_SWIG_VALUE_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), SWIG_arg(Type));
_SWIG_VALUE_INOUT_TYPEMAP(SWIG_arg(Type));
%define %typemaps_inout(Code, AsValMeth, FromMeth, AsValFrag, FromFrag, Type...)
%_value_input_typemap(%arg(Code), %arg(AsValMeth),
%arg(AsValFrag), %arg(Type));
%_value_output_typemap(%arg(FromMeth), %arg(FromFrag), %arg(Type));
%_value_inout_typemap(%arg(Type));
%enddef
%define %typemap_inoutn(Code,Type...)
%typemap_inout(SWIG_arg(Code),
SWIG_arg(SWIG_AsVal(Type)),
SWIG_arg(SWIG_From(Type)),
SWIG_arg(SWIG_AsVal_frag(Type)),
SWIG_arg(SWIG_From_frag(Type)),
SWIG_arg(Type));
%define %typemaps_inoutn(Code,Type...)
%typemaps_inout(%arg(Code),
%arg(SWIG_AsVal(Type)),
%arg(SWIG_From(Type)),
%arg(SWIG_AsVal_frag(Type)),
%arg(SWIG_From_frag(Type)),
%arg(Type));
%enddef

View file

@ -1,9 +1,40 @@
/* ------------------------------------------------------------
* typemap for primitive type with no pointer representation
* Basic fragments derived from long and double types
* ------------------------------------------------------------ */
%define %typemap_primitive(Code, Type...)
%typemap_asvalfromn(SWIG_arg(Code), Type);
/* signed/unsigned char */
%numeric_slong(signed char, "<limits.h>", SCHAR_MIN, SCHAR_MAX)
%numeric_ulong(unsigned char, "<limits.h>", UCHAR_MAX)
/* short/unsigned short */
%numeric_slong(short, "<limits.h>", SHRT_MIN, SHRT_MAX)
%numeric_ulong(unsigned short, "<limits.h>", USHRT_MAX)
/* int/unsigned int */
%numeric_slong(int, "<limits.h>", INT_MIN, INT_MAX)
%numeric_ulong(unsigned int, "<limits.h>", UINT_MAX)
/* signed/unsigned wchar_t */
#ifdef __cplusplus
%numeric_slong(signed wchar_t, "<wchar.h>", WCHAR_MIN, WCHAR_MAX)
%numeric_ulong(unsigned wchar_t, "<wchar.h>", UWCHAR_MAX)
#endif
/* float */
%numeric_double(float, "<float.h>", -FLT_MAX, FLT_MAX)
/* ------------------------------------------------------------
* typemap macro for primitive types with asval/from methods
* ------------------------------------------------------------ */
%define %typemaps_primitive(Code, Type)
%typemaps_asvalfromn(%arg(Code), Type);
%enddef
/* ------------------------------------------------------------
@ -14,7 +45,7 @@
%define _apply_macro(macro, arg2, arg1...)
#if #arg1 != ""
macro(SWIG_arg(arg1),arg2);
macro(%arg(arg1),arg2);
#else
macro(arg2);
#endif
@ -53,80 +84,27 @@ _apply_macro(Macro, std::complex<double>, __VA_ARGS__);
%enddef
%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);
Macro(%checkcode(BOOL), bool);
Macro(%checkcode(INT8), signed char);
Macro(%checkcode(UINT8), unsigned char);
Macro(%checkcode(INT16), short);
Macro(%checkcode(UINT16), unsigned short);
Macro(%checkcode(INT32), int);
Macro(%checkcode(UINT32), unsigned int);
Macro(%checkcode(INT64), long);
Macro(%checkcode(UINT64), unsigned long);
Macro(%checkcode(INT128), long long);
Macro(%checkcode(UINT128), unsigned long long);
Macro(%checkcode(FLOAT), float);
Macro(%checkcode(DOUBLE), double);
Macro(%checkcode(CHAR), char);
Macro(%checkcode(UNICHAR), wchar_t);
%enddef
/* ------------------------------------------------------------
* common fragments and macro helpers
* Apply the primitive typemap for all the types with checkcode
* ------------------------------------------------------------ */
%fragment("<limits.h>","header") %{
#include <limits.h>
%}
%fragment("<wchar.h>","header") %{
#include <wchar.h>
%}
%fragment("<float.h>","header") %{
#include <float.h>
%}
/* Macros for derived types */
%define %derived_type_from(Base, Type)
%fragment(SWIG_From_frag(Type),"header",
fragment=SWIG_From_frag(Base)) {
SWIG_define(SWIG_From_dec(Type), SWIG_From_dec(Base))
}
%enddef
%define %derived_type_asval(Base, Type, Frag, OverflowCond)
%check_swig_object()
%fragment(SWIG_AsVal_frag(Type),"header",
fragment=Frag,
fragment=SWIG_AsVal_frag(Base)) {
SWIGINTERN int
SWIG_AsVal_dec(Type)(SWIG_Object obj, Type *val)
{
Base v;
int res = SWIG_AsVal(Base)(obj, &v);
if (res == SWIG_OK) {
if (OverflowCond) {
return SWIG_OverflowError;
} else {
if (val) *val = SWIG_numeric_cast(v, Type);
return SWIG_OK;
}
}
return res;
}
}
%enddef
%define %signed_derived_type_asval(Base, Type, Frag, Min, Max)
%derived_type_asval(Base, Type, Frag, (v < Min || v > Max))
%enddef
%define %unsigned_derived_type_asval(Base, Type, Frag, Max)
%derived_type_asval(Base, Type, Frag, (v > Max))
%enddef
%apply_checkctypes(%typemaps_primitive);

View file

@ -1,82 +1,101 @@
/*
Value typemaps (Type, const Type&) for "Ptr" types, such as swig
wrapped classes, that define the AsPtr/From methods
*/
/*---------------------------------------------------------------------
* Value typemaps (Type, const Type&) for "Ptr" types, such as swig
* wrapped classes, that define the AsPtr/From methods
*
* To apply them, just use one of the following macros:
*
* %typemaps_asptr(CheckCode, AsPtrMeth, AsPtrFrag, Type)
* %typemaps_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type)
*
* or the simpler and normalize form:
*
* %typemaps_asptrfromn(CheckCode, Type)
*
* Also, you can use the individual typemap definitions:
*
* %ptr_in_typemap(asptr_meth,frag,Type)
* %ptr_varin_typemap(asptr_meth,frag,Type)
* %ptr_typecheck_typemap(check,asptr_meth,frag,Type)
* %ptr_directorout_typemap(asptr_meth,frag,Type)
*
*---------------------------------------------------------------------*/
%include <typemaps/valtypes.swg>
/* in */
%define SWIG_PTR_IN_TYPEMAP(asptr_meth,frag,Type...)
%define %ptr_in_typemap(asptr_meth,frag,Type...)
%typemap(in,fragment=frag) Type {
Type *ptr = (Type *)0;
int res = asptr_meth($input, &ptr);
if (!res || !ptr) { SWIG_arg_fail(SWIG_TypeError, "$type", $argnum); }
if (!res || !ptr) { %argument_fail(SWIG_TypeError, "$type", $argnum); }
$1 = *ptr;
if (res == SWIG_NEWOBJ) SWIG_delete(ptr);
if (res == SWIG_NEWOBJ) %delete(ptr);
}
%typemap(in,fragment=frag) const Type & (int res = 0) {
Type *ptr = (Type *)0;
res = asptr_meth($input, &ptr);
if (!res) { SWIG_arg_fail(SWIG_TypeError,"$type",$argnum); }
if (!ptr) { SWIG_arg_nullref("$type",$argnum); }
if (!res) { %argument_fail(SWIG_TypeError,"$type",$argnum); }
if (!ptr) { %argument_nullref("$type",$argnum); }
$1 = ptr;
}
%typemap(freearg,noblock=1) const Type & {
if (res$argnum == SWIG_NEWOBJ) SWIG_delete($1);
if (res$argnum == SWIG_NEWOBJ) %delete($1);
}
%enddef
/* varin */
%define SWIG_PTR_VARIN_TYPEMAP(asptr_meth,frag,Type...)
%define %ptr_varin_typemap(asptr_meth,frag,Type...)
%typemap(varin,fragment=frag) Type {
Type *ptr = (Type *)0;
int res = asptr_meth($input, &ptr);
if (!res || !ptr) { SWIG_var_fail(SWIG_TypeError, "$type", "$name"); }
if (!res || !ptr) { %variable_fail(SWIG_TypeError, "$type", "$name"); }
$1 = *ptr;
if (res == SWIG_NEWOBJ) SWIG_delete(ptr);
if (res == SWIG_NEWOBJ) %delete(ptr);
}
%enddef
#ifdef SWIG_DIRECTOR_TYPEMAPS
/* directorout */
%define SWIG_PTR_DIRECTOROUT_TYPEMAP(asptr_meth,frag,Type...)
%define %ptr_directorout_typemap(asptr_meth,frag,Type...)
%typemap(directorargout,noblock=1,fragment=frag) Type *DIRECTOROUT ($*ltype temp) {
Type *optr = 0;
int ores = $input ? asptr_meth($input, &optr) : 0;
if (!ores || !optr) {
SWIG_dout_fail(SWIG_TypeError,"$type");
%dirout_fail(SWIG_TypeError,"$type");
}
temp = *optr;
$result = &temp;
if (ores == SWIG_NEWOBJ) SWIG_delete(optr);
if (ores == SWIG_NEWOBJ) %delete(optr);
}
%typemap(directorout,noblock=1,fragment=frag) Type {
Type *optr = 0;
int ores = asptr_meth($input, &optr);
if (!ores || !optr) {
SWIG_dout_fail(SWIG_TypeError,"$type");
%dirout_fail(SWIG_TypeError,"$type");
}
$result = *optr;
if (ores == SWIG_NEWOBJ) SWIG_delete(optr);
if (ores == SWIG_NEWOBJ) %delete(optr);
}
%typemap(directorout,noblock=1,fragment=frag,warning=SWIG_WARN_TYPEMAP_THREAD_UNSAFE) const Type& {
Type *optr = 0;
int ores = asptr_meth($input, &optr);
if (!ores) {
SWIG_dout_fail(SWIG_TypeError,"$type");
%dirout_fail(SWIG_TypeError,"$type");
} else {
if (!optr) {
SWIG_dout_nullref("$type");
%dirout_nullref("$type");
}
}
if (ores == SWIG_NEWOBJ) {
/* Possible thread/reentrant problem here! */
static $*ltype temp = *optr;
$result = &temp;
SWIG_delete(optr);
%delete(optr);
} else {
$result = optr;
}
@ -88,26 +107,26 @@
#else
#define SWIG_PTR_DIRECTOROUT_TYPEMAP(asptr_meth,frag,Type...)
#define %ptr_directorout_typemap(asptr_meth,frag,Type...)
#endif /* SWIG_DIRECTOR_TYPEMAPS */
/* typecheck */
%define SWIG_PTR_TYPECHECK_TYPEMAP(check,asptr_meth,frag,Type...)
%define %ptr_typecheck_typemap(check,asptr_meth,frag,Type...)
%typemap(typecheck,precedence=check,fragment=frag)
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
/*---------------------------------------------------------------------
* typemap definition for types with asptr method
*---------------------------------------------------------------------*/
%define %typemaps_asptr(CheckCode, AsPtrMeth, AsPtrFrag, Type...)
%fragment(SWIG_AsVal_frag(Type),"header",fragment=SWIG_AsPtr_frag(Type)) {
SWIGINTERNINLINE int
SWIG_AsVal(Type)(SWIG_Object obj, Type *val)
{
Type *v = (Type *)0;
@ -115,43 +134,38 @@
if (!res || !v) return SWIG_ERROR;
if (val) {
*val = *v;
if (res == SWIG_NEWOBJ) SWIG_delete(v);
if (res == SWIG_NEWOBJ) %delete(v);
}
return SWIG_OK;
}
%}
%fragment(SWIG_As_frag(Type),"header",
fragment=SWIG_AsVal_frag(Type)) %{
SWIGINTERNINLINE Type
SWIG_As(Type)(SWIG_Object obj)
{
Type v;
SWIG_AsVal(Type)(obj, &v);
return v;
}
%}
SWIG_PTR_IN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
SWIG_PTR_VARIN_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
SWIG_PTR_DIRECTOROUT_TYPEMAP(SWIG_arg(AsPtrMeth), SWIG_arg(AsPtrFrag), Type);
SWIG_PTR_TYPECHECK_TYPEMAP(SWIG_arg(CheckCode), SWIG_arg(AsPtrMeth),
SWIG_arg(AsPtrFrag), Type);
%typemap_from(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
SWIG_PTR_INPUT_TYPEMAP(SWIG_arg(CheckCode),SWIG_arg(AsPtrMeth),
SWIG_arg(AsPtrFrag),Type);
SWIG_VALUE_OUTPUT_TYPEMAP(SWIG_arg(FromMeth), SWIG_arg(FromFrag), Type);
SWIG_PTR_INOUT_TYPEMAP(Type);
}
%ptr_in_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
%ptr_varin_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
%ptr_directorout_typemap(%arg(AsPtrMeth), %arg(AsPtrFrag), Type);
%ptr_typecheck_typemap(%arg(CheckCode), %arg(AsPtrMeth),%arg(AsPtrFrag), Type);
%ptr_input_typemap(%arg(CheckCode),%arg(AsPtrMeth),%arg(AsPtrFrag),Type);
%enddef
/*
typemap for simple swig types with only AsPtr/From methods
*/
/*---------------------------------------------------------------------
* typemap definition for types with 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)),
%define %typemaps_asptrfrom(CheckCode, AsPtrMeth, FromMeth, AsPtrFrag, FromFrag, Type...)
%typemaps_asptr(%arg(CheckCode), %arg(AsPtrMeth), %arg(AsPtrFrag), Type)
%typemaps_from(%arg(FromMeth), %arg(FromFrag), Type);
%value_output_typemap(%arg(FromMeth), %arg(FromFrag), Type);
%ptr_inout_typemap(Type);
%enddef
/*---------------------------------------------------------------------
* typemap definition for types with for 'normalized' asptr/from methods
*---------------------------------------------------------------------*/
%define %typemaps_asptrfromn(CheckCode, Type...)
%typemaps_asptrfrom(%arg(CheckCode),
%arg(SWIG_AsPtr(Type)),
%arg(SWIG_From(Type)),
%arg(SWIG_AsPtr_frag(Type)),
%arg(SWIG_From_frag(Type)),
Type);
%enddef

View file

@ -1,69 +1,24 @@
//
// String
//
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_STRING
%include <typemaps/std_strings.swg>
/* defining the String asptr/from methods */
%define %std_string_asptr_frag(String, Char, SWIG_AsCharPtrAndSize, Frag)
%check_swig_object()
%fragment(SWIG_AsPtr_frag(String),"header",fragment=Frag) {
SWIGINTERN int
SWIG_AsPtr_dec(String)(SWIG_Object obj, String **val)
%{
#include <string>
%}
namespace std
{
static swig_type_info* string_info = SWIG_TypeQuery(#String " *");
String *vptr;
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) {
if (val) *val = vptr;
return SWIG_OLDOBJ;
} else {
Char* buf = 0 ; size_t size = 0; int alloc = SWIG_OLDOBJ;
if (SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
if (buf) {
if (val) *val = new String(buf, size - 1);
if (alloc == SWIG_NEWOBJ) SWIG_delete_array(buf);
return SWIG_NEWOBJ;
}
}
return 0;
}
class string;
}
}
%enddef
%define %std_string_from_frag(String, SWIG_FromCharPtrAndSize, Frag)
%check_swig_object()
%fragment(SWIG_From_frag(String),"header",fragment=Frag) {
SWIGINTERNINLINE SWIG_Object
SWIG_From_dec(String)(const String& s)
{
return SWIG_FromCharPtrAndSize(s.data(), s.size());
}
}
%enddef
%typemaps_std_string(std::string, char, SWIG_AsCharPtrAndSize, SWIG_FromCharPtrAndSize, %checkcode(STRING));
%define %std_string_asval_frag(String, Frag)
%check_swig_object()
%fragment(SWIG_AsVal_frag(String),"header", fragment=Frag) {
SWIGINTERN int
SWIG_AsVal_dec(String)(SWIG_Object obj, String *val)
{
String* s;
int res = SWIG_AsPtr(String)(obj, &s);
if ((res != 0) && s) {
if (val) *val = *s;
if (res == SWIG_NEWOBJ) delete s;
return SWIG_OK;
}
return SWIG_TypeError;
}
}
%enddef
#else
%include <std/std_string.i>
#define %std_string_asptr(String, Char, Method) %std_string_asptr_frag(String, Char, Method, #Method)
#define %std_string_asval(String) %std_string_asval_frag(String, SWIG_AsPtr_frag(String))
#define %std_string_from(String, Method) %std_string_from_frag(String, Method, #Method)
#endif

View file

@ -0,0 +1,65 @@
/* defining the String asptr/from methods */
%define %std_string_asptr(String, Char, SWIG_AsCharPtrAndSize, Frag)
%fragment(SWIG_AsPtr_frag(String),"header",fragment=Frag) {
SWIGINTERN int
SWIG_AsPtr_dec(String)(SWIG_Object obj, String **val)
{
static swig_type_info* string_info = SWIG_TypeQuery(#String " *");
String *vptr;
if (SWIG_ConvertPtr(obj, (void**)&vptr, string_info, 0) != -1) {
if (val) *val = vptr;
return SWIG_OLDOBJ;
} else {
Char* buf = 0 ; size_t size = 0; int alloc = SWIG_OLDOBJ;
if (SWIG_AsCharPtrAndSize(obj, &buf, &size, &alloc) == SWIG_OK) {
if (buf) {
if (val) *val = new String(buf, size - 1);
if (alloc == SWIG_NEWOBJ) %delete_array(buf);
return SWIG_NEWOBJ;
}
}
return 0;
}
}
}
%enddef
%define %std_string_from(String, SWIG_FromCharPtrAndSize, Frag)
%fragment(SWIG_From_frag(String),"header",fragment=Frag) {
SWIGINTERNINLINE SWIG_Object
SWIG_From_dec(String)(const String& s)
{
return SWIG_FromCharPtrAndSize(s.data(), s.size());
}
}
%enddef
%define %std_string_asval(String)
%fragment(SWIG_AsVal_frag(String),"header", fragment=SWIG_AsPtr_frag(String)) {
SWIGINTERN int
SWIG_AsVal_dec(String)(SWIG_Object obj, String *val)
{
String* s;
int res = SWIG_AsPtr(String)(obj, &s);
if ((res != 0) && s) {
if (val) *val = *s;
if (res == SWIG_NEWOBJ) delete s;
return SWIG_OK;
}
return SWIG_TypeError;
}
}
%enddef
%define %typemaps_std_string(String, Char, AsPtrMethod, FromMethod, CheckCode)
%std_string_asptr(String, Char, AsPtrMethod, #AsPtrMethod)
%std_string_asval(String)
%std_string_from(String, FromMethod, #FromMethod)
%typemaps_asptrfromn(%arg(CheckCode), String);
%enddef

View file

@ -0,0 +1,25 @@
%include <typemaps/wstring.swg>
#ifndef SWIG_STD_BASIC_STRING
#define SWIG_STD_WSTRING
%include <typemaps/std_strings.swg>
%{
#include <cwchar>
#include <string>
%}
namespace std
{
class wstring;
}
%typemaps_std_string(std::wstring, wchar_t, SWIG_AsWCharPtrAndSize, SWIG_FromWCharPtrAndSize, %checkcode(UNISTRING));
#else
%include <std/std_wstring.i>
#endif

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