On 8/14/19 4:05 PM, Richard W.M. Jones wrote:
---
generator/generator | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/generator/generator b/generator/generator
+ (* If there is a BytesPersistIn/Out parameter then we need to
+ * increment the refcount and save the pointer into
+ * completion_callback.user_data so we can decrement the
+ * refcount on command completion.
+ *)
+ List.iter (
+ function
+ | BytesPersistIn (n, _) | BytesPersistOut (n, _) ->
+ pr " /* Increment refcount since buffer may be saved by libnbd.
*/\n";
+ pr " Py_INCREF (%s);\n" n;
+ pr " completion_user_data->buf = %s;\n" n;
+ | _ -> ()
+ ) args;
+
Is it worth a sanity check that we never have more than one
BytesPersist* parameter (as otherwise, we'd have to store more than one
pointer in the user_data struct)? Doesn't change current code
generation (since we satisfy that constraint), but would make future
additions less likely to mess up (and as it affects both python and
ocaml, doing it in a separate patch is fine).
@@ -4403,7 +4425,10 @@ let generate_python_methods_c () =
pr "{\n";
pr " struct user_data *data = user_data;\n";
pr "\n";
- pr " Py_DECREF (data->fn);\n";
+ pr " if (data->fn != NULL)\n";
+ pr " Py_DECREF (data->fn);\n";
+ pr " if (data->buf != NULL)\n";
+ pr " Py_DECREF (data->buf);\n";
Spell these Py_XDECREF() and you can avoid the 'if's.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization:
qemu.org |
libvirt.org