[PPL-devel] [GIT] ppl/ppl(master): If setitimer() is not available, no initialization is necessary.
Roberto Bagnara
bagnara at cs.unipr.it
Sun Feb 21 11:17:33 CET 2010
Module: ppl/ppl
Branch: master
Commit: 1fa465112d1f5519310f47de08494b765c420b8f
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=1fa465112d1f5519310f47de08494b765c420b8f
Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date: Sun Feb 21 11:16:27 2010 +0100
If setitimer() is not available, no initialization is necessary.
This also works around a linking bug in Mingw.
C tests improved with error-handling code.
---
Watchdog/src/Watchdog.cc | 4 +-
Watchdog/src/Watchdog.defs.hh | 8 ++++++
Watchdog/src/Watchdog.inlines.hh | 16 -----------
interfaces/C/tests/watchdog1.c | 51 +++++++++++++++++++++++++++++++++++-
interfaces/C/tests/weightwatch1.c | 43 +++++++++++++++++++++++++++++-
5 files changed, 100 insertions(+), 22 deletions(-)
diff --git a/Watchdog/src/Watchdog.cc b/Watchdog/src/Watchdog.cc
index 68ed01f..84ccda3 100644
--- a/Watchdog/src/Watchdog.cc
+++ b/Watchdog/src/Watchdog.cc
@@ -242,6 +242,6 @@ void
PWL::Watchdog::finalize() {
}
-#endif // PWL_HAVE_DECL_SETITIMER
-
unsigned int PWL::Init::count = 0;
+
+#endif // PWL_HAVE_DECL_SETITIMER
diff --git a/Watchdog/src/Watchdog.defs.hh b/Watchdog/src/Watchdog.defs.hh
index a6ec958..674954d 100644
--- a/Watchdog/src/Watchdog.defs.hh
+++ b/Watchdog/src/Watchdog.defs.hh
@@ -136,6 +136,8 @@ private:
#endif // PWL_HAVE_DECL_SETITIMER
};
+#if PWL_HAVE_DECL_SETITIMER
+
class Init {
private:
//! Count the number of objects created.
@@ -149,15 +151,21 @@ public:
~Init();
};
+#endif // PWL_HAVE_DECL_SETITIMER
+
} // namespace Parma_Watchdog_Library
#include "Watchdog.inlines.hh"
+#if PWL_HAVE_DECL_SETITIMER
+
namespace {
Parma_Watchdog_Library::Init Parma_Watchdog_Library_initializer;
} // namespace
+#endif // PWL_HAVE_DECL_SETITIMER
+
#endif // !defined(PWL_Watchdog_defs_hh)
diff --git a/Watchdog/src/Watchdog.inlines.hh b/Watchdog/src/Watchdog.inlines.hh
index 80258dd..6cdd654 100644
--- a/Watchdog/src/Watchdog.inlines.hh
+++ b/Watchdog/src/Watchdog.inlines.hh
@@ -109,22 +109,6 @@ inline
Watchdog::~Watchdog() {
}
-inline
-Init::Init() {
- // Only when the first Init object is constructed...
- if (count++ == 0) {
- // ... the library is initialized.
- }
-}
-
-inline
-Init::~Init() {
- // Only when the last Init object is destroyed...
- if (--count == 0) {
- // ... the library is finalized.
- }
-}
-
#endif // !PWL_HAVE_DECL_SETITIMER
} // namespace Parma_Watchdog_Library
diff --git a/interfaces/C/tests/watchdog1.c b/interfaces/C/tests/watchdog1.c
index 2fa9097..45a01cc 100644
--- a/interfaces/C/tests/watchdog1.c
+++ b/interfaces/C/tests/watchdog1.c
@@ -22,6 +22,40 @@ site: http://www.cs.unipr.it/ppl/ . */
#include "ppl_c.h"
#include <stdlib.h>
+#include <stdarg.h>
+
+static const char* program_name = 0;
+
+static void
+my_exit(int status) {
+ (void) ppl_finalize();
+ exit(status);
+}
+
+static void
+fatal(const char* format, ...) {
+ va_list ap;
+ fprintf(stderr, "%s: ", program_name);
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+ my_exit(1);
+}
+
+static void
+error_handler(enum ppl_enum_error_code code,
+ const char* description) {
+#if !PWL_WATCHDOG_OBJECTS_ARE_SUPPORTED
+ /* If Watchdog objects are not supported, an error will occur:
+ this is normal.
+ FIXME: what is not normal is the use of this error code, which
+ the documentation reserves for PPL bugs. */
+ if (code == PPL_ERROR_INTERNAL_ERROR)
+ my_exit(0);
+#endif
+ fatal("PPL error code %d: %s", code, description);
+}
void
open_hypercube(int dimension, ppl_Polyhedron_t ph) {
@@ -93,9 +127,22 @@ timed_compute_open_hypercube_generators(int hundredth_secs,
}
int
-main() {
- ppl_initialize();
+main(int argc, char **argv) {
+ program_name = argv[0];
+
+ if (argc != 1) {
+ fprintf(stderr, "usage: %s\n", program_name);
+ exit(1);
+ }
+
+ if (ppl_initialize() < 0)
+ fatal("cannot initialize the Parma Polyhedra Library");
+
+ if (ppl_set_error_handler(error_handler) < 0)
+ fatal("cannot install the custom error handler");
+
timed_compute_open_hypercube_generators(200, 20);
+
ppl_finalize();
return 0;
}
diff --git a/interfaces/C/tests/weightwatch1.c b/interfaces/C/tests/weightwatch1.c
index a054624..7882be1 100644
--- a/interfaces/C/tests/weightwatch1.c
+++ b/interfaces/C/tests/weightwatch1.c
@@ -22,6 +22,32 @@ site: http://www.cs.unipr.it/ppl/ . */
#include "ppl_c.h"
#include <stdlib.h>
+#include <stdarg.h>
+
+static const char* program_name = 0;
+
+static void
+my_exit(int status) {
+ (void) ppl_finalize();
+ exit(status);
+}
+
+static void
+fatal(const char* format, ...) {
+ va_list ap;
+ fprintf(stderr, "%s: ", program_name);
+ va_start(ap, format);
+ vfprintf(stderr, format, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+ my_exit(1);
+}
+
+static void
+error_handler(enum ppl_enum_error_code code,
+ const char* description) {
+ fatal("PPL error code %d: %s", code, description);
+}
void
open_hypercube(int dimension, ppl_Polyhedron_t ph) {
@@ -93,9 +119,22 @@ weighted_compute_open_hypercube_generators(unsigned weight,
}
int
-main() {
- ppl_initialize();
+main(int argc, char **argv) {
+ program_name = argv[0];
+
+ if (argc != 1) {
+ fprintf(stderr, "usage: %s\n", program_name);
+ exit(1);
+ }
+
+ if (ppl_initialize() < 0)
+ fatal("cannot initialize the Parma Polyhedra Library");
+
+ if (ppl_set_error_handler(error_handler) < 0)
+ fatal("cannot install the custom error handler");
+
weighted_compute_open_hypercube_generators(1000, 20);
+
ppl_finalize();
return 0;
}
More information about the PPL-devel
mailing list