Care about refcounts when reclaiming memory allocated for static objects.
Richard Kreckel [Tue, 31 May 2011 06:46:32 +0000 (08:46 +0200)]
With commit aff357309f6 we started freeing numeric flyweights when the library
usage count drops to zero. But that triggers assertions in basic::~basic
when compiled with -DDO_GINAC_ASSERT because these flyweights are still being
used by their matching ex objects (their refcount is still 1). Instead of
removing that assertion, let's just call the ex::~ex manually and let it do
the freeing.

ginac/utils.cpp

index b3efb8c..aa01f7b 100644 (file)
@@ -391,55 +391,56 @@ library_init::~library_init()
                // It's really necessary to clean up, since the program
                // lifetime might not be the same as libginac.{so,dll} one
                // (e.g. consider // dlopen/dlsym/dlclose sequence).
-               delete _num120_p;
-               delete _num_120_p;
-               delete _num60_p;
-               delete _num_60_p;
-               delete _num48_p;
-               delete _num_48_p;
-               delete _num30_p;
-               delete _num_30_p;
-               delete _num25_p;
-               delete _num_25_p;
-               delete _num24_p;
-               delete _num_24_p;
-               delete _num20_p;
-               delete _num_20_p;
-               delete _num18_p;
-               delete _num_18_p;
-               delete _num15_p;
-               delete _num_15_p;
-               delete _num12_p;
-               delete _num_12_p;
-               delete _num11_p;
-               delete _num_11_p;
-               delete _num10_p;
-               delete _num_10_p;
-               delete _num9_p;
-               delete _num_9_p;
-               delete _num8_p;
-               delete _num_8_p;
-               delete _num7_p;
-               delete _num_7_p;
-               delete _num6_p;
-               delete _num_6_p;
-               delete _num5_p;
-               delete _num_5_p;
-               delete _num4_p;
-               delete _num_4_p;
-               delete _num3_p;
-               delete _num_3_p;
-               delete _num2_p;
-               delete _num_2_p;
-               delete _num1_p;
-               delete _num_1_p;
-               delete _num1_2_p;
-               delete _num_1_2_p;
-               delete _num1_3_p;
-               delete _num_1_3_p;
-               delete _num1_4_p;
-               delete _num_1_4_p;
-               delete _num0_p;
+               // Let the ex dtors care for deleting the numerics!
+               _ex120.~ex();
+               _ex_120.~ex();
+               _ex60.~ex();
+               _ex_60.~ex();
+               _ex48.~ex();
+               _ex_48.~ex();
+               _ex30.~ex();
+               _ex_30.~ex();
+               _ex25.~ex();
+               _ex_25.~ex();
+               _ex24.~ex();
+               _ex_24.~ex();
+               _ex20.~ex();
+               _ex_20.~ex();
+               _ex18.~ex();
+               _ex_18.~ex();
+               _ex15.~ex();
+               _ex_15.~ex();
+               _ex12.~ex();
+               _ex_12.~ex();
+               _ex11.~ex();
+               _ex_11.~ex();
+               _ex10.~ex();
+               _ex_10.~ex();
+               _ex9.~ex();
+               _ex_9.~ex();
+               _ex8.~ex();
+               _ex_8.~ex();
+               _ex7.~ex();
+               _ex_7.~ex();
+               _ex6.~ex();
+               _ex_6.~ex();
+               _ex5.~ex();
+               _ex_5.~ex();
+               _ex4.~ex();
+               _ex_4.~ex();
+               _ex3.~ex();
+               _ex_3.~ex();
+               _ex2.~ex();
+               _ex_2.~ex();
+               _ex1.~ex();
+               _ex_1.~ex();
+               _ex1_2.~ex();
+               _ex_1_2.~ex();
+               _ex1_3.~ex();
+               _ex_1_3.~ex();
+               _ex1_4.~ex();
+               _ex_1_4.~ex();
+               _ex0.~ex();
        }
 }