Three months ago we discussed about an issue with PySlice_GetIndicesEx(). (https://mail.python.org/pipermail/python-dev/2016-August/145901.html) The problem was that PySlice_GetIndicesEx() takes the size of the sequence, but the size of the sequence can be changed when call custom __index__() methods inside PySlice_GetIndicesEx(). The solution is to split PySlice_GetIndicesEx() into two functions: one function convert Python objects to C integers by calling __index__() methods, other function takes the size of the sequence and adjusts indices, it is atomic from Python view. The code if (PySlice_GetIndicesEx(item, length, &start, &stop, &step, &slicelength) < 0) return -1; should be replaced with if (foo(item, &start, &stop, &step) < 0) return -1; slicelength = bar(&start, &stop, step, length); PySlice_GetIndicesEx() can be converted to a macro calling these two functions. It would be enough just recompile an extension to make it invulnerable to the original bug. But there is a problem. New functions should be added to stable ABI. This means that we should design names and signatures of these functions even if don't make them a part of public API. Let's start bikeshedding. What are your ideas about names and the order of arguments of two following functions? 1. Takes a slice object, returns it's start, stop and step as Py_ssize_t values. Can fail. 2. Takes slice's start, stop, step, and the length of the sequence (all are Py_ssize_t), returns adjusted start, stop, and the length of sliced subsequence (as Py_ssize_t). Always success.
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