Browse Source

Replace CL_REQUIRE/CL_PROVIDE(cl_UP) 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
022f958fc0
  1. 9
      include/cln/univpoly.h
  2. 25
      src/polynomial/elem/cl_UP.cc

9
include/cln/univpoly.h

@ -352,7 +352,14 @@ extern const cl_univpoly_ring find_univpoly_ring (const cl_ring& r);
// Lookup or create a univariate polynomial ring with a named variable over r. // Lookup or create a univariate polynomial ring with a named variable over r.
extern const cl_univpoly_ring find_univpoly_ring (const cl_ring& r, const cl_symbol& varname); extern const cl_univpoly_ring find_univpoly_ring (const cl_ring& r, const cl_symbol& varname);
CL_REQUIRE(cl_UP)
class cl_UP_init_helper
{
static int count;
public:
cl_UP_init_helper();
~cl_UP_init_helper();
};
static cl_UP_init_helper cl_UP_init_helper_instance;
// Operations on polynomials. // Operations on polynomials.

25
src/polynomial/elem/cl_UP.cc

@ -3,8 +3,6 @@
// General includes. // General includes.
#include "cl_sysdep.h" #include "cl_sysdep.h"
CL_PROVIDE(cl_UP)
// Specification. // Specification.
#define CL_GV_NO_RANGECHECKS #define CL_GV_NO_RANGECHECKS
#define CL_SV_NO_RANGECHECKS #define CL_SV_NO_RANGECHECKS
@ -43,10 +41,24 @@ static void cl_univpoly_ring_destructor (cl_heap* pointer)
(*(cl_heap_univpoly_ring*)pointer).~cl_heap_univpoly_ring(); (*(cl_heap_univpoly_ring*)pointer).~cl_heap_univpoly_ring();
} }
cl_class cl_class_univpoly_ring = {
cl_univpoly_ring_destructor,
cl_class_flags_univpoly_ring
};
cl_class cl_class_univpoly_ring;
int cl_UP_init_helper::count = 0;
cl_UP_init_helper::cl_UP_init_helper()
{
if (count++ == 0) {
cl_class_univpoly_ring.destruct = cl_univpoly_ring_destructor;
cl_class_univpoly_ring.flags = cl_class_flags_univpoly_ring;
}
}
cl_UP_init_helper::~cl_UP_init_helper()
{
if (--count == 0) {
// nothing to clean up
}
}
cl_heap_univpoly_ring::cl_heap_univpoly_ring (const cl_ring& r, cl_univpoly_setops* setopv, cl_univpoly_addops* addopv, cl_univpoly_mulops* mulopv, cl_univpoly_modulops* modulopv, cl_univpoly_polyops* polyopv) cl_heap_univpoly_ring::cl_heap_univpoly_ring (const cl_ring& r, cl_univpoly_setops* setopv, cl_univpoly_addops* addopv, cl_univpoly_mulops* mulopv, cl_univpoly_modulops* modulopv, cl_univpoly_polyops* polyopv)
: setops (setopv), addops (addopv), mulops (mulopv), modulops (modulopv), polyops (polyopv), : setops (setopv), addops (addopv), mulops (mulopv), modulops (modulopv), polyops (polyopv),
@ -74,4 +86,3 @@ cl_heap_univpoly_ring* cl_make_univpoly_ring (const cl_ring& r)
} // namespace cln } // namespace cln
CL_PROVIDE_END(cl_UP)
Loading…
Cancel
Save