More python 2.7 fun: deprecation of PyCObject API

Richard W.M. Jones rjones at redhat.com
Sat Aug 14 18:42:41 UTC 2010


On Fri, Aug 13, 2010 at 02:20:51PM -0400, David Malcolm wrote:
> (Sorry about the length of this email)
> 
> Python 2.7 deprecated the PyCObject API in favor of a new "capsule" API.
>   http://docs.python.org/dev/whatsnew/2.7.html#capsules
>   (b) try to fix the ones that are self-contained; send fixes upstream

I couldn't really tell from the link above how one can migrate code.
Any suggestion how to change the code below?  Variants of this are
used in both libvirt and libguestfs.

typedef struct {
  PyObject_HEAD
  guestfs_h *g;
} Pyguestfs_Object;

static guestfs_h *
get_handle (PyObject *obj)
{
  assert (obj);
  assert (obj != Py_None);
  return ((Pyguestfs_Object *) obj)->g;
}

static PyObject *
put_handle (guestfs_h *g)
{
  assert (g);
  return
    PyCObject_FromVoidPtrAndDesc ((void *) g, (char *) "guestfs_h", NULL);
}

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://et.redhat.com/~rjones/libguestfs/
See what it can do: http://et.redhat.com/~rjones/libguestfs/recipes.html


More information about the devel mailing list