On 8/13/19 5:06 AM, Richard W.M. Jones wrote:
An optional Closure parameter, but otherwise works the same way as Closure.
@@ -3778,6 +3777,7 @@ let generate_lib_api_c () = ) args; List.iter ( function + | OClosure { cbname } -> pr ", %s_callback ? \"<fun>\" : \"NULL\"" cbname
Well, it also permits a NULL fn pointer.
@@ -4383,6 +4387,16 @@ let print_python_binding name { args; optargs; ret; may_set_error } = ) args; List.iter ( function + | OClosure { cbname } -> + pr " if (%s_user_data) {\n" cbname; + pr " /* Increment refcount since pointer may be saved by libnbd. */\n"; + pr " Py_INCREF (%s_user_data);\n" cbname; + pr " if (!PyCallable_Check (%s_user_data)) {\n" cbname;
I don't think PyNone is callable; this probably needs to gain a special case for when the user omitted the optional argument and we thus...
+ pr " PyErr_SetString (PyExc_TypeError,\n"; + pr " \"callback parameter %s is not callable\");\n" cbname; + pr " return NULL;\n"; + pr " }\n"; + pr " }\n" | OFlags (n, _) -> pr " %s_u32 = %s;\n" n n ) optargs;
@@ -4412,6 +4426,9 @@ let print_python_binding name { args; optargs; ret; may_set_error } = ) args; List.iter ( function + | OClosure { cbname } -> + pr ", %s_user_data ? %s_wrapper : NULL" cbname cbname; + pr ", %s_user_data" cbname | OFlags (n, _) -> pr ", %s_u32" n ) optargs; pr ");\n"; @@ -4668,6 +4685,7 @@ class NBD (object): let optargs = List.map ( function + | OClosure { cbname } -> cbname, Some "None", None
...passed in the default Python 'None' in its place.
@@ -5202,6 +5223,19 @@ let print_ocaml_binding (name, { args; optargs; ret }) =
List.iter ( function + | OClosure { cbname } -> + pr " const void *%s_callback = NULL;\n" cbname; + pr " value *%s_user_data = NULL;\n" cbname; + pr " if (%sv != Val_int (0)) { /* Some closure */\n" cbname;
But for OCaml you got it right - you are handling 'None' vs. 'Some closure'. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org