diff --git a/gobject/pygobject.c b/gobject/pygobject.c
index 70dc89a..d258a8e 100644
a
|
b
|
GQuark pygobject_ref_sunk_key; |
58 | 58 | void |
59 | 59 | pygobject_data_free(PyGObjectData *data) |
60 | 60 | { |
61 | | PyGILState_STATE state = pyglib_gil_state_ensure(); |
| 61 | /* This function may be called after the python interpreter has already |
| 62 | * been shut down. If this happens, we cannot do any python calls, so just |
| 63 | * free the memory. */ |
| 64 | PyGILState_STATE state; |
| 65 | PyThreadState *_save = NULL; |
| 66 | |
62 | 67 | GSList *closures, *tmp; |
63 | | Py_DECREF(data->type); |
| 68 | |
| 69 | if (Py_IsInitialized()) { |
| 70 | state = pyglib_gil_state_ensure(); |
| 71 | Py_DECREF(data->type); |
| 72 | |
| 73 | /* We cannot use pyg_begin_allow_threads here because this is inside |
| 74 | * a branch. */ |
| 75 | if (pyg_threads_enabled) |
| 76 | _save = PyEval_SaveThread(); |
| 77 | } |
| 78 | |
64 | 79 | tmp = closures = data->closures; |
65 | 80 | #ifndef NDEBUG |
66 | 81 | data->closures = NULL; |
67 | 82 | data->type = NULL; |
68 | 83 | #endif |
69 | | pyg_begin_allow_threads; |
| 84 | |
70 | 85 | while (tmp) { |
71 | 86 | GClosure *closure = tmp->data; |
72 | 87 | |
… |
… |
pygobject_data_free(PyGObjectData *data) |
75 | 90 | tmp = tmp->next; |
76 | 91 | g_closure_invalidate(closure); |
77 | 92 | } |
78 | | pyg_end_allow_threads; |
79 | | |
| 93 | |
80 | 94 | if (data->closures != NULL) |
81 | 95 | g_warning("invalidated all closures, but data->closures != NULL !"); |
82 | 96 | |
83 | 97 | g_free(data); |
84 | | pyglib_gil_state_release(state); |
| 98 | |
| 99 | if (Py_IsInitialized()) { |
| 100 | if (pyg_threads_enabled) |
| 101 | PyEval_RestoreThread(_save); |
| 102 | |
| 103 | pyglib_gil_state_release(state); |
| 104 | } |
85 | 105 | } |
86 | 106 | |
87 | 107 | static inline PyGObjectData * |