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:
William S Fulton 2008-11-26 22:50:35 +00:00
commit b266e1f68c
29 changed files with 19 additions and 72 deletions

View file

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

View file

@ -1,18 +0,0 @@
%module abstractbase
%include <pyabc.i>
%include <std_map.i>
%include <std_multimap.i>
%include <std_set.i>
%include <std_multiset.i>
%include <std_list.i>
%include <std_vector.i>
namespace std
{
%template(Mapii) map<int, int>;
%template(Multimapii) multimap<int, int>;
%template(IntSet) set<int>;
%template(IntMultiset) multiset<int>;
%template(IntVector) vector<int>;
%template(IntList) list<int>;
}

View file

@ -1,23 +0,0 @@
%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)
{
}
%}

View file

@ -1,95 +0,0 @@
%module(docstring="hello") autodoc
%feature("autodoc");
// especial typemap and its docs
%typemap(in) (int c, int d) "$1 =0; $2 = 0;";
%typemap(doc,name="hello",type="Tuple") (int c, int d) "hello: int tuple[2]";
// testing for different documentation levels
%feature("autodoc","0") A::func0; // names
%feature("autodoc","1") A::func1; // names + types
%feature("autodoc","2") A::func2; // extended
%feature("autodoc","3") A::func3; // extended + types
%feature("autodoc","just a string") A::func; // names
%inline {
enum Hola {
hi, hello
};
struct A
{
A(int a, short b, Hola h)
{
}
int func(int a)
{
return a;
}
int func0(int c, int d)
{
return c;
}
int func1(int c, int d)
{
return c;
}
int func2(A* c, double d = 2)
{
return 2;
}
int func3(A* c, double d = 2)
{
return 2;
}
};
}
// deleting typemaps and docs
%typemap(in) (int c, int d) ;
%typemap(doc) (int c, int d);
// docs for some parameters
%typemap(doc) int a "a: special comment for parameter a";
%typemap(doc) int b "b: another special comment for parameter b";
%callback(1) func_cb;
%inline {
struct B
{
B(int a, int b, Hola h)
{
}
int func(int c, int d)
{
return c;
}
};
int func(int c, int d) {
return c;
}
int funcio(int *INOUT) {
return 1;
}
int func_cb(int c, int d) {
return c;
}
}

View file

@ -1,72 +0,0 @@
%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>;

View file

@ -1,61 +0,0 @@
%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

View file

@ -1,64 +0,0 @@
%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);
}
};
%}

View file

@ -1,76 +0,0 @@
%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); }
};
}

View file

@ -1,12 +0,0 @@
%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"

View file

@ -1,48 +0,0 @@
%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);

View file

@ -1,40 +0,0 @@
%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;
}
};
%}

View file

@ -1,41 +0,0 @@
%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;
}
%}

View file

@ -1,112 +0,0 @@
%module kwargs
%nocopyctor;
%kwargs;
%rename(myDel) del;
%inline
{
struct s { int del; };
}
// Simple class
%extend Foo
{
int efoo(int a = 1, int b = 0) {return a + b; }
static int sfoo(int a = 1, int b = 0) { return a + b; }
}
%newobject Foo::create;
%inline %{
struct Foo
{
Foo(int a, int b = 0) {}
virtual int foo(int a = 1, int b = 0) {return a + b; }
static int statfoo(int a = 1, int b = 0) {return a + b; }
static Foo *create(int a = 1, int b = 0)
{
return new Foo(a, b);
}
virtual ~Foo() {
}
};
%}
// Templated class
%extend Bar
{
T ebar(T a = 1, T b = 0) {return a + b; }
static T sbar(T a = 1, T b = 0) { return a + b; }
}
%inline %{
template <typename T> struct Bar
{
Bar(T a, T b = 0){}
T bar(T a = 1, T b = 0) {return a + b; }
static T statbar(T a = 1, T b = 0) {return a + b; }
};
%}
%template(BarInt) Bar<int>;
// Functions
%inline %{
int foo(int a = 1, int b = 0) {return a + b; }
template<typename T> T templatedfunction(T a = 1, T b = 0) { return a + b; }
%}
%template(templatedfunction) templatedfunction<int>;
// Deafult args with references
%inline
%{
typedef int size_type;
struct Hello
{
static const size_type hello = 3;
};
int rfoo( const size_type& x = Hello::hello, const Hello& y = Hello() )
{
return x;
}
%}
%{
const int Hello::hello;
%}
// Functions with keywords
%warnfilter(SWIGWARN_PARSE_KEYWORD);
%inline %{
/* silently rename the parameter names in python */
int foo_kw(int from = 1, int except = 2) {return from + except; }
int foo_nu(int from = 1, int = 0) {return from; }
int foo_mm(int min = 1, int max = 2) {return min + max; }
%}

