diff --git a/config.h.in b/config.h.in index b6c216c59..19d719fb5 100755 --- a/config.h.in +++ b/config.h.in @@ -1,6 +1,9 @@ #include "parms.h" +/* are dynamic arrays supported? */ +#undef HAVE_DYNARRAY + /* are we using gcc */ #undef HAVE_GCC diff --git a/configure b/configure index c96a96cb6..018950ad1 100755 --- a/configure +++ b/configure @@ -3712,6 +3712,12 @@ done +ac_ext=c +ac_cpp='$CPP $CPPFLAGS' +ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5' +ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5' +ac_compiler_gnu=$ac_cv_c_compiler_gnu + ac_ext=c @@ -4186,6 +4192,36 @@ else use_gecode=$use_gecode_default fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking if dynamic arrays are supported" >&5 +$as_echo_n "checking if dynamic arrays are supported... " >&6; } +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ + + void foo(int n) { int a[n]; a[1]=0; } +int +main () +{ +foo(3); + ; + return 0; +} + +_ACEOF +if ac_fn_c_try_compile "$LINENO"; then : + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } + +$as_echo "#define HAVE_DYNARRAY 1" >>confdefs.h + + +else + + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } + +fi +rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext # Check whether --enable-tabling was given. if test "${enable_tabling+set}" = set; then : diff --git a/configure.in b/configure.in index e26ecaf6d..64858c402 100644 --- a/configure.in +++ b/configure.in @@ -55,6 +55,7 @@ AC_PROG_AWK AC_SUBST(GCC) AC_SUBST(C_INTERF_FLAGS) AC_SUBST(C_PARSER_FLAGS) +AC_LANG(C) dnl Gecode support AC_CHECK_HEADER(gecode/support/config.hpp, @@ -80,6 +81,15 @@ AC_ARG_ENABLE(gecode, AC_MSG_ERROR([cannot enable gecode: python not found]) fi fi], use_gecode=$use_gecode_default) +AC_MSG_CHECKING([if dynamic arrays are supported]) +AC_COMPILE_IFELSE([ + AC_LANG_PROGRAM([[void foo(int n) { int a[n]; a[1]=0; }]],[[foo(3);]]) + ],[ + AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_DYNARRAY],[1],[Define if dynamic arrays are supported]) + ],[ + AC_MSG_RESULT([no]) + ]) AC_ARG_ENABLE(tabling, [ --enable-tabling support tabling ], diff --git a/library/gecode/Makefile.in b/library/gecode/Makefile.in index 2c74454e0..0ae3ef8a8 100644 --- a/library/gecode/Makefile.in +++ b/library/gecode/Makefile.in @@ -57,7 +57,7 @@ gecode_yap.o: \ gecode_yap_cc_forward_auto_generated.icc \ $(srcdir)/disjunctor.icc \ $(srcdir)/disjunctor.hh - $(CXX) -c -I. $(CXXFLAGS) $(DISJUNCTOR) -o $@ $< + $(CXX) -c $(CXXFLAGS) $(DISJUNCTOR) -o $@ $< @DO_SECOND_LD@gecode_yap.@SO@: gecode_yap.o @DO_SECOND_LD@ @SHLIB_LD@ -o gecode_yap.@SO@ gecode_yap.o $(LDFLAGS) -lgecodeint -lgecodeset -lgecodesearch @EXTRA_LIBS_FOR_DLLS@ diff --git a/library/gecode/gecode_yap.cc b/library/gecode/gecode_yap.cc index e58b48a27..8d4d4f3de 100644 --- a/library/gecode/gecode_yap.cc +++ b/library/gecode/gecode_yap.cc @@ -22,6 +22,45 @@ using namespace std; using namespace generic_gecode; using namespace Gecode; +extern "C" +{ +#include "config.h" +} + +namespace generic_gecode +{ +#ifndef HAVE_DYNARRAY +#error hello + template struct DynArray + { + T* _array; + DynArray(int n): _array(new T[n]) {} + ~DynArray() { delete[] _array; } + T& operator[](int i) { return _array[i]; } + }; +#define DYNARRAY(T,A,N) DynArray A(N) +#else +#define DYNARRAY(T,A,N) T A[N] +#endif + +#ifndef HAVE_DYNARRAY + struct SpecArray + { + int (*_array)[2]; + SpecArray(int n): _array((int (*)[2]) new int[n*2]) {} + ~SpecArray() { delete[] _array; } + int& operator()(int i,int j) { return _array[i][j]; } + }; +#define SPECARRAY(A,N) SpecArray A(N) +#define SPECARRAYELEM(A,I,J) A(I,J) +#define SPECARRAYDEREF(A) A._array +#else +#define SPECARRAY(A,N) int A[N][2] +#define SPECARRAYELEM(A,I,J) A[I][J] +#define SPECARRAYDEREF(A) A +#endif +} + extern "C" { #include "SWI-Stream.h" @@ -261,22 +300,6 @@ extern "C" return n; } -#ifndef HAVE_DYNARRAY - struct SpecArray - { - int* _array; - SpecArray(int n): _array(new int[n][2]) {} - ~SpecArray() { delete[] _array; } - typedef int (*_specarray)[][2]; - T& operator()(int i,int j) { return ((_specarray)_array)[i][j]; } - }; -#define SPECARRAY(A,N) SpecArray A(N) -#define SPECARRAYELEM(A,I,J) A(I,J) -#else -#define SPECARRAY(A,N) int A[N][2] -#define SPECARRAYELEM(A,I,J) A[I][J] -#endif - static IntSet gecode_IntSet_from_term(YAP_Term specs) { @@ -291,7 +314,7 @@ extern "C" SPECARRAYELEM(r,i,1) = YAP_IntOfTerm(YAP_ArgOfTerm(2, head)); i += 1; } - return IntSet(r, n); + return IntSet(SPECARRAYDEREF(r), n); } static int gecode_new_intvar_from_intset(void) @@ -844,19 +867,6 @@ extern "C" return YAP_Unify(result, YAP_MkIntTerm(x.glbMax())); } -#ifndef HAVE_DYNARRAY - template struct DynArray - { - T* _array; - DynArray(int n): _array(new T[n]) {} - ~DynArray() { delete[] _array; } - T& operator[](int i) { return _array[i]; } - }; -#define DYNARRAY(T,A,N) DynArray A(N) -#else -#define DYNARRAY(T,A,N) T A[N] -#endif - static YAP_Functor gecode_COMMA2; static int gecode_setvar_glb_ranges(void)