[Libguestfs] [PATCH v6 09/41] utils: Split out structs cleanups and printing into common/structs.

Richard W.M. Jones
Thu, 15 Jun 2017 17:05:59 -0000

These won't be used by the daemon, so interfere with us using
common/utils in the daemon, so they are moved to a different library.
---
 .gitignore                               |  8 +++---
 Makefile.am                              |  1 +
 align/Makefile.am                        |  2 ++
 align/scan.c                             |  1 +
 cat/Makefile.am                          | 10 ++++++++
 cat/filesystems.c                        |  1 +
 cat/log.c                                |  1 +
 cat/tail.c                               |  1 +
 common/mlvisit/Makefile.am               |  3 ++-
 common/structs/Makefile.am               | 44 ++++++++++++++++++++++++++++++++
 common/utils/Makefile.am                 | 16 ------------
 common/utils/guestfs-internal-frontend.h |  5 ----
 common/visit/Makefile.am                 |  3 ++-
 common/visit/visit.c                     |  1 +
 configure.ac                             |  1 +
 df/Makefile.am                           |  2 ++
 df/df.c                                  |  1 +
 diff/Makefile.am                         |  1 +
 docs/C_SOURCE_FILES                      |  8 +++---
 docs/guestfs-hacking.pod                 |  5 ++++
 fish/Makefile.am                         |  4 +++
 generator/c.ml                           | 17 +++++-------
 generator/c.mli                          |  4 +--
 generator/java.ml                        |  1 +
 generator/main.ml                        | 12 ++++-----
 generator/tests_c_api.ml                 |  1 +
 inspector/Makefile.am                    |  2 ++
 inspector/inspector.c                    |  1 +
 java/Makefile.am                         |  2 ++
 lib/Makefile.am                          |  6 ++++-
 lib/file.c                               |  1 +
 lib/fuse.c                               |  1 +
 lib/inspect-apps.c                       |  1 +
 lib/inspect-fs-cd.c                      |  1 +
 lib/inspect-fs-windows.c                 |  1 +
 lib/inspect-fs.c                         |  1 +
 lib/launch.c                             |  1 +
 lib/listfs.c                             |  1 +
 lib/mountable.c                          |  2 +-
 make-fs/Makefile.am                      |  2 ++
 make-fs/make-fs.c                        |  1 +
 sysprep/Makefile.am                      |  2 ++
 tests/c-api/Makefile.am                  |  2 ++
 tests/c-api/tests-main.c                 |  1 +
 44 files changed, 132 insertions(+), 51 deletions(-)

diff --git a/.gitignore b/.gitignore
index e0dbe280c..934d9f291 100644
--- a/.gitignore
+++ b/.gitignore
@@ -137,10 +137,10 @@ Makefile.in
 /common/protocol/guestfs_protocol.h
 /common/protocol/guestfs_protocol.x
 /common/qemuopts/qemuopts-tests
-/common/utils/guestfs-internal-frontend-cleanups.h
-/common/utils/structs-cleanup.c
-/common/utils/structs-print.c
-/common/utils/structs-print.h
+/common/structs/structs-cleanups.c
+/common/structs/structs-cleanups.h
+/common/structs/structs-print.c
+/common/structs/structs-print.h
 /compile
 /config.cache
 /config.guess
diff --git a/Makefile.am b/Makefile.am
index 7189519fb..b3eb35349 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -41,6 +41,7 @@ endif
 SUBDIRS += common/errnostring common/protocol common/qemuopts
 SUBDIRS += common/cleanups
 SUBDIRS += common/utils
+SUBDIRS += common/structs
 SUBDIRS += lib docs examples po

 # The daemon and the appliance.
diff --git a/align/Makefile.am b/align/Makefile.am
index 99a80dd73..9cfa4cc91 100644
--- a/align/Makefile.am
+++ b/align/Makefile.am
@@ -32,6 +32,7 @@ virt_alignment_scan_CPPFLAGS = \
 	-DGUESTFS_WARN_DEPRECATED=1 \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
 	-I$(top_srcdir)/common/parallel -I$(top_builddir)/common/parallel \
