From 1d5a8b7aa497c6d3d3257887f95832eda397347c Mon Sep 17 00:00:00 2001 From: Patrick Monnerat Date: Sun, 17 Feb 2019 17:36:11 +0100 Subject: Make Caja.OperationHandle usable. The Caja.OperationHandle.handle property is added: this gives access to the effective handle taking the form of a non-zero signed integer that can be stored in a void pointer. Trying to set this property with an invalid value raises an exception. Upon update_file_info_full call, the new Caja.OperationHandle is preset with a "unique" non-null value generated from an atomic counter. When the python method returns, the handle value is transmitted to Caja whatever it is: this fixes the problem of Caja expecting a non-null handle when CAJA_OPERATION_IN_PROGRESS is returned. Ref: https://github.com/mate-desktop/python-caja/issues/36 --- src/caja-python-object.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/caja-python-object.c') diff --git a/src/caja-python-object.c b/src/caja-python-object.c index e2bdf85..fbc5f79 100644 --- a/src/caja-python-object.c +++ b/src/caja-python-object.c @@ -411,20 +411,34 @@ caja_python_object_update_file_info (CajaInfoProvider *provider, CajaOperationResult ret = CAJA_OPERATION_COMPLETE; PyObject *py_ret = NULL; PyGILState_STATE state = pyg_gil_state_ensure(); - PyObject *py_handle = caja_python_boxed_new (_PyCajaOperationHandle_Type, *handle, FALSE); + static volatile gssize handle_generator = 1; debug_enter(); CHECK_OBJECT(object); + *handle = NULL; + if (PyObject_HasAttrString(object->instance, "update_file_info_full")) { + PyObject *py_handle; + void *h; + + /* Generate a new handle with a default value. */ + do { + h = (CajaOperationHandle *) g_atomic_pointer_add (&handle_generator, 1); + } while (!h); + py_handle = caja_python_boxed_new (_PyCajaOperationHandle_Type, + h, FALSE); + + py_ret = PyObject_CallMethod(object->instance, METHOD_PREFIX "update_file_info_full", "(NNNN)", pygobject_new((GObject*)provider), py_handle, pyg_boxed_new(G_TYPE_CLOSURE, update_complete, TRUE, TRUE), pygobject_new((GObject*)file)); + *handle = (void *) ((PyGBoxed *) py_handle)->boxed; } else if (PyObject_HasAttrString(object->instance, "update_file_info")) { @@ -447,6 +461,9 @@ caja_python_object_update_file_info (CajaInfoProvider *provider, } ret = INT_ASLONG(py_ret); + + if (!*handle && ret == CAJA_OPERATION_IN_PROGRESS) + ret = CAJA_OPERATION_FAILED; beach: free_pygobject_data(file, NULL); -- cgit v1.2.1