[Raymond Hettinger] wrote: >>>> * list_ass_slice() should add a line to maintain them, >>>> * list_resize() can drop the test for ob_item != NULL, and [ditto] > > Will put these in. [Armin Rigo] > I think the list_ass_slice() 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 <wink>. > list_resize() dropping the test for ob_item != 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 PyList_SetSlice() to clear a > list, but directly zero out ob_size and ob_item -- 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 PyList_Clear() 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 > PyList_SetSlice(lst, 0, PyList_GET_SIZE(lst), (PyObject *)NULL) Brrrrrrr. > (which BTW could fail with a MemoryError up to yesterday; Yet never has, and never would have <wink>. > 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, PyList_Clear(), like list_clear(), would never fail and could return > void. Yup!
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4