tiny extension crashes
Fredrik Lundh
fredrik at pythonware.com
Wed Mar 14 17:22:16 EST 2001
John J. Lee wrote:
> static PyObject *iround(PyObject *self, PyObject *args) {
> /* round to integer type, 0.49->0, 0.5->1 */
> double number;
> double *intp;
>
> if (!PyArg_ParseTuple(args, "d", &number))
> return NULL;
> if (fabs(modf(number, intp)) >= 0.5) {
> *intp >= 0 ? (*intp)++ : (*intp)--;
> }
> return Py_BuildValue("l", (long)*intp);
umm. aren't you supposed to pass a pointer to an existing
double as the second argument to modf? (instead of an un-
initialized pointer...)
> static PyObject *iround(PyObject *self, PyObject *args) {
> /* round to integer type, 0.49->0, 0.5->1 */
> double number;
= double intpart;
>
> if (!PyArg_ParseTuple(args, "d", &number))
> return NULL;
= if (fabs(modf(number, &intpart)) >= 0.5) {
= intvalue >= 0 ? intvalue++ : intvalue--;
> }
= return Py_BuildValue("l", (long) intvalue);
Cheers /F
More information about the Python-list
mailing list