[CLN-list] Segfault when using univpoly

Richard B. Kreckel kreckel at ginac.de
Mon Mar 14 23:47:09 CET 2005


My latest findings:

On Sat, 12 Mar 2005, I wrote:
> Rather, some debugging has revealed that we are having some sort of
> type-punning problem in include/cln/modinteger.h.  It happens in the ctor
> from cl_modint_ring*:
>
> inline cl_modint_ring::cl_modint_ring (cl_heap_modint_ring* r)
>         : cl_ring ((cl_private_thing) (cl_inc_pointer_refcount((cl_heap*)r), r)) {}
>
> The code generated by this function stomps on the type* member variable of
> cl_heap_modint_ring (inherited from cl_heap).  I am unable to see why,
> though.  Anyone else sees clearer?  Oh, yes, the fact that it stomps on
> type* has something to do with the vptr being there or not.  But what?

Of course, taking the cl_heap* part of a cl_heap_modint_ring* results in
an offset the size of the vptr.  And for it to work it's required that the
definitions are visible.  Otherwise the offset will be zero.

Owwww, this is soo painful!

This is a first patch (two, actually).  But it's still not enough to make
it work properly:

diff -a -u -r1.5 modinteger.h
--- modinteger.h        6 May 2002 10:29:18 -0000       1.5
+++ modinteger.h        14 Mar 2005 22:38:26 -0000
@@ -37,8 +37,7 @@
        // Assignment operator.
        cl_modint_ring& operator= (const cl_modint_ring&);
        // Automatic dereferencing.
-       cl_heap_modint_ring* operator-> () const
-       { return (cl_heap_modint_ring*)heappointer; }
+       cl_heap_modint_ring* operator-> () const;
 };

 // Z/0Z
@@ -51,10 +50,6 @@
 CL_DEFINE_COPY_CONSTRUCTOR2(cl_modint_ring,cl_ring)
 CL_DEFINE_ASSIGNMENT_OPERATOR(cl_modint_ring,cl_modint_ring)

-// Normal constructor for `cl_modint_ring'.
-inline cl_modint_ring::cl_modint_ring (cl_heap_modint_ring* r)
-       : cl_ring ((cl_private_thing) (cl_inc_pointer_refcount((cl_heap*)r), r)) {}
-
 // Operations on modular integer rings.

 inline bool operator== (const cl_modint_ring& R1, const cl_modint_ring& R2)
@@ -358,6 +353,13 @@
 };
 #define SUBCLASS_cl_heap_modint_ring() \
   SUBCLASS_cl_heap_ring()
+
+// Normal constructor for `cl_modint_ring'.
+inline cl_modint_ring::cl_modint_ring (cl_heap_modint_ring* r)
+       : cl_ring ((cl_private_thing) (cl_inc_pointer_refcount(r), (cl_heap*)r)) {}
+
+inline cl_heap_modint_ring* cl_modint_ring::operator-> () const
+{ return (cl_heap_modint_ring*)heappointer; }

 // Lookup or create a modular integer ring  Z/mZ
 extern const cl_modint_ring find_modint_ring (const cl_I& m);


breathless
  -richy.
-- 
Richard B. Kreckel
<http://www.ginac.de/~kreckel/>





More information about the CLN-list mailing list