@@ -2319,17 +2319,26 @@ test_weakref_capi(PyObject *Py_UNUSED(module), PyObject *Py_UNUSED(args))
23192319struct simpletracer_data {
23202320 int create_count ;
23212321 int destroy_count ;
2322+ int tracker_removed ;
23222323 void * addresses [10 ];
23232324};
23242325
23252326static int _simpletracer (PyObject * obj , PyRefTracerEvent event , void * data ) {
23262327 struct simpletracer_data * the_data = (struct simpletracer_data * )data ;
23272328 assert (the_data -> create_count + the_data -> destroy_count < (int )Py_ARRAY_LENGTH (the_data -> addresses ));
23282329 the_data -> addresses [the_data -> create_count + the_data -> destroy_count ] = obj ;
2329- if (event == PyRefTracer_CREATE ) {
2330- the_data -> create_count ++ ;
2331- } else {
2332- the_data -> destroy_count ++ ;
2330+ switch (event ) {
2331+ case PyRefTracer_CREATE :
2332+ the_data -> create_count ++ ;
2333+ break ;
2334+ case PyRefTracer_DESTROY :
2335+ the_data -> destroy_count ++ ;
2336+ break ;
2337+ case PyRefTracer_TRACKER_REMOVED :
2338+ the_data -> tracker_removed ++ ;
2339+ break ;
2340+ default :
2341+ return -1 ;
23332342 }
23342343 return 0 ;
23352344}
@@ -2393,6 +2402,10 @@ test_reftracer(PyObject *ob, PyObject *Py_UNUSED(ignored))
23932402 PyErr_SetString (PyExc_ValueError , "The object destruction was not correctly traced" );
23942403 goto failed ;
23952404 }
2405+ if (tracer_data .tracker_removed != 1 ) {
2406+ PyErr_SetString (PyExc_ValueError , "The tracker removal was not correctly traced" );
2407+ goto failed ;
2408+ }
23962409 PyRefTracer_SetTracer (current_tracer , current_data );
23972410 Py_RETURN_NONE ;
23982411failed :
@@ -2533,11 +2546,15 @@ code_offset_to_line(PyObject* self, PyObject* const* args, Py_ssize_t nargsf)
25332546static int
25342547_reftrace_printer (PyObject * obj , PyRefTracerEvent event , void * counter_data )
25352548{
2536- if (event == PyRefTracer_CREATE ) {
2537- printf ("CREATE %s\n" , Py_TYPE (obj )-> tp_name );
2538- }
2539- else { // PyRefTracer_DESTROY
2540- printf ("DESTROY %s\n" , Py_TYPE (obj )-> tp_name );
2549+ switch (event ) {
2550+ case PyRefTracer_CREATE :
2551+ printf ("CREATE %s\n" , Py_TYPE (obj )-> tp_name );
2552+ break ;
2553+ case PyRefTracer_DESTROY :
2554+ printf ("DESTROY %s\n" , Py_TYPE (obj )-> tp_name );
2555+ break ;
2556+ case PyRefTracer_TRACKER_REMOVED :
2557+ return 0 ;
25412558 }
25422559 return 0 ;
25432560}
0 commit comments