clear_weakref() in Objects/weakrefobject.c is Confusing
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 36k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
(inspired by https://github.com/python/cpython/pull/95302#discussion_r931261376)
In Objects/weakrefobject.c, the clear_weakref() function is used to:
- pop the
PyWeakReferenceobject off its referenced object'stp_weaklist(a linked list) - clear (but not call) the callback, if any
However, in the places it is used, it isn't clear what it's doing. When adding a new use of clear_weakref() in one of my PRs it was particularly confusing to a reviewer what the relationship was between clear_weakref() and an object's weakref list (i.e. tp_weaklist).
While we could simply rename it to "remove_and_clear_weakref", it may make sense to do the following:
- move the linked-list part to a separate
remove_weakref()that has an explicitPyWeakReference **parameter - (hence, remove the linked list parts from
clear_weakref()) - add
remove_weakref_from_referent()which callsGET_WEAKREFS_LISTPTR(self->wr_object)and callsremove_weakref()on it - add a call to it everywhere we already call
clear_weakref()
Other observations:
- currently we aren't reseting
self->hashorself->vectorcallto NULL inclear_weakref() - we may be leaking weakref objects
PyObject_ClearWeakRefs()when the weakref doesn't have a callback
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza en Objects/weakrefobject.c leyendo clear_weakref(), sus llamadores y el tratamiento de tp_weaklist. Compara la separación propuesta entre remove_weakref() y remove_weakref_from_referent() con la discusión del PR enlazado y, después, investiga las observaciones sobre hash, vectorcall y posibles weakref-leak. Se considera terminado cuando se haya decidido y revisado el alcance de las responsabilidades confusas y las preocupaciones restantes.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- c, python
- Área
- backend
- Tipo de issue
- Refactorización
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100