@@ -1068,8 +1068,13 @@ gc_enable_impl(PyObject *module)
1068
1068
/*[clinic end generated code: output=45a427e9dce9155c input=81ac4940ca579707]*/
1069
1069
{
1070
1070
if (_PyRuntime .gc .disabled_threads ){
1071
- PyErr_WarnEx (PyExc_RuntimeWarning , "Garbage collector enabled while another "
1072
- "thread is inside gc.ensure_enabled" ,1 );
1071
+ if (PyErr_WarnEx (
1072
+ PyExc_RuntimeWarning ,
1073
+ "Garbage collector enabled while another "
1074
+ "thread is inside gc.ensure_enabled" , 1 ) < 0 )
1075
+ {
1076
+ return NULL ;
1077
+ }
1073
1078
}
1074
1079
_PyRuntime .gc .enabled = 1 ;
1075
1080
Py_RETURN_NONE ;
@@ -1530,8 +1535,13 @@ ensure_disabled__enter__method(ensure_disabled_object *self, PyObject *args)
1530
1535
PyGILState_STATE gstate = PyGILState_Ensure ();
1531
1536
++ _PyRuntime .gc .disabled_threads ;
1532
1537
self -> previous_gc_state = _PyRuntime .gc .enabled ;
1533
- gc_disable_impl (NULL );
1538
+
1539
+ PyObject * ret = gc_disable_impl (NULL );
1534
1540
PyGILState_Release (gstate );
1541
+ if (ret == NULL ) {
1542
+ return NULL ;
1543
+ }
1544
+ Py_DECREF (ret );
1535
1545
Py_RETURN_NONE ;
1536
1546
}
1537
1547
@@ -1540,12 +1550,19 @@ ensure_disabled__exit__method(ensure_disabled_object *self, PyObject *args)
1540
1550
{
1541
1551
PyGILState_STATE gstate = PyGILState_Ensure ();
1542
1552
-- _PyRuntime .gc .disabled_threads ;
1543
- if (self -> previous_gc_state ){
1544
- gc_enable_impl (NULL );
1545
- }else {
1546
- gc_disable_impl (NULL );
1553
+
1554
+ PyObject * ret ;
1555
+ if (self -> previous_gc_state ) {
1556
+ ret = gc_enable_impl (NULL );
<
8000
/code>
1557
+ }
1558
+ else {
1559
+ ret = gc_disable_impl (NULL );
1547
1560
}
1548
1561
PyGILState_Release (gstate );
1562
+ if (ret == NULL ) {
1563
+ return NULL ;
1564
+ }
1565
+ Py_DECREF (ret );
1549
1566
Py_RETURN_NONE ;
1550
1567
}
1551
1568
@@ -1650,8 +1667,11 @@ PyInit_gc(void)
1650
1667
1651
1668
if (PyType_Ready (& gc_ensure_disabled_type ) < 0 )
1652
1669
return NULL ;
1653
- if (PyModule_AddObject (m , "ensure_disabled" , (PyObject * ) & gc_ensure_disabled_type ) < 0 )
1670
+ if (PyModule_AddObject (m , "ensure_disabled" ,
1671
+ (PyObject * ) & gc_ensure_disabled_type ) < 0 )
1672
+ {
1654
1673
return NULL ;
1674
+ }
1655
1675
1656
1676
1657
1677
#define ADD_INT (NAME ) if (PyModule_AddIntConstant(m, #NAME, NAME) < 0) return NULL
0 commit comments