Verified Commit f3775511 authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

Add context to the callback API

For frontends to manage their callback state libalpm added a void
*context argument as this is ABI breakage.
parent 59069c1b
......@@ -156,7 +156,7 @@ static struct _alpm_str_getset logfile_getset = { alpm_option_get_logfile, alpm_
static struct _alpm_str_getset gpgdir_getset = { alpm_option_get_gpgdir, alpm_option_set_gpgdir };
/* Callback attributes get/setters */
typedef int (*alpm_cb_setter)(alpm_handle_t*, void*);
typedef int (*alpm_cb_setter)(alpm_handle_t*, void*, void*);
struct _alpm_cb_getset {
alpm_cb_setter setter;
void *cb_wrapper;
......@@ -200,12 +200,12 @@ static int _set_cb_attr(PyObject *self, PyObject *value, const struct _alpm_cb_g
AlpmHandle *it = (AlpmHandle *)self;
if (value == Py_None) {
Py_CLEAR(global_py_callbacks[closure->id]);
closure->setter(it->c_data, NULL);
closure->setter(it->c_data, NULL, NULL);
} else if (PyCallable_Check(value)) {
Py_CLEAR(global_py_callbacks[closure->id]);
Py_INCREF(value);
global_py_callbacks[closure->id] = value;
closure->setter(it->c_data, closure->cb_wrapper);
closure->setter(it->c_data, closure->cb_wrapper, NULL);
} else {
PyErr_SetString(PyExc_TypeError, "value must be None or a function");
return -1;
......
......@@ -325,7 +325,7 @@ PyObject* option_remove_ignoregrp_alpm(PyObject *self, PyObject *args)
/** Callback wrappers */
extern PyObject *global_py_callbacks[N_CALLBACKS];
void pyalpm_logcb(alpm_loglevel_t level, const char *fmt, va_list va_args) {
void pyalpm_logcb(void *ctx, alpm_loglevel_t level, const char *fmt, va_list va_args) {
char *log;
PyObject *result;
int ret;
......@@ -339,14 +339,14 @@ void pyalpm_logcb(alpm_loglevel_t level, const char *fmt, va_list va_args) {
if (ret != -1) free(log);
}
void pyalpm_dlcb(const char *filename, off_t xfered, off_t total) {
void pyalpm_dlcb(void *ctx, const char *filename, off_t xfered, off_t total) {
PyObject *result;
result = PyObject_CallFunction(global_py_callbacks[CB_DOWNLOAD], "sii", filename, xfered, total);
if (!result) PyErr_Print();
Py_CLEAR(result);
}
int pyalpm_fetchcb(const char *url, const char *localpath, int force) {
int pyalpm_fetchcb(void *ctx, const char *url, const char *localpath, int force) {
PyObject *result;
result = PyObject_CallFunction(global_py_callbacks[CB_FETCH], "ssi", url, localpath, force);
if (!result) return -1;
......
......@@ -64,9 +64,9 @@ PyObject * option_add_ignoregrp_alpm(PyObject *self, PyObject *args);
PyObject * option_remove_ignoregrp_alpm(PyObject *self, PyObject *args);
/** Callback options */
void pyalpm_logcb(alpm_loglevel_t level, const char *fmt, va_list va_args);
void pyalpm_dlcb(const char *filename, off_t xfered, off_t total);
int pyalpm_fetchcb(const char *url, const char *localpath, int force);
void pyalpm_logcb(void *ctx, alpm_loglevel_t level, const char *fmt, va_list va_args);
void pyalpm_dlcb(void *ctx, const char *filename, off_t xfered, off_t total);
int pyalpm_fetchcb(void *ctx, const char *url, const char *localpath, int force);
#endif
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment