• Kirill Smelkov's avatar
    Fix build with python-dbg · 83ebd4d8
    Kirill Smelkov authored
    I've tried to use gevent with debug build of CPython and got:
    
        $ virtualenv -p python-dbg 1.venv
        $ . 1.venv/bin/activate
        (1.venv) kirr@deco:~/src/tools/py/gevent$ pip install -v -e .
        ...
        (1.venv) kirr@deco:~/src/tools/py/gevent$ python
        Python 2.7.16 (default, Apr  6 2019, 01:42:57)
        [GCC 8.3.0] on linux2
        Type "help", "copyright", "credits" or "license" for more information.
        >>> import gevent
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          File "/home/kirr/src/tools/py/gevent/src/gevent/__init__.py", line 87, in <module>
            from gevent._hub_local import get_hub
          File "/home/kirr/src/tools/py/gevent/src/gevent/_hub_local.py", line 101, in <module>
            import_c_accel(globals(), 'gevent.__hub_local')
          File "/home/kirr/src/tools/py/gevent/src/gevent/_util.py", line 105, in import_c_accel
            mod = importlib.import_module(cname)
          File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
            __import__(name)
        ImportError: /home/kirr/src/tools/py/gevent/src/gevent/__hub_local_d.so: undefined symbol: Py_InitModule4_64
    
    Looking around I dound that CPython changes Py_InitModule4_64 symbol name under
    debug build and that this change is used to catch usage of modules built for
    normal interpreter with debug cpython build:
    
    https://github.com/python/cpython/blob/v2.7.16-120-g46c2eff5adc/Include/modsupport.h#L105-L115
    https://github.com/python/cpython/blob/v2.7.16-120-g46c2eff5adc/Include/object.h#L54-L57
    
    Looking at C flags used to build __hub_local_d.o
    
        (1.venv) kirr@deco:~/src/tools/py/gevent$ touch src/gevent/_hub_local.c
        (1.venv) kirr@deco:~/src/tools/py/gevent$ python setup.py build_ext -i
        ...
        x86_64-linux-gnu-gcc -pthread -g -O0 -Wall -Wstrict-prototypes -fno-strict-aliasing -Wdate-time -g -O0 -fdebug-prefix-map=/build/python2.7-IbFBHb/python2.7-2.7.16=. -fstack-protector -Wformat -Werror=format-security -fPIC -I/home/kirr/tmp/trashme/1.venv/local/include/python2.7 -I/home/kirr/tmp/trashme/1.venv/include/site/python2.7 -Ideps -I/usr/include/python2.7_d -c src/gevent/_hub_local.c -o build/temp.linux-x86_64-2.7-pydebug/src/gevent/_hub_local.o
    
    XXX
    83ebd4d8
setup.py 14.1 KB