@@ -47,6 +48,7 @@ virt_alignment_scan_CFLAGS = \
 virt_alignment_scan_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
 	$(top_builddir)/common/parallel/libparallel.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
diff --git a/align/scan.c b/align/scan.c
index 4fa95c0a3..b9f29868c 100644
--- a/align/scan.c
+++ b/align/scan.c
@@ -41,6 +41,7 @@
 #include "getprogname.h"

 #include "guestfs.h"
+#include "structs-cleanups.h"
 #include "options.h"
 #include "display-options.h"
 #include "parallel.h"
diff --git a/cat/Makefile.am b/cat/Makefile.am
index 94e0285af..aeabab6e7 100644
--- a/cat/Makefile.am
+++ b/cat/Makefile.am
@@ -40,6 +40,7 @@ virt_cat_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
 	-I$(top_srcdir)/common/windows -I$(top_builddir)/common/windows \
@@ -52,6 +53,7 @@ virt_cat_CFLAGS = \
 virt_cat_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
 	$(top_builddir)/common/windows/libwindows.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
@@ -68,6 +70,7 @@ virt_filesystems_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
 	-I$(top_srcdir)/common/windows -I$(top_builddir)/common/windows \
@@ -80,6 +83,7 @@ virt_filesystems_CFLAGS = \
 virt_filesystems_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
 	$(top_builddir)/common/windows/libwindows.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
@@ -96,6 +100,7 @@ virt_log_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
 	-I$(top_srcdir)/common/windows -I$(top_builddir)/common/windows \
@@ -107,6 +112,7 @@ virt_log_CFLAGS = \

 virt_log_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
@@ -123,6 +129,7 @@ virt_ls_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/visit \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
@@ -136,6 +143,7 @@ virt_ls_CFLAGS = \
 virt_ls_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
 	$(top_builddir)/common/visit/libvisit.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
@@ -152,6 +160,7 @@ virt_tail_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
 	-I$(top_srcdir)/common/windows -I$(top_builddir)/common/windows \
@@ -164,6 +173,7 @@ virt_tail_CFLAGS = \
 virt_tail_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
 	$(top_builddir)/common/windows/libwindows.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
diff --git a/cat/filesystems.c b/cat/filesystems.c
index f3dd265ab..74e994169 100644
--- a/cat/filesystems.c
+++ b/cat/filesystems.c
@@ -37,6 +37,7 @@
 #include "getprogname.h"

 #include "guestfs.h"
+#include "structs-cleanups.h"
 #include "options.h"
 #include "display-options.h"

diff --git a/cat/log.c b/cat/log.c
index 92272b8d1..6e445af0b 100644
--- a/cat/log.c
+++ b/cat/log.c
@@ -38,6 +38,7 @@
 #include "getprogname.h"

 #include "guestfs.h"
+#include "structs-cleanups.h"
 #include "options.h"
 #include "display-options.h"

diff --git a/cat/tail.c b/cat/tail.c
index 4ac73ad36..e932820e6 100644
--- a/cat/tail.c
+++ b/cat/tail.c
@@ -37,6 +37,7 @@
 #include "ignore-value.h"

 #include "guestfs.h"
+#include "structs-cleanups.h"
 #include "options.h"
 #include "display-options.h"
 #include "windows.h"
diff --git a/common/mlvisit/Makefile.am b/common/mlvisit/Makefile.am
index 51cbd2de6..2019efd75 100644
--- a/common/mlvisit/Makefile.am
+++ b/common/mlvisit/Makefile.am
@@ -74,6 +74,7 @@ OCAMLPACKAGES = \
 	-I $(top_builddir)/gnulib/lib/.libs \
 	-I $(top_builddir)/ocaml \
 	-I $(top_builddir)/common/utils/.libs \
+	-I $(top_builddir)/common/structs/.libs \
 	-I $(top_builddir)/common/visit/.libs \
 	-I $(builddir)
 OCAMLPACKAGES_TESTS = $(MLVISIT_CMA)
@@ -115,7 +116,7 @@ visit_tests_DEPENDENCIES = \
 	$(top_srcdir)/ocaml-link.sh
 visit_tests_LINK = \
 	$(top_srcdir)/ocaml-link.sh \
