]> www.ginac.de Git - cln.git/blobdiff - src/vector/cl_GV_I.cc
Use paths relative the `src' directory in the #include directives.
[cln.git] / src / vector / cl_GV_I.cc
index 1471cefe903519148894011070bda1135817a804..4162d681fc7eab807bf3b979299c12146e4cb0de 100644 (file)
@@ -1,9 +1,7 @@
 // cl_make_heap_GV_I().
 
 // General includes.
-#include "cl_sysdep.h"
-
-CL_PROVIDE(cl_GV_I)
+#include "base/cl_sysdep.h"
 
 // Specification.
 #include "cln/GV_integer.h"
@@ -11,10 +9,10 @@ CL_PROVIDE(cl_GV_I)
 
 // Implementation.
 
-#include "cl_I.h"
-#include "cl_DS.h"
-#include "cln/abort.h"
-#include "cl_offsetof.h"
+#include "integer/cl_I.h"
+#include "base/digitseq/cl_DS.h"
+#include "cln/exception.h"
+#include "base/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<cl_I>* vec)
 {
@@ -70,9 +73,9 @@ static inline cl_GV_I_vectorops* outcast (cl_GV_vectorops<cl_I>* 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<cl_I>* 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<cl_I> (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<cl_I>* 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<cl_I>* vec, uintC index, const cl_I&
                        return;
                }
        }
-       cl_abort();
+       throw runtime_exception();
 }
 
 
@@ -315,7 +318,7 @@ static void bits2_set_element (cl_GV_inner<cl_I>* vec, uintC index, const cl_I&
                        return;
                }
        }
-       cl_abort();
+       throw runtime_exception();
 }
 
 
@@ -337,7 +340,7 @@ static void bits4_set_element (cl_GV_inner<cl_I>* vec, uintC index, const cl_I&
                        return;
                }
        }
-       cl_abort();
+       throw runtime_exception();
 }
 
 
@@ -369,7 +372,7 @@ static void bits8_set_element (cl_GV_inner<cl_I>* vec, uintC index, const cl_I&
                        return;
                }
        }
-       cl_abort();
+       throw runtime_exception();
 }
 
 
@@ -401,7 +404,7 @@ static void bits16_set_element (cl_GV_inner<cl_I>* 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<cl_I> (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)