[PPL-devel] [GIT] ppl/ppl(master): Make sure we have a declaration of setrlimit() before trying to use it.
Roberto Bagnara
bagnara at cs.unipr.it
Thu Jul 28 09:55:25 CEST 2011
Module: ppl/ppl
Branch: master
Commit: ffb68c3d33f787ec99856d129c82ad8328c343cb
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=ffb68c3d33f787ec99856d129c82ad8328c343cb
Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date: Thu Jul 28 09:53:52 2011 +0200
Make sure we have a declaration of setrlimit() before trying to use it.
We still assume that a system that provides setrlimit() also provides
getrlimit(), the converse being false for, e.g., Minix.
(Thanks to Thomas Cort.)
---
configure.ac | 6 +++---
demos/ppl_lcdd/ppl_lcdd.cc | 3 ++-
demos/ppl_lpsol/ppl_lpsol.c | 3 ++-
demos/ppl_pips/ppl_pips.cc | 2 +-
m4/ac_cxx_limit_memory.m4 | 4 ++++
5 files changed, 12 insertions(+), 6 deletions(-)
diff --git a/configure.ac b/configure.ac
index 8a675d9..eb56f66 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1491,7 +1491,7 @@ AC_CHECK_DECLS([RLIMIT_DATA, RLIMIT_RSS, RLIMIT_VMEM, RLIMIT_AS],
#endif
])
-AC_CHECK_DECLS([getrusage],
+AC_CHECK_DECLS([getrusage, setrlimit],
,
,
[
@@ -1502,6 +1502,7 @@ AC_CHECK_DECLS([getrusage],
# include <sys/resource.h>
#endif
])
+
AC_CHECK_DECLS([sigaction], , , [#include <csignal>])
# Checks for typedefs, structures, and compiler characteristics.
@@ -1510,8 +1511,7 @@ AC_CHECK_TYPES([siginfo_t], [], [], [[
#include <signal.h>
]])
-# Check whether the IEEE inexact flag is supported and available to
-# C++ programs.
+# Check whether we can limit memory in C and C++ using setrlimit().
AC_CXX_SUPPORTS_LIMITING_MEMORY
# Checks for library functions.
diff --git a/demos/ppl_lcdd/ppl_lcdd.cc b/demos/ppl_lcdd/ppl_lcdd.cc
index e62e300..68e6f53 100644
--- a/demos/ppl_lcdd/ppl_lcdd.cc
+++ b/demos/ppl_lcdd/ppl_lcdd.cc
@@ -141,6 +141,7 @@ typedef Polyhedron* POLYHEDRON_TYPE;
#endif
#if defined(PPL_HAVE_SYS_RESOURCE_H) \
+ && PPL_CXX_SUPPORTS_LIMITING_MEMORY \
&& (defined(SA_ONESHOT) || defined(SA_RESETHAND))
# define PPL_LCDD_SUPPORTS_LIMIT_ON_CPU_TIME
#endif
@@ -331,7 +332,7 @@ set_alarm_on_cpu_time(const unsigned seconds, sig_handler_type handler) {
#endif // PPL_LCDD_SUPPORTS_LIMIT_ON_CPU_TIME
-#if PPL_HAVE_DECL_RLIMIT_AS
+#if PPL_CXX_SUPPORTS_LIMITING_MEMORY && PPL_HAVE_DECL_RLIMIT_AS
void
limit_virtual_memory(const unsigned long bytes) {
diff --git a/demos/ppl_lpsol/ppl_lpsol.c b/demos/ppl_lpsol/ppl_lpsol.c
index cef707e..5c1e16a 100644
--- a/demos/ppl_lpsol/ppl_lpsol.c
+++ b/demos/ppl_lpsol/ppl_lpsol.c
@@ -96,6 +96,7 @@ static const char* ppl_source_version = PPL_VERSION;
#endif
#if defined(PPL_HAVE_SYS_RESOURCE_H) \
+ && PPL_CXX_SUPPORTS_LIMITING_MEMORY \
&& (defined(SA_ONESHOT) || defined(SA_RESETHAND))
# define PPL_LPSOL_SUPPORTS_LIMIT_ON_CPU_TIME
#endif
@@ -524,7 +525,7 @@ set_alarm_on_cpu_time(unsigned seconds, void (*handler)(int)) {
#endif /* defined(PPL_LPSOL_SUPPORTS_LIMIT_ON_CPU_TIME) */
-#if PPL_HAVE_DECL_RLIMIT_AS
+#if PPL_CXX_SUPPORTS_LIMITING_MEMORY && PPL_HAVE_DECL_RLIMIT_AS
void
limit_virtual_memory(unsigned long bytes) {
diff --git a/demos/ppl_pips/ppl_pips.cc b/demos/ppl_pips/ppl_pips.cc
index 51cdbac..69f2f8a 100644
--- a/demos/ppl_pips/ppl_pips.cc
+++ b/demos/ppl_pips/ppl_pips.cc
@@ -622,7 +622,7 @@ warning(const char* format, ...) {
va_end(ap);
}
-#if PPL_HAVE_DECL_RLIMIT_AS
+#if PPL_CXX_SUPPORTS_LIMITING_MEMORY && PPL_HAVE_DECL_RLIMIT_AS
void
limit_virtual_memory(const unsigned long bytes) {
diff --git a/m4/ac_cxx_limit_memory.m4 b/m4/ac_cxx_limit_memory.m4
index a0151a5..a3332e1 100644
--- a/m4/ac_cxx_limit_memory.m4
+++ b/m4/ac_cxx_limit_memory.m4
@@ -30,6 +30,10 @@ AC_LANG_PUSH(C++)
AC_MSG_CHECKING([whether we can limit memory in C++ using setrlimit()])
AC_RUN_IFELSE([AC_LANG_SOURCE([[
+#if !HAVE_DECL_SETRLIMIT
+# error "cannot limit memory without setrlimit()"
+#endif
+
#include <stdexcept>
#ifdef HAVE_SYS_TYPES_H
More information about the PPL-devel
mailing list