[Bf-python] checking PyInt_FromLong..
Campbell Barton
cbarton at metavr.com
Tue Jun 26 05:43:24 CEST 2007
While looking through the API
I noticed some functions check that the result of PyInt_FromLong is NULL
(rather then a valid PyObject pointer)
I dont think theres any point in this since python its self dosnt check
if its valid before assigning an the int value to a member of the
pointer - see
"v->ob_ival = ival;"
if the pointer was invalid it could crash anyway-
Can we remove these checks from our own code?
And limit them to Append New lists and operations that create data of
unknown size.
_________________
PyObject *
PyInt_FromLong(long ival)
{
register PyIntObject *v;
#if NSMALLNEGINTS + NSMALLPOSINTS > 0
if (-NSMALLNEGINTS <= ival && ival < NSMALLPOSINTS) {
v = small_ints[ival + NSMALLNEGINTS];
Py_INCREF(v);
#ifdef COUNT_ALLOCS
if (ival >= 0)
quick_int_allocs++;
else
quick_neg_int_allocs++;
#endif
return (PyObject *) v;
}
#endif
if (free_list == NULL) {
if ((free_list = fill_free_list()) == NULL)
return NULL;
}
/* Inline PyObject_New */
v = free_list;
free_list = (PyIntObject *)v->ob_type;
PyObject_INIT(v, &PyInt_Type);
v->ob_ival = ival;
return (PyObject *) v;
}
--
Campbell J Barton (ideasman42)
More information about the Bf-python
mailing list