Browse Source

Replace CL_REQUIRE/CL_PROVIDE(cl_I_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 17 years ago
parent
commit
ae1b7178f7
  1. 10
      include/cln/integer_ring.h
  2. 2
      include/cln/univpoly_integer.h
  3. 34
      src/integer/ring/cl_I_ring.cc

10
include/cln/integer_ring.h

@ -11,7 +11,15 @@ namespace cln {
typedef cl_specialized_number_ring<cl_I> cl_integer_ring;
extern const cl_integer_ring cl_I_ring; // math. Z
extern cl_class cl_class_integer_ring;
//CL_REQUIRE(cl_I_ring)
class cl_I_ring_init_helper
{
static int count;
public:
cl_I_ring_init_helper();
~cl_I_ring_init_helper();
};
static cl_I_ring_init_helper cl_I_ring_init_helper_instance;
} // namespace cln

2
include/cln/univpoly_integer.h

@ -218,8 +218,6 @@ inline const cl_UP_I deriv (const cl_UP_I& x)
#endif
CL_REQUIRE(cl_I_ring)
// Returns the n-th Tchebychev polynomial (n >= 0).
extern const cl_UP_I tschebychev (sintL n);

34
src/integer/ring/cl_I_ring.cc

@ -3,8 +3,6 @@
// General includes.
#include "cl_sysdep.h"
CL_PROVIDE(cl_I_ring)
// Specification.
#include "cln/integer_ring.h"
@ -143,19 +141,35 @@ static void cl_integer_ring_dprint (cl_heap* pointer)
fprint(cl_debugout, "(cl_integer_ring) cl_I_ring");
}
cl_class cl_class_integer_ring = {
cl_integer_ring_destructor,
cl_class_flags_number_ring,
cl_integer_ring_dprint
};
cl_class cl_class_integer_ring;
static cl_heap_integer_ring* cl_heap_integer_ring_instance;
// Constructor.
template <>
inline cl_integer_ring::cl_specialized_number_ring ()
: cl_number_ring (new cl_heap_integer_ring()) {}
: cl_number_ring(cl_heap_integer_ring_instance) {}
const cl_integer_ring cl_I_ring = cl_I_ring;
const cl_integer_ring cl_I_ring;
int cl_I_ring_init_helper::count = 0;
cl_I_ring_init_helper::cl_I_ring_init_helper()
{
if (count++ == 0) {
cl_class_integer_ring.destruct = cl_integer_ring_destructor;
cl_class_integer_ring.flags = cl_class_flags_number_ring;
cl_class_integer_ring.dprint = cl_integer_ring_dprint;
cl_heap_integer_ring_instance = new cl_heap_integer_ring();
new ((void *)&cl_I_ring) cl_integer_ring();
}
}
cl_I_ring_init_helper::~cl_I_ring_init_helper()
{
if (--count == 0) {
delete cl_heap_integer_ring_instance;
}
}
} // namespace cln
CL_PROVIDE_END(cl_I_ring)
Loading…
Cancel
Save