diff --git a/include/cln/GV_integer.h b/include/cln/GV_integer.h index 5dd2b79..3c5c88c 100644 --- a/include/cln/GV_integer.h +++ b/include/cln/GV_integer.h @@ -54,7 +54,14 @@ inline cl_GV_I::cl_GV_I (uintC len, sintC m) extern const cl_GV_I cl_null_GV_I; inline cl_GV_I::cl_GV_I () : cl_GV ((cl_heap_GV_I*) cl_null_GV_I) {} -CL_REQUIRE(cl_GV_I) +class cl_GV_I_init_helper +{ + static int count; +public: + cl_GV_I_init_helper(); + ~cl_GV_I_init_helper(); +}; +static cl_GV_I_init_helper cl_GV_I_init_helper_instance; // Copy a vector. extern const cl_GV_I copy (const cl_GV_I&); diff --git a/src/vector/cl_GV_I.cc b/src/vector/cl_GV_I.cc index 456388b..4b46fa6 100644 --- a/src/vector/cl_GV_I.cc +++ b/src/vector/cl_GV_I.cc @@ -3,8 +3,6 @@ // General includes. #include "cl_sysdep.h" -CL_PROVIDE(cl_GV_I) - // Specification. #include "cln/GV_integer.h" @@ -36,11 +34,16 @@ static void cl_gvector_integer_destructor (cl_heap* pointer) #endif } -cl_class cl_class_gvector_integer = { - cl_gvector_integer_destructor, - 0 -}; - +// XXX: Ugh, this needs to be non-const (and non-static) for overriding +// the printing function (see cl_GV_I_debug.cc) +cl_class& cl_class_gvector_integer() +{ + static cl_class instance = { + cl_gvector_integer_destructor, + 0 + }; + return instance; +} static inline cl_heap_GV_I * outcast (cl_GV_inner* vec) { @@ -126,7 +129,7 @@ cl_heap_GV_I* cl_make_heap_GV_I (uintC len) { var cl_heap_GV_I_general* hv = (cl_heap_GV_I_general*) malloc_hook(offsetofa(cl_heap_GV_I_general,data)+sizeof(cl_I)*len); hv->refcount = 1; - hv->type = &cl_class_gvector_integer; + hv->type = &cl_class_gvector_integer(); new (&hv->v) cl_GV_inner (len,&general_vectorops.ops); for (var uintC i = 0; i < len; i++) init1(cl_I, hv->data[i]) (); @@ -472,7 +475,7 @@ cl_heap_GV_I* cl_make_heap_GV_I (uintC len, sintC m) (((sintC)len-1)>>(log2_intDsize-log2_bits))+1; var cl_heap_GV_I_bits32* hv = (cl_heap_GV_I_bits32*) malloc_hook(offsetofa(cl_heap_GV_I_bits32,data)+sizeof(uintD)*words); hv->refcount = 1; - hv->type = &cl_class_gvector_integer; + hv->type = &cl_class_gvector_integer(); new (&hv->v) cl_GV_inner (len,&bits_vectorops[log2_bits]->ops); var uintD* ptr = (uintD*)(hv->data); for (var uintC i = 0; i < words; i++) @@ -488,8 +491,22 @@ sintC cl_heap_GV_I::maxbits () const // An empty vector. -const cl_GV_I cl_null_GV_I = cl_GV_I((uintC)0); +const cl_GV_I cl_null_GV_I = cl_null_GV_I; + +int cl_GV_I_init_helper::count = 0; + +cl_GV_I_init_helper::cl_GV_I_init_helper() +{ + if (count++ == 0) + new ((void *)&cl_null_GV_I) cl_GV_I((uintC)0); +} + +cl_GV_I_init_helper::~cl_GV_I_init_helper() +{ + if (--count == 0) { + // Nothing to clean up + } +}; } // namespace cln -CL_PROVIDE_END(cl_GV_I) diff --git a/src/vector/cl_GV_I_debug.cc b/src/vector/cl_GV_I_debug.cc index 723d25e..f291f39 100644 --- a/src/vector/cl_GV_I_debug.cc +++ b/src/vector/cl_GV_I_debug.cc @@ -20,7 +20,7 @@ static void dprint (cl_heap* pointer) fprint(cl_debugout, obj); } AT_INITIALIZATION(dprint_GV_I) -{ cl_register_type_printer(cl_class_gvector_integer,dprint); } +{ extern cl_class& cl_class_gvector_integer(); cl_class_gvector_integer().dprint = dprint; } // This dummy links in this module when requires it. int cl_GV_I_debug_module;