PyInt_AsLong()
Ralf Juengling
juenglin at informatik.uni-freiburg.de
Wed Apr 3 06:22:06 EST 2002
"Fredrik Lundh" <fredrik at pythonware.com> writes:
> Ralf Juengling wrote:
>
> > PyInt_AsLong() returns '-1ยด to indicate an error, this meets the convetion
> > for PyXXX()-functions which return integers. But how do you distinguish an
> > '-1' indicating an error from a the legal long-value '-1'?
>
> hint: when in doubt, grep the Modules directory in the
> Python source distribution:
>
> v = PyInt_AsLong(obj);
> if (v == -1 && PyErr_Occurred())
> return NULL; /* error */
> /* v is valid */
>
> hope this helps!
>
> </F>
Okay. So the reason to indicate an error by '-1' is efficiency,
I guess (i.e. calling PyErr_Occured() each time is more
expensive than the prior check 'v == -1') ?
Thanks,
Ralf
More information about the Python-list
mailing list