[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH 1/3] generator: c: move internal functions



Move the generate_all_structs and generate_all_headers functions,
previously internal within the implementation of generate_guestfs_h, to
be usable by other functions in the same "C" module (but not public).

Only code motion.
---
 generator/c.ml | 163 +++++++++++++++++++++++++++++----------------------------
 1 file changed, 82 insertions(+), 81 deletions(-)

diff --git a/generator/c.ml b/generator/c.ml
index 6f5a517..f0df5ea 100644
--- a/generator/c.ml
+++ b/generator/c.ml
@@ -585,21 +585,85 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char *
 /* Structures. */
 ";
 
-  (* 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
-   * here is just so we don't have to export the whole of
-   * guestfs_protocol.h (which includes much unrelated and
-   * XDR-dependent stuff that we don't want to be public, or required
-   * by clients).
-   *
-   * To reiterate, we will pass these structures to and from the client
-   * with a simple assignment or memcpy, so the format must be
-   * identical to what rpcgen / the RFC defines.
-   *)
-
   (* Public structures. *)
-  let generate_all_structs = List.iter (
+  generate_all_structs external_structs;
+
+  pr "\
+/* Actions. */
+";
+
+  generate_all_headers public_functions_sorted;
+
+  pr "\
+#if GUESTFS_PRIVATE
+/* Symbols protected by GUESTFS_PRIVATE are NOT part of the public,
+ * stable API, and can change at any time!  We export them because
+ * they are used by some of the language bindings.
+ */
+
+/* Private functions. */
+
+";
+
+  generate_all_headers private_functions_sorted;
+
+  pr "\
+/* Private structures. */
+
+";
+
+  generate_all_structs internal_structs;
+
+pr "\
+
+#endif /* End of GUESTFS_PRIVATE. */
+
+/* Deprecated macros.  Use GUESTFS_HAVE_* instead. */
+
+#define LIBGUESTFS_HAVE_CREATE_FLAGS 1
+#define LIBGUESTFS_HAVE_LAST_ERRNO 1
+#define LIBGUESTFS_HAVE_PUSH_ERROR_HANDLER 1
+#define LIBGUESTFS_HAVE_POP_ERROR_HANDLER 1
+#define LIBGUESTFS_HAVE_SET_EVENT_CALLBACK 1
+#define LIBGUESTFS_HAVE_DELETE_EVENT_CALLBACK 1
+#define LIBGUESTFS_HAVE_SET_CLOSE_CALLBACK 1
+#define LIBGUESTFS_HAVE_SET_PROGRESS_CALLBACK 1
+#define LIBGUESTFS_HAVE_SET_PRIVATE 1
+#define LIBGUESTFS_HAVE_GET_PRIVATE 1
+#define LIBGUESTFS_HAVE_FIRST_PRIVATE 1
+#define LIBGUESTFS_HAVE_NEXT_PRIVATE 1
+
+";
+
+  List.iter (
+    fun { name = shortname } ->
+      pr "#define LIBGUESTFS_HAVE_%s 1\n" (String.uppercase shortname);
+  ) public_functions_sorted;
+
+  pr "
+/* End of deprecated macros. */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* GUESTFS_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
+ * here is just so we don't have to export the whole of
+ * guestfs_protocol.h (which includes much unrelated and
+ * XDR-dependent stuff that we don't want to be public, or required
+ * by clients).
+ *
+ * To reiterate, we will pass these structures to and from the client
+ * with a simple assignment or memcpy, so the format must be
+ * identical to what rpcgen / the RFC defines.
+ *)
+and generate_all_structs structs =
+  List.iter (
     fun { s_name = typ; s_cols = cols } ->
       pr "#define GUESTFS_HAVE_STRUCT_%s 1\n" (String.uppercase typ);
       pr "\n";
@@ -634,14 +698,9 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char *
       pr "extern GUESTFS_DLL_PUBLIC void guestfs_free_%s (struct guestfs_%s *);\n" typ typ;
       pr "extern GUESTFS_DLL_PUBLIC void guestfs_free_%s_list (struct guestfs_%s_list *);\n" typ typ;
       pr "\n"
-  ) in
-
-  generate_all_structs external_structs;
-
-  pr "\
-/* Actions. */
-";
+  ) structs
 
+and generate_all_headers actions =
   let generate_action_header { name = shortname;
                                style = ret, args, optargs as style;
                                deprecated_by = deprecated_by } =
@@ -700,7 +759,7 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char *
     pr "\n"
   in
 
-  let generate_all_headers = List.iter (
+  List.iter (
     fun ({ name = name; style = ret, args, _ } as f) ->
       (* If once_had_no_optargs is set, then we need to generate a
        * <name>_opts variant, plus a backwards-compatible wrapper
@@ -712,65 +771,7 @@ extern GUESTFS_DLL_PUBLIC void *guestfs_next_private (guestfs_h *g, const char *
       )
       else
         generate_action_header f
-  ) in
-
-  generate_all_headers public_functions_sorted;
-
-  pr "\
-#if GUESTFS_PRIVATE
-/* Symbols protected by GUESTFS_PRIVATE are NOT part of the public,
- * stable API, and can change at any time!  We export them because
- * they are used by some of the language bindings.
- */
-
-/* Private functions. */
-
-";
-
-  generate_all_headers private_functions_sorted;
-
-  pr "\
-/* Private structures. */
-
-";
-
-  generate_all_structs internal_structs;
-
-pr "\
-
-#endif /* End of GUESTFS_PRIVATE. */
-
-/* Deprecated macros.  Use GUESTFS_HAVE_* instead. */
-
-#define LIBGUESTFS_HAVE_CREATE_FLAGS 1
-#define LIBGUESTFS_HAVE_LAST_ERRNO 1
-#define LIBGUESTFS_HAVE_PUSH_ERROR_HANDLER 1
-#define LIBGUESTFS_HAVE_POP_ERROR_HANDLER 1
-#define LIBGUESTFS_HAVE_SET_EVENT_CALLBACK 1
-#define LIBGUESTFS_HAVE_DELETE_EVENT_CALLBACK 1
-#define LIBGUESTFS_HAVE_SET_CLOSE_CALLBACK 1
-#define LIBGUESTFS_HAVE_SET_PROGRESS_CALLBACK 1
-#define LIBGUESTFS_HAVE_SET_PRIVATE 1
-#define LIBGUESTFS_HAVE_GET_PRIVATE 1
-#define LIBGUESTFS_HAVE_FIRST_PRIVATE 1
-#define LIBGUESTFS_HAVE_NEXT_PRIVATE 1
-
-";
-
-  List.iter (
-    fun { name = shortname } ->
-      pr "#define LIBGUESTFS_HAVE_%s 1\n" (String.uppercase shortname);
-  ) public_functions_sorted;
-
-  pr "
-/* End of deprecated macros. */
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* GUESTFS_H_ */
-"
+  ) actions
 
 (* Generate the guestfs-internal-actions.h file. *)
 and generate_internal_actions_h () =
-- 
2.7.4


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]