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:
@ -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)
|
||||
{
|
||||
|
Reference in New Issue
Block a user