[Libguestfs] [PATCH 2/3] Split internal stuff out of guestfs.h
Richard W.M. Jones
rjones at redhat.com
Wed Dec 7 12:49:18 UTC 2016
On Tue, Nov 08, 2016 at 02:30:19PM +0100, Pino Toscano wrote:
> Create a new guestfs-private.h header, and move there the definitions of
> all the actions with visibility VInternal, and all the private structs:
> they are not meant to be used, not even seen, outside of the library.
>
> Include the new header where needed, which means also a couple of places
> outside the library (but they are tests, so it is acceptable for now).
>
> The result of this is mostly motion of function and structs
> declarations.
OK I understand why this change is made, but the naming of the new
header is super-confusing. We already have guestfs-internal.h and
guestfs-internal-actions.h (containing guestfs_impl_*), and now we're
adding guestfs-private.h containing guestfs_internal_* functions.
Hmm.
So the idea is fine, but renaming things to make them more sensible.
How about guestfs-internal-impl.h for guestfs_impl_*
and guestfs-internal-apis.h for guestfs_internal_* ?
Rich.
> .gitignore | 1 +
> generator/c.ml | 52 +++++++++++++++++++++----
> generator/c.mli | 1 +
> generator/main.ml | 1 +
> generator/tests_c_api.ml | 1 +
> src/available.c | 1 +
> src/drives.c | 1 +
> src/file.c | 1 +
> src/handle.c | 1 +
> src/inspect-fs.c | 1 +
> src/journal.c | 1 +
> src/mountable.c | 1 +
> src/tsk.c | 1 +
> tests/mountable/test-internal-parse-mountable.c | 1 +
> tests/regressions/rhbz914931.c | 1 +
> 15 files changed, 58 insertions(+), 8 deletions(-)
>
> diff --git a/.gitignore b/.gitignore
> index 633b39d..8235f77 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -505,6 +505,7 @@ Makefile.in
> /src/guestfs_protocol.c
> /src/guestfs_protocol.h
> /src/guestfs_protocol.x
> +/src/guestfs-private.h
> /src/guestfs-structs.pod
> /src/libguestfs.3
> /src/libguestfs.pc
> diff --git a/generator/c.ml b/generator/c.ml
> index f0df5ea..4497c48 100644
> --- a/generator/c.ml
> +++ b/generator/c.ml
> @@ -39,7 +39,13 @@ let is_public { visibility = v } = match v with
> | VPublic | VPublicNoFish | VStateTest | VDebug -> true
> | VBindTest | VInternal -> false
>
> -let is_private f = not (is_public f)
> +let is_private { visibility = v } = match v with
> + | VBindTest -> true
> + | VPublic | VPublicNoFish | VStateTest | VDebug | VInternal -> false
> +
> +let is_internal { visibility = v } = match v with
> + | VInternal -> true
> + | VPublic | VPublicNoFish | VStateTest | VDebug | VBindTest -> false
>
> let public_functions_sorted =
> List.filter is_public (actions |> sort)
> @@ -47,6 +53,9 @@ let public_functions_sorted =
> let private_functions_sorted =
> List.filter is_private (actions |> sort)
>
> +let internal_functions_sorted =
> + List.filter is_internal (actions |> sort)
> +
> (* Generate a C function prototype. *)
> let rec generate_prototype ?(extern = true) ?(static = false)
> ?(semicolon = true)
> @@ -607,13 +616,6 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char *
>
> generate_all_headers private_functions_sorted;
>
> - pr "\
> -/* Private structures. */
> -
> -";
> -
> - generate_all_structs internal_structs;
> -
> pr "\
>
> #endif /* End of GUESTFS_PRIVATE. */
> @@ -650,6 +652,34 @@ pr "\
> #endif /* GUESTFS_H_ */
> "
>
> +(* Generate the guestfs-private.h file. *)
> +and generate_guestfs_private_h () =
> + generate_header CStyle LGPLv2plus;
> +
> + pr "\
> +#ifndef GUESTFS_PRIVATE_H_
> +#define GUESTFS_PRIVATE_H_
> +
> +#include \"guestfs.h\"
> +
> +/* Private functions. */
> +
> +";
> +
> + generate_all_headers internal_functions_sorted;
> +
> + pr "\
> +/* Private structures. */
> +
> +";
> +
> + generate_all_structs internal_structs;
> +
> + pr "\
> +
> +#endif /* GUESTFS_PRIVATE_H_ */
> +"
> +
> (* The structures are carefully written to have exactly the same
> * in-memory format as the XDR structures that we use on the wire to
> * the daemon. The reason for creating copies of these structures
> @@ -856,6 +886,7 @@ and generate_client_structs_free () =
> #include <stdlib.h>
>
> #include \"guestfs.h\"
> +#include \"guestfs-private.h\"
> #include \"guestfs-internal.h\"
> #include \"guestfs_protocol.h\"
>
> @@ -905,6 +936,7 @@ and generate_client_structs_compare () =
> #include <errno.h>
>
> #include \"guestfs.h\"
> +#include \"guestfs-private.h\"
> #include \"guestfs-internal.h\"
>
> ";
> @@ -990,6 +1022,7 @@ and generate_client_structs_copy () =
> #include <errno.h>
>
> #include \"guestfs.h\"
> +#include \"guestfs-private.h\"
> #include \"guestfs-internal.h\"
>
> ";
> @@ -1173,6 +1206,7 @@ and generate_client_structs_cleanup () =
> #include <stdlib.h>
>
> #include \"guestfs.h\"
> +#include \"guestfs-private.h\"
> #include \"guestfs-internal-frontend.h\"
>
> ";
> @@ -1213,6 +1247,7 @@ and generate_client_structs_print_c () =
> #include \"c-ctype.h\"
>
> #include \"guestfs.h\"
> +#include \"guestfs-private.h\"
> #include \"structs-print.h\"
>
> ";
> @@ -1341,6 +1376,7 @@ and generate_client_actions actions () =
> #include <string.h>
>
> #include \"guestfs.h\"
> +#include \"guestfs-private.h\"
> #include \"guestfs-internal.h\"
> #include \"guestfs-internal-actions.h\"
> #include \"guestfs_protocol.h\"
> diff --git a/generator/c.mli b/generator/c.mli
> index 8c4e86c..2d4dcfa 100644
> --- a/generator/c.mli
> +++ b/generator/c.mli
> @@ -34,6 +34,7 @@ val generate_client_structs_print_h : unit -> unit
> val generate_client_structs_print_c : unit -> unit
> val generate_event_string_c : unit -> unit
> val generate_guestfs_h : unit -> unit
> +val generate_guestfs_private_h : unit -> unit
> val generate_internal_actions_h : unit -> unit
> val generate_internal_frontend_cleanups_h : unit -> unit
> val generate_linker_script : unit -> unit
> diff --git a/generator/main.ml b/generator/main.ml
> index 8d385d1..9016063 100644
> --- a/generator/main.ml
> +++ b/generator/main.ml
> @@ -96,6 +96,7 @@ Run it from the top source directory using the command
>
> output_to "src/guestfs_protocol.x" generate_xdr;
> output_to "src/guestfs.h" generate_guestfs_h;
> + output_to "src/guestfs-private.h" generate_guestfs_private_h;
> output_to "src/guestfs-internal-actions.h" generate_internal_actions_h;
> output_to "src/guestfs-internal-frontend-cleanups.h"
> generate_internal_frontend_cleanups_h;
> diff --git a/generator/tests_c_api.ml b/generator/tests_c_api.ml
> index 21ef6e3..83a8332 100644
> --- a/generator/tests_c_api.ml
> +++ b/generator/tests_c_api.ml
> @@ -46,6 +46,7 @@ let rec generate_c_api_tests () =
> #include <errno.h>
>
> #include \"guestfs.h\"
> +#include \"guestfs-private.h\"
> #include \"guestfs-internal-frontend.h\"
>
> #include \"tests.h\"
> diff --git a/src/available.c b/src/available.c
> index ae0bd84..4609f34 100644
> --- a/src/available.c
> +++ b/src/available.c
> @@ -22,6 +22,7 @@
> #include <libintl.h>
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal.h"
> #include "guestfs-internal-actions.h"
>
> diff --git a/src/drives.c b/src/drives.c
> index 1e3b0af..de0ab2b 100644
> --- a/src/drives.c
> +++ b/src/drives.c
> @@ -37,6 +37,7 @@
> #include "ignore-value.h"
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal.h"
> #include "guestfs-internal-actions.h"
>
> diff --git a/src/file.c b/src/file.c
> index d57c4e1..2499000 100644
> --- a/src/file.c
> +++ b/src/file.c
> @@ -30,6 +30,7 @@
> #include "full-write.h"
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal.h"
> #include "guestfs-internal-actions.h"
>
> diff --git a/src/handle.c b/src/handle.c
> index 0796015..1d89e4b 100644
> --- a/src/handle.c
> +++ b/src/handle.c
> @@ -37,6 +37,7 @@
> #include "getprogname.h"
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal.h"
> #include "guestfs-internal-actions.h"
>
> diff --git a/src/inspect-fs.c b/src/inspect-fs.c
> index 5e5b004..244a0ee 100644
> --- a/src/inspect-fs.c
> +++ b/src/inspect-fs.c
> @@ -34,6 +34,7 @@
> #include "xstrtol.h"
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal.h"
>
> static int check_filesystem (guestfs_h *g, const char *mountable,
> diff --git a/src/journal.c b/src/journal.c
> index 22b81de..e79520d 100644
> --- a/src/journal.c
> +++ b/src/journal.c
> @@ -42,6 +42,7 @@
> #include "full-read.h"
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal.h"
> #include "guestfs-internal-actions.h"
>
> diff --git a/src/mountable.c b/src/mountable.c
> index 9f7b451..45e7299 100644
> --- a/src/mountable.c
> +++ b/src/mountable.c
> @@ -21,6 +21,7 @@
> #include <errno.h>
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal.h"
> #include "guestfs-internal-actions.h"
>
> diff --git a/src/tsk.c b/src/tsk.c
> index 1def9c9..b017550 100644
> --- a/src/tsk.c
> +++ b/src/tsk.c
> @@ -29,6 +29,7 @@
> #include <rpc/types.h>
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs_protocol.h"
> #include "guestfs-internal.h"
> #include "guestfs-internal-all.h"
> diff --git a/tests/mountable/test-internal-parse-mountable.c b/tests/mountable/test-internal-parse-mountable.c
> index ab86ccb..961ee25 100644
> --- a/tests/mountable/test-internal-parse-mountable.c
> +++ b/tests/mountable/test-internal-parse-mountable.c
> @@ -27,6 +27,7 @@
> #include <error.h>
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal-all.h"
>
> int
> diff --git a/tests/regressions/rhbz914931.c b/tests/regressions/rhbz914931.c
> index 93878db..6d09b19 100644
> --- a/tests/regressions/rhbz914931.c
> +++ b/tests/regressions/rhbz914931.c
> @@ -31,6 +31,7 @@
> #include <error.h>
>
> #include "guestfs.h"
> +#include "guestfs-private.h"
> #include "guestfs-internal-frontend.h"
>
> #include "getprogname.h"
> --
> 2.7.4
>
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html
More information about the Libguestfs
mailing list