X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;ds=sidebyside;f=src%2Fvector%2Fcl_GV_I.cc;h=4b46fa6caa9e7c43fc126d3992448be1691c8a64;hb=478f9e32c706f314e23cc20640f8650ce5631fe5;hp=456388b7c3456a791cc266a97076b6fd13b5e993;hpb=c486b78a1a0613f07a10816d6f6ca9e485bc8290;p=cln.git 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)