This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Bus error in extension with gcc 3.3
Type: Stage:
Components: Extension Modules Versions: Python 2.3
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: esrever_otua, garyrob, nnorwitz, terry.reedy
Priority: normal Keywords:

Created on 2005-06-29 15:43 by garyrob, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg25682 - (view) Author: Gary Robinson (garyrob) Date: 2005-06-29 15:43
This text contains a c module with 4 versions of the same 
extremely simple function. All they do is return a float double to 

On Windows I have received a report from someone who can built 
the module, imported it into Python, and ran it successfully. 

It has also been reported that there is no problem when the 
extension is compiled with gcc 4.0 on OS X.

However, on OS X, if the extension is compiled with gcc 3.3, the 4th 
of the 4 function results in a bus error:

>>> from check import *
>>> fun1()
>>> fun2()
>>> fun3()
Bus error

I originally reported this on the C++ sig's mail list. They suggested I 
try dev-python. Scott David Daniels on that list helped me refine 
test cases and verified that they all worked on Windows. 

Along the way it was suggested that I post a bug report. So this is it.

The code follows:

#include "Python.h"
static double value = 411.0;

static PyObject *
fun0(PyObject *self, PyObject *args)
    if (!PyArg_ParseTuple(args, "", NULL)) return NULL;
    return Py_BuildValue("d", value);

static PyObject *
fun1(PyObject *self, PyObject *args)
    return Py_BuildValue("d", 1.3*value);

static PyObject *
fun2(PyObject *self, PyObject *args)
    return PyFloat_FromDouble(value);

static PyObject *
fun3(PyObject *self, PyObject *args)
    return Py_BuildValue("d", value);

static PyMethodDef TestMethods[] = {
    {"fun0", fun0, METH_VARARGS, "Read args and return value"},
    {"fun1", fun1, METH_VARARGS, "Return value multiplied inline 
    {"fun2", fun2, METH_VARARGS, "Return value using 
    {"fun3", fun3, METH_VARARGS, "Return value using 
without reading args -- causes bus error on OS X Panther with 
XCode 1.5 
    {NULL, NULL, 0, NULL}        /* Sentinel */

    PyObject *module;

    module = Py_InitModule3("check", TestMethods,
		"extension module with three functions.");
    if (module) {
	PyModule_AddStringConstant(module, "__version__", "0.02");
msg25683 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2005-06-30 20:05
Logged In: YES 

Do you have any reason to think the bug is in Python rather than 
the older version of gcc?  Or OSX?  Or even your computer?

If not, please consider closing.

Does OSX give you a stack trace?  If so,what is executing when 
the crash occurs?  In fun3, Py_BuildValue, or somehow 
msg25684 - (view) Author: Gary Robinson (garyrob) Date: 2005-06-30 20:15
Logged In: YES 

It was reproduced by someone with Python 2.4 and gcc 3.3. So it is not 
my machine.

As to closing it, a couple of people in the python C++ sig and python-dev 
suggested I post it here as a bug, so I did. I'm just doing what was 
requested of me. I don't mind if someone else feels it should be closed 
without doing anything about it, but I don't think everyone would agree with 
that action.

As for stack trace, I don't know how to look for that. All I got was the "bus 
error" message. If you tell me what to look for I'll look for it. 
msg25685 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2005-07-02 03:13
Logged In: YES 

I understand that you got advice to post, but I strongly doubt that 
core Python code is involved for three reasons.

1. On the Unix I used, bus errors were much rarer and esoteric 
than segmentation violations (from bad pointers).  But maybe 
BSD-derived OSX is different.

2. The only difference between fun1 that works and fun3 that 
doesn't, seems to be how the arg in computed.  The receiving 
function only gets a value (which it copies) and does not know its 

3. You report that upgrading the compiler fixes the problem.  (So 
why not just do that?)

If you want to experiment more, redo fun1 and fun3 with 'value' 
replaced by its literal value.  Then redo again with value = 
534.30000000000007 instead of 411 and change arg in fun1 to 
value/1.3 instead of 1.3*value.

About stack trace: On unix (of 15 years ago), program crashes 
usually resulted in a file called 'core' added to either the startup 
or current working directory.  A debugger program could extract 
a stack trace, which was more readable if the executable still had 
the symbol table attached and not stripped.  I don't know 
equivalent for OSX, but I found it very helpful for debugging.
msg25686 - (view) Author: Darryl Dixon (esrever_otua) Date: 2005-07-13 04:36
Logged In: YES 

Bus errors are generally caused by unaligned memory
accesses, or by attempts to read past the end of a
file-descriptor (or something along those lines).  This
sounds like a gcc bug rather than a Python bug.  Can I
suggest changing your compiler flags and experimenting with
things like different -O levels?  (-O3, -O1, etc) to see if
it makes a difference...  Also, you may want to raise a bug
with gcc (although I've no idea how seriously they would
take it :(  ).  Finally, what version of gcc is Python
compiled with on Panther?  There may be a conflict there
(once again, different optimisations might be the problem).

Anyhow, just my random thoughts,
msg25687 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-07-21 05:56
Logged In: YES 

Gary, care to comment?  It's possible there was a bug fix or
two related to alignment of floats.  But if we can't
reproduce this bug, we will have to close it.  Please
respond if you still have this problem within a week or two.
msg25688 - (view) Author: Neal Norwitz (nnorwitz) * (Python committer) Date: 2006-11-21 09:52
Closing due to no response.
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42143
2005-06-29 15:43:12garyrobcreate