aboutsummaryrefslogtreecommitdiffstats
path: root/lang/python/helpers.c
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2016-09-13 11:25:15 +0000
committerJustus Winter <[email protected]>2016-09-13 11:29:43 +0000
commit4abff7d750a1abf5b388a4c87ec321fc3e4aed10 (patch)
tree3a0ee407bf2049e8c3bb7398d2f31e93aa0151cb /lang/python/helpers.c
parentpython: Avoid Python3-only form of super(). (diff)
downloadgpgme-4abff7d750a1abf5b388a4c87ec321fc3e4aed10.tar.gz
gpgme-4abff7d750a1abf5b388a4c87ec321fc3e4aed10.zip
python: Fix types and error handling.
* lang/python/helpers.c (_pyme_edit_cb): Drop the const. (_pyme_assuan_{data,inquire,status}_cb): Fix error handling. Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'lang/python/helpers.c')
-rw-r--r--lang/python/helpers.c37
1 files changed, 26 insertions, 11 deletions
diff --git a/lang/python/helpers.c b/lang/python/helpers.c
index 6e63c97a..5b13fee0 100644
--- a/lang/python/helpers.c
+++ b/lang/python/helpers.c
@@ -692,7 +692,7 @@ gpgme_error_t _pyme_edit_cb(void *opaque, gpgme_status_code_t status,
} else {
if (fd>=0 && retval && PyUnicode_Check(retval)) {
PyObject *encoded = NULL;
- const char *buffer;
+ char *buffer;
Py_ssize_t size;
encoded = PyUnicode_AsUTF8String(retval);
@@ -999,7 +999,10 @@ _pyme_assuan_data_cb (void *hook, const void *data, size_t datalen)
py_data = PyBytes_FromStringAndSize(data, datalen);
if (py_data == NULL)
- return NULL; /* raise */
+ {
+ err = _pyme_exception2code();
+ goto leave;
+ }
retval = PyObject_CallFunctionObjArgs(func, py_data, NULL);
if (PyErr_Occurred())
@@ -1033,23 +1036,29 @@ _pyme_assuan_inquire_cb (void *hook, const char *name, const char *args,
py_name = PyUnicode_FromString(name);
if (py_name == NULL)
- return NULL; /* raise */
+ {
+ err = _pyme_exception2code();
+ goto leave;
+ }
py_args = PyUnicode_FromString(args);
if (py_args == NULL)
- return NULL; /* raise */
+ {
+ err = _pyme_exception2code();
+ goto leave;
+ }
retval = PyObject_CallFunctionObjArgs(func, py_name, py_args, NULL);
if (PyErr_Occurred())
err = _pyme_exception2code();
- Py_DECREF(py_name);
- Py_DECREF(py_args);
Py_XDECREF(retval);
/* FIXME: Returning data is not yet implemented. */
- r_data = NULL;
+ *r_data = NULL;
leave:
+ Py_XDECREF(py_name);
+ Py_XDECREF(py_args);
if (err)
_pyme_stash_callback_exception(self);
return err;
@@ -1074,20 +1083,26 @@ _pyme_assuan_status_cb (void *hook, const char *status, const char *args)
py_status = PyUnicode_FromString(status);
if (py_status == NULL)
- return NULL; /* raise */
+ {
+ err = _pyme_exception2code();
+ goto leave;
+ }
py_args = PyUnicode_FromString(args);
if (py_args == NULL)
- return NULL; /* raise */
+ {
+ err = _pyme_exception2code();
+ goto leave;
+ }
retval = PyObject_CallFunctionObjArgs(func, py_status, py_args, NULL);
if (PyErr_Occurred())
err = _pyme_exception2code();
- Py_DECREF(py_status);
- Py_DECREF(py_args);
Py_XDECREF(retval);
leave:
+ Py_XDECREF(py_status);
+ Py_XDECREF(py_args);
if (err)
_pyme_stash_callback_exception(self);
return err;