Message 108340 - Python tracker (original) (raw)
I'm a newbie what it comes to Python's C-sources, so please do not take me too seriously. I fetched the sources 'svn checkout http://svn.python.org/projects/python/branches/release26-maint ' studied the issue, and my best guess is that Modules/_ctypes/cfield.c 's funktion d_set is called, when converting something to ctypes.c_double
Please check, that this is what happens :)
If so, Objects/longobject.c's function double PyLong_AsDouble(PyObject *vv) sets the overflow exception, but d_set overwrites it, like you can see:
static PyObject * d_set(void *ptr, PyObject *value, Py_ssize_t size) { double x;
x = PyFloat_AsDouble(value);
if (x == -1 && PyErr_Occurred()) {
PyErr_Format(PyExc_TypeError,
" float expected instead of %s instance",
value->ob_type->tp_name);
return NULL;
}
memcpy(ptr, &x, sizeof(double));
_RET(value);
}
Perhaps something like: if (PyErr_ExceptionMatches(PyExc_OverflowError)){ return NULL; }
just after the line: 'f (x == -1 && PyErr_Occurred()) {' could fix this?
But like I said, I'm an newbie, this was actually my first look into Python/C API and I have not tested this fix in any way whatsoever