1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-30 23:41:52 +03:00

override: Replace PyString_AsString with libvirt_charPtrUnwrap

Replace calls to PyString_AsString with the helper method
libvirt_charPtrUnwrap. This isolates the code that will
change in Python3.

In making this change, all callers now have responsibility
for free'ing the string.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange
2013-12-05 16:36:41 +00:00
parent e5161dec9e
commit aac76e7630
3 changed files with 81 additions and 44 deletions

View File

@ -315,6 +315,24 @@ libvirt_boolUnwrap(PyObject *obj, bool *val)
return 0;
}
int
libvirt_charPtrUnwrap(PyObject *obj, char **str)
{
const char *ret;
*str = NULL;
if (!obj) {
PyErr_SetString(PyExc_TypeError, "unexpected type");
return -1;
}
ret = PyString_AsString(obj);
if (ret &&
!(*str = strdup(ret)))
return -1;
return 0;
}
PyObject *
libvirt_virDomainPtrWrap(virDomainPtr node)
{