weird error with gcc 4.4, gomp, cython, and matplotlib

I'm really not sure which mailing list to report this on -- it has got
to rank up there with one of the most obscure errors of all times. I
suspect it's an error in gcc's new openmp implementation, gomp, but
not sure; I can report it there if people think I should.

In gcc 4.4.1, when I compile a completely empty .pyx module in (1) c++
mode and (2) pass -lgomp to the linker, simply (3) importing that
empty module causes any subsequent use of matplotlib to segfault the
program. Changing either (1), (2) or (3) makes the error go away.

I'm using the latest 32bit ubuntu (9.10), python 2.6.4, with the
latest cython-devel (2820:105c661599c9) and the latest matplotlib from
svn (8097). In matplotlib, I'm using the qt4agg backend. Everything
else appears to be working save for this error.

If my main file is simply:

import tests.emptymodule
import tests.plottest

where emptymodules is a completely empty cython module and plottest is

from matplotlib.pylab import *

figure()
plot([0,1], [0,1], '-b')
show()

The program segfaults on the plot() call, with backtrace

(gdb) bt 8
#0 0x00e03bc7 in __cxa_allocate_exception () from /usr/lib/libstdc++.so.6
#1 0x0093f282 in py_to_agg_transformation_matrix (obj=0x8223f58,
errors=false) at src/agg_py_transforms.cpp:20
#2 0x00946ff3 in _path_module::update_path_extents (this=0x8856098,
args=...) at src/path.cpp:346
#3 0x0094e2fd in
Py::ExtensionModule<_path_module>::invoke_method_varargs (this=<value
optimized out>, method_def=0x8476e00, args=...)
    at ./CXX/Python2/ExtensionModule.hxx:184
#4 0x0093ae26 in method_varargs_call_handler
(_self_and_name_tuple=0x888448c, _args=0x8f052fc) at
CXX/Python2/cxx_extensions.cxx:1714
#5 0x080dc0d0 in PyEval_EvalFrameEx ()
#6 0x080dddf2 in PyEval_EvalCodeEx ()
#7 0x080dc1b4 in PyEval_EvalFrameEx ()

Other commands like imshow also cause a segfault.

Anyway, I can get by for now without openmp, but I'm curious if anyone
has ideas about this bug. I've attached a tarball with the code that
reproduces it for me; simply run build.sh and run.

Thanks!
-- hoyt

cython-gomp-matplotlib-error.tar.bz2 (2.73 KB)

···

++++++++++++++++++++++++++++++++++++++++++++++++
+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ hoytak@...149...
++++++++++++++++++++++++++++++++++++++++++

Hoyt Koepke wrote:

I'm really not sure which mailing list to report this on -- it has got
to rank up there with one of the most obscure errors of all times. I
suspect it's an error in gcc's new openmp implementation, gomp, but
not sure; I can report it there if people think I should.

In gcc 4.4.1, when I compile a completely empty .pyx module in (1) c++
mode and (2) pass -lgomp to the linker, simply (3) importing that
empty module causes any subsequent use of matplotlib to segfault the
program. Changing either (1), (2) or (3) makes the error go away.

I'm using the latest 32bit ubuntu (9.10), python 2.6.4, with the
latest cython-devel (2820:105c661599c9) and the latest matplotlib from
svn (8097). In matplotlib, I'm using the qt4agg backend. Everything
else appears to be working save for this error.

If my main file is simply:

import tests.emptymodule
import tests.plottest

where emptymodules is a completely empty cython module and plottest is

from matplotlib.pylab import *

figure()
plot([0,1], [0,1], '-b')
show()

The program segfaults on the plot() call, with backtrace

(gdb) bt 8
#0 0x00e03bc7 in __cxa_allocate_exception () from /usr/lib/libstdc++.so.6
#1 0x0093f282 in py_to_agg_transformation_matrix (obj=0x8223f58,
errors=false) at src/agg_py_transforms.cpp:20
#2 0x00946ff3 in _path_module::update_path_extents (this=0x8856098,
args=...) at src/path.cpp:346
#3 0x0094e2fd in
Py::ExtensionModule<_path_module>::invoke_method_varargs (this=<value
optimized out>, method_def=0x8476e00, args=...)
    at ./CXX/Python2/ExtensionModule.hxx:184
#4 0x0093ae26 in method_varargs_call_handler
(_self_and_name_tuple=0x888448c, _args=0x8f052fc) at
CXX/Python2/cxx_extensions.cxx:1714
#5 0x080dc0d0 in PyEval_EvalFrameEx ()
#6 0x080dddf2 in PyEval_EvalCodeEx ()
#7 0x080dc1b4 in PyEval_EvalFrameEx ()

It works for me here, but of course, I have a slightly different system.

gcc-4.3, python 2.5.2, Cython 0.12, and matplotlib SVN 8097.

Have you verified that the same C++ compiler and version of libstdc++ is being used for everything?

Mike

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

[snip]

I'm guessing that's the issue, but just to be sure, try using the bare

I still get the error with the super-bare extension module, so
cython's off the hook :-).

Have you verified that the same C++ compiler and version of libstdc++ is
being used for everything?

I've tried it two ways; first with everything -- numpy, scipy,
matplotlib -- installed and compiled from svn, and one with them
installed from the latest ubuntu repositories. I also tried it on
both machines I have access to; a 64bit server with gcc 4.3.3 and
python 2.6.2, and a 32bit one with gcc 4.4.1 and python 2.6.4. The
error is the same on both of those. The python version and the gcc
compiler are the two things in common.

If you did upgrade NumPy, rebuild *everything* of compiled code
which depends on it.

Yes I did do that, and recompiled everything, but still good to check.

gcc is smelling fishier and fishier (or maybe python 2.6?).

-- Hoyt

···

On Thu, Jan 28, 2010 at 2:00 AM, Robert Bradshaw <robertwb@...811...> wrote:

++++++++++++++++++++++++++++++++++++++++++++++++
+ Hoyt Koepke
+ University of Washington Department of Statistics
+ http://www.stat.washington.edu/~hoytak/
+ hoytak@...149...
++++++++++++++++++++++++++++++++++++++++++