X-Git-Url: https://sigrok.org/gitweb/?p=libsigrokdecode.git;a=blobdiff_plain;f=util.c;h=3a5e336a83e7be2db601e660a4ad6c3149b872e6;hp=430a7fb5e5c5bff8800ae7fd711425d276cc20bc;hb=HEAD;hpb=514b2edc54efda9c6698456748c4256bb901eddd diff --git a/util.c b/util.c index 430a7fb..3a5e336 100644 --- a/util.c +++ b/util.c @@ -115,7 +115,7 @@ err: SRD_PRIV int py_attr_as_strlist(PyObject *py_obj, const char *attr, GSList **outstrlist) { PyObject *py_list; - Py_ssize_t i; + ssize_t idx; int ret; char *outstr; PyGILState_STATE gstate; @@ -139,10 +139,10 @@ SRD_PRIV int py_attr_as_strlist(PyObject *py_obj, const char *attr, GSList **out *outstrlist = NULL; - for (i = 0; i < PyList_Size(py_list); i++) { - ret = py_listitem_as_str(py_list, i, &outstr); + for (idx = 0; idx < PyList_Size(py_list); idx++) { + ret = py_listitem_as_str(py_list, idx, &outstr); if (ret < 0) { - srd_dbg("Couldn't get item %" PY_FORMAT_SIZE_T "d.", i); + srd_dbg("Couldn't get item %zd.", idx); goto err; } *outstrlist = g_slist_append(*outstrlist, outstr); @@ -217,8 +217,9 @@ err: SRD_PRIV int py_listitem_as_str(PyObject *py_obj, Py_ssize_t idx, char **outstr) { - PyObject *py_value; PyGILState_STATE gstate; + ssize_t item_idx; + PyObject *py_value; gstate = PyGILState_Ensure(); @@ -227,8 +228,9 @@ SRD_PRIV int py_listitem_as_str(PyObject *py_obj, Py_ssize_t idx, goto err; } - if (!(py_value = PyList_GetItem(py_obj, idx))) { - srd_dbg("Couldn't get list item %" PY_FORMAT_SIZE_T "d.", idx); + item_idx = idx; + if (!(py_value = PyList_GetItem(py_obj, item_idx))) { + srd_dbg("Couldn't get list item %zd.", item_idx); goto err; } @@ -281,6 +283,8 @@ SRD_PRIV int py_pydictitem_as_str(PyObject *py_obj, PyObject *py_key, goto err; } + PyGILState_Release(gstate); + return py_str_as_str(py_value, outstr); err: @@ -301,7 +305,7 @@ err: * * @private */ -SRD_PRIV int py_pydictitem_as_long(PyObject *py_obj, PyObject *py_key, uint64_t *out) +SRD_PRIV int py_pydictitem_as_long(PyObject *py_obj, PyObject *py_key, int64_t *out) { PyObject *py_value; PyGILState_STATE gstate; @@ -326,7 +330,7 @@ SRD_PRIV int py_pydictitem_as_long(PyObject *py_obj, PyObject *py_key, uint64_t goto err; } - *out = PyLong_AsUnsignedLongLong(py_value); + *out = PyLong_AsLongLong(py_value); PyGILState_Release(gstate); @@ -383,7 +387,7 @@ SRD_PRIV int py_str_as_str(PyObject *py_str, char **outstr) /** * Convert a Python list of unicode strings to a C string vector. - * On success, a pointer to a newly allocated NULL-terminated array of + * On success, a pointer to a newly allocated NUL-terminated array of * allocated C strings is written to @a out_strv. The caller must g_free() * each string and the array itself. * @@ -445,6 +449,8 @@ SRD_PRIV int py_strseq_to_char(PyObject *py_strseq, char ***out_strv) } *out_strv = strv; + PyGILState_Release(gstate); + return SRD_OK; err_out: @@ -486,7 +492,6 @@ SRD_PRIV GVariant *py_obj_to_variant(PyObject *py_obj) } if (!var) srd_exception_catch("Failed to extract string value"); - } else if (PyLong_Check(py_obj)) { /* integer */ int64_t val; @@ -495,7 +500,6 @@ SRD_PRIV GVariant *py_obj_to_variant(PyObject *py_obj) var = g_variant_new_int64(val); else srd_exception_catch("Failed to extract integer value"); - } else if (PyFloat_Check(py_obj)) { /* float */ double val; @@ -504,7 +508,6 @@ SRD_PRIV GVariant *py_obj_to_variant(PyObject *py_obj) var = g_variant_new_double(val); else srd_exception_catch("Failed to extract float value"); - } else { srd_err("Failed to extract value of unsupported type."); }