void* data, const char* message, const char* question) {
PyObject* callback = data;
PyObject* ret = NULL;
- int r = 0;
+ int r = -1;
+
+ // Acquire the GIL
+ PyGILState_STATE state = PyGILState_Ensure();
// Call the callback function
ret = PyObject_CallFunction(callback, "ss", message, question);
if (!ret)
- return -1;
+ goto ERROR;
// Return if the result is True
if (PyObject_IsTrue(ret))
r = 1;
- // Cleanup
- Py_DECREF(ret);
+ERROR:
+ Py_XDECREF(ret);
+
+ // Release the GIL
+ PyGILState_Release(state);
return r;
}
PyObject* p = data;
int r = -1;
+ // Acquire the GIL
+ PyGILState_STATE state = PyGILState_Ensure();
+
// Fetch the start method
PyObject* start = PyObject_GetAttrString(p, "start");
if (!start)
Py_XDECREF(start);
Py_XDECREF(ret);
+ // Release the GIL
+ PyGILState_Release(state);
+
return r;
}
PyObject* p = data;
int r = -1;
+ // Acquire the GIL
+ PyGILState_STATE state = PyGILState_Ensure();
+
// Fetch the finish method
PyObject* finish = PyObject_GetAttrString(p, "finish");
if (!finish)
Py_XDECREF(finish);
Py_XDECREF(ret);
+ // Release the GIL
+ PyGILState_Release(state);
+
return r;
}
PyObject* p = data;
int r = -1;
+ // Acquire the GIL
+ PyGILState_STATE state = PyGILState_Ensure();
+
// Fetch the update method
PyObject* update = PyObject_GetAttrString(p, "update");
if (!update)
Py_XDECREF(update);
Py_XDECREF(ret);
+ // Release the GIL
+ PyGILState_Release(state);
+
return r;
}
struct pakfire_ctx* ctx, struct pakfire_progress* progress, void* data) {
PyObject* p = data;
+ // Acquire the GIL
+ PyGILState_STATE state = PyGILState_Ensure();
+
// Free the object
Py_XDECREF(p);
+
+ // Release the GIL
+ PyGILState_Release(state);
}
static int Ctx_progress_callback(
struct pakfire_ctx* ctx, void* data, struct pakfire_progress* progress) {
PyObject* callback = data;
PyObject* p = NULL;
+ int r = -1;
+
+ // Acquire the GIL
+ PyGILState_STATE state = PyGILState_Ensure();
// Fetch the title
const char* title = pakfire_progress_get_title(progress);
// Call the callback to create a new progress object
p = PyObject_CallFunction(callback, "z", title);
if (!p)
- return -1;
+ goto ERROR;
// Set callback data
pakfire_progress_set_callback_data(progress, p);
// Set free callback
pakfire_progress_set_free_callback(progress, Ctx_progress_free);
- return 0;
+ // Success
+ r = 0;
+
+ERROR:
+ // Release the GIL
+ PyGILState_Release(state);
+
+ return r;
}
static PyObject* Ctx_set_progress_callback(CtxObject* self, PyObject* args) {