Queue cleanup
Lawrence D'Oliveiro
ldo at geek-central.gen.new_zealand
Fri Sep 3 19:02:18 EDT 2010
In message <7xvd6sv0n4.fsf at ruckus.brouhaha.com>, Paul Rubin wrote:
> 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.
That reinforces my point, about how easy it was to check the correctness of
the code. In this case one simple fix, like this
diff --git a/spuhelper.c b/spuhelper.c
index 83fd4eb..2ba8197 100644
--- a/spuhelper.c
+++ b/spuhelper.c
@@ -151,10 +151,12 @@ static void GetBufferInfo
if (TheBufferInfo == 0)
break;
AddrObj = PyTuple_GetItem(TheBufferInfo, 0);
- LenObj = PyTuple_GetItem(TheBufferInfo, 1);
if (PyErr_Occurred())
break;
Py_INCREF(AddrObj);
+ LenObj = PyTuple_GetItem(TheBufferInfo, 1);
+ if (PyErr_Occurred())
+ break;
Py_INCREF(LenObj);
*addr = PyInt_AsUnsignedLongMask(AddrObj);
*len = PyInt_AsUnsignedLongMask(LenObj);
would render the code watertight. See how easy it is?
More information about the Python-list
mailing list