-	  -cclib '-lvisit -lutils $(LIBXML2_LIBS) -lgnu' -- \
+	  -cclib '-lvisit -lstructs -lutils $(LIBXML2_LIBS) -lgnu' -- \
 	  $(OCAMLFIND) $(BEST) $(OCAMLFLAGS) $(OCAMLLINKFLAGS) \
 	  $(OCAMLPACKAGES) $(OCAMLPACKAGES_TESTS) \
 	  $(visit_tests_THEOBJECTS) -o $@
diff --git a/common/structs/Makefile.am b/common/structs/Makefile.am
new file mode 100644
index 000000000..1762af276
--- /dev/null
+++ b/common/structs/Makefile.am
@@ -0,0 +1,44 @@
+# libguestfs
+# Copyright (C) 2017 Red Hat Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+
+include $(top_srcdir)/subdir-rules.mk
+
+generator_built = \
+	structs-cleanups.c \
+	structs-cleanups.h \
+	structs-print.c \
+	structs-print.h
+
+BUILT_SOURCES = \
+	$(generator_built)
+
+EXTRA_DIST = \
+	$(BUILT_SOURCES)
+
+noinst_LTLIBRARIES = libstructs.la
+
+libstructs_la_SOURCES = \
+	../../lib/guestfs.h \
+	$(BUILT_SOURCES)
+libstructs_la_CPPFLAGS = \
+	-DGUESTFS_WARN_DEPRECATED=1 \
+	-DGUESTFS_PRIVATE=1 \
+	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
+	-I$(top_srcdir)/lib -I$(top_builddir)/lib
+libstructs_la_CFLAGS = \
+	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
+	$(GCC_VISIBILITY_HIDDEN)
diff --git a/common/utils/Makefile.am b/common/utils/Makefile.am
index 47a4186d7..9aabda4e2 100644
--- a/common/utils/Makefile.am
+++ b/common/utils/Makefile.am
@@ -17,27 +17,11 @@

 include $(top_srcdir)/subdir-rules.mk

-generator_built = \
-	guestfs-internal-frontend-cleanups.h \
-	structs-cleanup.c \
-	structs-print.c \
-	structs-print.h
-
-BUILT_SOURCES = \
-	$(generator_built)
-
-EXTRA_DIST = \
-	$(BUILT_SOURCES)
-
 noinst_LTLIBRARIES = libutils.la

 libutils_la_SOURCES = \
 	../../lib/guestfs.h \
 	guestfs-internal-frontend.h \
-	guestfs-internal-frontend-cleanups.h \
-	structs-cleanup.c \
-	structs-print.c \
-	structs-print.h \
 	utils.c
 libutils_la_CPPFLAGS = \
 	-DGUESTFS_WARN_DEPRECATED=1 \
diff --git a/common/utils/guestfs-internal-frontend.h
b/common/utils/guestfs-internal-frontend.h
index 92c9ae902..8de38bf9b 100644
--- a/common/utils/guestfs-internal-frontend.h
+++ b/common/utils/guestfs-internal-frontend.h
@@ -71,11 +71,6 @@ extern void guestfs_int_fadvise_noreuse (int fd);
 extern char *guestfs_int_shell_unquote (const char *str);
 extern void guestfs_int_cleanup_free_string_list (char ***ptr);

