[PPL-devel] [GIT] ppl/ppl(master): Initialization machinery improved.
Roberto Bagnara
roberto.bagnara at bugseng.com
Tue Jan 20 13:05:44 CET 2015
Module: ppl/ppl
Branch: master
Commit: 74d3a39c15fe5a1feeb3513859470f4fa9d74cd9
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=74d3a39c15fe5a1feeb3513859470f4fa9d74cd9
Author: Roberto Bagnara <roberto.bagnara at bugseng.com>
Date: Tue Jan 20 13:01:00 2015 +0100
Initialization machinery improved.
Previously there was undefined behavior for the case where the user
defined PPL_NO_AUTOMATIC_INITIALIZATION.
(Thanks to Esseger.)
---
src/Init.cc | 32 ++++++++++++++++++++++++++++++--
src/initializer.hh | 19 ++++++++++++-------
2 files changed, 42 insertions(+), 9 deletions(-)
diff --git a/src/Init.cc b/src/Init.cc
index 8359b96..b572ab7 100644
--- a/src/Init.cc
+++ b/src/Init.cc
@@ -92,9 +92,9 @@ namespace Implementation {
int (* volatile ppl_check_function_p)() = ppl_check_function;
int (* volatile ppl_setround_function_p)(int) = ppl_setround_function;
-} // Implementation
+} // namespace Implementation
-} // Parma_Polyhedra_Library
+} // namespace Parma_Polyhedra_Library
namespace {
@@ -214,3 +214,31 @@ PPL::Init::~Init() {
Coefficient_constants_finalize();
}
}
+
+namespace Parma_Polyhedra_Library {
+
+namespace Implementation {
+
+namespace {
+
+static Parma_Polyhedra_Library::Init* Parma_Polyhedra_Library_initializer_p;
+
+} // namespace
+
+void
+initialize_aux() {
+ if (Parma_Polyhedra_Library_initializer_p == 0) {
+ Parma_Polyhedra_Library_initializer_p = new Init();
+ }
+}
+
+void
+finalize_aux() {
+ PPL_ASSERT(Parma_Polyhedra_Library_initializer_p != 0);
+ delete Parma_Polyhedra_Library_initializer_p;
+ Parma_Polyhedra_Library_initializer_p = 0;
+}
+
+} // namespace Implementation
+
+} // namespace Parma_Polyhedra_Library
diff --git a/src/initializer.hh b/src/initializer.hh
index 6963c0f..d10f54d 100644
--- a/src/initializer.hh
+++ b/src/initializer.hh
@@ -32,7 +32,16 @@ static Parma_Polyhedra_Library::Init Parma_Polyhedra_Library_initializer;
#else
-static Parma_Polyhedra_Library::Init* Parma_Polyhedra_Library_initializer_p;
+namespace Parma_Polyhedra_Library {
+
+namespace Implementation {
+
+void initialize_aux();
+void finalize_aux();
+
+} // namespace Implementation
+
+} // namespace Parma_Polyhedra_Library
#endif
@@ -42,9 +51,7 @@ namespace Parma_Polyhedra_Library {
inline void
initialize() {
#ifdef PPL_NO_AUTOMATIC_INITIALIZATION
- if (Parma_Polyhedra_Library_initializer_p == 0) {
- Parma_Polyhedra_Library_initializer_p = new Init();
- }
+ Implementation::initialize_aux();
#endif
}
@@ -52,9 +59,7 @@ initialize() {
inline void
finalize() {
#ifdef PPL_NO_AUTOMATIC_INITIALIZATION
- PPL_ASSERT(Parma_Polyhedra_Library_initializer_p != 0);
- delete Parma_Polyhedra_Library_initializer_p;
- Parma_Polyhedra_Library_initializer_p = 0;
+ Implementation::finalize_aux();
#endif
}
More information about the PPL-devel
mailing list