Browse Source

Replace CL_REQUIRE/CL_PROVIDE(cl_R_ring) 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.
master
Alexei Sheplyakov 16 years ago
parent
commit
311046b5c7
  1. 11
      include/cln/real_ring.h
  2. 2
      include/cln/univpoly_real.h
  3. 35
      src/real/ring/cl_R_ring.cc

11
include/cln/real_ring.h

@ -11,7 +11,16 @@ namespace cln {
typedef cl_specialized_number_ring<cl_R> cl_real_ring; typedef cl_specialized_number_ring<cl_R> cl_real_ring;
extern const cl_real_ring cl_R_ring; // math. R extern const cl_real_ring cl_R_ring; // math. R
extern cl_class cl_class_real_ring; extern cl_class cl_class_real_ring;
//CL_REQUIRE(cl_R_ring)
class cl_R_ring_init_helper
{
static int count;
public:
cl_R_ring_init_helper();
~cl_R_ring_init_helper();
};
static cl_R_ring_init_helper cl_R_ring_init_helper_instance;
} // namespace cln } // namespace cln

2
include/cln/univpoly_real.h

@ -223,8 +223,6 @@ inline const cl_UP_R deriv (const cl_UP_R& x)
#endif #endif
CL_REQUIRE(cl_R_ring)
} // namespace cln } // namespace cln
#endif /* _CL_UNIVPOLY_REAL_H */ #endif /* _CL_UNIVPOLY_REAL_H */

35
src/real/ring/cl_R_ring.cc

@ -3,8 +3,6 @@
// General includes. // General includes.
#include "cl_sysdep.h" #include "cl_sysdep.h"
CL_PROVIDE(cl_R_ring)
// Specification. // Specification.
#include "cln/real_ring.h" #include "cln/real_ring.h"
@ -145,19 +143,36 @@ static void cl_real_ring_dprint (cl_heap* pointer)
fprint(cl_debugout, "(cl_real_ring) cl_R_ring"); fprint(cl_debugout, "(cl_real_ring) cl_R_ring");
} }
cl_class cl_class_real_ring = {
cl_real_ring_destructor,
cl_class_flags_number_ring,
cl_real_ring_dprint
};
static cl_heap_real_ring* cl_heap_real_ring_instance;
cl_class cl_class_real_ring;
// Constructor. // Constructor.
template <> template <>
inline cl_real_ring::cl_specialized_number_ring () inline cl_real_ring::cl_specialized_number_ring ()
: cl_number_ring (new cl_heap_real_ring()) {}
: cl_number_ring (cl_heap_real_ring_instance) {}
const cl_real_ring cl_R_ring = cl_R_ring;
int cl_R_ring_init_helper::count = 0;
cl_R_ring_init_helper::cl_R_ring_init_helper()
{
if (count++ == 0) {
cl_class_real_ring.destruct = cl_real_ring_destructor;
cl_class_real_ring.flags = cl_class_flags_number_ring;
cl_class_real_ring.dprint = cl_real_ring_dprint;
cl_heap_real_ring_instance = new cl_heap_real_ring();
new((void *)&cl_R_ring) cl_real_ring();
}
}
cl_R_ring_init_helper::~cl_R_ring_init_helper()
{
if (--count == 0) {
delete cl_heap_real_ring_instance;
}
}
const cl_real_ring cl_R_ring;
} // namespace cln } // namespace cln
CL_PROVIDE_END(cl_R_ring)
Loading…
Cancel
Save