-/* These are in a separate header so the header can be generated.
- * Don't include the following file directly:
- */
-#include "guestfs-internal-frontend-cleanups.h"
-
 /* Not all language bindings know how to deal with Pointer arguments.
  * Those that don't will use this macro which complains noisily and
  * returns NULL.
diff --git a/common/visit/Makefile.am b/common/visit/Makefile.am
index 519088769..a2d22f10e 100644
--- a/common/visit/Makefile.am
+++ b/common/visit/Makefile.am
@@ -28,7 +28,8 @@ libvisit_la_CPPFLAGS = \
 	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
-	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils
+	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs
 libvisit_la_CFLAGS = \
 	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
 	$(GCC_VISIBILITY_HIDDEN)
diff --git a/common/visit/visit.c b/common/visit/visit.c
index 5045f9f71..491f9dda3 100644
--- a/common/visit/visit.c
+++ b/common/visit/visit.c
@@ -37,6 +37,7 @@

 #include "guestfs.h"
 #include "guestfs-internal-frontend.h"
+#include "structs-cleanups.h"

 #include "visit.h"

diff --git a/configure.ac b/configure.ac
index 33cdbd39e..9b7f61a2e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -196,6 +196,7 @@ AC_CONFIG_FILES([Makefile
                  common/progress/Makefile
                  common/protocol/Makefile
                  common/qemuopts/Makefile
+                 common/structs/Makefile
                  common/utils/Makefile
                  common/visit/Makefile
                  common/windows/Makefile
diff --git a/df/Makefile.am b/df/Makefile.am
index 30faf3ee1..cffcb55d6 100644
--- a/df/Makefile.am
+++ b/df/Makefile.am
@@ -37,6 +37,7 @@ virt_df_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
 	-I$(top_srcdir)/common/parallel -I$(top_builddir)/common/parallel \
@@ -51,6 +52,7 @@ virt_df_CFLAGS = \
 virt_df_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
 	$(top_builddir)/common/parallel/libparallel.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
diff --git a/df/df.c b/df/df.c
index a13cc5910..66b1d8334 100644
--- a/df/df.c
+++ b/df/df.c
@@ -27,6 +27,7 @@
 #include <errno.h>

 #include "guestfs.h"
+#include "structs-cleanups.h"
 #include "options.h"
 #include "domains.h"
 #include "virt-df.h"
diff --git a/diff/Makefile.am b/diff/Makefile.am
index 06378dc78..de65bcf8c 100644
--- a/diff/Makefile.am
+++ b/diff/Makefile.am
@@ -45,6 +45,7 @@ virt_diff_CFLAGS = \
 virt_diff_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
 	$(top_builddir)/common/visit/libvisit.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
diff --git a/docs/C_SOURCE_FILES b/docs/C_SOURCE_FILES
index 0ba99e259..fce01da3e 100644
--- a/docs/C_SOURCE_FILES
+++ b/docs/C_SOURCE_FILES
@@ -46,11 +46,11 @@ common/progress/progress.h
 common/qemuopts/qemuopts-tests.c
 common/qemuopts/qemuopts.c
 common/qemuopts/qemuopts.h
-common/utils/guestfs-internal-frontend-cleanups.h
+common/structs/structs-cleanups.c
+common/structs/structs-cleanups.h
+common/structs/structs-print.c
+common/structs/structs-print.h
 common/utils/guestfs-internal-frontend.h
-common/utils/structs-cleanup.c
-common/utils/structs-print.c
-common/utils/structs-print.h
 common/utils/utils.c
 common/visit/visit.c
 common/visit/visit.h
diff --git a/docs/guestfs-hacking.pod b/docs/guestfs-hacking.pod
index fdb7a9e63..6ee4c236b 100644
--- a/docs/guestfs-hacking.pod
+++ b/docs/guestfs-hacking.pod
@@ -142,6 +142,11 @@ and the daemon running inside the appliance is defined
here.

 Mini-library for writing qemu command lines and qemu config files.

+=item F<common/structs>
+
+Common code for printing and freeing libguestfs structs, used by the
+library and some tools.
+
 =item F<common/utils>

 Various utility functions used throughout the library and tools.
diff --git a/fish/Makefile.am b/fish/Makefile.am
index d74a70af7..4aac8067b 100644
--- a/fish/Makefile.am
+++ b/fish/Makefile.am
@@ -109,10 +109,12 @@ libcmds_la_SOURCES = cmds-gperf.c
 libcmds_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(srcdir)/../gnulib/lib -I../gnulib/lib
 libcmds_la_CFLAGS  libcmds_la_LIBADD = \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(LTLIBINTL)
@@ -127,6 +129,7 @@ guestfish_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/edit -I$(top_builddir)/common/edit \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
@@ -144,6 +147,7 @@ guestfish_LDADD = \
 	$(top_builddir)/common/edit/libedit.la \
 	$(top_builddir)/common/options/liboptions.la \
 	$(top_builddir)/common/progress/libprogress.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
diff --git a/generator/c.ml b/generator/c.ml
index 27bf1ebf9..c9fd867de 100644
--- a/generator/c.ml
+++ b/generator/c.ml
@@ -794,20 +794,17 @@ and generate_internal_actions_h ()    pr "\n";
   pr "#endif /* GUESTFS_INTERNAL_ACTIONS_H_ */\n"

