From 5f802ec6473029e89d2db9cbd71cf0ce86a1b653 Mon Sep 17 00:00:00 2001 From: Bert Vermeulen <bert@biot.com> Date: Tue, 27 Dec 2011 22:15:53 +0100 Subject: python 3 port --- util.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 3aa0fd9..b6de2fb 100644 --- a/util.c +++ b/util.c @@ -32,22 +32,25 @@ */ 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; } -- cgit v1.2.3-70-g09d2