[issue23743] Python crashes upon exit if importing g++ compiled mod after importing gcc compiled mod

matham report at bugs.python.org
Mon Mar 23 06:10:35 CET 2015


New submission from matham:

I have encountered a situation where python crashes when python exits if one imports a c compiled extension followed by a cpp compiled extension (but not if imported in the reverse order). This is on windows with mingw (current using mingw-get install gcc g++ msys-make) and py2.7.9.

This is basically the issue reported at https://mail.python.org/pipermail/python-win32/2013-April/012798.html a while back by someone else, but I'm filing it in bug form so it can't be ignored :D

Here's how to replicate it:

cplayground.c:

#include <Python.h>

static PyObject*
say_hello(PyObject* self, PyObject* args)
{
    Py_RETURN_NONE;
}

static PyMethodDef HelloMethods[] =
{
     {"say_hello", say_hello, METH_VARARGS, "Greet somebody."},
     {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
initcplayground(void)
{
     (void) Py_InitModule("cplayground", HelloMethods);
}


cplayground.cpp:

#include <Python.h>

static PyObject*
say_hello(PyObject* self, PyObject* args)
{
    Py_RETURN_NONE;
}

static PyMethodDef HelloMethods[] =
{
     {"say_hello", say_hello, METH_VARARGS, "Greet somebody."},
     {NULL, NULL, 0, NULL}
};

PyMODINIT_FUNC
initcppplayground(void)
{
     (void) Py_InitModule("cppplayground", HelloMethods);
}


setup.py:

from distutils.core import setup
from distutils.extension import Extension
import Cython.Compiler.Options
from Cython.Distutils import build_ext
from os.path import join, sep, dirname, abspath

def get_extensions_from_sources():
    ext_modules = []
    ext_modules.append(Extension('src.cplayground', sources=['src/cplayground.c']))
    ext_modules.append(Extension('src.cppplayground', sources=['src/cplayground.cpp']))
    return ext_modules

setup(
    name='Playground',
    version='.1',
    author='Matthew Einhorn',
    ext_modules=get_extensions_from_sources(),
    cmdclass={'build_ext': build_ext},
    packages=['src']
      )


Here's a demonstration of the issue:

G:\Python\libs\Playground\src>python
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cplayground
>>> import cppplayground
>>> exit()

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

G:\Python\libs\Playground\src>python
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cppplayground
>>> import cplayground
>>> exit()

Here's my config:

G:\Python\libs\Playground\src>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=g:/python/env/test/py279_x86/mingw/bin/../libexec/gcc/mingw3
2/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=m
ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto
--enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++
,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l
ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm
p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --
with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-
libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/
mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)

G:\Python\libs\Playground\src>g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=g:/python/env/test/py279_x86/mingw/bin/../libexec/gcc/mingw3
2/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=m
ingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto
--enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++
,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-l
ibstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gm
p-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --
with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-
libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/
mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)

----------
components: Extension Modules, Windows
messages: 238981
nosy: matham, steve.dower, tim.golden, zach.ware
priority: normal
severity: normal
status: open
title: Python crashes upon exit if importing g++ compiled mod after importing gcc compiled mod
type: crash
versions: Python 2.7

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue23743>
_______________________________________


More information about the Python-bugs-list mailing list