@@ -447,7 +447,9 @@ PyImport_Cleanup(void)
447
447
dict = PyModule_GetDict (value );
448
448
if (Py_VerboseFlag )
449
449
PySys_WriteStderr ("# clear __builtin__._\n" );
450
- PyDict_SetItemString (dict , "_" , Py_None );
450
+ if (PyDict_SetItemString (dict , "_" , Py_None ) < 0 ) {
451
+ PyErr_Clear ();
452
+ }
451
453
}
452
454
value = PyDict_GetItemString (modules , "sys" );
453
455
if (value != NULL && PyModule_Check (value )) {
@@ -457,15 +459,19 @@ PyImport_Cleanup(void)
457
459
for (p = sys_deletes ; * p != NULL ; p ++ ) {
458
460
if (Py_VerboseFlag )
459
461
PySys_WriteStderr ("# clear sys.%s\n" , * p );
460
- PyDict_SetItemString (dict , * p , Py_None );
462
+ if (PyDict_SetItemString (dict , * p , Py_None ) < 0 ) {
463
+ PyErr_Clear ();
464
+ }
461
465
}
462
466
for (p = sys_files ; * p != NULL ; p += 2 ) {
463
467
if (Py_VerboseFlag )
464
468
PySys_WriteStderr ("# restore sys.%s\n" , * p );
465
469
v = PyDict_GetItemString (dict , * (p + 1 ));
466
470
if (v == NULL )
467
471
v = Py_None ;
468
- PyDict_SetItemString (dict , * p , v );
472
+ if (PyDict_SetItemString (dict , * p , v ) < 0 ) {
473
+ PyErr_Clear ();
474
+ }
469
475
}
470
476
}
471
477
@@ -475,7 +481,9 @@ PyImport_Cleanup(void)
475
481
if (Py_VerboseFlag )
476
482
PySys_WriteStderr ("# cleanup __main__\n" );
477
483
_PyModule_Clear (value );
478
- PyDict_SetItemString (modules , "__main__" , Py_None );
484
+ if (PyDict_SetItemString (modules , "__main__" , Py_None ) < 0 ) {
485
+ PyErr_Clear ();
486
+ }
479
487
}
480
488
481
489
/* The special treatment of __builtin__ here is because even
@@ -510,10 +518,15 @@ PyImport_Cleanup(void)
510
518
PySys_WriteStderr (
511
519
"# cleanup[1] %s\n" , name );
512
520
_PyModule_Clear (value );
513
- PyDict_SetItem (modules , key , Py_None );
521
+ if (PyDict_SetItem (modules , key , Py_None ) < 0 ) {
522
+ PyErr_Clear ();
523
+ }
514
524
ndone ++ ;
515
525
}
516
526
}
527
+ if (PyErr_Occurred ()) {
528
+ PyErr_Clear ();
529
+ }
517
530
} while (ndone > 0 );
518
531
519
532
/* Next, delete all modules (still skipping __builtin__ and sys) */
@@ -528,7 +541,12 @@ PyImport_Cleanup(void)
528
541
if (Py_VerboseFlag )
529
542
PySys_WriteStderr ("# cleanup[2] %s\n" , name );
530
543
_PyModule_Clear (value );
531
- PyDict_SetItem (modules , key , Py_None );
544
+ if (PyDict_SetItem (modules , key , Py_None ) < 0 ) {
545
+ PyErr_Clear ();
546
+ }
547
+ }
548
+ if (PyErr_Occurred ()) {
549
+ PyErr_Clear ();
532
550
}
533
551
}
534
552
@@ -538,14 +556,18 @@ PyImport_Cleanup(void)
538
556
if (Py_VerboseFlag )
539
557
PySys_WriteStderr ("# cleanup sys\n" );
540
558
_PyModule_Clear (value );
541
- PyDict_SetItemString (modules , "sys" , Py_None );
559
+ if (PyDict_SetItemString (modules , "sys" , Py_None ) < 0 ) {
560
+ PyErr_Clear ();
561
+ }
542
562
}
543
563
value = PyDict_GetItemString (modules , "__builtin__" );
544
564
if (value != NULL && PyModule_Check (value )) {
545
565
if (Py_VerboseFlag )
546
566
PySys_WriteStderr ("# cleanup __builtin__\n" );
547
567
_PyModule_Clear (value );
548
- PyDict_SetItemString (modules , "__builtin__" , Py_None );
568
+ if (PyDict_SetItemString (modules , "__builtin__" , Py_None ) < 0 ) {
569
+ PyErr_Clear ();
570
+ }
549
571
}
550
572
551
573
/* Finally, clear and delete the modules directory */
0 commit comments