diff options
author | Richard Jones <rjones@redhat.com> | 2010-08-17 10:31:39 +0100 |
---|---|---|
committer | Richard Jones <rjones@redhat.com> | 2010-08-17 10:31:39 +0100 |
commit | 834077946a4a7a44bf7f0e5d19aa1d54d39022a4 (patch) | |
tree | c5452a097709548b544bcc322d37805d0972ef2c | |
parent | 29925244c1be2d1d5f71d46eba205278624a1366 (diff) | |
download | libguestfs-834077946a4a7a44bf7f0e5d19aa1d54d39022a4.tar.gz libguestfs-834077946a4a7a44bf7f0e5d19aa1d54d39022a4.tar.xz libguestfs-834077946a4a7a44bf7f0e5d19aa1d54d39022a4.zip |
Python: Use new PyCapsule API where supported.
See:
http://lists.fedoraproject.org/pipermail/devel/2010-August/141064.html
-rw-r--r-- | configure.ac | 5 | ||||
-rwxr-xr-x | src/generator.ml | 13 |
2 files changed, 18 insertions, 0 deletions
diff --git a/configure.ac b/configure.ac index a14dfd91..19227738 100644 --- a/configure.ac +++ b/configure.ac @@ -551,6 +551,11 @@ if test "x$PYTHON" != "xno"; then fi AC_MSG_RESULT([not found]) done + + old_LIBS="$LIBS" + LIBS="$LIBS -lpython$PYTHON_VERSION" + AC_CHECK_FUNCS([PyCapsule_New]) + LIBS="$old_LIBS" fi AC_SUBST(PYTHON_PREFIX) diff --git a/src/generator.ml b/src/generator.ml index 52e7aba0..a3333ed6 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -9496,25 +9496,35 @@ typedef int Py_ssize_t; #include \"guestfs.h\" +#ifndef HAVE_PYCAPSULE_NEW typedef struct { PyObject_HEAD guestfs_h *g; } Pyguestfs_Object; +#endif static guestfs_h * get_handle (PyObject *obj) { assert (obj); assert (obj != Py_None); +#ifndef HAVE_PYCAPSULE_NEW return ((Pyguestfs_Object *) obj)->g; +#else + return (guestfs_h*) PyCapsule_GetPointer(obj, \"guestfs_h\"); +#endif } static PyObject * put_handle (guestfs_h *g) { assert (g); +#ifndef HAVE_PYCAPSULE_NEW return PyCObject_FromVoidPtrAndDesc ((void *) g, (char *) \"guestfs_h\", NULL); +#else + return PyCapsule_New ((void *) g, \"guestfs_h\", NULL); +#endif } /* This list should be freed (but not the strings) after use. */ @@ -9608,6 +9618,9 @@ py_guestfs_create (PyObject *self, PyObject *args) return NULL; } guestfs_set_error_handler (g, NULL, NULL); + /* This can return NULL, but in that case put_handle will have + * set the Python error string. + */ return put_handle (g); } |