Richard W.M. Jones
2010-Aug-17 09:54 UTC
[Libguestfs] [PATCH] Python: Use new PyCapsule API where supported.
I have run the automated tests on two machines, with Python 2.6 and 2.7 respectively, and at least it didn't fail on either. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into Xen guests. http://et.redhat.com/~rjones/virt-p2v -------------- next part -------------->From 834077946a4a7a44bf7f0e5d19aa1d54d39022a4 Mon Sep 17 00:00:00 2001From: Richard Jones <rjones at redhat.com> Date: Tue, 17 Aug 2010 10:31:39 +0100 Subject: [PATCH] Python: Use new PyCapsule API where supported. See: http://lists.fedoraproject.org/pipermail/devel/2010-August/141064.html --- configure.ac | 5 +++++ src/generator.ml | 13 +++++++++++++ 2 files changed, 18 insertions(+), 0 deletions(-) diff --git a/configure.ac b/configure.ac index a14dfd9..1922773 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 52e7aba..a3333ed 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); } -- 1.7.1
Possibly Parallel Threads
- Re: [PATCH nbdkit v2 02/10] python: Add various constants to the API.
- Re: [PATCH nbdkit v2 02/10] python: Add various constants to the API.
- Re: Re: guestfs_mount_local* api undefined symbols
- Change to unstable mkfs-btrfs API
- [Bug 602599] New: [RFE] A new API for custom cleanup prior to close in perl bindings