[Libguestfs] [PATCH libnbd 6/7] python: Use free callback to free closure root.
Eric Blake
eblake at redhat.com
Mon Aug 12 17:14:06 UTC 2019
On 8/12/19 11:08 AM, Richard W.M. Jones wrote:
> Same as the previous commit, but for Python.
> ---
> generator/generator | 14 +++++++++++---
> 1 file changed, 11 insertions(+), 3 deletions(-)
>
> @@ -4454,6 +4451,11 @@ let print_python_binding name { args; optargs; ret; may_set_error } =
> pr " PyErr_SetString (PyExc_TypeError,\n";
> pr " \"callback parameter %s is not callable\");\n" cbname;
> pr " return NULL;\n";
> + pr " }\n";
> + pr " if (nbd_add_free_callback (h, %s_user_data,\n" cbname;
> + pr " decref, NULL) == -1) {\n";
> + pr " PyErr_NoMemory ();\n";
> + pr " return NULL;\n";
> pr " }\n"
> | Enum _ -> ()
> | Flags (n, _) -> pr " %s_u32 = %s;\n" n n
> @@ -4600,6 +4602,12 @@ let generate_python_methods_c () =
> pr "\n";
> pr "#include <methods.h>\n";
> pr "\n";
> + pr "static void\n";
> + pr "decref (void *ptr, void *user_data)\n";
> + pr "{\n";
> + pr " Py_DECREF (ptr);\n";
> + pr "}\n";
Well, in the OCaml case, you were actively using the fact that ptr and
user_data might be different, and freeing the second; where in the
Python case you are only ever caring about the ptr argument and always
passing NULL for the second (meaning you had to write a shim around
Py_DecRef, as hidden under the Py_DECREF macro).
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libguestfs/attachments/20190812/72f24704/attachment.sig>
More information about the Libguestfs
mailing list