View file

@ -1,8 +0,0 @@
%module li_std_carray
%include <std_carray.i>
%template(Vector3) std::carray<double, 3>;
%template(Matrix3) std::carray<std::carray<double, 3>, 3>;

View file

@ -1,65 +0,0 @@
%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 *> >;

View file

@ -1,59 +0,0 @@
%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;
}
}

View file

@ -1,58 +0,0 @@
%module nondynamic
/*
Use the %pythonnondynamic directuve to make the wrapped class a
nondynamic one, ie, a python class that doesn't dynamically add new
attributes. Hence, for the class
%pythonnondynamic A;
struct A
{
int a;
int b;
};
you will get:
aa = A()
aa.a = 1 # Ok
aa.b = 1 # Ok
aa.c = 3 # error
Since "nondynamic" is a feature, if you use
%pythonnondynamic;
it will make all the wrapped class nondynamic ones.
The implementation is based on the recipe:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252158
and works for modern (-modern) and plain python.
*/
%pythonnondynamic A;
%pythondynamic C;
%inline %{
struct A
{
int a;
int b;
};
struct C
{
int a;
int b;
};
%}

View file

@ -1,4 +0,0 @@
// Simple tests of overloaded functions
%module("castmode") overload_simple_cast
%include overload_simple.i

View file

@ -1,64 +0,0 @@
%module pybuf
%include<pybuffer.i>
%include<cstring.i>
/*functions for the test case*/
%pybuffer_mutable_binary(char *buf1, int len);
%pybuffer_mutable_string(char *buf2);
%pybuffer_binary(const char *buf3, int len);
%pybuffer_string(const char *buf4);
%inline %{
void func1(char *buf1, int len)
{
int i;
for (i=0; i<len; ++i)
buf1[i] = 'a';
return;
}
void func2(char *buf2)
{
strcpy(buf2, "Hello world!");
}
int func3(const char *buf3, int len)
{
int count = 0;
int i;
for(i=0; i<len; ++i)
if (isalnum(buf3[i]))
++count;
return count;
}
int func4(const char *buf4)
{
return strlen(buf4);
}
%}
/*functions for the benchmark*/
%pybuffer_mutable_string(char *str1);
%cstring_mutable(char *str2);
%inline %{
void title(char *str) {
int outword = 1;
while(*str) {
if (isalnum(*str)) {
if (outword) {
outword = 0;
*str = toupper(*str);
}
}
else {
outword = 0;
}
str++;
}
}
void title1(char *str1) {
title(str1);
}
void title2(char *str2) {
title(str2);
}
%}

View file

@ -1,4 +1,4 @@
from abstractbase import *
from python_abstractbase import *
from collections import *
assert issubclass(Mapii, MutableMapping)
assert issubclass(Multimapii, MutableMapping)

View file

@ -1,4 +1,4 @@
from kwargs import *
from python_kwargs import *
class MyFoo(Foo):
def __init__(self, a , b = 0):

View file