-(* Generate guestfs-internal-frontend-cleanups.h file. *)
-and generate_internal_frontend_cleanups_h () +(* Generate structs-cleanups.h
file. *)
+and generate_client_structs_cleanups_h ()    generate_header CStyle LGPLv2plus;

   pr "\
 /* These CLEANUP_* macros automatically free the struct or struct list
  * pointed to by the local variable at the end of the current scope.
- *
- * Don't include this file directly!  To use these cleanups in library
- * bindings and tools, include \"guestfs-internal-frontend.h\" only.
  */

-#ifndef GUESTFS_INTERNAL_FRONTEND_CLEANUPS_H_
-#define GUESTFS_INTERNAL_FRONTEND_CLEANUPS_H_
+#ifndef GUESTFS_STRUCTS_CLEANUPS_H_
+#define GUESTFS_STRUCTS_CLEANUPS_H_

 #ifdef HAVE_ATTRIBUTE_CLEANUP
 ";
@@ -846,7 +843,7 @@ and generate_internal_frontend_cleanups_h ()    ) structs;

   pr "\n";
-  pr "#endif /* GUESTFS_INTERNAL_FRONTEND_CLEANUPS_H_ */\n"
+  pr "#endif /* GUESTFS_STRUCTS_CLEANUPS_H_ */\n"

 (* Functions to free structures. *)
 and generate_client_structs_free () @@ -1166,7 +1163,7 @@ and
generate_client_structs_copy ()    ) structs

 (* Functions to free structures used by the CLEANUP_* macros. *)
-and generate_client_structs_cleanup () +and generate_client_structs_cleanups_c
()    generate_header CStyle LGPLv2plus;

   pr "\
@@ -1176,7 +1173,7 @@ and generate_client_structs_cleanup ()  #include
<stdlib.h>

 #include \"guestfs.h\"
-#include \"guestfs-internal-frontend.h\"
+#include \"structs-cleanups.h\"

 ";

diff --git a/generator/c.mli b/generator/c.mli
index 0884a8dfe..6d8cae891 100644
--- a/generator/c.mli
+++ b/generator/c.mli
@@ -26,7 +26,8 @@ val generate_actions_pod : unit -> unit
 val generate_availability_pod : unit -> unit
 val generate_client_actions : Types.action list -> unit -> unit
 val generate_client_actions_variants : unit -> unit
-val generate_client_structs_cleanup : unit -> unit
+val generate_client_structs_cleanups_h : unit -> unit
+val generate_client_structs_cleanups_c : unit -> unit
 val generate_client_structs_compare : unit -> unit
 val generate_client_structs_copy : unit -> unit
 val generate_client_structs_free : unit -> unit
@@ -35,7 +36,6 @@ val generate_client_structs_print_c : unit -> unit
 val generate_event_string_c : unit -> unit
 val generate_guestfs_h : unit -> unit
 val generate_internal_actions_h : unit -> unit
-val generate_internal_frontend_cleanups_h : unit -> unit
 val generate_linker_script : unit -> unit
 val generate_max_proc_nr : unit -> unit
 val generate_structs_pod : unit -> unit
diff --git a/generator/java.ml b/generator/java.ml
index 7c3212a49..a7d0ed359 100644
--- a/generator/java.ml
+++ b/generator/java.ml
@@ -586,6 +586,7 @@ and generate_java_c actions ()  #include
\"com_redhat_et_libguestfs_GuestFS.h\"
 #include \"guestfs.h\"
 #include \"guestfs-internal-frontend.h\"
