Ticket #3670: pygobject.patch

File pygobject.patch, 1.3 KB (added by benzea, 12 years ago)

The untested patch, sorry, it doesn't want to compile here right now.

  • gi/_gobject/pygobject.c

    diff --git a/gi/_gobject/pygobject.c b/gi/_gobject/pygobject.c
    index 75c8ba3..1f8bdb1 100644
    a b GQuark pygobject_instance_data_key; 
    5757void
    5858pygobject_data_free(PyGObjectData *data)
    5959{
     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. */
    6063    PyGILState_STATE state = pyglib_gil_state_ensure();
    6164    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
    6371    tmp = closures = data->closures;
    6472#ifndef NDEBUG
    6573    data->closures = NULL;
    6674    data->type = NULL;
    6775#endif
    68     pyg_begin_allow_threads;
     76
    6977    while (tmp) {
    7078        GClosure *closure = tmp->data;
    7179 
    pygobject_data_free(PyGObjectData *data) 
    7482        tmp = tmp->next;
    7583        g_closure_invalidate(closure);
    7684    }
    77     pyg_end_allow_threads;
    78  
     85
    7986    if (data->closures != NULL)
    8087        g_warning("invalidated all closures, but data->closures != NULL !");
    8188
    8289    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    }
    8495}
    8596
    8697static inline PyGObjectData *