Skip to content

Instantly share code, notes, and snippets.



Last active Dec 20, 2015
What would you like to do?
A Possible bug in Cython? This is the code for a message that I'm posting to the cython-users group at!forum/cython-users
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)
print("4 - val = %d" % val)
val = foo.x
print("5 - val = %d" % val)
print("6 - val = %d" % val)
python -c 'import hello; hello.byte_bugginess()' hello.pyx
python build_ext --inplace
$(RM) -r *.so *.c *.pyc __pycache__ *.egg-info build
import sys
from setuptools import setup
from setuptools.extension import Extension
except ImportError:
print("Couldn't import setuptools. Falling back to distutils.")
from distutils.core import setup
# Force `setup_requires` stuff like Cython to be installed before proceeding
from setuptools.dist import Distribution
from Cython.Distutils import build_ext
except ImportError:
print("Could not import Cython.Distutils. Install `cython` and rerun.")
ext_modules = [Extension("hello", ["hello.pyx"])]
name = 'Hello world app',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
setup_requires = ['Cython'],

This comment has been minimized.

Copy link
Owner Author

@msabramo msabramo commented Jul 24, 2013

Sample output

marca@marca-mac:~/dev/git-repos/cython-test$ make
python 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/
python -c 'import hello; hello.byte_bugginess(1)'
1 - val = 1
4 - val = 1
5 - val = 0
6 - val = 2

How the heck is val == 2?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment