From d03e58e766e69d0c23d5ff95ea2eaadc24c99dfb Mon Sep 17 00:00:00 2001 From: Alexei Sheplyakov Date: Thu, 21 Aug 2008 15:17:06 +0400 Subject: [PATCH] Replace CL_REQUIRE/CL_PROVIDE(cl_st_null) with portable code. The order of initialization of non-local objects in different compilation units is not specified in C++. Hence special care should be taken to avoid static initialization order fiasco. CLN solved the problem with some evil (GCC specific, and even GCC-version-specific) hack. Replace it with a technique similar to one used in STL to initialize std::cout and friends. --- include/cln/string.h | 5 ++--- src/base/string/cl_st_null.cc | 4 +--- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/include/cln/string.h b/include/cln/string.h index c316f04..f7da4a2 100644 --- a/include/cln/string.h +++ b/include/cln/string.h @@ -124,10 +124,9 @@ inline cl_string::operator cl_heap_string* () const } inline cl_string::cl_string () { - extern const cl_string cl_null_string; - pointer = (cl_heap_string*) cl_null_string; + static const cl_string cl_null_st(NULL, 0); + pointer = (cl_heap_string*) cl_null_st; } -CL_REQUIRE(cl_st_null) // Hash code. extern unsigned long hashcode (const cl_string& str); diff --git a/src/base/string/cl_st_null.cc b/src/base/string/cl_st_null.cc index e62b0a1..3ba0fb4 100644 --- a/src/base/string/cl_st_null.cc +++ b/src/base/string/cl_st_null.cc @@ -3,13 +3,12 @@ // General includes. #include "cl_sysdep.h" -CL_PROVIDE(cl_st_null) - // Specification. #include "cln/string.h" namespace cln { +#warning "Please remove me" extern const cl_string cl_null_string; } // namespace cln @@ -22,4 +21,3 @@ const cl_string cl_null_string = cl_string(NULL,0); } // namespace cln -CL_PROVIDE_END(cl_st_null)