}
static void Pakfire_dealloc(PakfireObject* self) {
- if (self->pakfire)
- pakfire_unref(self->pakfire);
+ if (self->pakfire) {
+ // Drop references to all callbacks
+ pakfire_reset_all_callbacks(self->pakfire);
-#if 0
- /*
- It might happen, that the Pakfire python object is deallocated but the
- actual struct pakfire object isn't yet. However, it might still happen
- that the logging function is called which will try to call the logging
- callback which has already been deallocated.
+ pakfire_unref(self->pakfire);
+ }
- TODO This has to move into struct pakfire or something similar.
- */
+ // Free callbacks
Py_XDECREF(self->callbacks.log);
Py_XDECREF(self->callbacks.status);
Py_XDECREF(self->callbacks.progress);
-#endif
Py_TYPE(self)->tp_free((PyObject *)self);
}
struct pakfire* pakfire_ref(struct pakfire* pakfire);
struct pakfire* pakfire_unref(struct pakfire* pakfire);
+void pakfire_reset_all_callbacks(struct pakfire* pakfire);
const char* pakfire_get_path(struct pakfire* pakfire);
pakfire_list_keys;
pakfire_ref;
pakfire_refresh;
+ pakfire_reset_all_callbacks;
pakfire_search;
pakfire_sync;
pakfire_unref;
p->nrefs = 1;
p->flags = flags;
+ // Initialize callbacks
+ pakfire_reset_all_callbacks(p);
+
// Copy callbacks
if (callbacks) {
if (callbacks->data)
p->callbacks.progress = callbacks->progress;
}
- // Log to syslog by default
- if (!p->callbacks.log)
- p->callbacks.log = pakfire_log_syslog;
-
// Set architecture
pakfire_string_set(p->arch, arch);
return NULL;
}
+/*
+ Drops all callbacks.
+
+ This is useful when Pakfire is being called from Python and we cannot
+ determine the order when things are being freed.
+*/
+PAKFIRE_EXPORT void pakfire_reset_all_callbacks(struct pakfire* pakfire) {
+ pakfire->callbacks.data = NULL;
+
+ // Reset callbacks
+ pakfire->callbacks.status = NULL;
+ pakfire->callbacks.progress = NULL;
+ pakfire->callbacks.speed = NULL;
+
+ // Log to syslog by default
+ pakfire->callbacks.log = pakfire_log_syslog;
+}
+
int pakfire_has_flag(struct pakfire* pakfire, int flag) {
return pakfire->flags & flag;
}