[Pyrex] Does __Pyx_ImportType need to check struct sizes? (Cython-relevant, too)

Robert Bradshaw robertwb at math.washington.edu
Sat May 30 17:52:23 CEST 2009


On May 24, 2009, at 5:07 AM, Greg Ewing wrote:

> Robert Kern wrote:
>> What is the reasoning behind having __Pyx_ImportType check that  
>> the imported
>> type's size at runtime matches exactly the type's size at compile  
>> time?
>
> It's meant to provide some degree of safeguard against
> changing the definition of a type and failing to
> recompile all the Pyrex modules that import it.
>
> I know it's not a perfect check, but I thought it
> would be better than nothing. Remember that it may
> not only be you that's affected by the change, but
> someone else importing your type into their Pyrex
> module. Without any check, they'll just get a
> segfault with no clue as to what went wrong.

Perhaps the check should be even stronger, similar to the check we do  
for public c api methods. (Not sure if it's worth the break in  
backwards compatibility though).

> Also note that adding fields to the end is only
> safe in the absence of subclassing.
>
> I might be persuaded to drop the check, but only
> if everyone promises not to complain if their
> Pyrex modules fail inexplicably. :-)

My thoughts exactly. Before we had a build dependancy code for .pyx  
files in Sage, this saved us a lot of headaches.

- Robert





More information about the Pyrex mailing list