@@ -103,6 +103,7 @@ CTracer_dealloc(CTracer *self)
103
103
Py_XDECREF (self -> should_start_context );
104
104
Py_XDECREF (self -> switch_context );
105
105
Py_XDECREF (self -> context );
106
+ Py_XDECREF (self -> disable_plugin );
106
107
107
108
DataStack_dealloc (& self -> stats , & self -> data_stack );
108
109
if (self -> data_stacks ) {
@@ -570,66 +571,24 @@ CTracer_handle_call(CTracer *self, PyFrameObject *frame)
570
571
static void
571
572
CTracer_disable_plugin (CTracer * self , PyObject * disposition )
572
573
{
573
- PyObject * file_tracer = NULL ;
574
- PyObject * plugin = NULL ;
575
- PyObject * plugin_name = NULL ;
576
- PyObject * msg = NULL ;
577
- PyObject * ignored = NULL ;
578
-
574
+ PyObject * ret ;
579
575
PyErr_Print ();
580
576
581
- file_tracer = PyObject_GetAttr (disposition , str_file_tracer );
582
- if (file_tracer == NULL ) {
583
- goto error ;
584
- }
585
- if (file_tracer == Py_None ) {
586
- /* This shouldn't happen... */
587
- goto ok ;
588
- }
589
- plugin = PyObject_GetAttr (file_tracer , str__coverage_plugin );
590
- if (plugin == NULL ) {
591
- goto error ;
592
- }
593
- plugin_name = PyObject_GetAttr (plugin , str__coverage_plugin_name );
594
- if (plugin_name == NULL ) {
595
- goto error ;
596
- }
597
- msg = MyText_FromFormat (
598
- "Disabling plug-in '%s' due to previous exception" ,
599
- MyText_AsString (plugin_name )
600
- );
601
- if (msg == NULL ) {
602
- goto error ;
603
- }
604
577
STATS ( self -> stats .pycalls ++ ; )
605
- ignored = PyObject_CallFunctionObjArgs (self -> warn , msg , NULL );
606
- if (ignored == NULL ) {
607
- goto error ;
608
- }
609
-
610
- /* Disable the plugin for future files, and stop tracing this file. */
611
- if (PyObject_SetAttr (plugin , str__coverage_enabled , Py_False ) < 0 ) {
612
- goto error ;
613
- }
614
- if (PyObject_SetAttr (disposition , str_trace , Py_False ) < 0 ) {
578
+ ret = PyObject_CallFunctionObjArgs (self -> disable_plugin , disposition , NULL );
579
+ if (ret == NULL ) {
615
580
goto error ;
616
581
}
582
+ Py_DECREF (ret );
617
583
618
- goto ok ;
584
+ return ;
619
585
620
586
error :
621
587
/* This function doesn't return a status, so if an error happens, print it,
622
588
* but don't interrupt the flow. */
623
589
/* PySys_WriteStderr is nicer, but is not in the public API. */
624
590
fprintf (stderr , "Error occurred while disabling plug-in:\n" );
625
591
PyErr_Print ();
626
-
627
- ok :
628
- Py_XDECREF (file_tracer );
629
- Py_XDECREF (plugin );
630
- Py_XDECREF (plugin_name );
631
- Py_XDECREF (msg );
632
- Py_XDECREF (ignored );
633
592
}
634
593
635
594
@@ -1121,6 +1080,9 @@ CTracer_members[] = {
1121
1080
{ "switch_context" , T_OBJECT , offsetof(CTracer , switch_context ), 0 ,
1122
1081
PyDoc_STR ("Function for switching to a new context." ) },
1123
1082
1083
+ { "disable_plugin" , T_OBJECT , offsetof(CTracer , disable_plugin ), 0 ,
1084
+ PyDoc_STR ("Function for disabling a plugin." ) },
1085
+
1124
1086
{ NULL }
1125
1087
};
1126
1088
0 commit comments