Python source sensitive to PyObject_HEAD layout?

Petter Haggholm unmiserable at gmail.com
Sun May 21 19:41:32 EDT 2006


For academic reasons, I'm hacking on the Python source trying to add
some new capabilities. At present, I'm making minor changes mostly to
familiarise myself with the code and gain awareness of what issues I
may encounter, with the result that I encountered a fairly strange one
(to me, anyway).

As I wanted to add new fields to all Python objects, it seemed to make
the most sense to add them to PyObject_HEAD. When I added an int field
to the end of PyObject_HEAD, however, the make process failed (see
below). This was on a Pentium-M running GCC 3.4.6 under Gentoo Linux. I
switched to my other computer, and Athlon 64 running GCC 4.1.0 under
Gentoo Linux, and it compiled; I dismissed the earlier failure as an
irritating but fixed GCC bug, and went on---until I added another int
field and ran into a failure at exactly the same place.

The error looks fairly uninformative, as such:

/bin/sh: line 1:  6926 Segmentation fault      CC='gcc -pthread'
LDSHARED='gcc -pthread -shared' OPT='-DNDEBUG -g -O3 -Wall
-Wstrict-prototypes' ./python -E ./setup.py build
make: *** [sharedmods] Error 139

I can supply more information if desired (I ran a GDB backtrace), but
it really didn't tell me very much. None of the functions on the stack
were ones I had modified, so the only factor is the presence of that
second additional field in PyObject_HEAD (I can make it build by simply
commenting out that field and its initialiser in PyObject_HEAD_INIT).

My question is therefore a vague, nebulous, open, and at least mildly
desperate one: What is the problem? The only notion that occurs to me
is that some part of the Python source is somehow upset by alignment
issues (or padding of some sort); if so then I have no clue where that
might be. If not, then I have no idea what's causing the errors at all.

Any help, thoughts, or advice would be vastly appreciated.

--
Petter Haggholm




More information about the Python-list mailing list