diff options
author | Daniel P. Berrange <berrange@redhat.com> | 2013-12-05 16:36:41 +0000 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2013-12-11 16:12:54 +0000 |
commit | aac76e7630f5899e221672ef63b46baa066e1b8e (patch) | |
tree | 206face22a8d308028217bf0ca3b4a94dbbbd1bf /typewrappers.c | |
parent | e5161dec9e3ad3d1738e1316fddd39f887298734 (diff) | |
download | libvirt-python-aac76e7630f5899e221672ef63b46baa066e1b8e.tar.gz |
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>
Diffstat (limited to 'typewrappers.c')
-rw-r--r-- | typewrappers.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/typewrappers.c b/typewrappers.c index 7b644a1..526df0a 100644 --- a/typewrappers.c +++ b/typewrappers.c @@ -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) { |