
July 13, 2007
11:27 a.m.
double PyNumber_AsDouble(PyObject * value) { if (PyFloat_Check(value) || PyInt_Check(value)) { return PyFloat_AsDouble(value); } else { PyObject *pyfloat; double d;
pyfloat = PyNumber_Float(value); d = PyNumber_AsDouble(pyfloat);
I assume this should be PyFloat_AsDouble?
Py_XDECREF(pyfloat); return d;
} }
What happens if PyNumber_Float raises an exception? As far as I can tell, PyNumber_AsDouble will result in a "bad argument" exception being raised and will return -1, losing track of the original exception in the process.
Come to think of it, error checking problems could very well be the reason why the API doesn't provide a PyNumber_AsDouble.