
Module: ppl/ppl Branch: master Commit: 12f97bbef1ad3223c630d10474851eb5d67611db URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=12f97bbef1ad3...
Author: Roberto Bagnara bagnara@cs.unipr.it Date: Tue Mar 15 12:06:59 2011 +0100
For increased portability, use zero-length arrays (when available), not flexible arrays.
---
configure.ac | 4 +- m4/Makefile.am | 2 +- ...ible_arrays.m4 => ac_cxx_zero_length_arrays.m4} | 22 ++++++++++---------- src/DB_Row.defs.hh | 4 ++- src/DB_Row.inlines.hh | 8 +++--- src/DB_Row.templates.hh | 20 +++++++++--------- 6 files changed, 31 insertions(+), 29 deletions(-)
diff --git a/configure.ac b/configure.ac index 117e8b1..bccdcbe 100644 --- a/configure.ac +++ b/configure.ac @@ -703,8 +703,8 @@ AC_CXX_LONG_DOUBLE_BINARY_FORMAT # long doubles. #AC_CXX_LONG_DOUBLE_EXACT_OUTPUT
-# Check whether the C++ compiler supports flexible arrays. -AC_CXX_SUPPORTS_FLEXIBLE_ARRAYS +# Check whether the C++ compiler supports zero-length arrays. +AC_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS
# Check whether the IEEE inexact flag is supported in C++. AC_CXX_SUPPORTS_IEEE_INEXACT_FLAG diff --git a/m4/Makefile.am b/m4/Makefile.am index 313d28a..651d019 100644 --- a/m4/Makefile.am +++ b/m4/Makefile.am @@ -39,7 +39,7 @@ ac_check_xsb_prolog.m4 \ ac_cxx_attribute_weak.m4 \ ac_cxx_double_binary_format.m4 \ ac_cxx_double_exact_output.m4 \ -ac_cxx_flexible_arrays.m4 \ +ac_cxx_zero_length_arrays.m4 \ ac_cxx_float_binary_format.m4 \ ac_cxx_float_exact_output.m4 \ ac_cxx_ieee_inexact_flag.m4 \ diff --git a/m4/ac_cxx_flexible_arrays.m4 b/m4/ac_cxx_zero_length_arrays.m4 similarity index 81% rename from m4/ac_cxx_flexible_arrays.m4 rename to m4/ac_cxx_zero_length_arrays.m4 index 5ad6b33..2ba7491 100644 --- a/m4/ac_cxx_flexible_arrays.m4 +++ b/m4/ac_cxx_zero_length_arrays.m4 @@ -1,4 +1,4 @@ -dnl A function to check whether the C++ compiler supports flexible arrays. +dnl A function to check whether the C++ compiler supports zero-length arrays. dnl Copyright (C) 2001-2010 Roberto Bagnara bagnara@cs.unipr.it dnl Copyright (C) 2010-2011 BUGSENG srl (http://bugseng.com) dnl @@ -21,13 +21,13 @@ dnl dnl For the most up-to-date information see the Parma Polyhedra Library dnl site: http://www.cs.unipr.it/ppl/ .
-AC_DEFUN([AC_CXX_SUPPORTS_FLEXIBLE_ARRAYS], +AC_DEFUN([AC_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS], [ ac_save_CPPFLAGS="$CPPFLAGS" ac_save_LIBS="$LIBS" AC_LANG_PUSH(C++)
-AC_MSG_CHECKING([whether the C++ compiler supports flexible arrays]) +AC_MSG_CHECKING([whether the C++ compiler supports zero-length arrays]) AC_RUN_IFELSE([AC_LANG_SOURCE([[ #include <new> #include <cstddef> @@ -74,9 +74,9 @@ main() { } ]])], AC_MSG_RESULT(yes) - ac_cxx_supports_flexible_arrays=yes, + ac_cxx_supports_zero_length_arrays=yes, AC_MSG_RESULT(no) - ac_cxx_supports_flexible_arrays=no, + ac_cxx_supports_zero_length_arrays=no, AC_COMPILE_IFELSE([AC_LANG_SOURCE([[ #include <new> #include <cstddef> @@ -95,7 +95,7 @@ public: class B { private: int capacity; - A vec[]; + A vec[0];
public: void* operator new(size_t fixed_size, int c) { @@ -123,18 +123,18 @@ main() { } ]])], AC_MSG_RESULT(yes) - ac_cxx_supports_flexible_arrays=yes, + ac_cxx_supports_zero_length_arrays=yes, AC_MSG_RESULT(no) - ac_cxx_supports_flexible_arrays=no)) + ac_cxx_supports_zero_length_arrays=no))
-if test x"$ac_cxx_supports_flexible_arrays" = xyes +if test x"$ac_cxx_supports_zero_length_arrays" = xyes then value=1 else value=0 fi -AC_DEFINE_UNQUOTED(PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS, $value, - [Not zero if the C++ compiler supports flexible arrays.]) +AC_DEFINE_UNQUOTED(PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS, $value, + [Not zero if the C++ compiler supports zero_length arrays.])
AC_LANG_POP(C++) CPPFLAGS="$ac_save_CPPFLAGS" diff --git a/src/DB_Row.defs.hh b/src/DB_Row.defs.hh index 071738c..90a322b 100644 --- a/src/DB_Row.defs.hh +++ b/src/DB_Row.defs.hh @@ -432,7 +432,9 @@ private:
//! The vector of coefficients. T vec_[ -#if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS + 0 +#else 1 #endif ]; diff --git a/src/DB_Row.inlines.hh b/src/DB_Row.inlines.hh index 7db5f22..66423ac 100644 --- a/src/DB_Row.inlines.hh +++ b/src/DB_Row.inlines.hh @@ -37,7 +37,7 @@ template <typename T> inline void* DB_Row_Impl_Handler<T>::Impl::operator new(const size_t fixed_size, const dimension_type capacity) { -#if PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS return ::operator new(fixed_size + capacity*sizeof(T)); #else PPL_ASSERT(capacity >= 1); @@ -64,7 +64,7 @@ DB_Row_Impl_Handler<T>::Impl return sizeof(*this) + capacity*sizeof(T) -#if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if !PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS - 1*sizeof(T) #endif + external_memory_in_bytes(); @@ -172,13 +172,13 @@ DB_Row<T>::DB_Row() template <typename T> inline void DB_Row<T>::allocate( -#if PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS const #endif dimension_type capacity) { DB_Row<T>& x = *this; PPL_ASSERT(capacity <= max_size()); -#if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if !PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS if (capacity == 0) ++capacity; #endif diff --git a/src/DB_Row.templates.hh b/src/DB_Row.templates.hh index 590ff43..ea6f54d 100644 --- a/src/DB_Row.templates.hh +++ b/src/DB_Row.templates.hh @@ -33,13 +33,13 @@ template <typename U> void DB_Row_Impl_Handler<T>::Impl::construct_upward_approximation(const U& y) { const dimension_type y_size = y.size(); -#if PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS // Construct in direct order: will destroy in reverse order. for (dimension_type i = 0; i < y_size; ++i) { construct(vec_[i], y[i], ROUND_UP); bump_size(); } -#else // PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#else // PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS if (y_size > 0) { assign_r(vec_[0], y[0], ROUND_UP); bump_size(); @@ -49,7 +49,7 @@ DB_Row_Impl_Handler<T>::Impl::construct_upward_approximation(const U& y) { bump_size(); } } -#endif // PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#endif // PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS }
template <typename T> @@ -57,7 +57,7 @@ void DB_Row_Impl_Handler<T>:: Impl::expand_within_capacity(const dimension_type new_size) { PPL_ASSERT(size() <= new_size && new_size <= max_size()); -#if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if !PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS if (size() == 0 && new_size > 0) { // vec_[0] is already constructed: we just need to assign +infinity. assign_r(vec_[0], PLUS_INFINITY, ROUND_NOT_NEEDED); @@ -78,7 +78,7 @@ DB_Row_Impl_Handler<T>::Impl::shrink(dimension_type new_size) { PPL_ASSERT(new_size <= old_size); // Since ~T() does not throw exceptions, nothing here does. set_size(new_size); -#if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if !PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS // Make sure we do not try to destroy vec_[0]. if (new_size == 0) ++new_size; @@ -93,13 +93,13 @@ template <typename T> void DB_Row_Impl_Handler<T>::Impl::copy_construct_coefficients(const Impl& y) { const dimension_type y_size = y.size(); -#if PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#if PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS // Construct in direct order: will destroy in reverse order. for (dimension_type i = 0; i < y_size; ++i) { new (&vec_[i]) T(y.vec_[i]); bump_size(); } -#else // PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#else // PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS if (y_size > 0) { vec_[0] = y.vec_[0]; bump_size(); @@ -109,7 +109,7 @@ DB_Row_Impl_Handler<T>::Impl::copy_construct_coefficients(const Impl& y) { bump_size(); } } -#endif // PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +#endif // PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS }
template <typename T> @@ -138,7 +138,7 @@ DB_Row<T>::OK(const dimension_type row_size, bool is_broken = false;
#if PPL_DB_ROW_EXTRA_DEBUG -# if !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +# if !PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS if (x.capacity_ == 0) { cerr << "Illegal row capacity: is 0, should be at least 1" << endl; @@ -148,7 +148,7 @@ DB_Row<T>::OK(const dimension_type row_size, // This is fine. ; else -# endif // !PPL_CXX_SUPPORTS_FLEXIBLE_ARRAYS +# endif // !PPL_CXX_SUPPORTS_ZERO_LENGTH_ARRAYS if (x.capacity_ != row_capacity) { cerr << "DB_Row capacity mismatch: is " << x.capacity_ << ", should be " << row_capacity << "."