clear_weakref() in Objects/weakrefobject.c is Confusing
Personne n'a encore pris cette issue.
- Langage dominant
- Python
- Étoiles
- 77.2k
- Forks
- 36k
- Métriques de merge des PR
- Métriques de PR en attente
Description
(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
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez dans Objects/weakrefobject.c par lire clear_weakref(), ses appelants et la gestion de tp_weaklist. Comparez la séparation proposée entre remove_weakref() et remove_weakref_from_referent() avec la discussion du PR associé, puis examinez les observations concernant hash, vectorcall et d’éventuelles weakref-leak. Le travail est terminé lorsque la portée des responsabilités confuses et des préoccupations restantes a été définie et revue.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- c, python
- Domaine
- backend
- Type d'issue
- Refactorisation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100