summaryrefslogtreecommitdiff
path: root/typewrappers.c
diff options
context:
space:
mode:
authorDaniel P. Berrange <berrange@redhat.com>2013-12-05 17:10:55 +0000
committerDaniel P. Berrange <berrange@redhat.com>2013-12-11 16:14:46 +0000
commitb4d886346905e735827235fb881e3e547350a41a (patch)
tree69a742a3dcf904df7fab2e1020feacf5f040843b /typewrappers.c
parentd021f89dfcf8790c486b248360503784017f2948 (diff)
downloadlibvirt-python-b4d886346905e735827235fb881e3e547350a41a.tar.gz
typewrappers: Replace use of PyString class
Replace use of PyString with either PyBytes or PyUnicode. The former is used for buffers with explicit sizes, which are used by APIs processing raw bytes. Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'typewrappers.c')
-rw-r--r--typewrappers.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/typewrappers.c b/typewrappers.c
index f5110a3..64db9b8 100644
--- a/typewrappers.c
+++ b/typewrappers.c
@@ -92,7 +92,11 @@ libvirt_charPtrSizeWrap(char *str, Py_ssize_t size)
Py_INCREF(Py_None);
return Py_None;
}
+#if PY_MAJOR_VERSION > 2
+ ret = PyBytes_FromStringAndSize(str, size);
+#else
ret = PyString_FromStringAndSize(str, size);
+#endif
return ret;
}
@@ -105,7 +109,11 @@ libvirt_charPtrWrap(char *str)
Py_INCREF(Py_None);
return Py_None;
}
+#if PY_MAJOR_VERSION > 2
+ ret = PyUnicode_FromString(str);
+#else
ret = PyString_FromString(str);
+#endif
return ret;
}
@@ -118,7 +126,11 @@ libvirt_constcharPtrWrap(const char *str)
Py_INCREF(Py_None);
return Py_None;
}
+#if PY_MAJOR_VERSION > 2
+ ret = PyUnicode_FromString(str);
+#else
ret = PyString_FromString(str);
+#endif
return ret;
}
@@ -326,17 +338,24 @@ libvirt_boolUnwrap(PyObject *obj, bool *val)
int
libvirt_charPtrUnwrap(PyObject *obj, char **str)
{
+#if PY_MAJOR_VERSION < 3
const char *ret;
+#endif
*str = NULL;
if (!obj) {
PyErr_SetString(PyExc_TypeError, "unexpected type");
return -1;
}
+#if PY_MAJOR_VERSION > 2
+ if (!(*str = PyUnicode_AsUTF8(obj)))
+ return -1;
+#else
ret = PyString_AsString(obj);
if (ret &&
!(*str = strdup(ret)))
return -1;
+#endif
return 0;
}