A plea for a bugfix was Re: [Pyrex] Unlucky fellow needs help (pyrex crashes)

Lenard Lindstrom len-l at telus.net
Wed Mar 8 19:03:41 CET 2006


The Pyrex doc suggests moving such initialization code to an __init__ 
method, which works as expected for Python. Another solution is to 
declare the class B __new__ to accept arbitrary arguments which it 
then ignores:

cdef class B:
    cdef int Seen
    def __new__(self, *args, **kwds):
        self.Seen=17

But if there is ever a chance that the subclass will itself be 
suclassed by a Pyrex extension type it too should allow extra 
arguments:

cdef class D(B):
    ...
    def __new__(self, int DS, *args, **kwds):
        self.Seen = DS

This solution is not ideal, since a subclass's __new__ must include  
the arguments of its parents' __new__:

cdef class E(D):
    cdef int something_else
    def __new__(self, int DS, int SE, *args, **kwds):  # This works.
        self.something_else = SE

cdef class F(D):
    def __new__(self, char *s, *args, **kwds): # This fails.
        self.Seen = int(s)

Lenard Lindstrom
<len-l at telus.net>


PS. While reading the remaining postings I see you already answered 
your own question.


On 8 Mar 2006 at 12:16, Helmut Jarausch wrote:

> It would be very kind if someone could help me
> in fixing Pyrex 0.9.3 (.1)
> 
> I could benefit quite a lot from subclassing.
> But my base class __new__ takes only self as
> argument whereas my derived classes take more
> parameters.
> So, I again stumbled on the bug below.
> I've never looked at Pyrex source before
> but I probably need to.
> Can anybody help a bit where this bug
> can be fixed?
> 
> The problem has nothing to do with a forward
> declaration as in the original example
> Just try
> 
> cdef class B:
>   cdef int Seen
>   def __new__(self):
>     self.Seen=17
> 
> cdef class D(B):
>   def __new__(self,int DS):
>     self.Seen= DS
> 
>   def showme(self):
>     print self.Seen
> 
> # ===================================================
> 
> # from CES import D
> # X=D(13)
> # X.showme()
> 
> 
> Is there a debug mode for Pyrex itself?
> 
> Many thanks,
> Helmut.
> 
> 
> On 23 Feb, Lenard Lindstrom wrote:
> > On 23 Feb 2006 at 17:25, Greg Ewing wrote:
> > 
> >> Helmut Jarausch wrote:
> >> 
> >> > cdef class ITNO    # forward declaration
> >> > 
> >> > cdef class ITNO_List(ITNO):
> >> >   cdef int cnt
> >> >   cdef int From
> >> >   cdef int To
> >> 
> >> This is an error, since I never intended to support
> >> using a class as a base class prior to its definition.
> >> It's a bug that Pyrex crashes instead of reporting the
> >> error, though.
> >> 
> >> > Variant II is accepted by pyrexc but
> >> > gives a segment fault while running the loop
> >> > 
> >> > cdef class ITNO             # forward declaration
> >> > cdef class ITNO_List(ITNO)  # forward declaration
> >> 
> >> I'm not sure whether this should be allowed or not.
> >> I'll look into these.
> >> 
> >> Thanks,
> >> 
> > The problem is that the ITNO  __new__ takes no arguments while the 
> > ITNO_List  __new__ takes two. When creating a new ITNO_List instance  
> > the INTO __new__ function is called with the wrong number of 
> > arguments and raises an exception.
> > 
> > The segment fault is because Pyrex is not checking if ITNO.__new__ 
> > has raised an exception so calls INTO_List.__new__ with an invalid 
> > object. Pyrex generated tp_new slot functions do not test if the 
> > pointer to the newly allocated object is NULL.
> > 
> > Lenard Lindstrom
> > <len-l at telus.net>
> > 
> > 
> > _______________________________________________
> > Pyrex mailing list
> > Pyrex at lists.copyleft.no
> > http://lists.copyleft.no/mailman/listinfo/pyrex
> > 
> 
> -- 
> Helmut Jarausch
> 
> Lehrstuhl fuer Numerische Mathematik
> RWTH - Aachen University
> D 52056 Aachen, Germany
> 





More information about the Pyrex mailing list