X-Git-Url: https://ginac.de/CLN/cln.git//cln.git?a=blobdiff_plain;f=src%2Fvector%2Fcl_GV_I.cc;h=4b46fa6caa9e7c43fc126d3992448be1691c8a64;hb=478f9e32c706f314e23cc20640f8650ce5631fe5;hp=1471cefe903519148894011070bda1135817a804;hpb=c84c6db5d56829d69083c819688a973867694a2a;p=cln.git diff --git a/src/vector/cl_GV_I.cc b/src/vector/cl_GV_I.cc index 1471cef..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" @@ -13,7 +11,7 @@ CL_PROVIDE(cl_GV_I) #include "cl_I.h" #include "cl_DS.h" -#include "cln/abort.h" +#include "cln/exception.h" #include "cl_offsetof.h" namespace cln { @@ -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) { @@ -70,9 +73,9 @@ static inline cl_GV_I_vectorops* outcast (cl_GV_vectorops* vectorops) struct cl_heap_GV_I_general : public cl_heap_GV_I { cl_I data[1]; // Standard allocation disabled. - void* operator new (size_t size) { unused size; cl_abort(); return (void*)1; } + void* operator new (size_t size) { unused size; throw runtime_exception(); } // Standard deallocation disabled. - void operator delete (void* ptr) { unused ptr; cl_abort(); } + void operator delete (void* ptr) { unused ptr; throw runtime_exception(); } // No default constructor. cl_heap_GV_I_general (); }; @@ -105,9 +108,9 @@ static void general_copy_elements (const cl_GV_inner* srcvec, uintC srcind var uintC srclen = srcv->v.length(); var uintC destlen = destv->v.length(); if (!(srcindex <= srcindex+count && srcindex+count <= srclen)) - cl_abort(); + throw runtime_exception(); if (!(destindex <= destindex+count && destindex+count <= destlen)) - cl_abort(); + throw runtime_exception(); do { destv->data[destindex++] = srcv->data[srcindex++]; } while (--count > 0); @@ -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]) (); @@ -140,9 +143,9 @@ cl_heap_GV_I* cl_make_heap_GV_I (uintC len) struct cl_heap_GV_I_bits##m : public cl_heap_GV_I { \ uint_t data[1]; \ /* Standard allocation disabled. */ \ - void* operator new (size_t size) { unused size; cl_abort(); return (void*)1; } \ + void* operator new (size_t size) { unused size; throw runtime_exception(); } \ /* Standard deallocation disabled. */ \ - void operator delete (void* ptr) { unused ptr; cl_abort(); } \ + void operator delete (void* ptr) { unused ptr; throw runtime_exception(); } \ /* No default constructor. */ \ cl_heap_GV_I_bits##m (); \ }; \ @@ -158,9 +161,9 @@ static void bits##m##_copy_elements (const cl_GV_inner* srcvec, uintC srci var uintC srclen = srcv->v.length(); \ var uintC destlen = destv->v.length(); \ if (!(srcindex <= srcindex+count && srcindex+count <= srclen)) \ - cl_abort(); \ + throw runtime_exception(); \ if (!(destindex <= destindex+count && destindex+count <= destlen)) \ - cl_abort(); \ + throw runtime_exception(); \ if (m == intDsize) { \ var const uintD* srcptr = &srcv->data[srcindex]; \ var uintD* destptr = &destv->data[destindex]; \ @@ -293,7 +296,7 @@ static void bits1_set_element (cl_GV_inner* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -315,7 +318,7 @@ static void bits2_set_element (cl_GV_inner* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -337,7 +340,7 @@ static void bits4_set_element (cl_GV_inner* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -369,7 +372,7 @@ static void bits8_set_element (cl_GV_inner* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -401,7 +404,7 @@ static void bits16_set_element (cl_GV_inner* vec, uintC index, const cl_I& return; } } - cl_abort(); + throw runtime_exception(); } @@ -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)