PyArg_Parse weirds
Robin Becker
robin at jessikat.fsnet.co.uk
Tue Apr 24 17:46:30 EDT 2001
In article <3AE5C1EB.CE354D2A at letterror.com>, Just van Rossum
<just at letterror.com> writes
>Michael Hudson wrote:
>>
>> Robin Becker <robin at jessikat.fsnet.co.uk> writes:
>>
>> > no I was testing for another possible value and when that fails I
>> > try a secondd argument type; I just didn't realise that PyArg_Parse
>> > would barf if an error was already set.
>>
>> This is because there's no way to tell from the return value of
>> PyDouble_FromDouble whether an error has occurred, so the code for
>> PyArg_Parse has to check PyError_Occurred.
>
>But then again: _any_ API may barf if it gets called while an exception
>is set. You get similar troubles if you set an exception but don't return
>NULL to Python. So I think it's good advice to _always_ do PyErr_Clear()
>after you ignore an exception.
>
>Just
of course you're right, I always try and clear; it's not always obvious
which routines set exceptions. For some reason I thought that the
integer return implied the user had to check and set an exception, but
then this thing is like PyArg_ParseTuple anyhow so I was just being
dumber than usual.
--
Robin Becker
More information about the Python-list
mailing list