[Python-ideas] Exploiting type-homogeneity in list.sort() (again!)

INADA Naoki songofacandy at gmail.com
Mon Mar 6 01:39:05 EST 2017


On Mon, Mar 6, 2017 at 3:28 PM, Elliot Gorokhovsky
<elliot.gorokhovsky at gmail.com> wrote:
> On Sun, Mar 5, 2017 at 11:21 PM Jelle Zijlstra <jelle.zijlstra at gmail.com>
> wrote:
>>
>>
>> I think using a global is unsafe even without multithreading, because
>> the compare function itself could end up doing list.sort() (it's
>> calling arbitrary Python code after all).
>
>
> Right, of course. So, clearly, the only safe solution is to just keep
> everything in local scope and pass the compare function pointer into every
> function that calls ISLT or IFLT. Too bad. I'll rewrite the patch to
> implement this and open a new issue on the bug tracker (and close my current
> issue).

I think there is another safe solution:  Gave up unsafe_object_compare.

Compare function of long, float, and unicode must not call list.sort(),
and must not release GIL.
So all you need is, backup old compare_function before sort, and
restore it after sort.


More information about the Python-ideas mailing list