"enable_ccache", "enable_snapshot", NULL };
const char* path = NULL;
const char* arch = NULL;
+ PyObject* logger = NULL;
const char* conf = NULL;
int offline = 0;
int build = 0;
int enable_snapshot = 1;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|zzOpzppp", kwlist,
- &path, &arch, &self->logger, &offline, &conf, &build,
+ &path, &arch, &logger, &offline, &conf, &build,
&enable_ccache, &enable_snapshot))
return -1;
// Check if logger is callable
- if (self->logger && !PyCallable_Check(self->logger)) {
+ if (logger && !PyCallable_Check(logger)) {
PyErr_SetString(PyExc_TypeError, "logger must be callable\n");
return -1;
}
// Create a new Pakfire instance
int r = pakfire_create(&self->pakfire, path, arch, conf, flags,
- (self->logger) ? Pakfire_logging_callback : NULL, self->logger);
+ (logger) ? Pakfire_logging_callback : NULL, logger);
if (r) {
switch (errno) {
// Invalid architecture or path
return -1;
}
- Py_XINCREF(self->logger);
+ // Store a reference to the logger
+ if (logger) {
+ self->logger = logger;
+ Py_INCREF(self->logger);
+ }
return 0;
}
if (self->pakfire)
pakfire_unref(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.
+
+ TODO This has to move into struct pakfire or something similar.
+ */
if (self->logger)
Py_DECREF(self->logger);
+#endif
Py_TYPE(self)->tp_free((PyObject *)self);
}