On Sat, 2012-02-25 at 00:34 +0000, Daniele Varrazzo wrote:
Hello,
attached there is a patch to implement PySequence_SetItem, which
*doesn't* steal a reference as the PyList/PyTuple variants do, and
returns 0 on success, -1 on error.
Good stuff - thanks!
I noticed that the patch only has the "success" case, which got me
wondering - what would it take for a call to PySequence_SetItem to fail?
(I added a defined_in='Objects/abstract.c' to the FnMeta: I find it's
handy to document this when diving into the CPython source to figure out
exactly what the behaviors are).
Looking at the implementation of PySequence_SetItem, like many functions
in abstract.c it can handle a NULL object without crashing (I added
handling for this). It looks like if passed an arbitrary object (e.g.
not a sequence) it can raise a TypeError; also if some of the calls to
PySequenceMethods fail. But it doesn't seem worth handling these cases
yet: I added some comments about this. I hope to improve type handling
at some point.
I've committed/pushed this to git, albeit with the minor changes
qmentioned above - thanks! (2f093468d53f9a6f20242c426d8357a48cacc2d8)
After cleaning many genuine errors in psycopg, mostly about
unchecked
return values, I'm left with several false positives related exactly
I'm very happy to hear that the checker is finding many genuine errors,
thanks for posting this! Would it be OK if we add a section about this
to the "Success Stories" section of the documentation? (see
docs/success.rst in the source tree).
to this type of functions, returning 0 on success, -1 on failure and
setting an exception. Each of these functions caller is reported as
"returning (PyObject*)NULL without setting an exception".
Is there any way to flag the behaviour of these functions? An
__attribute__? I'm trying implementing it but time is out for tonight.
I've find how to register the attribute callback but haven't found yet
where and how to use it.
I started writing an attribute to do this some months ago,
but the patch
has likely bitrotted; I'll see if I can get it working again...