@@ -210,69 +210,19 @@ refchain_fini(PyInterpreterState *interp)
210210 if (has_own_refchain (interp )) {
211211 _Py_hashtable_destroy (REFCHAIN (interp ));
212212 }
213- // This extra branch can be removed once we start setting
214- // interp->feature_flags *before* refchain_init() gets called.
215- else if (REFCHAIN (interp ) != REFCHAIN (_PyInterpreterState_Main ())) {
216- _Py_hashtable_destroy (REFCHAIN (interp ));
217- }
218213 REFCHAIN (interp ) = NULL ;
219214}
220215
221- /* Currently refchain_init() is called during interpreter initialization,
222- via _PyObject_InitState(), before interp->feature_flags is set,
223- so an interpreter may have its own refchain even though it shouldn't.
224- Until that gets fixed, we patch it all up wherever apprpriate.
225- maybe_fix_refchain() and move_refchain_item() can be dropped
226- once we sort out the init order problem. */
227-
228- static int
229- copy_refchain_item (_Py_hashtable_t * ht ,
230- const void * key , const void * value ,
231- void * user_data )
232- {
233- if (value != REFCHAIN_VALUE ) {
234- assert (value == NULL );
235- return 0 ;
236- }
237- _Py_hashtable_t * new_chain = (_Py_hashtable_t * )user_data ;
238- if (_Py_hashtable_set (new_chain , key , REFCHAIN_VALUE ) < 0 ) {
239- Py_FatalError ("_Py_hashtable_set() memory allocation failed" );
240- }
241- return 0 ;
242- }
243-
244- static void
245- maybe_fix_refchain (PyInterpreterState * interp )
246- {
247- if (has_own_refchain (interp )) {
248- // It's okay or we haven't set the feature flags correctly yet.
249- return ;
250- }
251-
252- _Py_hashtable_t * cur_chain = REFCHAIN (interp );
253- _Py_hashtable_t * main_chain = REFCHAIN (_PyInterpreterState_Main ());
254- if (cur_chain == main_chain ) {
255- // It was already fixed.
256- return ;
257- }
258- REFCHAIN (interp ) = main_chain ;
259-
260- (void )_Py_hashtable_foreach (cur_chain , copy_refchain_item , main_chain );
261- _Py_hashtable_destroy (cur_chain );
262- }
263-
264216bool
265217_PyRefchain_IsTraced (PyInterpreterState * interp , PyObject * obj )
266218{
267- maybe_fix_refchain (interp );
268219 return (_Py_hashtable_get (REFCHAIN (interp ), obj ) == REFCHAIN_VALUE );
269220}
270221
271222
272223static void
273224_PyRefchain_Trace (PyInterpreterState * interp , PyObject * obj )
274225{
275- maybe_fix_refchain (interp );
276226 if (_Py_hashtable_set (REFCHAIN (interp ), obj , REFCHAIN_VALUE ) < 0 ) {
277227 // Use a fatal error because _Py_NewReference() cannot report
278228 // the error to the caller.
@@ -284,7 +234,6 @@ _PyRefchain_Trace(PyInterpreterState *interp, PyObject *obj)
284234static void
285235_PyRefchain_Remove (PyInterpreterState * interp , PyObject * obj )
286236{
287- maybe_fix_refchain (interp );
288237 void * value = _Py_hashtable_steal (REFCHAIN (interp ), obj );
289238#ifndef NDEBUG
290239 assert (value == REFCHAIN_VALUE );
@@ -2630,7 +2579,6 @@ _Py_PrintReferences(PyInterpreterState *interp, FILE *fp)
26302579 interp = _PyInterpreterState_Main ();
26312580 }
26322581 fprintf (fp , "Remaining objects:\n" );
2633- maybe_fix_refchain (interp );
26342582 _Py_hashtable_foreach (REFCHAIN (interp ), _Py_PrintReference , fp );
26352583}
26362584
@@ -2659,7 +2607,6 @@ void
26592607_Py_PrintReferenceAddresses (PyInterpreterState * interp , FILE * fp )
26602608{
26612609 fprintf (fp , "Remaining object addresses:\n" );
2662- maybe_fix_refchain (interp );
26632610 _Py_hashtable_foreach (REFCHAIN (interp ), _Py_PrintReferenceAddress , fp );
26642611}
26652612
@@ -2739,7 +2686,6 @@ _Py_GetObjects(PyObject *self, PyObject *args)
27392686 .limit = limit ,
27402687 };
27412688 PyInterpreterState * interp = _PyInterpreterState_GET ();
2742- maybe_fix_refchain (interp );
27432689 int res = _Py_hashtable_foreach (REFCHAIN (interp ), _Py_GetObject , & data );
27442690 if (res == _PY_GETOBJECTS_ERROR ) {
27452691 Py_DECREF (list );
0 commit comments