Bugs item #1229788, was opened at 2005-06-29 08:43 Message generated for change (Comment added) made by nnorwitz You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1229788&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Extension Modules Group: Python 2.3 Status: Open Resolution: None Priority: 5 Submitted By: Gary Robinson (garyrob) Assigned to: Nobody/Anonymous (nobody) Summary: Bus error in extension with gcc 3.3 Initial Comment: This text contains a c module with 4 versions of the same extremely simple function. All they do is return a float double to python. 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 * fun0() 411.0 >>> fun1() 534.30000000000007 >>> fun2() 411.0 >>> 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 some 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 by 1.3"}, {"fun2", fun2, METH_VARARGS, "Return value using PyFloat_FromDouble"}, {"fun3", fun3, METH_VARARGS, "Return value using Py_BuildValue without reading args -- causes bus error on OS X Panther with XCode 1.5 installed"}, {NULL, NULL, 0, NULL} /* Sentinel */ }; PyMODINIT_FUNC initcheck(void) { PyObject *module; module = Py_InitModule3("check", TestMethods, "extension module with three functions."); if (module) { PyModule_AddStringConstant(module, "__version__", "0.02"); } } ---------------------------------------------------------------------- >Comment By: Neal Norwitz (nnorwitz) Date: 2006-07-20 22:56 Message: Logged In: YES user_id=33168 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. ---------------------------------------------------------------------- Comment By: Darryl Dixon (esrever_otua) Date: 2005-07-12 21:36 Message: Logged In: YES user_id=567623 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, D ---------------------------------------------------------------------- Comment By: Terry J. Reedy (tjreedy) Date: 2005-07-01 20:13 Message: Logged In: YES user_id=593130 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 history. 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. ---------------------------------------------------------------------- Comment By: Gary Robinson (garyrob) Date: 2005-06-30 13:15 Message: Logged In: YES user_id=136420 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. ---------------------------------------------------------------------- Comment By: Terry J. Reedy (tjreedy) Date: 2005-06-30 13:05 Message: Logged In: YES user_id=593130 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 inbewteen? ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1229788&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com