Queue cleanup

Paul Rubin no.email at nospam.invalid
Mon Aug 30 12:46:23 CEST 2010


Lawrence D'Oliveiro <ldo at geek-central.gen.new_zealand> writes:
>>          AddrObj = PyTuple_GetItem(TheBufferInfo, 0);
>>          LenObj = PyTuple_GetItem(TheBufferInfo, 1);
>> 
>> the first PyTuple_GetItem succeeds and the second one fails.
>
> Admittedly, I did take a shortcut here: array.buffer_info returns a tuple of 
> two items, so I’m not expecting one GetItem to succeed and the other to 
> fail.

FromArray is a parameter to the function, with no type check to make
sure it's really an array.  In fact your code allows for the possibility
that it doesn't support the buffer_info operation (if I understand the
purpose of the null return check after the PyObject_CallMethod) which
means it's prepared for the argument to -not- be an array.  In that case
maybe it's some other object with a "buffer_info" operation that returns
a 1-element tuple.  If the function is callable from Python code, then
that arg type is completely out of the C code's control.  Even if it's
only callable from C, you're still depending on not one but two
different invariants (that the arg is an array, and that
array.buffer_info returns a 2-tuple) that are undocumented and unchecked
in the function.  I cannot agree with your claim that the approach
scales.



More information about the Python-list mailing list