modifying build system not to rely on the -I path to find the input files avoiding warning 125: move python .i files up one directory, some files have been renamed - prepended with python
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@10953 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
c3047165d6
commit
b266e1f68c
29 changed files with 19 additions and 72 deletions
23
Examples/test-suite/argcargvtest.i
Normal file
23
Examples/test-suite/argcargvtest.i
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
%module argcargvtest
|
||||
|
||||
%include <argcargv.i>
|
||||
|
||||
%apply (int ARGC, char **ARGV) { (size_t argc, const char **argv) }
|
||||
|
||||
%inline %{
|
||||
|
||||
int mainc(size_t argc, const char **argv)
|
||||
{
|
||||
return (int)argc;
|
||||
}
|
||||
|
||||
const char* mainv(size_t argc, const char **argv, int idx)
|
||||
{
|
||||
return argv[idx];
|
||||
}
|
||||
|
||||
void initializeApp(size_t argc, const char **argv, bool setPGid = true, bool isMakeline = false)
|
||||
{
|
||||
}
|
||||
|
||||
%}
|
||||
72
Examples/test-suite/callback.i
Normal file
72
Examples/test-suite/callback.i
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
%module callback
|
||||
|
||||
%callback(1) foo;
|
||||
%callback(1) foof;
|
||||
%callback(1) A::bar;
|
||||
%callback(1) A::foom;
|
||||
%callback("%s_Cb_Ptr") foo_T; // old style, still works.
|
||||
|
||||
%inline %{
|
||||
|
||||
int foo(int a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
int foof(int a) {
|
||||
return 3*a;
|
||||
}
|
||||
|
||||
struct A
|
||||
{
|
||||
static int bar(int a) {
|
||||
return 2*a;
|
||||
}
|
||||
|
||||
int foom(int a)
|
||||
{
|
||||
return -a;
|
||||
}
|
||||
|
||||
//friend int foof(int a);
|
||||
};
|
||||
|
||||
|
||||
extern "C" int foobar(int a, int (*pf)(int a)) {
|
||||
return pf(a);
|
||||
}
|
||||
|
||||
extern "C" int foobarm(int a, A ap, int (A::*pf)(int a)) {
|
||||
return (ap.*pf)(a);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T foo_T(T a)
|
||||
{
|
||||
return a;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
T foo_T(T a, T b)
|
||||
{
|
||||
return a + b;
|
||||
}
|
||||
|
||||
|
||||
template <class T>
|
||||
T foobar_T(T a, T (*pf)(T a)) {
|
||||
return pf(a);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
const T& ident(const T& x) {
|
||||
return x;
|
||||
}
|
||||
%}
|
||||
|
||||
%template(foo_i) foo_T<int>;
|
||||
%template(foobar_i) foobar_T<int>;
|
||||
|
||||
%template(foo_d) foo_T<double>;
|
||||
%template(foobar_d) foobar_T<double>;
|
||||
|
||||
%template(ident_d) ident<double>;
|
||||
61
Examples/test-suite/complextest.i
Normal file
61
Examples/test-suite/complextest.i
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
%module complextest
|
||||
|
||||
%include <complex.i>
|
||||
|
||||
#ifdef __cplusplus
|
||||
%{
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
%}
|
||||
%include <std_vector.i>
|
||||
|
||||
#if 1
|
||||
%template(VectorStdCplx) std::vector<std::complex<double> >;
|
||||
#endif
|
||||
|
||||
%inline
|
||||
{
|
||||
std::complex<double> Conj(const std::complex<double>& a)
|
||||
{
|
||||
return std::conj(a);
|
||||
}
|
||||
|
||||
std::complex<float> Conjf(const std::complex<float>& a)
|
||||
{
|
||||
return std::conj(a);
|
||||
}
|
||||
|
||||
#if 1
|
||||
std::vector<std::complex<double> > Copy_h(const std::vector<std::complex<double> >& a)
|
||||
{
|
||||
std::vector<std::complex<double> > b(a.size()/2);
|
||||
std::copy(a.begin(), a.begin()+a.size()/2, b.begin());
|
||||
return b;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#else
|
||||
|
||||
|
||||
%{
|
||||
%}
|
||||
|
||||
%inline
|
||||
{
|
||||
complex Conj(complex a)
|
||||
{
|
||||
return conj(a);
|
||||
}
|
||||
|
||||
|
||||
complex float Conjf(float complex a)
|
||||
{
|
||||
return conj(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
64
Examples/test-suite/director_profile.i
Normal file
64
Examples/test-suite/director_profile.i
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
%module(directors="1") director_profile
|
||||
|
||||
%include std_string.i
|
||||
|
||||
%feature("director") B;
|
||||
|
||||
|
||||
%inline %{
|
||||
|
||||
class A {
|
||||
public:
|
||||
A() {}
|
||||
};
|
||||
|
||||
class B
|
||||
{
|
||||
A aa;
|
||||
public:
|
||||
B() {}
|
||||
|
||||
virtual A fn(const A* a) {
|
||||
return *a;
|
||||
}
|
||||
|
||||
virtual int vfi(int a) {
|
||||
return a + 1;
|
||||
}
|
||||
|
||||
int fi(int a) {
|
||||
return vfi(a);
|
||||
}
|
||||
|
||||
int fj(const A* a) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
B* fk(int i) {
|
||||
return this;
|
||||
}
|
||||
|
||||
const char* fl(int i) {
|
||||
return "hello";
|
||||
}
|
||||
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
|
||||
static B* get_self(B *b)
|
||||
{
|
||||
return b;
|
||||
}
|
||||
|
||||
virtual std::string vfs(const std::string& a) {
|
||||
return a;
|
||||
}
|
||||
|
||||
std::string fs(const std::string& a) {
|
||||
return vfs(a);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
%}
|
||||
76
Examples/test-suite/director_stl.i
Normal file
76
Examples/test-suite/director_stl.i
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
%module(directors="1") director_stl
|
||||
#pragma SWIG nowarn=SWIGWARN_TYPEMAP_THREAD_UNSAFE,SWIGWARN_TYPEMAP_DIRECTOROUT_PTR
|
||||
|
||||
%include "std_string.i"
|
||||
%include "std_pair.i"
|
||||
%include "std_vector.i"
|
||||
|
||||
#ifndef SWIG_STD_DEFAULT_INSTANTIATION
|
||||
%template() std::vector<double>;
|
||||
%template() std::vector<int>;
|
||||
%template() std::vector<std::string>;
|
||||
%template() std::pair<std::string, int>;
|
||||
%template() std::pair<int,double>;
|
||||
%template() std::pair<double,int>;
|
||||
#endif
|
||||
|
||||
%feature("director") Foo;
|
||||
|
||||
%feature("director:except") {
|
||||
if ($error != NULL) {
|
||||
throw Swig::DirectorMethodException();
|
||||
}
|
||||
}
|
||||
|
||||
%exception {
|
||||
try { $action }
|
||||
catch (...) { SWIG_fail; }
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
class Foo {
|
||||
public:
|
||||
virtual ~Foo() {}
|
||||
|
||||
virtual std::string& bar(std::string& s)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
virtual std::string ping(std::string s) = 0;
|
||||
virtual std::string pong(const std::string& s)
|
||||
{ return std::string("Foo::pong:") + s + ":" + ping(s); }
|
||||
|
||||
std::string tping(std::string s) { return ping(s); }
|
||||
std::string tpong(const std::string& s) { return pong(s); }
|
||||
|
||||
virtual std::pair<double, int>
|
||||
pident(const std::pair<double, int>& p) { return p; }
|
||||
|
||||
virtual std::vector<int>
|
||||
vident(const std::vector<int>& p) { return p; }
|
||||
|
||||
virtual std::vector<int>
|
||||
vsecond(const std::vector<int>& p, const std::vector<int>& s) { return s; }
|
||||
|
||||
std::pair<double, int>
|
||||
tpident(const std::pair<double, int>& p) { return pident(p); }
|
||||
|
||||
std::vector<int>
|
||||
tvident(const std::vector<int>& p) { return vident(p); }
|
||||
|
||||
virtual std::vector<int>
|
||||
tvsecond(const std::vector<int>& p, const std::vector<int>& s) { return vsecond(p,s); }
|
||||
|
||||
|
||||
virtual std::vector<std::string>
|
||||
vidents(const std::vector<std::string>& p) { return p; }
|
||||
|
||||
std::vector<std::string>
|
||||
tvidents(const std::vector<std::string>& p) { return vidents(p); }
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
12
Examples/test-suite/iadd.i
Normal file
12
Examples/test-suite/iadd.i
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
%module iadd
|
||||
|
||||
%include attribute.i
|
||||
%{
|
||||
#include "iadd.h"
|
||||
%}
|
||||
class Foo;
|
||||
%attribute_ref(test::Foo, test::A& , AsA);
|
||||
%attribute_ref(test::Foo, long, AsLong);
|
||||
|
||||
|
||||
%include "iadd.h"
|
||||
48
Examples/test-suite/inout.i
Normal file
48
Examples/test-suite/inout.i
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
%module inout
|
||||
|
||||
%include "typemaps.i"
|
||||
%include "std_pair.i"
|
||||
|
||||
%{
|
||||
inline void AddOne3(double* a, double* b, double* c) {
|
||||
*a += 1;
|
||||
*b += 1;
|
||||
*c += 1;
|
||||
}
|
||||
|
||||
inline void AddOne1(double* a) {
|
||||
*a += 1;
|
||||
}
|
||||
|
||||
inline void AddOne1p(std::pair<double, double>* p) {
|
||||
p->first += 1;
|
||||
p->second += 1;
|
||||
}
|
||||
|
||||
inline void AddOne2p(std::pair<double, double>* p,double* a) {
|
||||
*a += 1;
|
||||
p->first += 1;
|
||||
p->second += 1;
|
||||
}
|
||||
|
||||
inline void AddOne3p(double* a, std::pair<double, double>* p,double* b) {
|
||||
*a += 1;
|
||||
*b += 1;
|
||||
p->first += 1;
|
||||
p->second += 1;
|
||||
}
|
||||
|
||||
inline void AddOne1r(double& a) {
|
||||
a += 1;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%template() std::pair<double, double>;
|
||||
|
||||
void AddOne1(double* INOUT);
|
||||
void AddOne3(double* INOUT, double* INOUT, double* INOUT);
|
||||
void AddOne1p(std::pair<double, double>* INOUT);
|
||||
void AddOne2p(std::pair<double, double>* INOUT, double* INOUT);
|
||||
void AddOne3p(double* INOUT, std::pair<double, double>* INOUT, double* INOUT);
|
||||
void AddOne1r(double& INOUT);
|
||||
40
Examples/test-suite/inplaceadd.i
Normal file
40
Examples/test-suite/inplaceadd.i
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
%module inplaceadd
|
||||
%{
|
||||
#include <iostream>
|
||||
%}
|
||||
|
||||
|
||||
%inline %{
|
||||
struct A
|
||||
{
|
||||
int val;
|
||||
|
||||
A(int v): val(v)
|
||||
{
|
||||
}
|
||||
|
||||
A& operator+=(int v)
|
||||
{
|
||||
val += v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A& operator+=(const A& a)
|
||||
{
|
||||
val += a.val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A& operator-=(int v)
|
||||
{
|
||||
val -= v;
|
||||
return *this;
|
||||
}
|
||||
|
||||
A& operator*=(int v)
|
||||
{
|
||||
val *= v;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
%}
|
||||
41
Examples/test-suite/input.i
Normal file
41
Examples/test-suite/input.i
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
%module input
|
||||
|
||||
%apply int *INPUT {int *bar};
|
||||
|
||||
%typemap(out, fragment=SWIG_From_frag(int)) int *foo {
|
||||
if ($1) {
|
||||
$result = SWIG_From(int)(*$1);
|
||||
} else {
|
||||
$result = SWIG_Py_Void();
|
||||
}
|
||||
}
|
||||
|
||||
%inline
|
||||
{
|
||||
struct Foo {
|
||||
int *foo(int *bar = 0) {
|
||||
if (bar) {
|
||||
*bar *= 2;
|
||||
}
|
||||
return (bar) ? bar : 0;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
%include std_string.i
|
||||
%apply std::string *INPUT {std::string *bar};
|
||||
|
||||
%typemap(out, fragment=SWIG_From_frag(std::string)) std::string *sfoo {
|
||||
if ($1) {
|
||||
$result = SWIG_From(std::string)(*$1);
|
||||
} else {
|
||||
$result = SWIG_Py_Void();
|
||||
}
|
||||
}
|
||||
|
||||
%inline %{
|
||||
std::string *sfoo(std::string *bar = 0) {
|
||||
if (bar) *bar += " world";
|
||||
return (bar) ? bar : 0;
|
||||
}
|
||||
%}
|
||||
8
Examples/test-suite/li_std_carray.i
Normal file
8
Examples/test-suite/li_std_carray.i
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
%module li_std_carray
|
||||
|
||||
%include <std_carray.i>
|
||||
|
||||
%template(Vector3) std::carray<double, 3>;
|
||||
|
||||
%template(Matrix3) std::carray<std::carray<double, 3>, 3>;
|
||||
|
||||
65
Examples/test-suite/li_std_vectora.i
Normal file
65
Examples/test-suite/li_std_vectora.i
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
%module li_std_vectora
|
||||
|
||||
%include std_vectora.i
|
||||
|
||||
|
||||
%{
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <numeric>
|
||||
%}
|
||||
|
||||
|
||||
%template(vector_i) std::vector<int, std::allocator<int> >;
|
||||
|
||||
%template(matrix_i) std::vector<std::vector<int,std::allocator<int> >,std::allocator<std::vector<int,std::allocator<int> > > >;
|
||||
|
||||
%inline
|
||||
{
|
||||
typedef
|
||||
std::vector<std::vector<int,std::allocator<int> >,
|
||||
std::allocator<std::vector<int,std::allocator<int> > > >
|
||||
imatrix;
|
||||
|
||||
std::vector<int> vident(const std::vector<int,std::allocator<int> >& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
imatrix mident(const imatrix& v)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
%template(DoubleVector) std::vector<double, std::allocator<double> >;
|
||||
|
||||
%inline %{
|
||||
typedef float Real;
|
||||
%}
|
||||
|
||||
namespace std {
|
||||
%template(RealVector) vector<Real, std::allocator<Real> >;
|
||||
}
|
||||
|
||||
%inline %{
|
||||
|
||||
double average(std::vector<int, std::allocator<int> > v) {
|
||||
return std::accumulate(v.begin(),v.end(),0.0)/v.size();
|
||||
}
|
||||
|
||||
std::vector<Real,std::allocator<Real> >
|
||||
half(const std::vector<Real,std::allocator<Real> >& v) {
|
||||
std::vector<Real> w(v);
|
||||
for (unsigned int i=0; i<w.size(); i++)
|
||||
w[i] /= 2.0;
|
||||
return w;
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
%template(IntPtrVector) std::vector<int *,std::allocator<int *> >;
|
||||
|
||||
|
||||
|
||||
59
Examples/test-suite/li_std_wstream.i
Normal file
59
Examples/test-suite/li_std_wstream.i
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
%module li_std_wstream
|
||||
|
||||
%inline %{
|
||||
struct A;
|
||||
%}
|
||||
|
||||
%include <std_wiostream.i>
|
||||
%include <std_wsstream.i>
|
||||
|
||||
|
||||
|
||||
%callback(1) A::bar;
|
||||
|
||||
%inline %{
|
||||
|
||||
struct B {
|
||||
virtual ~B()
|
||||
{
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
struct A : B
|
||||
{
|
||||
void __add__(int a)
|
||||
{
|
||||
}
|
||||
|
||||
void __add__(double a)
|
||||
{
|
||||
}
|
||||
|
||||
static int bar(int a){
|
||||
return a;
|
||||
}
|
||||
|
||||
static int foo(int a, int (*pf)(int a))
|
||||
{
|
||||
return pf(a);
|
||||
}
|
||||
|
||||
|
||||
std::wostream& __rlshift__(std::wostream& out)
|
||||
{
|
||||
out << "A class";
|
||||
return out;
|
||||
}
|
||||
};
|
||||
%}
|
||||
|
||||
%extend std::basic_ostream<wchar_t>{
|
||||
std::basic_ostream<wchar_t>&
|
||||
operator<<(const A& a)
|
||||
{
|
||||
*self << "A class";
|
||||
return *self;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -64,9 +64,10 @@ CPP_TEST_CASES += \
|
|||
std_containers \
|
||||
swigobject \
|
||||
template_matrix \
|
||||
simutry \
|
||||
vector
|
||||
simutry
|
||||
|
||||
# li_std_carray
|
||||
# director_profile
|
||||
|
||||
C_TEST_CASES += \
|
||||
file_test \
|
||||
|
|
|
|||
8
Examples/test-suite/python/python_abstractbase_runme3.py
Normal file
8
Examples/test-suite/python/python_abstractbase_runme3.py
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
from python_abstractbase import *
|
||||
from collections import *
|
||||
assert issubclass(Mapii, MutableMapping)
|
||||
assert issubclass(Multimapii, MutableMapping)
|
||||
assert issubclass(IntSet, MutableSet)
|
||||
assert issubclass(IntMultiset, MutableSet)
|
||||
assert issubclass(IntVector, MutableSequence)
|
||||
assert issubclass(IntList, MutableSequence)
|
||||
67
Examples/test-suite/python/python_kwargs_runme.py
Normal file
67
Examples/test-suite/python/python_kwargs_runme.py
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
from python_kwargs import *
|
||||
|
||||
class MyFoo(Foo):
|
||||
def __init__(self, a , b = 0):
|
||||
Foo.__init__(self, a, b)
|
||||
|
||||
|
||||
|
||||
# Simple class
|
||||
f1 = MyFoo(2)
|
||||
|
||||
f = Foo(b=2,a=1)
|
||||
|
||||
if f.foo(b=1,a=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if Foo_statfoo(b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if f.efoo(b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if Foo_sfoo(b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
# Templated class
|
||||
b = BarInt(b=2,a=1)
|
||||
|
||||
if b.bar(b=1,a=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if BarInt_statbar(b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if b.ebar(b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if BarInt_sbar(b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
# Functions
|
||||
if templatedfunction(b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if foo(a=1,b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
if foo(b=2) != 3:
|
||||
raise RuntimeError
|
||||
|
||||
|
||||
#Funtions with keywords
|
||||
|
||||
if foo_kw(_from=2) != 4:
|
||||
raise RuntimeError
|
||||
|
||||
if foo_nu(_from=2, arg2=3) != 2:
|
||||
raise RuntimeError
|
||||
|
||||
if foo_mm(min=2) != 4:
|
||||
raise RuntimeError
|
||||
|
||||
if foo_mm(max=3) != 4:
|
||||
raise RuntimeError
|
||||
|
||||
39
Examples/test-suite/python/python_nondynamic_runme.py
Normal file
39
Examples/test-suite/python/python_nondynamic_runme.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import python_nondynamic
|
||||
|
||||
aa = python_nondynamic.A()
|
||||
|
||||
aa.a = 1
|
||||
aa.b = 2
|
||||
try:
|
||||
aa.c = 2
|
||||
err = 0
|
||||
except:
|
||||
err = 1
|
||||
|
||||
if not err:
|
||||
raise RuntimeError, "A is not static"
|
||||
|
||||
|
||||
class B(python_nondynamic.A):
|
||||
c = 4
|
||||
def __init__(self):
|
||||
python_nondynamic.A.__init__(self)
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
|
||||
bb = B()
|
||||
bb.c = 3
|
||||
try:
|
||||
bb.d = 2
|
||||
err = 0
|
||||
except:
|
||||
err = 1
|
||||
|
||||
if not err:
|
||||
raise RuntimeError, "B is not static"
|
||||
|
||||
|
||||
cc = python_nondynamic.C()
|
||||
cc.d = 3
|
||||
192
Examples/test-suite/python/python_overload_simple_cast_runme.py
Normal file
192
Examples/test-suite/python/python_overload_simple_cast_runme.py
Normal file
|
|
@ -0,0 +1,192 @@
|
|||
from python_overload_simple_cast import *
|
||||
|
||||
class Ai:
|
||||
def __init__(self,x):
|
||||
self.x = x
|
||||
|
||||
def __int__(self):
|
||||
return self.x
|
||||
|
||||
class Ad:
|
||||
def __init__(self,x):
|
||||
self.x = x
|
||||
|
||||
def __float__(self):
|
||||
return self.x
|
||||
|
||||
ai = Ai(4)
|
||||
|
||||
ad = Ad(5.0)
|
||||
add = Ad(5.5)
|
||||
|
||||
try:
|
||||
fint(add)
|
||||
good = 0
|
||||
except:
|
||||
good = 1
|
||||
|
||||
if not good:
|
||||
raise RuntimeError, "fint(int)"
|
||||
|
||||
|
||||
if fint(ad) != "fint:int":
|
||||
raise RuntimeError, "fint(int)"
|
||||
|
||||
if fdouble(ad) != "fdouble:double":
|
||||
raise RuntimeError, "fdouble(double)"
|
||||
|
||||
if fint(ai) != "fint:int":
|
||||
raise RuntimeError, "fint(int)"
|
||||
|
||||
if fint(5.0) != "fint:int":
|
||||
raise RuntimeError, "fint(int)"
|
||||
|
||||
if fint(3) != "fint:int":
|
||||
raise RuntimeError, "fint(int)"
|
||||
if fint(3.0) != "fint:int":
|
||||
raise RuntimeError, "fint(int)"
|
||||
|
||||
if fdouble(ad) != "fdouble:double":
|
||||
raise RuntimeError, "fdouble(double)"
|
||||
if fdouble(3) != "fdouble:double":
|
||||
raise RuntimeError, "fdouble(double)"
|
||||
if fdouble(3.0) != "fdouble:double":
|
||||
raise RuntimeError, "fdouble(double)"
|
||||
|
||||
if fid(3,3.0) != "fid:intdouble":
|
||||
raise RuntimeError, "fid:intdouble"
|
||||
|
||||
if fid(3.0,3) != "fid:doubleint":
|
||||
raise RuntimeError, "fid:doubleint"
|
||||
|
||||
if fid(ad,ai) != "fid:doubleint":
|
||||
raise RuntimeError, "fid:doubleint"
|
||||
|
||||
if fid(ai,ad) != "fid:intdouble":
|
||||
raise RuntimeError, "fid:intdouble"
|
||||
|
||||
|
||||
|
||||
if foo(3) != "foo:int":
|
||||
raise RuntimeError, "foo(int)"
|
||||
|
||||
if foo(3.0) != "foo:double":
|
||||
raise RuntimeError, "foo(double)"
|
||||
|
||||
if foo("hello") != "foo:char *":
|
||||
raise RuntimeError, "foo(char *)"
|
||||
|
||||
f = Foo()
|
||||
b = Bar()
|
||||
|
||||
if foo(f) != "foo:Foo *":
|
||||
raise RuntimeError, "foo(Foo *)"
|
||||
|
||||
if foo(b) != "foo:Bar *":
|
||||
raise RuntimeError, "foo(Bar *)"
|
||||
|
||||
v = malloc_void(32)
|
||||
|
||||
if foo(v) != "foo:void *":
|
||||
raise RuntimeError, "foo(void *)"
|
||||
|
||||
s = Spam()
|
||||
|
||||
if s.foo(3) != "foo:int":
|
||||
raise RuntimeError, "Spam::foo(int)"
|
||||
|
||||
if s.foo(3.0) != "foo:double":
|
||||
raise RuntimeError, "Spam::foo(double)"
|
||||
|
||||
if s.foo("hello") != "foo:char *":
|
||||
raise RuntimeError, "Spam::foo(char *)"
|
||||
|
||||
if s.foo(f) != "foo:Foo *":
|
||||
raise RuntimeError, "Spam::foo(Foo *)"
|
||||
|
||||
if s.foo(b) != "foo:Bar *":
|
||||
raise RuntimeError, "Spam::foo(Bar *)"
|
||||
|
||||
if s.foo(v) != "foo:void *":
|
||||
raise RuntimeError, "Spam::foo(void *)"
|
||||
|
||||
if Spam_bar(3) != "bar:int":
|
||||
raise RuntimeError, "Spam::bar(int)"
|
||||
|
||||
if Spam_bar(3.0) != "bar:double":
|
||||
raise RuntimeError, "Spam::bar(double)"
|
||||
|
||||
if Spam_bar("hello") != "bar:char *":
|
||||
raise RuntimeError, "Spam::bar(char *)"
|
||||
|
||||
if Spam_bar(f) != "bar:Foo *":
|
||||
raise RuntimeError, "Spam::bar(Foo *)"
|
||||
|
||||
if Spam_bar(b) != "bar:Bar *":
|
||||
raise RuntimeError, "Spam::bar(Bar *)"
|
||||
|
||||
if Spam_bar(v) != "bar:void *":
|
||||
raise RuntimeError, "Spam::bar(void *)"
|
||||
|
||||
# Test constructors
|
||||
|
||||
s = Spam()
|
||||
if s.type != "none":
|
||||
raise RuntimeError, "Spam()"
|
||||
|
||||
s = Spam(3)
|
||||
if s.type != "int":
|
||||
raise RuntimeError, "Spam(int)"
|
||||
|
||||
s = Spam(3.4)
|
||||
if s.type != "double":
|
||||
raise RuntimeError, "Spam(double)"
|
||||
|
||||
s = Spam("hello")
|
||||
if s.type != "char *":
|
||||
raise RuntimeError, "Spam(char *)"
|
||||
|
||||
s = Spam(f)
|
||||
if s.type != "Foo *":
|
||||
raise RuntimeError, "Spam(Foo *)"
|
||||
|
||||
s = Spam(b)
|
||||
if s.type != "Bar *":
|
||||
raise RuntimeError, "Spam(Bar *)"
|
||||
|
||||
s = Spam(v)
|
||||
if s.type != "void *":
|
||||
raise RuntimeError, "Spam(void *)"
|
||||
|
||||
|
||||
# unsigned long long
|
||||
ullmax = 9223372036854775807 #0xffffffffffffffff
|
||||
ullmaxd = 9007199254740992.0
|
||||
ullmin = 0
|
||||
ullmind = 0.0
|
||||
if ull(ullmin) != ullmin:
|
||||
raise runtimeerror, "ull(ullmin)"
|
||||
if ull(ullmax) != ullmax:
|
||||
raise runtimeerror, "ull(ullmax)"
|
||||
if ull(ullmind) != ullmind:
|
||||
raise RuntimeError, "ull(ullmind)"
|
||||
if ull(ullmaxd) != ullmaxd:
|
||||
raise RuntimeError, "ull(ullmaxd)"
|
||||
|
||||
# long long
|
||||
llmax = 9223372036854775807 #0x7fffffffffffffff
|
||||
llmin = -9223372036854775808
|
||||
# these are near the largest floats we can still convert into long long
|
||||
llmaxd = 9007199254740992.0
|
||||
llmind = -9007199254740992.0
|
||||
if ll(llmin) != llmin:
|
||||
raise runtimeerror, "ll(llmin)"
|
||||
if ll(llmax) != llmax:
|
||||
raise runtimeerror, "ll(llmax)"
|
||||
if ll(llmind) != llmind:
|
||||
raise RuntimeError, "ll(llmind)"
|
||||
if ll(llmaxd) != llmaxd:
|
||||
raise RuntimeError, "ll(llmaxd)"
|
||||
|
||||
|
||||
free_void(v)
|
||||
42
Examples/test-suite/python/python_pybuf_runme3.py
Normal file
42
Examples/test-suite/python/python_pybuf_runme3.py
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#run:
|
||||
# python python_pybuf_runme3.py benchmark
|
||||
#for the benchmark, other wise the test case will be run
|
||||
import python_pybuf
|
||||
import sys
|
||||
if len(sys.argv)>=2 and sys.argv[1]=="benchmark":
|
||||
#run the benchmark
|
||||
import time
|
||||
k=1000000 #number of times to excute the functions
|
||||
|
||||
t=time.time()
|
||||
a = bytearray(b'hello world')
|
||||
for i in range(k):
|
||||
pybuf.title1(a)
|
||||
print("Time used by bytearray:",time.time()-t)
|
||||
|
||||
t=time.time()
|
||||
b = 'hello world'
|
||||
for i in range(k):
|
||||
pybuf.title2(b)
|
||||
print("Time used by string:",time.time()-t)
|
||||
else:
|
||||
#run the test case
|
||||
buf1 = bytearray(10)
|
||||
buf2 = bytearray(50)
|
||||
|
||||
pybuf.func1(buf1)
|
||||
assert buf1 == b'a'*10
|
||||
|
||||
pybuf.func2(buf2)
|
||||
assert buf2.startswith(b"Hello world!\x00")
|
||||
|
||||
count = pybuf.func3(buf2)
|
||||
assert count==10 #number of alpha and number in 'Hello world!'
|
||||
|
||||
length = pybuf.func4(buf2)
|
||||
assert length==12
|
||||
|
||||
buf3 = bytearray(b"hello")
|
||||
pybuf.title1(buf3)
|
||||
assert buf3==b'Hello'
|
||||
|
||||
|
|
@ -1,3 +0,0 @@
|
|||
import enum_tag_no_clash_with_variable
|
||||
|
||||
error_action = error_action
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
%module vector
|
||||
%{
|
||||
#include <vector>
|
||||
%}
|
||||
|
||||
%define SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE...)
|
||||
public:
|
||||
typedef size_t size_type;
|
||||
typedef CTYPE value_type;
|
||||
size_type size() const;
|
||||
vector();
|
||||
%extend {
|
||||
static std::vector<CTYPE > *Repeat(const value_type& value, int count) /*throw (std::out_of_range)*/ {
|
||||
// if (count < 0)
|
||||
// throw std::out_of_range("count");
|
||||
return new std::vector<CTYPE >(count, value);
|
||||
}
|
||||
}
|
||||
%enddef
|
||||
|
||||
namespace std {
|
||||
// primary (unspecialized) class template for std::vector
|
||||
// does not require operator== to be defined
|
||||
template<class T> class vector {
|
||||
SWIG_STD_VECTOR_MINIMUM(T, T)
|
||||
};
|
||||
}
|
||||
|
||||
%define SWIG_STD_VECTOR_SPECIALIZE(CSTYPE, CTYPE...)
|
||||
namespace std {
|
||||
template<> class vector<CTYPE > {
|
||||
SWIG_STD_VECTOR_MINIMUM(CSTYPE, CTYPE)
|
||||
};
|
||||
}
|
||||
%enddef
|
||||
|
||||
SWIG_STD_VECTOR_SPECIALIZE(float, float)
|
||||
|
||||
%inline %{
|
||||
typedef float Real;
|
||||
%}
|
||||
|
||||
#if 1
|
||||
//fails
|
||||
namespace std {
|
||||
%template(RealVector) vector<Real>;
|
||||
}
|
||||
#else
|
||||
//works
|
||||
%template(RealVector) std::vector<Real>;
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue