Problems sending list/tuple to a C extension.

Tim Peters tim.one at comcast.net
Sun Nov 23 15:03:22 EST 2003


[Christian Seberino]
> ...
> 1. It seems very strange that checking/not checking return
>    value of PyArg_ParseTuple would make the difference
>    between working code and code that bombs. Not ALL code
>    is like this!!!

That's not right:  virtually every Python C API call *can* return an error
value (for example, it, or something it calls, may run out of memory, one
time in billions).  If you don't check every call for an error return, every
place you don't check it will eventually cause a mysterious bug.

>    I ignore lots of return codes and things work fine lots of times!

Dynamically, most calls don't return an error value.  If you ignore checking
the return value when it so happens it was a normal return value, then of
course nothing bad happens.  All such code is buggy, though, because it will
fail (and in miserable ways) when an error value *does* get returned.

>    Any idea why this API is so picky this way unlike others?

There's nothing unique about PyArg_ParseTuple here, so the question is based
on a confusion.  The only reason it *appears* unique to you is that it
happens to be the first time you got in trouble from neglecting to check for
errors.  The good news is that you'll get over this illusion as you
eventually spend most of your life tracking down "mysterious, unreproducible
problems" <wink>.






More information about the Python-list mailing list