Import clr fails on Linux64/Mono · Issue #119 · pythonnet/pythonnet

Running python -c 'import clr' 2>&1 gives

*** Error in `python': double free or corruption (out): 0x00007ff2a2b41180 ***
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) Python.Runtime.Runtime.Py_Initialize () <0xffffffff>
  at Python.Runtime.Runtime.Initialize () <0x0003f>
  at Python.Runtime.PythonEngine.Initialize () <0x00047>
  at Python.Runtime.PythonEngine.InitExt () <0x0000f>
  at (wrapper runtime-invoke) object.runtime_invoke_void (object,intptr,intptr,intptr) <0xffffffff>

Native stacktrace:

        /usr/lib/libmonoboehm-2.0.so.1(+0xcce3a) [0x7ff2a417de3a]
        /lib/x86_64-linux-gnu/libpthread.so.0(+0x10d10) [0x7ff2a56ffd10]
        /lib/x86_64-linux-gnu/libc.so.6(gsignal+0x37) [0x7ff2a535a267]
        /lib/x86_64-linux-gnu/libc.so.6(abort+0x16a) [0x7ff2a535beca]
        /lib/x86_64-linux-gnu/libc.so.6(+0x78c53) [0x7ff2a539dc53]
        /lib/x86_64-linux-gnu/libc.so.6(+0x80c69) [0x7ff2a53a5c69]
        /lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c) [0x7ff2a53a989c]
        /usr/lib/x86_64-linux-gnu/libpython2.7.so(PyString_InternInPlace+0x90) [0x7ff2a2c65ae0]
        /usr/lib/x86_64-linux-gnu/libpython2.7.so(PyString_InternFromString+0x2a) [0x7ff2a2c65b6a]
        /usr/lib/x86_64-linux-gnu/libpython2.7.so(PyType_Ready+0x1b25) [0x7ff2a2c6b6f5]
        /usr/lib/x86_64-linux-gnu/libpython2.7.so(_Py_ReadyTypes+0xb0) [0x7ff2a2c59360]
        /usr/lib/x86_64-linux-gnu/libpython2.7.so(Py_InitializeEx+0x76) [0x7ff2a2ce2106]
        [0x4181c411]

Debug info from gdb:


=================================================================
Got a SIGABRT while executing native code. This usually indicates
a fatal error in the mono runtime or one of the native libraries
used by your application.
=================================================================

Aborted (core dumped)

I'm on a clean Ubuntu Wily64 system with some deps installed ontop:

mono-complete
libperl-dev
libgtk2.0-dev
python-dev

Pythonnet seems to install fine. Installing from develop branch gives

Unpacking /home/vagrant/src/pythonnet
  Running setup.py (path:/tmp/pip-ndk1WW-build/setup.py) egg_info for package from file:///home/vagrant/src/pythonnet

Installing collected packages: pythonnet
  Running setup.py install for pythonnet
    All packages listed in packages.config are already installed.
    XBuild Engine Version 12.0
    Mono, Version 3.2.8.0
    Copyright (C) 2005-2013 Various Mono authors
    /tmp/pip-ndk1WW-build/pythonnet.sln:  warning : The project configuration for project 'clrmodule' corresponding to the solution configuration 'ReleaseMono|x64' was not found.
    XBuild Engine Version 12.0
    Mono, Version 3.2.8.0
    Copyright (C) 2005-2013 Various Mono authors
                Configuration: ReleaseMono Platform: x64
    /tmp/pip-ndk1WW-build/pythonnet.sln:  warning : The project configuration for project 'clrmodule' corresponding to the solution configuration 'ReleaseMono|x64' was not found.
        Configuration: ReleaseMono Platform: x64
    Configuration: ReleaseMono Platform: x64
    Configuration: Release Platform: x64
    assemblyinfo.cs(24,49): warning CS0618: `System.Security.Permissions.SecurityAction.RequestMinimum' is obsolete: `This requests should not be used'
    pythonconsole.cs(24,24): warning CS0219: The variable `a' is assigned but its value is never used
    building 'clr' extension
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/monoclr/pynetinit.c -o build/temp.linux-x86_64-2.7/src/monoclr/pynetinit.o -D_REENTRANT -I/usr/lib/pkgconfig/../../include/mono-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
    src/monoclr/pynetinit.c: In function ‘main_thread_handler’:
    src/monoclr/pynetinit.c:100:17: warning: variable ‘init_result’ set but not used [-Wunused-but-set-variable]
         MonoObject *init_result;
                     ^
    x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c src/monoclr/clrmod.c -o build/temp.linux-x86_64-2.7/src/monoclr/clrmod.o -D_REENTRANT -I/usr/lib/pkgconfig/../../include/mono-2.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include
    src/monoclr/clrmod.c:42:18: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
     static PyObject *_initclr() {
                      ^
    x86_64-linux-gnu-gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -Wl,-Bsymbolic-functions -Wl,-z,relro -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security build/temp.linux-x86_64-2.7/src/monoclr/pynetinit.o build/temp.linux-x86_64-2.7/src/monoclr/clrmod.o -o build/lib.linux-x86_64-2.7/clr.so -L/usr/lib/pkgconfig/../../lib -lmono-2.0 -lm -lrt -ldl -lpthread -lglib-2.0

Successfully installed pythonnet
Cleaning up...