On Wed, Mar 11, 2009 at 4:27 AM, Dag Sverre Seljebotn
<[email protected]> wrote:
> Since there's been some interest in how to get started coding on Cython
> on the mailing list lately, I thought I'd call attention to these two
> tickets:
>
> http://trac.cython.org/cython_trac/ticket/158
> http://trac.cython.org/cython_trac/ticket/203
>
> These seems to fit the sweet spot of not being too hard to fix for
> beginners (with some mentoring), but not being completely trivial either.
>
> I'm happy to provide an attack strategy/small amount of mentoring for
> these tickets if anybody's interested.

Hi Dag,

I'm interested in working on #158 if it isn't already claimed.

In the generated c code for these python functions:

def nocrash1():
     cdef str s = "Test"
     print "%s" % s

def crash1():
    print "%s" % s
    cdef str s = "Test"

They differ only in that each line in the function body is converted
into C in a different order.  The internal string s is assigned to a
non-null python object (the string "Test") in nocrash before being
printed, while 's' is assiged to "Test" after trying to print in
crash1.

One solution (as mentioned in the ticket comments) would be to raise a
compilation error since the s variable is declared after it's used.  I
imagine some checks would be in order to ensure this, but I don't have
ideas about where to start.

This function:

def nocrash2():
    print "%s" % s
    cdef str s

Prints "None", although it should raise an exception since the
analogous python code raises a "NameError."  The generated C code puts
the 'cdef str s' line before the 'print' line and sets s to None.

This would be solved by the fix suggested above.

The other solution involving flow analysis would be way beyond my
abilities (or a bug fixable by a beginner).

Kurt
_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to