It isn't possible to temporarily resurrect objects safely in the Py3.15t limited API
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- Python
- Estrelas
- 77.2k
- Forks
- 36k
- Métricas de merge de PRs
- Métricas de PR pendentes
Descrição
Bug report
Bug description:
In Cython we do something like
Py_SET_REFCNT(o, Py_REFCNT(o) + 1);
// Run user implemented deallocation code
Py_SET_REFCNT(o, Py_REFCNT(o) - 1);
The reason for this is that we don't want any refcounting (e.g. of temps) within the user code to accidentally trigger a recursive call to dealloc (the user code really shouldn't resurrect the object and it's their own problem if they do, but it is reasonable for it to generate temporaries, which may well be out of their control anyway).
This turns out not to be thread-safe in the freethreaded build because it makes TryIncRef succeed. Outside the limited API it's possible to fix by manual access to the reference count, but obviously not inside the limited API.
It would be nice to have a way of to avoid this.
- Most convenient would be to properly access
_PyObject_ResurrectStartand_PyObject_ResurrectEnd. - The other thing that could work is some way to defer the deallocation until the next GC cycle (when I think any
TryIncRefs would have fall out of scope anyway). I suspect I could manually arrange to do that, although it feels fragile, possibly relies on the GC being single-threaded, and which I haven't tested (so may not work...)
CPython versions tested on:
3.15
Operating systems tested on:
No response
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece revisando a superfície da limited-API envolvida na ressurreição da contagem de referências e no comportamento de TryIncRef em modo free-threaded descrito aqui; em seguida, compare-a com _PyObject_ResurrectStart e _PyObject_ResurrectEnd e com a issue #7769 do Cython. O trabalho estará concluído quando houver um mecanismo definido e thread-safe da limited-API que evite uma ressurreição temporária insegura durante o código de desalocação do usuário.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- c, python
- Domínio
- api
- Tipo de issue
- Funcionalidade
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Status de atividade
- Pouca atividade
- Clareza
- Precisa de esclarecimento
- Facilidade para iniciantes
- 35/100