]> www.ginac.de Git - cln.git/commitdiff
Replace CL_REQUIRE/CL_PROVIDE(cl_st_null) with portable code.
authorAlexei Sheplyakov <varg@theor.jinr.ru>
Thu, 21 Aug 2008 11:17:06 +0000 (15:17 +0400)
committerAlexei Sheplyakov <varg@theor.jinr.ru>
Wed, 27 Aug 2008 04:41:03 +0000 (08:41 +0400)
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
src/base/string/cl_st_null.cc

index c316f04e8a758d1d839c634365c447ada0285a8a..f7da4a2c7b9d03d6d85704e09fe7ad7c642c6f98 100644 (file)
@@ -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);
index e62b0a19926cc1eef3fcad946f8d12ec919d2f8e..3ba0fb4545bafb72c7cd3d5f45c7ad298be53373 100644 (file)
@@ -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)