0.87 on HP-UX 11.23/PA with Python 2.4.2

We've built 0.87 with Python 2.4.2/GCC 3.4.3 on Solaris,

    > HP-UX, Tru64 UNIX, IRIX, and Redhat Linux. It works fine
    > on all platforms except HP-UX/PA (HP-UX 11.23/IA64 works
    > fine). Some of the examples, like two_scales.py, work fine
    > if run once. However, with ~/.matplotlib/ttffont.cache
    > existing, a second run of two_scales.py (or any other
    > example), fails with the following: terminate called after
    > throwing an instance of 'Py::RuntimeError'

Please clear the tex cache dir and then run the example both times
with the --verbose-debug flag, and post the output along with the
complete traceback.

JDH

~/tex.cache is empty.

  $ rm -rf ~/.matplotlib
  $ python two_scales.py --verbose-debug 2>&1 | tee /tmp/output.1
  $ python two_scales.py --verbose-debug 2>&1 | tee /tmp/output.2

The failure occurs when displaying the data. I've also tried
anim_tk.py to determine if it was a problem with the GTK+ backend but
anim_tk.py fails in the same way.

What do you mean by "traceback"? Stack trace from Python after the
error? None is given.

output.1 (3.66 KB)

output.2 (2.36 KB)

···

On Wed, Feb 22, 2006 at 08:49:16PM -0600, John Hunter wrote:

    > We've built 0.87 with Python 2.4.2/GCC 3.4.3 on Solaris,
    > HP-UX, Tru64 UNIX, IRIX, and Redhat Linux. It works fine
    > on all platforms except HP-UX/PA (HP-UX 11.23/IA64 works
    > fine). Some of the examples, like two_scales.py, work fine
    > if run once. However, with ~/.matplotlib/ttffont.cache
    > existing, a second run of two_scales.py (or any other
    > example), fails with the following: terminate called after
    > throwing an instance of 'Py::RuntimeError'

Please clear the tex cache dir and then run the example both times
with the --verbose-debug flag, and post the output along with the
complete traceback.

--
albert chin (china@...319...)

I did some more digging and the "terminate called after throwing an
instance ..." error is coming from G++. Maybe something funk with C++
exceptions on HP/PA that isn't triggered on HP/IA.

···

On Wed, Feb 22, 2006 at 09:24:38PM -0600, Albert Chin wrote:

The failure occurs when displaying the data. I've also tried
anim_tk.py to determine if it was a problem with the GTK+ backend but
anim_tk.py fails in the same way.

--
albert chin (china@...319...)

The throw Py::RuntimeError is coming from src/ft2font.cpp. There's a
global that holds information for FreeType libraries:
  FT_Library _ft2Library;

This is initialized when Python loads the module. That works fine.
However, sometime after, _ft2Library is reinitialized to 0. This
doesn't occur the _first_ time matplotlib is run. Only on subsequent
runs when it reads in the font cache file does this occur. Odd.

···

On Fri, Feb 24, 2006 at 12:15:29AM -0600, Albert Chin wrote:

On Wed, Feb 22, 2006 at 09:24:38PM -0600, Albert Chin wrote:
>
> The failure occurs when displaying the data. I've also tried
> anim_tk.py to determine if it was a problem with the GTK+ backend but
> anim_tk.py fails in the same way.

I did some more digging and the "terminate called after throwing an
instance ..." error is coming from G++. Maybe something funk with C++
exceptions on HP/PA that isn't triggered on HP/IA.

--
albert chin (china@...319...)

Ok, I think I found the problem. src/ft2font.cpp is used by
_nc_backend_agg.so and ft2font.so. They _both_ have a global
_ft2Library. This isn't good. On HP-UX/PA, it seems the _ft2Library
from ft2font.so is used when matplotlib programs are run first.
However, after the cache file is generated, it seems to start using
the _ft2Library from ft2font.so but then when 'FT2Font()' is called,
the _ft2Library from _nc_backend_agg.so is used.

What we really want is just one _ft2Library, the one from
src/ft2font.cpp. src/_nc_backend_agg.cpp does need the functions in
src/ft2font.cpp but I think _nc_backend_agg.so should depend on
ft2font.so, not load a private copy of src/ft2font.cpp and expect
cross-platform behavior wrt a duplicate global _ft2Library.

Another alternative is to have anything requiring src/ft2font.cpp to
simply 'import ft2font'. For the moment, I've remove src/ft2font.cpp
from all modules except ft2font.so. This seems to work. Patch
attached. Should I submit patches to PyImport_ImportModule("ft2font")
as well?

a (1.33 KB)

···

On Sun, Feb 26, 2006 at 01:00:07AM -0600, Albert Chin wrote:

On Fri, Feb 24, 2006 at 12:15:29AM -0600, Albert Chin wrote:
> On Wed, Feb 22, 2006 at 09:24:38PM -0600, Albert Chin wrote:
> >
> > The failure occurs when displaying the data. I've also tried
> > anim_tk.py to determine if it was a problem with the GTK+ backend but
> > anim_tk.py fails in the same way.
>
> I did some more digging and the "terminate called after throwing an
> instance ..." error is coming from G++. Maybe something funk with C++
> exceptions on HP/PA that isn't triggered on HP/IA.

