generator: Implement Pointer arguments.

This implements Pointer arguments properly, at least for certain
limited definitions of "implements" and "properly".

'Pointer' as an argument type is meant to indicate a pointer passed to
an API.  The canonical example is the following proposed API:

  int guestfs_add_libvirt_dom (guestfs_h *g, virDomainPtr dom, ...);

where 'dom' is described in the generator as:

  Pointer ("virDomainPtr", "dom")

Pointer existed already in the generator, but the implementation was
broken.  It is not used by any existing API.

There are two basic difficulties of implementing Pointer:

(1) In language bindings there is no portable way to turn (eg.) a Perl
Sys::Virt 'dom' object into a C virDomainPtr.

(2) We can't rely on <libvirt/libvirt.h> being included (since it's an
optional dependency).

In this commit, we solve (2) by using a 'void *'.

We don't solve (1), really.  Instead we have a macro
POINTER_NOT_IMPLEMENTED which is used by currently all the non-C
language bindings.  It complains loudly and passes a NULL to the
underlying function.  The underlying function detects the NULL and
safely returns an error.  It is to be hoped that people will
contribute patches to make each language binding work, although in
some bindings it will always remain impossible to implement.
This commit is contained in:
Richard W.M. Jones
2014-12-10 17:04:38 +00:00
parent 841aa0faf3
commit fd9ac7f47d
13 changed files with 51 additions and 24 deletions

View File

@@ -473,7 +473,7 @@ guestfs_lua_delete_event_callback (lua_State *L)
| Bool n -> pr " int %s;\n" n
| Int n -> pr " int %s;\n" n
| Int64 n -> pr " int64_t %s;\n" n
| Pointer (t, n) -> pr " %s %s;\n" t n
| Pointer (t, n) -> pr " void * /* %s */ %s;\n" t n
) args;
if optargs <> [] then (
pr " struct %s optargs_s = { .bitmask = 0 };\n" c_function;
@@ -506,7 +506,8 @@ guestfs_lua_delete_event_callback (lua_State *L)
pr " %s = luaL_checkint (L, %d);\n" n i
| Int64 n ->
pr " %s = get_int64 (L, %d);\n" n i
| Pointer (t, n) -> assert false
| Pointer (t, n) ->
pr " %s = POINTER_NOT_IMPLEMENTED (\"%s\");\n" n t
) args;
if optargs <> [] then (