@ -1,6 +1,6 @@
import nondynamic
import python_nondynamic
aa = nondynamic.A()
aa = python_nondynamic.A()
aa.a = 1
aa.b = 2
@ -14,10 +14,10 @@ if not err:
raise RuntimeError, "A is not static"
class B(nondynamic.A):
class B(python_nondynamic.A):
c = 4
def __init__(self):
nondynamic.A.__init__(self)
python_nondynamic.A.__init__(self)
pass
pass
@ -35,5 +35,5 @@ if not err:
raise RuntimeError, "B is not static"
cc = nondynamic.C()
cc = python_nondynamic.C()
cc.d = 3

View file

@ -1,4 +1,4 @@
from overload_simple_cast import *
from python_overload_simple_cast import *
class Ai:
def __init__(self,x):

View file

@ -1,7 +1,7 @@
#run:
# python pybuf_runme3.py benchmark
# python python_pybuf_runme3.py benchmark
#for the benchmark, other wise the test case will be run
import pybuf
import python_pybuf
import sys
if len(sys.argv)>=2 and sys.argv[1]=="benchmark":
#run the benchmark

View file

@ -1,98 +0,0 @@
%module simutry
%include "std_vector.i"
%inline {
namespace simuPOP
{
// some simple pop class
template <class Type>
struct Population {
int m_a;
Population(int a):m_a(a){}
};
// base operator, output pop.m_a
template<class Pop>
struct Operator
{
Pop m_pop;
Operator(int a):m_pop(a){}
virtual ~Operator()
{
}
virtual int func() const
{ return m_pop.m_a; }
};
// derived operator, output double of pop.m_a
template<class Pop>
struct DerivedOperator: public Operator<Pop>
{
DerivedOperator(int a):Operator<Pop>(a){}
virtual int func() const
{ return 2*this->m_pop.m_a; }
};
}
}
#if 1
namespace simuPOP
{
%template(population) Population< std::pair<unsigned long,unsigned long> >;
}
%inline
{
namespace simuPOP
{
typedef Population< std::pair<unsigned long,unsigned long> > pop;
}
}
#else
%inline
{
namespace simuPOP
{
// %template(population) Population< std::pair<unsigned long,unsigned long> >;
struct pop {
int m_a;
pop(int a):m_a(a){}
};
}
}
#endif
namespace simuPOP
{
%template(baseOperator) Operator< pop >;
%template(derivedOperator) DerivedOperator< pop >;
}
namespace std
{
%template(vectorop) vector< simuPOP::Operator<simuPOP::pop> * >;
}
%inline
{
namespace simuPOP
{
// test function, use of a vector of Operator*
void test( const std::vector< Operator<pop>*>& para)
{
for( size_t i =0; i < para.size(); ++i)
para[i]->func();
}
}
}

View file

@ -1,25 +0,0 @@
%module swigobject
%inline
{
struct A {
char name[4];
};
const char* pointer_str(A *a){
static char result[1024];
sprintf(result,"0x%lx", (unsigned long)(void *)a);
return result;
}
A *a_ptr(A *a){
return a;
}
void *v_ptr(void *a){
return a;
}
}

View file

@ -1,3 +0,0 @@
import enum_tag_no_clash_with_variable
error_action = error_action

View file

@ -1,71 +0,0 @@
%module template_matrix
%{
#include <vector>
struct pop
{
};
%}
%include "std_vector.i"
%inline {
namespace simuPOP
{
struct POP
{
};
template<class _POP1, class _POP2 = POP>
class Operator
{
};
}
}
%template(vectorop) std::vector< simuPOP::Operator<pop> >;
namespace simuPOP
{
%template(baseOperator) Operator<pop>;
}
#if 1
namespace std
{
%template(vectori) vector<int>;
%template(matrixi) vector< vector<int> >;
%template(cubei) vector< vector< vector<int> > >;
}
%inline %{
std::vector<int>
passVector(const std::vector<int>& a)
{
return a;
}
std::vector< std::vector<int> >
passMatrix(const std::vector< std::vector<int> >& a)
{
return a;
}
std::vector< std::vector< std::vector<int> > >
passCube(const std::vector< std::vector< std::vector<int> > >& a)
{
return a;
}
%}
#endif

View file

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