Bump SWIG req to 2.0.8, remove our hacks around old SWIG.

This commit is contained in:
Alexey Sokolov
2012-11-07 02:02:22 +07:00
parent 071801a65d
commit da5c6b6a8b
10 changed files with 5 additions and 3151 deletions
+1 -1
View File
@@ -354,7 +354,7 @@ fi
if test "x$PERL" != xno -o "x$PYTHON" != xno; then
old_USESWIG="$USESWIG"
if test "x$USESWIG" != "xno"; then
AC_PROG_SWIG([2.0.4])
AC_PROG_SWIG([2.0.8])
test -z "$SWIG" && USESWIG=no
if test "x$USESWIG" = xno -a "x$old_USESWIG" = yes; then
AC_MSG_ERROR([Could not found appropriate SWIG installation. Check config.log for details.])
+2 -2
View File
@@ -123,7 +123,7 @@ AC_DEFUN([AC_PROG_SWIG],[
# "python 3 abc set", "PyInt_FromSize_t in python3" and "perl size_type" checks
echo "checking behavior of this SWIG" >&AS_MESSAGE_LOG_FD
$ac_path_SWIG -python -py3 -c++ -shadow -I"$srcdir"/swig_lib/python conftest-python.i >&AS_MESSAGE_LOG_FD && \
$ac_path_SWIG -python -py3 -c++ -shadow conftest-python.i >&AS_MESSAGE_LOG_FD && \
echo "python wrapper created" >&AS_MESSAGE_LOG_FD && \
echo "testing std::set... ">&AS_MESSAGE_LOG_FD && \
grep SInt_discard conftest.py >& /dev/null && \
@@ -131,7 +131,7 @@ AC_DEFUN([AC_PROG_SWIG],[
echo "testing PyInt_FromSize_t..." >&AS_MESSAGE_LOG_FD && \
grep '#define PyInt_FromSize_t' conftest-python_wrap.cxx >& /dev/null && \
echo "PyInt_FromSize_t is defined" >&AS_MESSAGE_LOG_FD && \
$ac_path_SWIG -perl -c++ -shadow -I"$srcdir"/swig_lib/perl5 conftest-perl.i >&AS_MESSAGE_LOG_FD && \
$ac_path_SWIG -perl -c++ -shadow conftest-perl.i >&AS_MESSAGE_LOG_FD && \
echo "perl wrapper created" >&AS_MESSAGE_LOG_FD && \
echo "testing size_type..." >&AS_MESSAGE_LOG_FD && \
test 0 -eq `grep -c 'NewPointerObj((' conftest-perl_wrap.cxx` && \
+1 -1
View File
@@ -26,7 +26,7 @@ modperl/swigperlrun.h:
modperl/ZNC.cpp: modperl/modperl.i modperl/module.h modperl/CString.i
$(E) Generating ZNC API for Perl...
@mkdir -p modperl .depend
$(Q)$(SWIG) -perl5 -c++ -shadow -outdir modperl -I$(srcdir) -I$(srcdir)/../swig_lib/perl5 -MD -MF .depend/modperl.swig.dep -w362,315,401,402 -o $@ $<
$(Q)$(SWIG) -perl5 -c++ -shadow -outdir modperl -I$(srcdir) -MD -MF .depend/modperl.swig.dep -w362,315,401,402 -o $@ $<
modperl/ZNC.pm: modperl/ZNC.cpp
+1 -1
View File
@@ -26,7 +26,7 @@ modpython/swigpyrun.h:
modpython/_znc_core.cpp: modpython/modpython.i modpython/module.h modpython/cstring.i
$(E) Generating ZNC API for python...
@mkdir -p modpython .depend
$(Q)$(SWIG) -python -py3 -c++ -shadow -outdir modpython -I$(srcdir) -I$(srcdir)/../swig_lib/python -MD -MF .depend/modpython.swig.dep -w362,315,401 -o $@ $<
$(Q)$(SWIG) -python -py3 -c++ -shadow -outdir modpython -I$(srcdir) -MD -MF .depend/modpython.swig.dep -w362,315,401 -o $@ $<
modpython/znc_core.py: modpython/_znc_core.cpp
-135
View File
@@ -1,135 +0,0 @@
/* -----------------------------------------------------------------------------
* _std_deque.i
*
* This file contains a generic definition of std::deque along with
* some helper functions. Specific language modules should include
* this file to generate wrappers.
* ----------------------------------------------------------------------------- */
%include <std_except.i>
%{
#include <deque>
#include <stdexcept>
%}
/* This macro defines all of the standard methods for a deque. This
is defined as a macro to simplify the task of specialization. For
example,
template<> class deque<int> {
public:
%std_deque_methods(int);
};
*/
%define %std_deque_methods_noempty(T)
typedef T &reference;
typedef const T& const_reference;
typedef size_t size_type;
deque();
deque(unsigned int size, const T& value=T());
deque(const deque<T> &);
~deque();
void assign(unsigned int n, const T& value);
void swap(deque<T> &x);
unsigned int size() const;
unsigned int max_size() const;
void resize(unsigned int n, T c = T());
const_reference front();
const_reference back();
void push_front(const T& x);
void push_back(const T& x);
void pop_front();
void pop_back();
void clear();
/* Some useful extensions */
%extend {
const_reference getitem(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i += size;
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("deque index out of range");
}
void setitem(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i+= size;
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("deque index out of range");
}
void delitem(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i<0) i+= size;
if (i>=0 && i<size) {
self->erase(self->begin()+i);
} else {
throw std::out_of_range("deque index out of range");
}
}
std::deque<T> getslice(int i, int j) {
int size = int(self->size());
if (i<0) i = size+i;
if (j<0) j = size+j;
if (i<0) i = 0;
if (j>size) j = size;
std::deque<T > tmp(j-i);
std::copy(self->begin()+i,self->begin()+j,tmp.begin());
return tmp;
}
void setslice(int i, int j, const std::deque<T>& v) {
int size = int(self->size());
if (i<0) i = size+i;
if (j<0) j = size+j;
if (i<0) i = 0;
if (j>size) j = size;
if (int(v.size()) == j-i) {
std::copy(v.begin(),v.end(),self->begin()+i);
} else {
self->erase(self->begin()+i,self->begin()+j);
if (i+1 <= size)
self->insert(self->begin()+i+1,v.begin(),v.end());
else
self->insert(self->end(),v.begin(),v.end());
}
}
void delslice(int i, int j) {
int size = int(self->size());
if (i<0) i = size+i;
if (j<0) j = size+j;
if (i<0) i = 0;
if (j>size) j = size;
self->erase(self->begin()+i,self->begin()+j);
}
};
%enddef
#ifdef SWIGPHP
%define %std_deque_methods(T)
%extend {
bool is_empty() const {
return self->empty();
}
};
%std_deque_methods_noempty(T)
%enddef
#else
%define %std_deque_methods(T)
bool empty() const;
%std_deque_methods_noempty(T)
%enddef
#endif
namespace std {
template<class T> class deque {
public:
%std_deque_methods(T);
};
}
-369
View File
@@ -1,369 +0,0 @@
/* -----------------------------------------------------------------------------
* std_list.i
*
* SWIG typemaps for std::list types
* ----------------------------------------------------------------------------- */
%include <std_common.i>
%include <exception.i>
// containers
// ------------------------------------------------------------------------
// std::list
//
// The aim of all that follows would be to integrate std::list with
// Perl as much as possible, namely, to allow the user to pass and
// be returned Perl arrays.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::list<T>), f(const std::list<T>&), f(const std::list<T>*):
// the parameter being read-only, either a Perl sequence or a
// previously wrapped std::list<T> can be passed.
// -- f(std::list<T>&), f(std::list<T>*):
// the parameter must be modified; therefore, only a wrapped std::list
// can be passed.
// -- std::list<T> f():
// the list is returned by copy; therefore, a Perl sequence of T:s
// is returned which is most easily used in other Perl functions
// -- std::list<T>& f(), std::list<T>* f(), const std::list<T>& f(),
// const std::list<T>* f():
// the list is returned by reference; therefore, a wrapped std::list
// is returned
// ------------------------------------------------------------------------
%{
#include <list>
#include <algorithm>
#include <stdexcept>
%}
// exported class
namespace std {
template<class T> class list {
%typemap(in) list<T> (std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1) {
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
$1.push_back(*obj);
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const list<T>& (std::list<T> temp,
std::list<T>* v),
const list<T>* (std::list<T> temp,
std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
temp.push_back(*obj);
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) list<T> {
std::list<T>::const_iterator i;
unsigned int j;
int len = $1.size();
SV **svs = new SV*[len];
for (i=$1.begin(), j=0; i!=$1.end(); i++, j++) {
T* ptr = new T(*i);
svs[j] = sv_newmortal();
SWIG_MakePtr(svs[j], (void*) ptr,
$descriptor(T *), $shadow|$owner);
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_LIST) list<T> {
{
/* wrapped list? */
std::list<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_&descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
SV **tv;
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
T* obj;
tv = av_fetch(av, 0, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_LIST) const list<T>&,
const list<T>* {
{
/* wrapped list? */
std::list<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
SV **tv;
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
T* obj;
tv = av_fetch(av, 0, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
typedef size_t size_type;
list();
list(const list<T> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(const T& x);
};
// specializations for built-ins
%define specialize_std_list(T,CHECK_T,TO_T,FROM_T)
template<> class list<T> {
%typemap(in) list<T> (std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1){
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (CHECK_T(*tv)) {
$1.push_back(TO_T(*tv));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const list<T>& (std::list<T> temp,
std::list<T>* v),
const list<T>* (std::list<T> temp,
std::list<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (CHECK_T(*tv)) {
temp.push_back(TO_T(*tv));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) list<T> {
std::list<T>::const_iterator i;
unsigned int j;
int len = $1.size();
SV **svs = new SV*[len];
for (i=$1.begin(), j=0; i!=$1.end(); i++, j++) {
svs[j] = sv_newmortal();
FROM_T(svs[j], *i);
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_LIST) list<T> {
{
/* wrapped list? */
std::list<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_&descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
SV **tv;
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
tv = av_fetch(av, 0, 0);
if (CHECK_T(*tv))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_LIST) const list<T>&,
const list<T>* {
{
/* wrapped list? */
std::list<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
SV **tv;
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
tv = av_fetch(av, 0, 0);
if (CHECK_T(*tv))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
typedef size_t size_type;
list();
list(const list<T> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(T x);
};
%enddef
specialize_std_list(bool,SvIOK,SvIVX,sv_setiv);
specialize_std_list(char,SvIOK,SvIVX,sv_setiv);
specialize_std_list(int,SvIOK,SvIVX,sv_setiv);
specialize_std_list(short,SvIOK,SvIVX,sv_setiv);
specialize_std_list(long,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned char,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned int,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned short,SvIOK,SvIVX,sv_setiv);
specialize_std_list(unsigned long,SvIOK,SvIVX,sv_setiv);
specialize_std_list(float,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_list(double,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_list(std::string,SvPOK,SvPVX,SwigSvFromString);
}
-571
View File
@@ -1,571 +0,0 @@
/* -----------------------------------------------------------------------------
* std_vector.i
*
* SWIG typemaps for std::vector types
* ----------------------------------------------------------------------------- */
%include <std_common.i>
// ------------------------------------------------------------------------
// std::vector
//
// The aim of all that follows would be to integrate std::vector with
// Perl as much as possible, namely, to allow the user to pass and
// be returned Perl arrays.
// const declarations are used to guess the intent of the function being
// exported; therefore, the following rationale is applied:
//
// -- f(std::vector<T>), f(const std::vector<T>&), f(const std::vector<T>*):
// the parameter being read-only, either a Perl sequence or a
// previously wrapped std::vector<T> can be passed.
// -- f(std::vector<T>&), f(std::vector<T>*):
// the parameter must be modified; therefore, only a wrapped std::vector
// can be passed.
// -- std::vector<T> f():
// the vector is returned by copy; therefore, a Perl sequence of T:s
// is returned which is most easily used in other Perl functions
// -- std::vector<T>& f(), std::vector<T>* f(), const std::vector<T>& f(),
// const std::vector<T>* f():
// the vector is returned by reference; therefore, a wrapped std::vector
// is returned
// ------------------------------------------------------------------------
%{
#include <vector>
#include <algorithm>
#include <stdexcept>
%}
// exported class
namespace std {
template<class T> class vector {
%typemap(in) vector<T> (std::vector<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1) {
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
$1.push_back(*obj);
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const vector<T>& (std::vector<T> temp,
std::vector<T>* v),
const vector<T>* (std::vector<T> temp,
std::vector<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
T* obj;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1) {
temp.push_back(*obj);
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) vector<T> {
size_t len = $1.size();
SV **svs = new SV*[len];
for (size_t i=0; i<len; i++) {
T* ptr = new T($1[i]);
svs[i] = sv_newmortal();
SWIG_MakePtr(svs[i], (void*) ptr,
$descriptor(T *), $shadow|$owner);
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> {
{
/* wrapped vector? */
std::vector<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
T* obj;
SV **tv = av_fetch(av, 0, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&,
const vector<T>* {
{
/* wrapped vector? */
std::vector<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
T* obj;
SV **tv = av_fetch(av, 0, 0);
if (SWIG_ConvertPtr(*tv, (void **)&obj,
$descriptor(T *),0) != -1)
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
typedef size_t size_type;
vector(unsigned int size = 0);
vector(unsigned int size, const T& value);
vector(const vector<T> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(const T& x);
%extend {
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
T& get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, const T& x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("vector index out of range");
}
}
};
// specializations for pointers
template<class T> class vector<T*> {
%typemap(in) vector<T*> (std::vector<T*>* v) {
int res = SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor,0);
if (SWIG_IsOK(res)){
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
void *v;
SV **tv = av_fetch(av, i, 0);
int res = SWIG_ConvertPtr(*tv, &v, $descriptor(T *),0);
if (SWIG_IsOK(res)) {
$1.push_back(%static_cast(v, T *));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const vector<T *>& (std::vector<T *> temp,std::vector<T *>* v),
const vector<T *>* (std::vector<T *> temp,std::vector<T *>* v) {
int res = SWIG_ConvertPtr($input,(void **) &v, $1_descriptor,0);
if (SWIG_IsOK(res)) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
void *v;
SV **tv = av_fetch(av, i, 0);
int res = SWIG_ConvertPtr(*tv, &v, $descriptor(T *),0);
if (SWIG_IsOK(res)) {
temp.push_back(%static_cast(v, T *));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) vector<T *> {
size_t len = $1.size();
SV **svs = new SV*[len];
for (size_t i=0; i<len; i++) {
T *x = (($1_type &)$1)[i];
svs[i] = sv_newmortal();
sv_setsv(svs[i], SWIG_NewPointerObj(x, $descriptor(T *), 0));
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T *> {
{
/* wrapped vector? */
std::vector<T *>* v;
int res = SWIG_ConvertPtr($input,(void **) &v, $&1_descriptor,0);
if (SWIG_IsOK(res)) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
void *v;
SV **tv = av_fetch(av, 0, 0);
int res = SWIG_ConvertPtr(*tv, &v, $descriptor(T *),0);
if (SWIG_IsOK(res))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T *>&,const vector<T *>* {
{
/* wrapped vector? */
std::vector<T *> *v;
int res = SWIG_ConvertPtr($input,%as_voidptrptr(&v), $1_descriptor,0);
if (SWIG_IsOK(res)) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
void *v;
SV **tv = av_fetch(av, 0, 0);
int res = SWIG_ConvertPtr(*tv, &v, $descriptor(T *),0);
if (SWIG_IsOK(res))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
typedef size_t size_type;
vector(unsigned int size = 0);
vector(unsigned int size, T *value);
vector(const vector<T *> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(T *x);
%extend {
T *pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T *x = self->back();
self->pop_back();
return x;
}
T *get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, T *x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("vector index out of range");
}
}
};
// specializations for built-ins
%define specialize_std_vector(T,CHECK_T,TO_T,FROM_T)
template<> class vector<T> {
%typemap(in) vector<T> (std::vector<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,1) != -1){
$1 = *v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (CHECK_T(*tv)) {
$1.push_back((T)TO_T(*tv));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(in) const vector<T>& (std::vector<T> temp,
std::vector<T>* v),
const vector<T>* (std::vector<T> temp,
std::vector<T>* v) {
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,1) != -1) {
$1 = v;
} else if (SvROK($input)) {
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) != SVt_PVAV)
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
SV **tv;
I32 len = av_len(av) + 1;
for (int i=0; i<len; i++) {
tv = av_fetch(av, i, 0);
if (CHECK_T(*tv)) {
temp.push_back((T)TO_T(*tv));
} else {
SWIG_croak("Type error in argument $argnum of "
"$symname. "
"Expected an array of " #T);
}
}
$1 = &temp;
} else {
SWIG_croak("Type error in argument $argnum of $symname. "
"Expected an array of " #T);
}
}
%typemap(out) vector<T> {
size_t len = $1.size();
SV **svs = new SV*[len];
for (size_t i=0; i<len; i++) {
svs[i] = sv_newmortal();
FROM_T(svs[i], $1[i]);
}
AV *myav = av_make(len, svs);
delete[] svs;
$result = newRV_noinc((SV*) myav);
sv_2mortal($result);
argvi++;
}
%typecheck(SWIG_TYPECHECK_VECTOR) vector<T> {
{
/* wrapped vector? */
std::vector<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$&1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
SV **tv = av_fetch(av, 0, 0);
if (CHECK_T(*tv))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
%typecheck(SWIG_TYPECHECK_VECTOR) const vector<T>&,
const vector<T>* {
{
/* wrapped vector? */
std::vector<T >* v;
if (SWIG_ConvertPtr($input,(void **) &v,
$1_descriptor,0) != -1) {
$1 = 1;
} else if (SvROK($input)) {
/* native sequence? */
AV *av = (AV *)SvRV($input);
if (SvTYPE(av) == SVt_PVAV) {
I32 len = av_len(av) + 1;
if (len == 0) {
/* an empty sequence can be of any type */
$1 = 1;
} else {
/* check the first element only */
SV **tv = av_fetch(av, 0, 0);
if (CHECK_T(*tv))
$1 = 1;
else
$1 = 0;
}
}
} else {
$1 = 0;
}
}
}
public:
typedef size_t size_type;
vector(unsigned int size = 0);
vector(unsigned int size, T value);
vector(const vector<T> &);
unsigned int size() const;
bool empty() const;
void clear();
%rename(push) push_back;
void push_back(T x);
%extend {
T pop() throw (std::out_of_range) {
if (self->size() == 0)
throw std::out_of_range("pop from empty vector");
T x = self->back();
self->pop_back();
return x;
}
T get(int i) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
return (*self)[i];
else
throw std::out_of_range("vector index out of range");
}
void set(int i, T x) throw (std::out_of_range) {
int size = int(self->size());
if (i>=0 && i<size)
(*self)[i] = x;
else
throw std::out_of_range("vector index out of range");
}
}
};
%enddef
specialize_std_vector(bool,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(char,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(int,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(short,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(long,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(unsigned char,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(unsigned int,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(unsigned short,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(unsigned long,SvIOK,SvIVX,sv_setiv);
specialize_std_vector(float,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_vector(double,SvNIOK,SwigSvToNumber,sv_setnv);
specialize_std_vector(std::string,SvPOK,SwigSvToString,SwigSvFromString);
}
-214
View File
@@ -1,214 +0,0 @@
/* Compatibility macros for Python 3 */
#if PY_VERSION_HEX >= 0x03000000
#define PyClass_Check(obj) PyObject_IsInstance(obj, (PyObject *)&PyType_Type)
#define PyInt_Check(x) PyLong_Check(x)
#define PyInt_AsLong(x) PyLong_AsLong(x)
#define PyInt_FromLong(x) PyLong_FromLong(x)
#define PyInt_FromSize_t(x) PyLong_FromSize_t(x)
#define PyString_Check(name) PyBytes_Check(name)
#define PyString_FromString(x) PyUnicode_FromString(x)
#define PyString_Format(fmt, args) PyUnicode_Format(fmt, args)
#define PyString_AsString(str) PyBytes_AsString(str)
#define PyString_Size(str) PyBytes_Size(str)
#define PyString_InternFromString(key) PyUnicode_InternFromString(key)
#define Py_TPFLAGS_HAVE_CLASS Py_TPFLAGS_BASETYPE
#define PyString_AS_STRING(x) PyUnicode_AS_STRING(x)
#define _PyLong_FromSsize_t(x) PyLong_FromSsize_t(x)
#endif
#ifndef Py_TYPE
# define Py_TYPE(op) ((op)->ob_type)
#endif
/* SWIG APIs for compatibility of both Python 2 & 3 */
#if PY_VERSION_HEX >= 0x03000000
# define SWIG_Python_str_FromFormat PyUnicode_FromFormat
#else
# define SWIG_Python_str_FromFormat PyString_FromFormat
#endif
/* Warning: This function will allocate a new string in Python 3,
* so please call SWIG_Python_str_DelForPy3(x) to free the space.
*/
SWIGINTERN char*
SWIG_Python_str_AsChar(PyObject *str)
{
#if PY_VERSION_HEX >= 0x03000000
char *cstr;
char *newstr;
Py_ssize_t len;
str = PyUnicode_AsUTF8String(str);
PyBytes_AsStringAndSize(str, &cstr, &len);
newstr = (char *) malloc(len+1);
memcpy(newstr, cstr, len+1);
Py_XDECREF(str);
return newstr;
#else
return PyString_AsString(str);
#endif
}
#if PY_VERSION_HEX >= 0x03000000
# define SWIG_Python_str_DelForPy3(x) free( (void*) (x) )
#else
# define SWIG_Python_str_DelForPy3(x)
#endif
SWIGINTERN PyObject*
SWIG_Python_str_FromChar(const char *c)
{
#if PY_VERSION_HEX >= 0x03000000
return PyUnicode_FromString(c);
#else
return PyString_FromString(c);
#endif
}
/* Add PyOS_snprintf for old Pythons */
#if PY_VERSION_HEX < 0x02020000
# if defined(_MSC_VER) || defined(__BORLANDC__) || defined(_WATCOM)
# define PyOS_snprintf _snprintf
# else
# define PyOS_snprintf snprintf
# endif
#endif
/* A crude PyString_FromFormat implementation for old Pythons */
#if PY_VERSION_HEX < 0x02020000
#ifndef SWIG_PYBUFFER_SIZE
# define SWIG_PYBUFFER_SIZE 1024
#endif
static PyObject *
PyString_FromFormat(const char *fmt, ...) {
va_list ap;
char buf[SWIG_PYBUFFER_SIZE * 2];
int res;
va_start(ap, fmt);
res = vsnprintf(buf, sizeof(buf), fmt, ap);
va_end(ap);
return (res < 0 || res >= (int)sizeof(buf)) ? 0 : PyString_FromString(buf);
}
#endif
/* Add PyObject_Del for old Pythons */
#if PY_VERSION_HEX < 0x01060000
# define PyObject_Del(op) PyMem_DEL((op))
#endif
#ifndef PyObject_DEL
# define PyObject_DEL PyObject_Del
#endif
/* A crude PyExc_StopIteration exception for old Pythons */
#if PY_VERSION_HEX < 0x02020000
# ifndef PyExc_StopIteration
# define PyExc_StopIteration PyExc_RuntimeError
# endif
# ifndef PyObject_GenericGetAttr
# define PyObject_GenericGetAttr 0
# endif
#endif
/* Py_NotImplemented is defined in 2.1 and up. */
#if PY_VERSION_HEX < 0x02010000
# ifndef Py_NotImplemented
# define Py_NotImplemented PyExc_RuntimeError
# endif
#endif
/* A crude PyString_AsStringAndSize implementation for old Pythons */
#if PY_VERSION_HEX < 0x02010000
# ifndef PyString_AsStringAndSize
# define PyString_AsStringAndSize(obj, s, len) {*s = PyString_AsString(obj); *len = *s ? strlen(*s) : 0;}
# endif
#endif
/* PySequence_Size for old Pythons */
#if PY_VERSION_HEX < 0x02000000
# ifndef PySequence_Size
# define PySequence_Size PySequence_Length
# endif
#endif
/* PyBool_FromLong for old Pythons */
#if PY_VERSION_HEX < 0x02030000
static
PyObject *PyBool_FromLong(long ok)
{
PyObject *result = ok ? Py_True : Py_False;
Py_INCREF(result);
return result;
}
#endif
/* Py_ssize_t for old Pythons */
/* This code is as recommended by: */
/* http://www.python.org/dev/peps/pep-0353/#conversion-guidelines */
#if PY_VERSION_HEX < 0x02050000 && !defined(PY_SSIZE_T_MIN)
typedef int Py_ssize_t;
# define PY_SSIZE_T_MAX INT_MAX
# define PY_SSIZE_T_MIN INT_MIN
typedef inquiry lenfunc;
typedef intargfunc ssizeargfunc;
typedef intintargfunc ssizessizeargfunc;
typedef intobjargproc ssizeobjargproc;
typedef intintobjargproc ssizessizeobjargproc;
typedef getreadbufferproc readbufferproc;
typedef getwritebufferproc writebufferproc;
typedef getsegcountproc segcountproc;
typedef getcharbufferproc charbufferproc;
static long PyNumber_AsSsize_t (PyObject *x, void *SWIGUNUSEDPARM(exc))
{
long result = 0;
PyObject *i = PyNumber_Int(x);
if (i) {
result = PyInt_AsLong(i);
Py_DECREF(i);
}
return result;
}
#endif
#if PY_VERSION_HEX < 0x02040000
#define Py_VISIT(op) \
do { \
if (op) { \
int vret = visit((op), arg); \
if (vret) \
return vret; \
} \
} while (0)
#endif
#if PY_VERSION_HEX < 0x02030000
typedef struct {
PyTypeObject type;
PyNumberMethods as_number;
PyMappingMethods as_mapping;
PySequenceMethods as_sequence;
PyBufferProcs as_buffer;
PyObject *name, *slots;
} PyHeapTypeObject;
#endif
#if PY_VERSION_HEX < 0x02030000
typedef destructor freefunc;
#endif
#if ((PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION > 6) || \
(PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION > 0) || \
(PY_MAJOR_VERSION > 3))
# define SWIGPY_USE_CAPSULE
# define SWIGPY_CAPSULE_NAME ((char*)"swig_runtime_data" SWIG_RUNTIME_VERSION ".type_pointer_capsule" SWIG_TYPE_TABLE_NAME)
#endif
#if PY_VERSION_HEX < 0x03020000
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
#endif
File diff suppressed because it is too large Load Diff
-63
View File
@@ -1,63 +0,0 @@
/*
Sets
*/
%fragment("StdSetTraits","header",fragment="StdSequenceTraits")
%{
namespace swig {
template <class SwigPySeq, class T>
inline void
assign(const SwigPySeq& swigpyseq, std::set<T>* seq) {
// seq->insert(swigpyseq.begin(), swigpyseq.end()); // not used as not always implemented
typedef typename SwigPySeq::value_type value_type;
typename SwigPySeq::const_iterator it = swigpyseq.begin();
for (;it != swigpyseq.end(); ++it) {
seq->insert(seq->end(),(value_type)(*it));
}
}
template <class T>
struct traits_asptr<std::set<T> > {
static int asptr(PyObject *obj, std::set<T> **s) {
return traits_asptr_stdseq<std::set<T> >::asptr(obj, s);
}
};
template <class T>
struct traits_from<std::set<T> > {
static PyObject *from(const std::set<T>& vec) {
return traits_from_stdseq<std::set<T> >::from(vec);
}
};
}
%}
%define %swig_set_methods(set...)
%swig_sequence_iterator(set);
%swig_container_methods(set);
%extend {
void append(value_type x) {
self->insert(x);
}
bool __contains__(value_type x) {
return self->find(x) != self->end();
}
value_type __getitem__(difference_type i) const throw (std::out_of_range) {
return *(swig::cgetpos(self, i));
}
void add(value_type x) {
self->insert(x);
}
void discard(value_type x) {
self->erase(x);
}
};
%enddef
%include <std/std_set.i>