New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cython crash with `import Cython.Build` in sdist #1855

Open
sonots opened this Issue Sep 4, 2017 · 1 comment

Comments

Projects
None yet
2 participants
@sonots
Contributor

sonots commented Sep 4, 2017

Hi, I met a trouble that cythonize causes SEGV.
This may not be a big problem, but let me issue anyway.

Environment

  • Python 3.6.1
  • Cython 0.26.1

How to reproduce

I made a repo https://github.com/sonots/cythonize-segv

$ python setup.py sdist
building without Cython

Installed /home/ubuntu/src/github.com/sonots/cythonize-segv/.eggs/fastrlock-0.3-py3.6-linux-x86_64.egg
running sdist
Compiling segv/_segv.pyx because it changed.
[1/1] Cythonizing segv/_segv.pyx
Compiling /home/ubuntu/src/github.com/sonots/cythonize-segv/segv/_segv.pyx
[1]    16510 segmentation fault (core dumped)  python setup.py sdist

The point was that

  1. Install a cython module with setup_requires
  2. import Cython.Build in sdist

as:

#!/usr/bin/env python

import os
import sys

from distutils.command.sdist import sdist
from distutils.command.build_ext import build_ext
from setuptools import setup, Extension

setup_requires = ['fastrlock>=0.3']
install_requires = ['fastrlock>=0.3']

pyx_ext_modules = [Extension('segv._segv',
                         sources=['segv/_segv.pyx'],
                         libraries=[],
                         include_dirs=[],
                         define_macros=[])]
ext_modules = [Extension('segv._segv',
                         sources=['segv/_segv.cpp'],
                         libraries=[],
                         include_dirs=[],
                         define_macros=[])]

class BuildExt(build_ext):
    def run(self):
        import Cython
        import Cython.Build
        Cython.Build.cythonize(pyx_ext_modules, verbose=True)
        build_ext.run(self)

class Sdist(sdist):
    def __init__(self, *args, **kwargs):
        import Cython
        import Cython.Build
        Cython.Build.cythonize(pyx_ext_modules, verbose=True)
        sdist.__init__(self, *args, **kwargs)

setup(
    name='segv',
    version='1.0.0',
    url='https://github.com/sonots/cython-segv',
    author='sonots',
    author_email='sonots@example.com',
    packages=['segv'],
    zip_safe=False,
    setup_requires=setup_requires,
    install_requires=install_requires,
    ext_modules=ext_modules,
    cmdclass={'build_ext': BuildExt, 'sdist': Sdist},
)

When I changed:

class Sdist(sdist):
    def __init__(self, *args, **kwargs):
        import Cython
        import Cython.Build
        Cython.Build.cythonize(pyx_ext_modules, verbose=True)
        sdist.__init__(self, *args, **kwargs)

to:

import Cython
import Cython.Build

class Sdist(sdist):
    def __init__(self, *args, **kwargs):
        Cython.Build.cythonize(pyx_ext_modules, verbose=True)
        sdist.__init__(self, *args, **kwargs)

The problem was resolved.

@scoder

This comment has been minimized.

Show comment
Hide comment
@scoder

scoder Sep 4, 2017

Contributor

Thanks for the report. My guess is that this is due to a circular import with the old build_ext machinery, or something like that.

Contributor

scoder commented Sep 4, 2017

Thanks for the report. My guess is that this is due to a circular import with the old build_ext machinery, or something like that.

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