+#include \"structs-cleanups.h\"

 /* Note that this function returns.  The exception is not thrown
  * until after the wrapper function returns.
diff --git a/generator/main.ml b/generator/main.ml
index 8ff698130..33fe2b2ee 100644
--- a/generator/main.ml
+++ b/generator/main.ml
@@ -86,13 +86,13 @@ Run it from the top source directory using the command
             Errnostring.generate_errnostring_h;
   output_to "common/protocol/guestfs_protocol.x"
             XDR.generate_xdr;
-  output_to "common/utils/guestfs-internal-frontend-cleanups.h"
-            C.generate_internal_frontend_cleanups_h;
-  output_to "common/utils/structs-cleanup.c"
-            C.generate_client_structs_cleanup;
-  output_to "common/utils/structs-print.c"
+  output_to "common/structs/structs-cleanups.h"
+            C.generate_client_structs_cleanups_h;
+  output_to "common/structs/structs-cleanups.c"
+            C.generate_client_structs_cleanups_c;
+  output_to "common/structs/structs-print.c"
             C.generate_client_structs_print_c;
-  output_to "common/utils/structs-print.h"
+  output_to "common/structs/structs-print.h"
             C.generate_client_structs_print_h;
   output_to "lib/uefi.c"
             UEFI.generate_uefi_c;
diff --git a/generator/tests_c_api.ml b/generator/tests_c_api.ml
index a680521f4..c3cb62c4d 100644
--- a/generator/tests_c_api.ml
+++ b/generator/tests_c_api.ml
@@ -48,6 +48,7 @@ let rec generate_c_api_tests ()
 #include \"guestfs.h\"
 #include \"guestfs-internal-frontend.h\"
+#include \"structs-cleanups.h\"

 #include \"tests.h\"

diff --git a/inspector/Makefile.am b/inspector/Makefile.am
index 980852cde..5009cc57c 100644
--- a/inspector/Makefile.am
+++ b/inspector/Makefile.am
@@ -60,6 +60,7 @@ virt_inspector_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
 	-I$(top_srcdir)/fish \
@@ -71,6 +72,7 @@ virt_inspector_CFLAGS = \

 virt_inspector_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
diff --git a/inspector/inspector.c b/inspector/inspector.c
index b00c85208..104310d1f 100644
--- a/inspector/inspector.c
+++ b/inspector/inspector.c
@@ -40,6 +40,7 @@
 #include "getprogname.h"

 #include "guestfs.h"
+#include "structs-cleanups.h"
 #include "options.h"
 #include "display-options.h"

diff --git a/java/Makefile.am b/java/Makefile.am
index 089ac0177..834130b20 100644
--- a/java/Makefile.am
+++ b/java/Makefile.am
@@ -110,6 +110,7 @@ libguestfs_jni_la_CPPFLAGS = \
 	-DGUESTFS_PRIVATE=1 \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib

 libguestfs_jni_la_CFLAGS = \
@@ -117,6 +118,7 @@ libguestfs_jni_la_CFLAGS = \
 	$(JNI_CFLAGS)

 libguestfs_jni_la_LIBADD = \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 12fdbcd6c..9cca1268a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -58,7 +58,7 @@ libguestfs_la_SOURCES = \
 	../common/protocol/guestfs_protocol.h \
 	../common/qemuopts/qemuopts.h \
 	../common/utils/guestfs-internal-frontend.h \
-	../common/utils/guestfs-internal-frontend-cleanups.h \
+	../common/structs/structs-cleanups.h \
 	guestfs.h \
 	guestfs-internal.h \
 	guestfs-internal-all.h \
@@ -141,6 +141,7 @@ libguestfs_la_CPPFLAGS = \
 	-I$(top_srcdir)/common/qemuopts -I$(top_builddir)/common/qemuopts \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib

 libguestfs_la_CFLAGS = \
@@ -156,6 +157,7 @@ libguestfs_la_LIBADD = \
 	../common/errnostring/liberrnostring.la \
 	../common/protocol/libprotocol.la \
 	../common/qemuopts/libqemuopts.la \
+	../common/structs/libstructs.la \
 	../common/utils/libutils.la \
 	../common/cleanups/libcleanups.la \
 	$(PCRE_LIBS) $(MAGIC_LIBS) \
@@ -219,6 +221,7 @@ unit_tests_CPPFLAGS = \
 	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I.
 unit_tests_CFLAGS = \
 	$(WARN_CFLAGS) $(WERROR_CFLAGS)
@@ -226,6 +229,7 @@ unit_tests_CFLAGS = \
 # non-exported functions we have to link with the objects not the
 # library.
 unit_tests_LDADD = \
+	../common/structs/libstructs.la \
 	../common/utils/libutils.la \
 	../common/cleanups/libcleanups.la \
 	$(libguestfs_la_OBJECTS) \
diff --git a/lib/file.c b/lib/file.c
index 53b859d4b..73c983c2b 100644
--- a/lib/file.c
+++ b/lib/file.c
@@ -32,6 +32,7 @@
 #include "guestfs.h"
 #include "guestfs-internal.h"
 #include "guestfs-internal-actions.h"
+#include "structs-cleanups.h"

 static int
 compare (const void *vp1, const void *vp2)
diff --git a/lib/fuse.c b/lib/fuse.c
index cde3783d9..de8c4d8f2 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -54,6 +54,7 @@
 #include "guestfs.h"
 #include "guestfs-internal.h"
 #include "guestfs-internal-actions.h"
+#include "structs-cleanups.h"

 #if HAVE_FUSE

diff --git a/lib/inspect-apps.c b/lib/inspect-apps.c
index c324f3bf0..25192340c 100644
--- a/lib/inspect-apps.c
+++ b/lib/inspect-apps.c
@@ -43,6 +43,7 @@
 #include "guestfs.h"
 #include "guestfs-internal.h"
 #include "guestfs-internal-actions.h"
+#include "structs-cleanups.h"

 #ifdef DB_DUMP
 static struct guestfs_application2_list *list_applications_rpm (guestfs_h *g,
struct inspect_fs *fs);
diff --git a/lib/inspect-fs-cd.c b/lib/inspect-fs-cd.c
index 1cff5606b..c9a4e219e 100644
--- a/lib/inspect-fs-cd.c
+++ b/lib/inspect-fs-cd.c
@@ -32,6 +32,7 @@

 #include "guestfs.h"
 #include "guestfs-internal.h"
+#include "structs-cleanups.h"

 /* Debian/Ubuntu install disks are easy ...
  *
diff --git a/lib/inspect-fs-windows.c b/lib/inspect-fs-windows.c
index 35f7cc821..b14dc2e14 100644
--- a/lib/inspect-fs-windows.c
+++ b/lib/inspect-fs-windows.c
@@ -48,6 +48,7 @@
 #include "guestfs.h"
 #include "guestfs-internal.h"
 #include "guestfs-internal-actions.h"
+#include "structs-cleanups.h"

 COMPILE_REGEXP (re_windows_version, "^(\\d+)\\.(\\d+)", 0)
 COMPILE_REGEXP (re_boot_ini_os_header, "^\\[operating
systems\\]\\s*$", 0)
diff --git a/lib/inspect-fs.c b/lib/inspect-fs.c
index 9f7630bcf..2da73d310 100644
--- a/lib/inspect-fs.c
+++ b/lib/inspect-fs.c
@@ -35,6 +35,7 @@

 #include "guestfs.h"
 #include "guestfs-internal.h"
+#include "structs-cleanups.h"

 static int check_filesystem (guestfs_h *g, const char *mountable,
                              const struct guestfs_internal_mountable *m,
diff --git a/lib/launch.c b/lib/launch.c
index 04d69d867..70e7f8897 100644
--- a/lib/launch.c
+++ b/lib/launch.c
@@ -45,6 +45,7 @@
 #include "guestfs-internal.h"
 #include "guestfs-internal-actions.h"
 #include "guestfs_protocol.h"
+#include "structs-cleanups.h"

 static struct backend {
   struct backend *next;
diff --git a/lib/listfs.c b/lib/listfs.c
index 88446cc9f..60aff3305 100644
--- a/lib/listfs.c
+++ b/lib/listfs.c
@@ -25,6 +25,7 @@
 #include "guestfs.h"
 #include "guestfs-internal.h"
 #include "guestfs-internal-actions.h"
+#include "structs-cleanups.h"

 /* List filesystems.
  *
diff --git a/lib/mountable.c b/lib/mountable.c
index 9f7b451fd..6e4a0c293 100644
--- a/lib/mountable.c
+++ b/lib/mountable.c
@@ -23,7 +23,7 @@
 #include "guestfs.h"
 #include "guestfs-internal.h"
 #include "guestfs-internal-actions.h"
-
+#include "structs-cleanups.h"

 char *
 guestfs_impl_mountable_device (guestfs_h *g, const char *mountable)
diff --git a/make-fs/Makefile.am b/make-fs/Makefile.am
index 7b5dee127..7ee453067 100644
--- a/make-fs/Makefile.am
+++ b/make-fs/Makefile.am
@@ -32,6 +32,7 @@ virt_make_fs_CPPFLAGS = \
 	-DLOCALEBASEDIR=\""$(datadir)/locale"\" \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib \
 	-I$(top_srcdir)/common/options -I$(top_builddir)/common/options \
 	-I$(top_srcdir)/fish \
@@ -43,6 +44,7 @@ virt_make_fs_CFLAGS = \

 virt_make_fs_LDADD = \
 	$(top_builddir)/common/options/liboptions.la \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
diff --git a/make-fs/make-fs.c b/make-fs/make-fs.c
index 27cdb9fd2..e30745a0f 100644
--- a/make-fs/make-fs.c
+++ b/make-fs/make-fs.c
@@ -40,6 +40,7 @@
 #include "xstrtol.h"
 #include "getprogname.h"

+#include "structs-cleanups.h"
 #include "options.h"
 #include "display-options.h"

diff --git a/sysprep/Makefile.am b/sysprep/Makefile.am
index fcd2923f5..8c94473da 100644
--- a/sysprep/Makefile.am
+++ b/sysprep/Makefile.am
@@ -110,6 +110,7 @@ OCAMLPACKAGES = \
 	-package str,unix \
 	-I $(top_builddir)/common/cleanups/.libs \
 	-I $(top_builddir)/common/utils/.libs \
+	-I $(top_builddir)/common/structs/.libs \
 	-I $(top_builddir)/lib/.libs \
 	-I $(top_builddir)/gnulib/lib/.libs \
 	-I $(top_builddir)/ocaml \
@@ -124,6 +125,7 @@ endif

 OCAMLCLIBS = \
 	-lvisit \
+	-lstructs \
 	-lutils \
 	-lcleanups \
 	$(LIBTINFO_LIBS) \
diff --git a/tests/c-api/Makefile.am b/tests/c-api/Makefile.am
index cc68e5e58..ab764db8d 100644
--- a/tests/c-api/Makefile.am
+++ b/tests/c-api/Makefile.am
@@ -94,12 +94,14 @@ tests_CPPFLAGS = \
 	-I$(top_srcdir)/gnulib/lib -I$(top_builddir)/gnulib/lib \
 	-I$(top_srcdir)/common/cleanups -I$(top_builddir)/common/cleanups \
 	-I$(top_srcdir)/common/utils -I$(top_builddir)/common/utils \
+	-I$(top_srcdir)/common/structs -I$(top_builddir)/common/structs \
 	-I$(top_srcdir)/lib -I$(top_builddir)/lib
 tests_CFLAGS = \
 	$(WARN_CFLAGS) $(WERROR_CFLAGS) \
 	$(PCRE_CFLAGS)
 tests_LDADD = \
 	$(PCRE_LIBS) \
+	$(top_builddir)/common/structs/libstructs.la \
 	$(top_builddir)/common/utils/libutils.la \
 	$(top_builddir)/common/cleanups/libcleanups.la \
 	$(top_builddir)/lib/libguestfs.la \
diff --git a/tests/c-api/tests-main.c b/tests/c-api/tests-main.c
index 0fd895423..f202a70ff 100644
--- a/tests/c-api/tests-main.c
+++ b/tests/c-api/tests-main.c
@@ -38,6 +38,7 @@

 #include "guestfs.h"
 #include "guestfs-internal-frontend.h"
+#include "structs-cleanups.h"

 #include "tests.h"

--
2.13.0