[Python-Dev] RE: test_sort.py failure (original) (raw)

Tim Peters tim.peters at gmail.com
Fri Jul 30 07:01:13 CEST 2004


[Raymond Hettinger] wrote:

* listassslice() should add a line to maintain them, * listresize() can drop the test for obitem != NULL, and

[ditto]

> Will put these in.

[Armin Rigo]

I think the listassslice() modification you are thinking about is obsolete since the check-in I documented in my latest e-mail.

Raymond did his checkin, and figured that out. listobject.c is again bug-free .

listresize() dropping the test for obitem != NULL looks like a sane plan: the only C extensions that I can think of that could break would be the ones that for extreme performance hacking don't use PyListSetSlice() to clear a list, but directly zero out obsize and obitem -- which is a real bad thing to do.

I'm not worried about that, but Raymond also added an assert() to catch it if it happens. Anyone writing such a gonzo extension must have learned by now to develop in a debug build.

About clearing lists efficiently: what about adding PyListClear() to the public API?

+1 provided the signature is changed to return void. Even inside listobject.c, the "it always returns 0" qurik is used only once. It's sometimes handy to have a function that always returns an error value (e.g., PyErr_NoMemory), but I think an API function that always returns a success value would be unprecedented. That's unexpected, hence jarring.

It's clearer than the current PyListSetSlice(lst, 0, PyListGETSIZE(lst), (PyObject *)NULL)

Brrrrrrr.

(which BTW could fail with a MemoryError up to yesterday;

Yet never has, and never would have .

I bet not all users of this idiom were aware of that.

I'd be surprised if any were!.

There was even an example of not checking the return value in listobject.c itself!)

Google quickly found two more, in an older revision of itertoolsmodule.c. There are probably more. Looks like this particular case ends up in list_clear() now, so that even users of the broken "clear-all-and-don't-check idiom" would become immune from the catastrophic consequences of their sloth.

By contrast, PyListClear(), like listclear(), would never fail and could return void.

Yup!



More information about the Python-Dev mailing list