[Python-Dev] Free threading and borrowing references from mutable types

Martin von Loewis loewis@informatik.hu-berlin.de
Tue, 11 Sep 2001 13:01:38 +0200 (MEST)


Considering the free threading issue (again), I found that functions
returning borrowed references are problematic if the container is
mutable.

In traditional Python, extension modules could safely borrow
references if they know that they maintain a reference to the
container. If a thread switch is possible between getting the borrowed
reference and using it, then this assumption is wrong: another thread
may remove the reference from the container, so that the object dies.

Therefore, I propose to deprecate these functions. I'm willing to
write a PEP elaborating on that if necessary, but I'd like to perform
a quick poll beforehand
- whether people think that deprecating these functions is reasonable
- whether it is sufficient to only have their abstract.c equivalents,
  or whether type-specific replacements that do return new references
  are needed
- what else I'm missing.

Specifically, I think the following functions are problematic:
- PyList_GetItem, PyList_GET_ITEM,
- PyDict_GetItem, PyDict_GetItemString

Any comments appreciated,

Martin