Skip to content

Commit

Permalink
Add several fixed files for swig.
Browse files Browse the repository at this point in the history
Workaround for broken swig, which allows old swig versions to work too.

These files should be removed when fixed swig is released.

Thanks to Juvenal for suggestion.
  • Loading branch information
DarthGandalf committed Aug 14, 2012
1 parent 6b550f2 commit cc52a7d
Show file tree
Hide file tree
Showing 10 changed files with 3,190 additions and 16 deletions.
8 changes: 4 additions & 4 deletions configure.ac
Expand Up @@ -318,17 +318,17 @@ 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.8])
AC_PROG_SWIG([2.0.4])
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])
fi
fi
if test "x$USESWIG" = xno; then
if test -r "$srcdir/modules/modperl/modperl.tar.bz2" -a -r "$srcdir/modules/modpython/modpython.tar.bz2"; then
AC_MSG_NOTICE([modperl and modpython files are found, no SWIG needed])
if test "(" "x$PERL" != xno -a ! -r "$srcdir/modules/modperl/ZNC.cpp" ")" -o "(" "x$PYTHON" != xno -a ! -r "$srcdir/modules/modpython/_znc_core.cpp" ")"; then
AC_MSG_ERROR([Can not build modperl/modpython. Either install SWIG, or build ZNC from a tarball, or disable modperl/modpython. Check config.log for details.])
else
AC_MSG_ERROR([Can not build modperl/modpython. Either install SWIG, or build ZNC from a tarball, or disable modperl/modpython.])
AC_MSG_NOTICE([modperl/modpython files are found, no SWIG needed])
fi
SWIG=""
else
Expand Down
48 changes: 38 additions & 10 deletions m4/ac_pkg_swig.m4
Expand Up @@ -55,13 +55,28 @@ AC_DEFUN([AC_PROG_SWIG],[
# for "python 3 abc set" and "PyInt_FromSize_t in python3" checks
cat <<-END > conftest.i
cat <<-END > conftest-python.i
%module conftest;
%include <pyabc.i>
%include <std_set.i>
%template(SInt) std::set<int>;
END
AC_CACHE_CHECK([for SWIG which produces working output], [znc_cv_path_SWIG], [
# check if perl has std::...::size_type defined. Don't add new tests to this .i; it'll break this test due to check for "NewPointerObj(("
cat <<-END > conftest-perl.i
%module conftest;
%include <std_vector.i>
%include <std_list.i>
%include <std_deque.i>
%template() std::vector<int>;
%template() std::list<int>;
%template() std::deque<int>;
std::vector<int>::size_type checkVector();
std::list<int>::size_type checkList();
std::deque<int>::size_type checkDeque();
END
AC_CACHE_CHECK([for SWIG], [znc_cv_path_SWIG], [
AC_PATH_PROGS_FEATURE_CHECK([SWIG], [swig swig2.0], [
echo trying $ac_path_SWIG >&AS_MESSAGE_LOG_FD
$ac_path_SWIG -version >&AS_MESSAGE_LOG_FD
Expand Down Expand Up @@ -102,26 +117,39 @@ AC_DEFUN([AC_PROG_SWIG],[
fi
if test $swig_right_version -eq 1; then
# "python 3 abc set" and "PyInt_FromSize_t in python3" checks
echo "checking behavior of SWIG" >&AS_MESSAGE_LOG_FD
# "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 conftest.i >&AS_MESSAGE_LOG_FD && \
echo "wrapper created" >&AS_MESSAGE_LOG_FD && \
$ac_path_SWIG -python -py3 -c++ -shadow -I"$srcdir"/swig_lib/python 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 && \
echo "std::set works" >&AS_MESSAGE_LOG_FD && \
grep '#define PyInt_FromSize_t' conftest_wrap.cxx >& /dev/null && \
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 && \
znc_cv_path_SWIG=$ac_path_SWIG \
$ac_path_SWIG -perl -c++ -shadow -I"$srcdir"/swig_lib/perl5 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` && \
echo "size_type work" >&AS_MESSAGE_LOG_FD && \
znc_cv_path_SWIG=$ac_path_SWIG \
ac_path_SWIG_found=:
rm -f conftest_wrap.cxx conftest.py
if test "x$ac_path_SWIG_found" != "x:"; then
echo "fail" >&AS_MESSAGE_LOG_FD
fi
rm -f conftest-python_wrap.cxx conftest.py
rm -f conftest-perl_wrap.cxx conftest.pm
else
echo "SWIG version >= $1 is required. You have '$swig_version'" >&AS_MESSAGE_LOG_FD
fi
fi
echo end trying $ac_path_SWIG >&AS_MESSAGE_LOG_FD
])
])
rm -f conftest.i
rm -f conftest-python.i conftest-perl.i
AC_SUBST([SWIG], [$znc_cv_path_SWIG])
if test -n "$SWIG"; then
Expand Down
2 changes: 1 addition & 1 deletion modules/modperl/Makefile.gen
Expand Up @@ -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
$(Q)$(SWIG) -perl5 -c++ -shadow -outdir modperl -I$(srcdir) -MD -MF .depend/modperl.swig.dep -w362,315,401,402 -o $@ $<
$(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 $@ $<

modperl/ZNC.pm: modperl/ZNC.cpp

Expand Down
2 changes: 1 addition & 1 deletion modules/modpython/Makefile.gen
Expand Up @@ -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
$(Q)$(SWIG) -python -py3 -c++ -shadow -outdir modpython -I$(srcdir) -MD -MF .depend/modpython.swig.dep -w362,315,401 -o $@ $<
$(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 $@ $<

modpython/znc_core.py: modpython/_znc_core.cpp

Expand Down
135 changes: 135 additions & 0 deletions swig_lib/perl5/std_deque.i
@@ -0,0 +1,135 @@
/* -----------------------------------------------------------------------------
* _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);
};
}

0 comments on commit cc52a7d

Please sign in to comment.