]> sigrok.org Git - libsigrokdecode.git/blobdiff - util.c
python 3 port
[libsigrokdecode.git] / util.c
diff --git a/util.c b/util.c
index 3aa0fd90a324ca5349c193f6129e6a858fbed2c1..b6de2fb8017c61dffb450b598e5bfa31ca62ed2d 100644 (file)
--- a/util.c
+++ b/util.c
  */
 int h_str(PyObject *py_res, PyObject *py_mod, const char *key, char **outstr)
 {
-       PyObject *py_str;
+       PyObject *py_str, *py_encstr;
        char *str;
        int ret;
 
-       py_str = PyObject_GetAttrString(py_res, (char *)key); /* NEWREF */
-       if (!py_str || !PyString_Check(py_str)) {
+       if (!(py_str = PyObject_GetAttrString(py_res, (char *)key))) {
                ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
                goto err_h_decref_mod;
        }
 
        /*
-        * PyString_AsString()'s returned string refers to an internal buffer
+        * PyBytes_AsString()'s returned string refers to an internal buffer
         * (not a copy), i.e. the data must not be modified, and the memory
         * must not be free()'d.
         */
-       if (!(str = PyString_AsString(py_str))) {
+       if (!(py_encstr = PyUnicode_AsEncodedString(py_str, "utf-8", NULL))) {
+               ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
+               goto err_h_decref_str;
+       }
+       if (!(str = PyBytes_AS_STRING(py_encstr))) {
                ret = SRD_ERR_PYTHON; /* TODO: More specific error? */
                goto err_h_decref_str;
        }