Last active
December 20, 2015 04:59
-
-
Save msabramo/6074572 to your computer and use it in GitHub Desktop.
A Possible bug in Cython? This is the code for a message that I'm posting to the cython-users group at https://groups.google.com/forum/#!forum/cython-users
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test: hello.so | |
python -c 'import hello; hello.byte_bugginess()' | |
hello.so: hello.pyx | |
python setup.py build_ext --inplace | |
clean: | |
$(RM) -r *.so *.c *.pyc __pycache__ *.egg-info build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
try: | |
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 | |
Distribution(dict(setup_requires='Cython')) | |
try: | |
from Cython.Distutils import build_ext | |
except ImportError: | |
print("Could not import Cython.Distutils. Install `cython` and rerun.") | |
sys.exit(1) | |
ext_modules = [Extension("hello", ["hello.pyx"])] | |
setup( | |
name = 'Hello world app', | |
cmdclass = {'build_ext': build_ext}, | |
ext_modules = ext_modules, | |
setup_requires = ['Cython'], | |
test_suite='test', | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output
How the heck is val == 2?