[Pythonmac-SIG] OS X C API bug?
Gary Robinson
grobinson at goombah.com
Tue Jun 28 00:16:07 CEST 2005
Hello,
The attached file contains a c module with 4 versions of the same
extremely simple function. All they do is return a float double to
python. The zip also contains the setup.py to build it.
On Windows I can import the module into Python and run all of them
successfully.
But on OS X Panther with XCode 1.5 installed, the first 3 work and the
last
one causes a bus error. There is no obvious reason why it should do so.
(At least not to me or the others who have looked at it.) Here's the
output on Panther:
>>> 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. He suggested I
try mac-python next, so here I am. We're thinking it may be
compiler-related.
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");
}
}
Any help or insight would be most appreciated.
Gary
-------------- next part --------------
A non-text attachment was scrubbed...
Name: check.zip
Type: application/zip
Size: 1484 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20050627/7aa50305/check.zip
-------------- next part --------------
--
Gary Robinson
CTO
Emergent Music, LLC
grobinson at goombah.com
207-942-3463
Company: http://www.goombah.com
Blog: http://www.garyrobinson.net
More information about the Pythonmac-SIG
mailing list