diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
index 75c8ba3..1f8bdb1 100644
a
|
b
|
GQuark pygobject_instance_data_key; |
57 | 57 | void |
58 | 58 | pygobject_data_free(PyGObjectData *data) |
59 | 59 | { |
| 60 | /* This function may be called after the python interpreter has already |
| 61 | * been shut down. If this happens, we cannot do any python calls, so just |
| 62 | * free the memory. */ |
60 | 63 | PyGILState_STATE state = pyglib_gil_state_ensure(); |
61 | 64 | GSList *closures, *tmp; |
62 | | Py_DECREF(data->type); |
| 65 | |
| 66 | if (Py_IsInitialized()) { |
| 67 | Py_DECREF(data->type); |
| 68 | pyg_begin_allow_threads; |
| 69 | } |
| 70 | |
63 | 71 | tmp = closures = data->closures; |
64 | 72 | #ifndef NDEBUG |
65 | 73 | data->closures = NULL; |
66 | 74 | data->type = NULL; |
67 | 75 | #endif |
68 | | pyg_begin_allow_threads; |
| 76 | |
69 | 77 | while (tmp) { |
70 | 78 | GClosure *closure = tmp->data; |
71 | 79 | |
… |
… |
pygobject_data_free(PyGObjectData *data) |
74 | 82 | tmp = tmp->next; |
75 | 83 | g_closure_invalidate(closure); |
76 | 84 | } |
77 | | pyg_end_allow_threads; |
78 | | |
| 85 | |
79 | 86 | if (data->closures != NULL) |
80 | 87 | g_warning("invalidated all closures, but data->closures != NULL !"); |
81 | 88 | |
82 | 89 | g_free(data); |
83 | | pyglib_gil_state_release(state); |
| 90 | |
| 91 | if (Py_IsInitialized()) { |
| 92 | pyg_end_allow_threads; |
| 93 | pyglib_gil_state_release(state); |
| 94 | } |
84 | 95 | } |
85 | 96 | |
86 | 97 | static inline PyGObjectData * |