The throw Py::RuntimeError is coming from src/ft2font.cpp. There's a
global that holds information for FreeType libraries:
  FT_Library _ft2Library;

This is initialized when Python loads the module. That works fine.
However, sometime after, _ft2Library is reinitialized to 0. This
doesn't occur the _first_ time matplotlib is run. Only on subsequent
runs when it reads in the font cache file does this occur. Odd.

--
albert chin (china@...319...)

Attached is a patch to import matplotlib.ft2font from
src/_backend_agg.cpp. I chose PyRun_SimpleString() rather than
PyImport_ImportModule() so the initf2font() function would be invoked
automatically.

I'm thinking that instead of:
  FT2Font *font = static_cast<FT2Font*>(args[0].ptr());
we could use some Python calls to essentially duplicate
"FT2Font(args[0].ptr())" like so:
  PyObject *fromlist = PyList_New (1);
  PyObject *matplotlib_ft2font = PyString_FromString ("matplotlib.ft2font");
  PyList_Append (fromlist, matplotlib_ft2font);
  PyObject *ft2font = PyImport_ImportModuleEx("FT2Font", NULL, NULL,
    fromlist);
  PyObject *font = PyInstance_New (PyDict_GetItemString (ft2font,
    (char *)"FT2Font"), Py_BuildValue ("s", args[0].ptr()), NULL);
  Py_INCREF (font);

Of course, we'd have to expose the FT2Image members to Python but that
seems cleaner. The above might not be right but it should give an idea
of what I'm talking about (I've never embedded Python in C/C++
before).

a (426 Bytes)

···

On Sun, Feb 26, 2006 at 01:32:44PM -0600, Albert Chin wrote:

Another alternative is to have anything requiring src/ft2font.cpp to
simply 'import ft2font'. For the moment, I've remove src/ft2font.cpp
from all modules except ft2font.so. This seems to work. Patch
attached. Should I submit patches to PyImport_ImportModule("ft2font")
as well?

--
albert chin (china@...319...)

src/_image.cpp is also duplicated and is a problem as well. It'll need
a similar fix.

···

On Sun, Feb 26, 2006 at 01:32:44PM -0600, Albert Chin wrote:

On Sun, Feb 26, 2006 at 01:00:07AM -0600, Albert Chin wrote:
> On Fri, Feb 24, 2006 at 12:15:29AM -0600, Albert Chin wrote:
> > On Wed, Feb 22, 2006 at 09:24:38PM -0600, Albert Chin wrote:
> > >
> > > The failure occurs when displaying the data. I've also tried
> > > anim_tk.py to determine if it was a problem with the GTK+ backend but
> > > anim_tk.py fails in the same way.
> >
> > I did some more digging and the "terminate called after throwing an
> > instance ..." error is coming from G++. Maybe something funk with C++
> > exceptions on HP/PA that isn't triggered on HP/IA.
>
> The throw Py::RuntimeError is coming from src/ft2font.cpp. There's a
> global that holds information for FreeType libraries:
> FT_Library _ft2Library;
>
> This is initialized when Python loads the module. That works fine.
> However, sometime after, _ft2Library is reinitialized to 0. This
> doesn't occur the _first_ time matplotlib is run. Only on subsequent
> runs when it reads in the font cache file does this occur. Odd.

Ok, I think I found the problem. src/ft2font.cpp is used by
_nc_backend_agg.so and ft2font.so. They _both_ have a global
_ft2Library. This isn't good. On HP-UX/PA, it seems the _ft2Library
from ft2font.so is used when matplotlib programs are run first.
However, after the cache file is generated, it seems to start using
the _ft2Library from ft2font.so but then when 'FT2Font()' is called,
the _ft2Library from _nc_backend_agg.so is used.

--
albert chin (china@...319...)

While it builds everywhere, it causes unresolved symbol errors on all
non-HP/PA platforms :frowning:

···

On Sun, Feb 26, 2006 at 01:32:44PM -0600, Albert Chin wrote:

On Sun, Feb 26, 2006 at 01:00:07AM -0600, Albert Chin wrote:
> On Fri, Feb 24, 2006 at 12:15:29AM -0600, Albert Chin wrote:
> > On Wed, Feb 22, 2006 at 09:24:38PM -0600, Albert Chin wrote:
> > >
> > > The failure occurs when displaying the data. I've also tried
> > > anim_tk.py to determine if it was a problem with the GTK+ backend but
> > > anim_tk.py fails in the same way.
> >
> > I did some more digging and the "terminate called after throwing an
> > instance ..." error is coming from G++. Maybe something funk with C++
> > exceptions on HP/PA that isn't triggered on HP/IA.
>
> The throw Py::RuntimeError is coming from src/ft2font.cpp. There's a
> global that holds information for FreeType libraries:
> FT_Library _ft2Library;
>
> This is initialized when Python loads the module. That works fine.
> However, sometime after, _ft2Library is reinitialized to 0. This
> doesn't occur the _first_ time matplotlib is run. Only on subsequent
> runs when it reads in the font cache file does this occur. Odd.

...

Another alternative is to have anything requiring src/ft2font.cpp to
simply 'import ft2font'. For the moment, I've remove src/ft2font.cpp
from all modules except ft2font.so. This seems to work. Patch
attached.

--
albert chin (china@...319...)