I have this Cython code:
cdef struct MyStruct: int x def byte_bugginess(x=1): cdef char val = 1 cdef MyStruct foo print("1 - val = %d" % val) if x in (3, 4): print("2 - val = %d" % val) val = 2 print("3 - val = %d" % val) else: print("4 - val = %d" % val) val = foo.x print("5 - val = %d" % val) print("6 - val = %d" % val)
and the output is:
marca@marca-mac:~/dev/git-repos/cython-test$ make python setup.py build_ext --inplace running build_ext gcc-4.2 not found, using clang instead cythoning hello.pyx to hello.c building 'hello' extension creating build creating build/temp.macosx-10.6-intel-2.7 clang -fno-strict-aliasing -fno-common -dynamic -isysroot /Developer/SDKs/MacOSX10.6.sdk -arch i386 -arch x86_64 -g -O2 -DNDEBUG -g -O3 -I/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c hello.c -o build/temp.macosx-10.6-intel-2.7/hello.o clang -bundle -undefined dynamic_lookup -arch i386 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -isysroot /Developer/SDKs/MacOSX10.6.sdk -g build/temp.macosx-10.6-intel-2.7/hello.o -o /Users/marca/dev/git-repos/cython-test/hello.so python -c 'import hello; hello.byte_bugginess(1)' 1 - val = 1 4 - val = 1 5 - val = 0 6 - val = 2
How could val be equal to 2? This implies that the false clause of the if statement is getting evaluated?
Weird.
Full code is at this gist.
I posted about this to the cython-users Google group. I am curious to see what they say.