[Python-Dev] RE: [Python-checkins] python/dist/src/Objects
typeobject.c, 2.244, 2.245
gminick
gminick at hacker.pl
Thu Oct 9 02:28:31 EDT 2003
On Wed, Oct 08, 2003 at 10:53:06PM -0400, Raymond Hettinger wrote:
> if (res == -1 && PyErr_Occurred())
> return NULL;
> ! return PyInt_FromLong((long)res);
> }
>
> --- 3577,3583 ----
> if (res == -1 && PyErr_Occurred())
> return NULL;
> ! ret = PyObject_IsTrue(PyInt_FromLong((long)res)) ? Py_True :
> Py_False;
>
>
> The line above leaks and does unnecessary work. I believe it should
> read:
>
> ret = res ? Py_True : Py_False;
PyInt_FromLong() returns PyObject, so you need to use PyObject_IsTrue()
(the way I did) or hack the code not to use PyInt_FromLong(). I used
PyInt_FromLong() because it was there before. Original code:
res = (*func)(self, value);
if (res == -1 && PyErr_Occurred())
return NULL;
return PyInt_FromLong((long)res);
}
If you're sure it isn't needed, then of course we can use the easier way
changing the snippet above into:
res = (*func)(self, value);
if (res == -1 && PyErr_Occurred())
return NULL;
ret = res ? Py_True : Py_False;
Py_INCREF(ret);
return ret;
}
So, why was there PyInt_FromLong()? :>
--
[ Wojtek Walczak - gminick (at) underground.org.pl ]
[ <http://gminick.linuxsecurity.pl/> ]
[ "...rozmaite zwroty, matowe od patyny dawnosci." ]
More information about the Python-Dev
mailing list