2 * Copyright (C) 2009-2011 Red Hat Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (* Please read generator/README first. *)
26 open Generator_docstrings
27 open Generator_api_versions
28 open Generator_optgroups
29 open Generator_actions
30 open Generator_structs
35 type optarg_proto = Dots | VA | Argv
37 (* Generate a C function prototype. *)
38 let rec generate_prototype ?(extern = true) ?(static = false)
40 ?(single_line = false) ?(indent = "") ?(newline = false)
42 ?(prefix = "") ?(suffix = "")
44 ?(optarg_proto = Dots)
45 name (ret, args, optargs) =
47 if extern then pr "extern ";
48 if static then pr "static ";
54 if single_line then pr " " else pr "\n%s" indent
57 if single_line then pr " " else pr "\n%s" indent
58 | RConstString _ | RConstOptString _ ->
60 if not single_line then pr "\n%s" indent
61 | RString _ | RBufferOut _ ->
63 if not single_line then pr "\n%s" indent
64 | RStringList _ | RHashtable _ ->
66 if not single_line then pr "\n%s" indent
68 if not in_daemon then pr "struct guestfs_%s *" typ
69 else pr "guestfs_int_%s *" typ;
70 if not single_line then pr "\n%s" indent
71 | RStructList (_, typ) ->
72 if not in_daemon then pr "struct guestfs_%s_list *" typ
73 else pr "guestfs_int_%s_list *" typ;
74 if not single_line then pr "\n%s" indent
76 let is_RBufferOut = match ret with RBufferOut _ -> true | _ -> false in
77 pr "%s%s%s (" prefix name suffix;
78 if handle = None && args = [] && optargs = [] && not is_RBufferOut then
81 let comma = ref false in
84 | Some handle -> pr "guestfs_h *%s" handle; comma := true
88 if single_line then pr ", "
90 let namelen = String.length prefix + String.length name +
91 String.length suffix + 2 in
92 pr ",\n%s%s" indent (spaces namelen)
100 | Device n | Dev_or_Path n
105 pr "const char *%s" n
106 | StringList n | DeviceList n ->
108 pr "char *const *%s" n
109 | Bool n -> next (); pr "int %s" n
110 | Int n -> next (); pr "int %s" n
111 | Int64 n -> next (); pr "int64_t %s" n
114 if not in_daemon then (next (); pr "const char *%s" n)
117 pr "const char *%s" n;
119 pr "size_t %s_size" n
124 if is_RBufferOut then (next (); pr "size_t *size_r");
125 if optargs <> [] then (
127 match optarg_proto with
129 | VA -> pr "va_list args"
130 | Argv -> pr "const struct guestfs_%s_argv *optargs" name
134 if semicolon then pr ";";
135 if newline then pr "\n"
137 (* Generate C call arguments, eg "(handle, foo, bar)" *)
138 and generate_c_call_args ?handle ?(implicit_size_ptr = "&size")
139 (ret, args, optargs) =
141 let comma = ref false in
143 if !comma then pr ", ";
148 | Some handle -> pr "%s" handle; comma := true
157 pr "%s" (name_of_argt arg)
159 (* For RBufferOut calls, add implicit size pointer parameter. *)
163 pr "%s" implicit_size_ptr
166 (* For calls with optional arguments, add implicit optargs parameter. *)
167 if optargs <> [] then (
173 (* Generate the pod documentation for the C API. *)
174 and generate_actions_pod () =
176 fun (shortname, (ret, args, optargs as style), _, flags, _, _, longdesc) ->
177 if not (List.mem NotInDocs flags) then (
178 let name = "guestfs_" ^ shortname in
179 pr "=head2 %s\n\n" name;
180 generate_prototype ~extern:false ~indent:" " ~handle:"g" name style;
183 let uc_shortname = String.uppercase shortname in
184 if optargs <> [] then (
185 pr "You may supply a list of optional arguments to this call.\n";
186 pr "Use zero or more of the following pairs of parameters,\n";
187 pr "and terminate the list with C<-1> on its own.\n";
188 pr "See L</CALLS WITH OPTIONAL ARGUMENTS>.\n\n";
191 let n = name_of_argt argt in
192 let uc_n = String.uppercase n in
193 pr " GUESTFS_%s_%s, " uc_shortname uc_n;
195 | Bool n -> pr "int %s,\n" n
196 | Int n -> pr "int %s,\n" n
197 | Int64 n -> pr "int64_t %s,\n" n
198 | String n -> pr "const char *%s,\n" n
204 pr "%s\n\n" longdesc;
205 let ret, args, optargs = style in
208 pr "This function returns 0 on success or -1 on error.\n\n"
210 pr "On error this function returns -1.\n\n"
212 pr "On error this function returns -1.\n\n"
214 pr "This function returns a C truth value on success or -1 on error.\n\n"
216 pr "This function returns a string, or NULL on error.
217 The string is owned by the guest handle and must I<not> be freed.\n\n"
218 | RConstOptString _ ->
219 pr "This function returns a string which may be NULL.
220 There is no way to return an error from this function.
221 The string is owned by the guest handle and must I<not> be freed.\n\n"
223 pr "This function returns a string, or NULL on error.
224 I<The caller must free the returned string after use>.\n\n"
226 pr "This function returns a NULL-terminated array of strings
227 (like L<environ(3)>), or NULL if there was an error.
228 I<The caller must free the strings and the array after use>.\n\n"
229 | RStruct (_, typ) ->
230 pr "This function returns a C<struct guestfs_%s *>,
231 or NULL if there was an error.
232 I<The caller must call C<guestfs_free_%s> after use>.\n\n" typ typ
233 | RStructList (_, typ) ->
234 pr "This function returns a C<struct guestfs_%s_list *>,
235 or NULL if there was an error.
236 I<The caller must call C<guestfs_free_%s_list> after use>.\n\n" typ typ
238 pr "This function returns a NULL-terminated array of
239 strings, or NULL if there was an error.
240 The array of strings will always have length C<2n+1>, where
241 C<n> keys and values alternate, followed by the trailing NULL entry.
242 I<The caller must free the strings and the array after use>.\n\n"
244 pr "This function returns a buffer, or NULL on error.
245 The size of the returned buffer is written to C<*size_r>.
246 I<The caller must free the returned buffer after use>.\n\n"
248 if List.mem Progress flags then
249 pr "%s\n\n" progress_message;
250 if List.mem ProtocolLimitWarning flags then
251 pr "%s\n\n" protocol_limit_warning;
252 if List.mem DangerWillRobinson flags then
253 pr "%s\n\n" danger_will_robinson;
254 if List.exists (function Key _ -> true | _ -> false) (args@optargs) then
255 pr "This function takes a key or passphrase parameter which
256 could contain sensitive material. Read the section
257 L</KEYS AND PASSPHRASES> for more information.\n\n";
258 (match deprecation_notice flags with
260 | Some txt -> pr "%s\n\n" txt
262 (match lookup_api_version name with
263 | Some version -> pr "(Added in %s)\n\n" version
267 (* Handling of optional argument variants. *)
268 if optargs <> [] then (
269 pr "=head2 %s_va\n\n" name;
270 generate_prototype ~extern:false ~indent:" " ~handle:"g"
271 ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
274 pr "This is the \"va_list variant\" of L</%s>.\n\n" name;
275 pr "See L</CALLS WITH OPTIONAL ARGUMENTS>.\n\n";
276 pr "=head2 %s_argv\n\n" name;
277 generate_prototype ~extern:false ~indent:" " ~handle:"g"
278 ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
281 pr "This is the \"argv variant\" of L</%s>.\n\n" name;
282 pr "See L</CALLS WITH OPTIONAL ARGUMENTS>.\n\n";
285 ) all_functions_sorted
287 and generate_structs_pod () =
288 (* Structs documentation. *)
291 pr "=head2 guestfs_%s\n" typ;
293 pr " struct guestfs_%s {\n" typ;
296 | name, FChar -> pr " char %s;\n" name
297 | name, FUInt32 -> pr " uint32_t %s;\n" name
298 | name, FInt32 -> pr " int32_t %s;\n" name
299 | name, (FUInt64|FBytes) -> pr " uint64_t %s;\n" name
300 | name, FInt64 -> pr " int64_t %s;\n" name
301 | name, FString -> pr " char *%s;\n" name
303 pr " /* The next two fields describe a byte array. */\n";
304 pr " uint32_t %s_len;\n" name;
305 pr " char *%s;\n" name
307 pr " /* The next field is NOT nul-terminated, be careful when printing it: */\n";
308 pr " char %s[32];\n" name
309 | name, FOptPercent ->
310 pr " /* The next field is [0..100] or -1 meaning 'not present': */\n";
311 pr " float %s;\n" name
315 pr " struct guestfs_%s_list {\n" typ;
316 pr " uint32_t len; /* Number of elements in list. */\n";
317 pr " struct guestfs_%s *val; /* Elements. */\n" typ;
320 pr " void guestfs_free_%s (struct guestfs_free_%s *);\n" typ typ;
321 pr " void guestfs_free_%s_list (struct guestfs_free_%s_list *);\n"
326 and generate_availability_pod () =
327 (* Availability documentation. *)
331 fun (group, functions) ->
332 pr "=item B<%s>\n" group;
334 pr "The following functions:\n";
335 List.iter (pr "L</guestfs_%s>\n") functions;
341 (* Generate the guestfs.h file. *)
342 and generate_guestfs_h () =
343 generate_header CStyle LGPLv2plus;
346 /* ---------- IMPORTANT NOTE ----------
348 * All API documentation is in the manpage, 'guestfs(3)'.
349 * To read it, type: man 3 guestfs
350 * Or read it online here: http://libguestfs.org/guestfs.3.html
352 * Go and read it now, I'll be right here waiting for you
353 * when you come back.
355 * ------------------------------------
370 # define GUESTFS_GCC_VERSION \\
371 (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
374 /* Define GUESTFS_WARN_DEPRECATED=1 to warn about deprecated API functions. */
375 #define GUESTFS_DEPRECATED_BY(s)
376 #if GUESTFS_WARN_DEPRECATED
377 # if defined(__GNUC__) && GUESTFS_GCC_VERSION >= 40500 /* gcc >= 4.5 */
378 # undef GUESTFS_DEPRECATED_BY
379 # define GUESTFS_DEPRECATED_BY(s) __attribute__((__deprecated__(\"change the program to use guestfs_\" s \" instead of this deprecated function\")))
381 #endif /* GUESTFS_WARN_DEPRECATED */
384 #ifndef GUESTFS_TYPEDEF_H
385 #define GUESTFS_TYPEDEF_H 1
386 typedef struct guestfs_h guestfs_h;
389 /* Connection management. */
390 extern guestfs_h *guestfs_create (void);
391 extern void guestfs_close (guestfs_h *g);
393 /* Error handling. */
394 extern const char *guestfs_last_error (guestfs_h *g);
395 #define LIBGUESTFS_HAVE_LAST_ERRNO 1
396 extern int guestfs_last_errno (guestfs_h *g);
398 #ifndef GUESTFS_TYPEDEF_ERROR_HANDLER_CB
399 #define GUESTFS_TYPEDEF_ERROR_HANDLER_CB 1
400 typedef void (*guestfs_error_handler_cb) (guestfs_h *g, void *opaque, const char *msg);
403 #ifndef GUESTFS_TYPEDEF_ABORT_CB
404 #define GUESTFS_TYPEDEF_ABORT_CB 1
405 typedef void (*guestfs_abort_cb) (void) __attribute__((__noreturn__));
408 extern void guestfs_set_error_handler (guestfs_h *g, guestfs_error_handler_cb cb, void *opaque);
409 extern guestfs_error_handler_cb guestfs_get_error_handler (guestfs_h *g, void **opaque_rtn);
411 extern void guestfs_set_out_of_memory_handler (guestfs_h *g, guestfs_abort_cb);
412 extern guestfs_abort_cb guestfs_get_out_of_memory_handler (guestfs_h *g);
418 fun (name, bitmask) ->
419 pr "#define GUESTFS_EVENT_%-16s 0x%04x\n"
420 (String.uppercase name) bitmask
422 pr "#define GUESTFS_EVENT_%-16s UINT64_MAX\n" "ALL";
426 #ifndef GUESTFS_TYPEDEF_EVENT_CALLBACK
427 #define GUESTFS_TYPEDEF_EVENT_CALLBACK 1
428 typedef void (*guestfs_event_callback) (
434 const char *buf, size_t buf_len,
435 const uint64_t *array, size_t array_len);
438 #define LIBGUESTFS_HAVE_SET_EVENT_CALLBACK 1
439 extern int guestfs_set_event_callback (guestfs_h *g,
440 guestfs_event_callback cb,
441 uint64_t event_bitmask,
444 #define LIBGUESTFS_HAVE_DELETE_EVENT_CALLBACK 1
445 extern void guestfs_delete_event_callback (guestfs_h *g, int event_handle);
447 /* Old-style event handling. */
448 #ifndef GUESTFS_TYPEDEF_LOG_MESSAGE_CB
449 #define GUESTFS_TYPEDEF_LOG_MESSAGE_CB 1
450 typedef void (*guestfs_log_message_cb) (guestfs_h *g, void *opaque, char *buf, int len);
453 #ifndef GUESTFS_TYPEDEF_SUBPROCESS_QUIT_CB
454 #define GUESTFS_TYPEDEF_SUBPROCESS_QUIT_CB 1
455 typedef void (*guestfs_subprocess_quit_cb) (guestfs_h *g, void *opaque);
458 #ifndef GUESTFS_TYPEDEF_LAUNCH_DONE_CB
459 #define GUESTFS_TYPEDEF_LAUNCH_DONE_CB 1
460 typedef void (*guestfs_launch_done_cb) (guestfs_h *g, void *opaque);
463 #ifndef GUESTFS_TYPEDEF_CLOSE_CB
464 #define GUESTFS_TYPEDEF_CLOSE_CB 1
465 typedef void (*guestfs_close_cb) (guestfs_h *g, void *opaque);
468 #ifndef GUESTFS_TYPEDEF_PROGRESS_CB
469 #define GUESTFS_TYPEDEF_PROGRESS_CB 1
470 typedef void (*guestfs_progress_cb) (guestfs_h *g, void *opaque, int proc_nr, int serial, uint64_t position, uint64_t total);
473 extern void guestfs_set_log_message_callback (guestfs_h *g, guestfs_log_message_cb cb, void *opaque)
474 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
475 extern void guestfs_set_subprocess_quit_callback (guestfs_h *g, guestfs_subprocess_quit_cb cb, void *opaque)
476 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
477 extern void guestfs_set_launch_done_callback (guestfs_h *g, guestfs_launch_done_cb cb, void *opaque)
478 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
479 #define LIBGUESTFS_HAVE_SET_CLOSE_CALLBACK 1
480 extern void guestfs_set_close_callback (guestfs_h *g, guestfs_close_cb cb, void *opaque)
481 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
482 #define LIBGUESTFS_HAVE_SET_PROGRESS_CALLBACK 1
483 extern void guestfs_set_progress_callback (guestfs_h *g, guestfs_progress_cb cb, void *opaque)
484 GUESTFS_DEPRECATED_BY(\"set_event_callback\");
486 /* User cancellation. */
487 #define LIBGUESTFS_HAVE_USER_CANCEL 1
488 extern void guestfs_user_cancel (guestfs_h *g);
490 /* Private data area. */
491 #define LIBGUESTFS_HAVE_SET_PRIVATE 1
492 extern void guestfs_set_private (guestfs_h *g, const char *key, void *data);
493 #define LIBGUESTFS_HAVE_GET_PRIVATE 1
494 extern void *guestfs_get_private (guestfs_h *g, const char *key);
495 #define LIBGUESTFS_HAVE_FIRST_PRIVATE 1
496 extern void *guestfs_first_private (guestfs_h *g, const char **key_rtn);
497 #define LIBGUESTFS_HAVE_NEXT_PRIVATE 1
498 extern void *guestfs_next_private (guestfs_h *g, const char **key_rtn);
503 (* The structures are carefully written to have exactly the same
504 * in-memory format as the XDR structures that we use on the wire to
505 * the daemon. The reason for creating copies of these structures
506 * here is just so we don't have to export the whole of
507 * guestfs_protocol.h (which includes much unrelated and
508 * XDR-dependent stuff that we don't want to be public, or required
511 * To reiterate, we will pass these structures to and from the client
512 * with a simple assignment or memcpy, so the format must be
513 * identical to what rpcgen / the RFC defines.
516 (* Public structures. *)
519 pr "struct guestfs_%s {\n" typ;
522 | name, FChar -> pr " char %s;\n" name
523 | name, FString -> pr " char *%s;\n" name
525 pr " uint32_t %s_len;\n" name;
526 pr " char *%s;\n" name
527 | name, FUUID -> pr " char %s[32]; /* this is NOT nul-terminated, be careful when printing */\n" name
528 | name, FUInt32 -> pr " uint32_t %s;\n" name
529 | name, FInt32 -> pr " int32_t %s;\n" name
530 | name, (FUInt64|FBytes) -> pr " uint64_t %s;\n" name
531 | name, FInt64 -> pr " int64_t %s;\n" name
532 | name, FOptPercent -> pr " float %s; /* [0..100] or -1 */\n" name
536 pr "struct guestfs_%s_list {\n" typ;
537 pr " uint32_t len;\n";
538 pr " struct guestfs_%s *val;\n" typ;
541 pr "extern void guestfs_free_%s (struct guestfs_%s *);\n" typ typ;
542 pr "extern void guestfs_free_%s_list (struct guestfs_%s_list *);\n" typ typ;
551 fun (shortname, (ret, args, optargs as style), _, flags, _, _, _) ->
554 Some (find_map (function DeprecatedBy fn -> Some fn | _ -> None)
556 with Not_found -> None in
558 String.length shortname >= 5 && String.sub shortname 0 5 = "test0" in
560 String.length shortname >= 5 && String.sub shortname 0 5 = "debug" in
561 if deprecated = None && not test0 && not debug then
562 pr "#define LIBGUESTFS_HAVE_%s 1\n" (String.uppercase shortname);
564 if optargs <> [] then (
567 let uc_shortname = String.uppercase shortname in
568 let n = name_of_argt argt in
569 let uc_n = String.uppercase n in
570 pr "#define GUESTFS_%s_%s %d\n" uc_shortname uc_n i;
574 generate_prototype ~single_line:true ~semicolon:false
575 ~handle:"g" ~prefix:"guestfs_" shortname style;
576 (match deprecated with
577 | Some fn -> pr "\n GUESTFS_DEPRECATED_BY (%S);\n" fn
581 if optargs <> [] then (
582 generate_prototype ~single_line:true ~newline:true ~handle:"g"
583 ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
587 pr "struct guestfs_%s_argv {\n" shortname;
588 pr " uint64_t bitmask;\n";
595 | Int64 n -> "int64_t "
596 | String n -> "const char *"
597 | _ -> assert false (* checked in generator_checks *) in
598 let uc_shortname = String.uppercase shortname in
599 let n = name_of_argt argt in
600 let uc_n = String.uppercase n in
602 pr "# define GUESTFS_%s_%s_BITMASK (UINT64_C(1)<<%d)\n" uc_shortname uc_n i;
603 pr " /* The field below is only valid in this struct if the\n";
604 pr " * GUESTFS_%s_%s_BITMASK bit is set\n" uc_shortname uc_n;
605 pr " * in the bitmask above. If not, the field is ignored.\n";
607 pr " %s%s;\n" c_type n
612 generate_prototype ~single_line:true ~newline:true ~handle:"g"
613 ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
618 ) all_functions_sorted;
622 /* Private functions.
624 * These are NOT part of the public, stable API, and can change at any
625 * time! We export them because they are used by some of the language
628 extern void *guestfs_safe_malloc (guestfs_h *g, size_t nbytes);
629 extern void *guestfs_safe_calloc (guestfs_h *g, size_t n, size_t s);
630 extern const char *guestfs_tmpdir (void);
631 #ifdef GUESTFS_PRIVATE_FOR_EACH_DISK
632 extern int guestfs___for_each_disk (guestfs_h *g, virDomainPtr dom, int (*)(guestfs_h *g, const char *filename, const char *format, void *data), void *data);
634 /* End of private functions. */
640 #endif /* GUESTFS_H_ */
643 (* Generate the guestfs-internal-actions.h file. *)
644 and generate_internal_actions_h () =
645 generate_header CStyle LGPLv2plus;
647 fun (shortname, style, _, _, _, _, _) ->
648 generate_prototype ~single_line:true ~newline:true ~handle:"g"
649 ~prefix:"guestfs__" ~optarg_proto:Argv
651 ) non_daemon_functions
653 (* Generate the client-side dispatch stubs. *)
654 and generate_client_actions () =
655 generate_header CStyle LGPLv2plus;
662 #include <inttypes.h>
664 #include <sys/types.h>
665 #include <sys/stat.h>
668 #include \"guestfs.h\"
669 #include \"guestfs-internal.h\"
670 #include \"guestfs-internal-actions.h\"
671 #include \"guestfs_protocol.h\"
672 #include \"errnostring.h\"
674 /* Check the return message from a call for validity. */
676 check_reply_header (guestfs_h *g,
677 const struct guestfs_message_header *hdr,
678 unsigned int proc_nr, unsigned int serial)
680 if (hdr->prog != GUESTFS_PROGRAM) {
681 error (g, \"wrong program (%%d/%%d)\", hdr->prog, GUESTFS_PROGRAM);
684 if (hdr->vers != GUESTFS_PROTOCOL_VERSION) {
685 error (g, \"wrong protocol version (%%d/%%d)\",
686 hdr->vers, GUESTFS_PROTOCOL_VERSION);
689 if (hdr->direction != GUESTFS_DIRECTION_REPLY) {
690 error (g, \"unexpected message direction (%%d/%%d)\",
691 hdr->direction, GUESTFS_DIRECTION_REPLY);
694 if (hdr->proc != proc_nr) {
695 error (g, \"unexpected procedure number (%%d/%%d)\", hdr->proc, proc_nr);
698 if (hdr->serial != serial) {
699 error (g, \"unexpected serial (%%d/%%d)\", hdr->serial, serial);
706 /* Check we are in the right state to run a high-level action. */
708 check_state (guestfs_h *g, const char *caller)
710 if (!guestfs__is_ready (g)) {
711 if (guestfs__is_config (g) || guestfs__is_launching (g))
712 error (g, \"%%s: call launch before using this function\\n(in guestfish, don't forget to use the 'run' command)\",
715 error (g, \"%%s called from the wrong state, %%d != READY\",
716 caller, guestfs__get_state (g));
722 /* Convenience wrapper for tracing. */
724 trace_open (guestfs_h *g)
726 assert (g->trace_fp == NULL);
729 g->trace_fp = open_memstream (&g->trace_buf, &g->trace_len);
737 trace_send_line (guestfs_h *g)
743 fclose (g->trace_fp);
746 /* The callback might invoke other libguestfs calls, so keep
747 * a copy of the pointer to the buffer and length.
752 guestfs___call_callbacks_message (g, GUESTFS_EVENT_TRACE, buf, len);
760 (* Generate code to check String-like parameters are not passed in
761 * as NULL (returning an error if they are).
763 let check_null_strings shortname (ret, args, optargs) =
764 let pr_newline = ref false in
767 (* parameters which should not be NULL *)
779 pr " if (%s == NULL) {\n" n;
780 pr " error (g, \"%%s: %%s: parameter cannot be NULL\",\n";
781 pr " \"%s\", \"%s\");\n" shortname n;
783 match errcode_of_ret ret with
784 | `CannotReturnError ->
785 if shortname = "test0rconstoptstring" then (* XXX hack *)
789 "%s: RConstOptString function has invalid parameter '%s'"
791 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
792 pr " return %s;\n" (string_of_errcode errcode);
805 (* For optional arguments. *)
809 pr " if ((optargs->bitmask & GUESTFS_%s_%s_BITMASK) &&\n"
810 (String.uppercase shortname) (String.uppercase n);
811 pr " optargs->%s == NULL) {\n" n;
812 pr " error (g, \"%%s: %%s: optional parameter cannot be NULL\",\n";
813 pr " \"%s\", \"%s\");\n" shortname n;
815 match errcode_of_ret ret with
816 | `CannotReturnError -> assert false
817 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
818 pr " return %s;\n" (string_of_errcode errcode);
823 | Bool _ | Int _ | Int64 _ -> ()
828 if !pr_newline then pr "\n";
831 (* Generate code to reject optargs we don't know about. *)
832 let reject_unknown_optargs shortname = function
835 let len = List.length optargs in
836 let mask = Int64.lognot (Int64.pred (Int64.shift_left 1L len)) in
837 pr " if (optargs->bitmask & UINT64_C(0x%Lx)) {\n" mask;
838 pr " error (g, \"%%s: unknown option in guestfs_%%s_argv->bitmask (this can happen if a program is compiled against a newer version of libguestfs, then dynamically linked to an older version)\",\n";
839 pr " \"%s\", \"%s\");\n" shortname shortname;
841 match errcode_of_ret ret with
842 | `CannotReturnError -> assert false
843 | (`ErrorIsMinusOne |`ErrorIsNULL) as e -> e in
844 pr " return %s;\n" (string_of_errcode errcode);
849 (* Generate code to generate guestfish call traces. *)
850 let trace_call shortname (ret, args, optargs) =
851 pr " if (trace_flag) {\n";
854 List.exists (function
855 | StringList _ | DeviceList _ -> true
856 | _ -> false) args in
862 pr " trace_fp = trace_open (g);\n";
864 pr " fprintf (trace_fp, \"%%s\", \"%s\");\n" shortname;
866 (* Required arguments. *)
869 | String n (* strings *)
875 (* guestfish doesn't support string escaping, so neither do we *)
876 pr " fprintf (trace_fp, \" \\\"%%s\\\"\", %s);\n" n
878 (* don't print keys *)
879 pr " fprintf (trace_fp, \" \\\"***\\\"\");\n"
880 | OptString n -> (* string option *)
881 pr " if (%s) fprintf (trace_fp, \" \\\"%%s\\\"\", %s);\n" n n;
882 pr " else fprintf (trace_fp, \" null\");\n"
884 | DeviceList n -> (* string list *)
885 pr " fputc (' ', trace_fp);\n";
886 pr " fputc ('\"', trace_fp);\n";
887 pr " for (i = 0; %s[i]; ++i) {\n" n;
888 pr " if (i > 0) fputc (' ', trace_fp);\n";
889 pr " fputs (%s[i], trace_fp);\n" n;
891 pr " fputc ('\"', trace_fp);\n";
892 | Bool n -> (* boolean *)
893 pr " fputs (%s ? \" true\" : \" false\", trace_fp);\n" n
895 pr " fprintf (trace_fp, \" %%d\", %s);\n" n
897 pr " fprintf (trace_fp, \" %%\" PRIi64, %s);\n" n
898 | BufferIn n -> (* RHBZ#646822 *)
899 pr " fputc (' ', trace_fp);\n";
900 pr " guestfs___print_BufferIn (trace_fp, %s, %s_size);\n" n n
902 pr " fprintf (trace_fp, \" (%s)%%p\", %s);\n" t n
905 (* Optional arguments. *)
908 let n = name_of_argt argt in
909 let uc_shortname = String.uppercase shortname in
910 let uc_n = String.uppercase n in
911 pr " if (optargs->bitmask & GUESTFS_%s_%s_BITMASK)\n"
915 pr " fprintf (trace_fp, \" \\\"%%s:%%s\\\"\", \"%s\", optargs->%s);\n" n n
917 pr " fprintf (trace_fp, \" \\\"%%s:%%s\\\"\", \"%s\", optargs->%s ? \"true\" : \"false\");\n" n n
919 pr " fprintf (trace_fp, \" \\\"%%s:%%d\\\"\", \"%s\", optargs->%s);\n" n n
921 pr " fprintf (trace_fp, \" \\\"%%s:%%\" PRIi64 \"\\\"\", \"%s\", optargs->%s);\n" n n
926 pr " trace_send_line (g);\n";
931 let trace_return ?(indent = 2) shortname (ret, _, _) rv =
932 let indent = spaces indent in
934 pr "%sif (trace_flag) {\n" indent;
938 | RStringList _ | RHashtable _ -> true
941 pr "%s size_t i;\n" indent;
945 pr "%s trace_fp = trace_open (g);\n" indent;
947 pr "%s fprintf (trace_fp, \"%%s = \", \"%s\");\n" indent shortname;
950 | RErr | RInt _ | RBool _ ->
951 pr "%s fprintf (trace_fp, \"%%d\", %s);\n" indent rv
953 pr "%s fprintf (trace_fp, \"%%\" PRIi64, %s);\n" indent rv
954 | RConstString _ | RString _ ->
955 pr "%s fprintf (trace_fp, \"\\\"%%s\\\"\", %s);\n" indent rv
956 | RConstOptString _ ->
957 pr "%s fprintf (trace_fp, \"\\\"%%s\\\"\", %s != NULL ? %s : \"NULL\");\n"
960 pr "%s guestfs___print_BufferOut (trace_fp, %s, *size_r);\n" indent rv
961 | RStringList _ | RHashtable _ ->
962 pr "%s fputs (\"[\", trace_fp);\n" indent;
963 pr "%s for (i = 0; %s[i]; ++i) {\n" indent rv;
964 pr "%s if (i > 0) fputs (\", \", trace_fp);\n" indent;
965 pr "%s fputs (\"\\\"\", trace_fp);\n" indent;
966 pr "%s fputs (%s[i], trace_fp);\n" indent rv;
967 pr "%s fputs (\"\\\"\", trace_fp);\n" indent;
969 pr "%s fputs (\"]\", trace_fp);\n" indent;
970 | RStruct (_, typ) ->
971 (* XXX There is code generated for guestfish for printing
972 * these structures. We need to make it generally available
975 pr "%s fprintf (trace_fp, \"<struct guestfs_%s *>\");\n"
977 | RStructList (_, typ) ->
978 pr "%s fprintf (trace_fp, \"<struct guestfs_%s_list *>\");\n"
981 pr "%s trace_send_line (g);\n" indent;
986 let trace_return_error ?(indent = 2) shortname (ret, _, _) errcode =
987 let indent = spaces indent in
989 pr "%sif (trace_flag)\n" indent;
991 pr "%s guestfs___trace (g, \"%%s = %%s (error)\",\n" indent;
992 pr "%s \"%s\", \"%s\");\n"
993 indent shortname (string_of_errcode errcode)
996 (* For non-daemon functions, generate a wrapper around each function. *)
998 fun (shortname, (ret, _, optargs as style), _, _, _, _, _) ->
1000 generate_prototype ~extern:false ~semicolon:false ~newline:true
1001 ~handle:"g" ~prefix:"guestfs_"
1004 generate_prototype ~extern:false ~semicolon:false ~newline:true
1005 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv" ~optarg_proto:Argv
1008 pr " int trace_flag = g->trace;\n";
1009 pr " FILE *trace_fp;\n";
1011 | RErr | RInt _ | RBool _ ->
1016 pr " const char *r;\n"
1017 | RConstOptString _ ->
1018 pr " const char *r;\n"
1019 | RString _ | RBufferOut _ ->
1021 | RStringList _ | RHashtable _ ->
1023 | RStruct (_, typ) ->
1024 pr " struct guestfs_%s *r;\n" typ
1025 | RStructList (_, typ) ->
1026 pr " struct guestfs_%s_list *r;\n" typ
1029 check_null_strings shortname style;
1030 reject_unknown_optargs shortname style;
1031 trace_call shortname style;
1032 pr " r = guestfs__%s " shortname;
1033 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1036 (match errcode_of_ret ret with
1037 | (`ErrorIsMinusOne | `ErrorIsNULL) as errcode ->
1038 pr " if (r != %s) {\n" (string_of_errcode errcode);
1039 trace_return ~indent:4 shortname style "r";
1041 trace_return_error ~indent:4 shortname style errcode;
1043 | `CannotReturnError ->
1044 trace_return shortname style "r";
1050 ) non_daemon_functions;
1052 (* Client-side stubs for each function. *)
1054 fun (shortname, (ret, args, optargs as style), _, _, _, _, _) ->
1055 let name = "guestfs_" ^ shortname in
1057 match errcode_of_ret ret with
1058 | `CannotReturnError -> assert false
1059 | (`ErrorIsMinusOne | `ErrorIsNULL) as e -> e in
1061 (* Generate the action stub. *)
1062 if optargs = [] then
1063 generate_prototype ~extern:false ~semicolon:false ~newline:true
1064 ~handle:"g" ~prefix:"guestfs_" shortname style
1066 generate_prototype ~extern:false ~semicolon:false ~newline:true
1067 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_argv"
1068 ~optarg_proto:Argv shortname style;
1074 | _ -> pr " struct %s_args args;\n" name
1077 pr " guestfs_message_header hdr;\n";
1078 pr " guestfs_message_error err;\n";
1082 | RConstString _ | RConstOptString _ ->
1083 failwithf "RConstString|RConstOptString cannot be used by daemon functions"
1085 | RBool _ | RString _ | RStringList _
1086 | RStruct _ | RStructList _
1087 | RHashtable _ | RBufferOut _ ->
1088 pr " struct %s_ret ret;\n" name;
1091 pr " int serial;\n";
1093 pr " int trace_flag = g->trace;\n";
1094 pr " FILE *trace_fp;\n";
1096 | RErr | RInt _ | RBool _ ->
1099 pr " int64_t ret_v;\n"
1100 | RConstString _ | RConstOptString _ ->
1101 pr " const char *ret_v;\n"
1102 | RString _ | RBufferOut _ ->
1103 pr " char *ret_v;\n"
1104 | RStringList _ | RHashtable _ ->
1105 pr " char **ret_v;\n"
1106 | RStruct (_, typ) ->
1107 pr " struct guestfs_%s *ret_v;\n" typ
1108 | RStructList (_, typ) ->
1109 pr " struct guestfs_%s_list *ret_v;\n" typ
1113 List.exists (function FileIn _ -> true | _ -> false) args in
1114 if has_filein then (
1115 pr " uint64_t progress_hint = 0;\n";
1116 pr " struct stat progress_stat;\n";
1118 pr " const uint64_t progress_hint = 0;\n";
1121 check_null_strings shortname style;
1122 reject_unknown_optargs shortname style;
1123 trace_call shortname style;
1125 (* Calculate the total size of all FileIn arguments to pass
1126 * as a progress bar hint.
1131 pr " if (stat (%s, &progress_stat) == 0 &&\n" n;
1132 pr " S_ISREG (progress_stat.st_mode))\n";
1133 pr " progress_hint += progress_stat.st_size;\n";
1138 (* Check we are in the right state for sending a request. *)
1139 pr " if (check_state (g, \"%s\") == -1) {\n" shortname;
1140 trace_return_error ~indent:4 shortname style errcode;
1141 pr " return %s;\n" (string_of_errcode errcode);
1143 pr " guestfs___set_busy (g);\n";
1146 (* Send the main header and arguments. *)
1147 if args = [] && optargs = [] then (
1148 pr " serial = guestfs___send (g, GUESTFS_PROC_%s, progress_hint, 0,\n"
1149 (String.uppercase shortname);
1150 pr " NULL, NULL);\n"
1154 | Pathname n | Device n | Dev_or_Path n | String n | Key n ->
1155 pr " args.%s = (char *) %s;\n" n n
1157 pr " args.%s = %s ? (char **) &%s : NULL;\n" n n n
1158 | StringList n | DeviceList n ->
1159 pr " args.%s.%s_val = (char **) %s;\n" n n n;
1160 pr " for (args.%s.%s_len = 0; %s[args.%s.%s_len]; args.%s.%s_len++) ;\n" n n n n n n n;
1162 pr " args.%s = %s;\n" n n
1164 pr " args.%s = %s;\n" n n
1166 pr " args.%s = %s;\n" n n
1167 | FileIn _ | FileOut _ -> ()
1169 pr " /* Just catch grossly large sizes. XDR encoding will make this precise. */\n";
1170 pr " if (%s_size >= GUESTFS_MESSAGE_MAX) {\n" n;
1171 trace_return_error ~indent:4 shortname style errcode;
1172 pr " error (g, \"%%s: size of input buffer too large\", \"%s\");\n"
1174 pr " guestfs___end_busy (g);\n";
1175 pr " return %s;\n" (string_of_errcode errcode);
1177 pr " args.%s.%s_val = (char *) %s;\n" n n n;
1178 pr " args.%s.%s_len = %s_size;\n" n n n
1179 | Pointer _ -> assert false
1184 let n = name_of_argt argt in
1185 let uc_shortname = String.uppercase shortname in
1186 let uc_n = String.uppercase n in
1187 pr " if ((optargs->bitmask & GUESTFS_%s_%s_BITMASK))\n"
1193 pr " args.%s = optargs->%s;\n" n n;
1195 pr " args.%s = 0;\n" n
1197 pr " args.%s = (char *) optargs->%s;\n" n n;
1199 pr " args.%s = (char *) \"\";\n" n
1204 pr " serial = guestfs___send (g, GUESTFS_PROC_%s,\n"
1205 (String.uppercase shortname);
1206 pr " progress_hint, %s,\n"
1207 (if optargs <> [] then "optargs->bitmask" else "0");
1208 pr " (xdrproc_t) xdr_%s_args, (char *) &args);\n"
1211 pr " if (serial == -1) {\n";
1212 pr " guestfs___end_busy (g);\n";
1213 trace_return_error ~indent:4 shortname style errcode;
1214 pr " return %s;\n" (string_of_errcode errcode);
1218 (* Send any additional files (FileIn) requested. *)
1219 let need_read_reply_label = ref false in
1223 pr " r = guestfs___send_file (g, %s);\n" n;
1224 pr " if (r == -1) {\n";
1225 pr " guestfs___end_busy (g);\n";
1226 trace_return_error ~indent:4 shortname style errcode;
1227 pr " /* daemon will send an error reply which we discard */\n";
1228 pr " guestfs___recv_discard (g, \"%s\");\n" shortname;
1229 pr " return %s;\n" (string_of_errcode errcode);
1231 pr " if (r == -2) /* daemon cancelled */\n";
1232 pr " goto read_reply;\n";
1233 need_read_reply_label := true;
1238 (* Wait for the reply from the remote end. *)
1239 if !need_read_reply_label then pr " read_reply:\n";
1240 pr " memset (&hdr, 0, sizeof hdr);\n";
1241 pr " memset (&err, 0, sizeof err);\n";
1242 if has_ret then pr " memset (&ret, 0, sizeof ret);\n";
1244 pr " r = guestfs___recv (g, \"%s\", &hdr, &err,\n " shortname;
1248 pr "(xdrproc_t) xdr_guestfs_%s_ret, (char *) &ret" shortname;
1251 pr " if (r == -1) {\n";
1252 pr " guestfs___end_busy (g);\n";
1253 trace_return_error ~indent:4 shortname style errcode;
1254 pr " return %s;\n" (string_of_errcode errcode);
1258 pr " if (check_reply_header (g, &hdr, GUESTFS_PROC_%s, serial) == -1) {\n"
1259 (String.uppercase shortname);
1260 pr " guestfs___end_busy (g);\n";
1261 trace_return_error ~indent:4 shortname style errcode;
1262 pr " return %s;\n" (string_of_errcode errcode);
1266 pr " if (hdr.status == GUESTFS_STATUS_ERROR) {\n";
1267 trace_return_error ~indent:4 shortname style errcode;
1268 pr " int errnum = 0;\n";
1269 pr " if (err.errno_string[0] != '\\0')\n";
1270 pr " errnum = guestfs___string_to_errno (err.errno_string);\n";
1271 pr " if (errnum <= 0)\n";
1272 pr " error (g, \"%%s: %%s\", \"%s\", err.error_message);\n"
1275 pr " guestfs_error_errno (g, errnum, \"%%s: %%s\", \"%s\",\n"
1277 pr " err.error_message);\n";
1278 pr " free (err.error_message);\n";
1279 pr " free (err.errno_string);\n";
1280 pr " guestfs___end_busy (g);\n";
1281 pr " return %s;\n" (string_of_errcode errcode);
1285 (* Expecting to receive further files (FileOut)? *)
1289 pr " if (guestfs___recv_file (g, %s) == -1) {\n" n;
1290 pr " guestfs___end_busy (g);\n";
1291 trace_return_error ~indent:4 shortname style errcode;
1292 pr " return %s;\n" (string_of_errcode errcode);
1298 pr " guestfs___end_busy (g);\n";
1303 | RInt n | RInt64 n | RBool n ->
1304 pr " ret_v = ret.%s;\n" n
1305 | RConstString _ | RConstOptString _ ->
1306 failwithf "RConstString|RConstOptString cannot be used by daemon functions"
1308 pr " ret_v = ret.%s; /* caller will free */\n" n
1309 | RStringList n | RHashtable n ->
1310 pr " /* caller will free this, but we need to add a NULL entry */\n";
1311 pr " ret.%s.%s_val =\n" n n;
1312 pr " safe_realloc (g, ret.%s.%s_val,\n" n n;
1313 pr " sizeof (char *) * (ret.%s.%s_len + 1));\n"
1315 pr " ret.%s.%s_val[ret.%s.%s_len] = NULL;\n" n n n n;
1316 pr " ret_v = ret.%s.%s_val;\n" n n
1318 pr " /* caller will free this */\n";
1319 pr " ret_v = safe_memdup (g, &ret.%s, sizeof (ret.%s));\n" n n
1320 | RStructList (n, _) ->
1321 pr " /* caller will free this */\n";
1322 pr " ret_v = safe_memdup (g, &ret.%s, sizeof (ret.%s));\n" n n
1324 pr " /* RBufferOut is tricky: If the buffer is zero-length, then\n";
1325 pr " * _val might be NULL here. To make the API saner for\n";
1326 pr " * callers, we turn this case into a unique pointer (using\n";
1327 pr " * malloc(1)).\n";
1329 pr " if (ret.%s.%s_len > 0) {\n" n n;
1330 pr " *size_r = ret.%s.%s_len;\n" n n;
1331 pr " ret_v = ret.%s.%s_val; /* caller will free */\n" n n;
1333 pr " free (ret.%s.%s_val);\n" n n;
1334 pr " char *p = safe_malloc (g, 1);\n";
1335 pr " *size_r = ret.%s.%s_len;\n" n n;
1339 trace_return shortname style "ret_v";
1340 pr " return ret_v;\n";
1344 (* Functions to free structures. *)
1345 pr "/* Structure-freeing functions. These rely on the fact that the\n";
1346 pr " * structure format is identical to the XDR format. See note in\n";
1347 pr " * generator.ml.\n";
1354 pr "guestfs_free_%s (struct guestfs_%s *x)\n" typ typ;
1356 pr " xdr_free ((xdrproc_t) xdr_guestfs_int_%s, (char *) x);\n" typ;
1362 pr "guestfs_free_%s_list (struct guestfs_%s_list *x)\n" typ typ;
1364 pr " xdr_free ((xdrproc_t) xdr_guestfs_int_%s_list, (char *) x);\n" typ;
1371 (* Functions which have optional arguments have two generated variants. *)
1374 | shortname, (ret, args, (_::_ as optargs) as style), _, _, _, _, _ ->
1375 let uc_shortname = String.uppercase shortname in
1377 (* Get the name of the last regular argument. *)
1380 | RBufferOut _ -> "size_r"
1384 | args -> name_of_argt (List.hd (List.rev args)) in
1388 | RErr | RInt _ | RBool _ -> "int "
1389 | RInt64 _ -> "int64_t "
1390 | RConstString _ | RConstOptString _ -> "const char *"
1391 | RString _ | RBufferOut _ -> "char *"
1392 | RStringList _ | RHashtable _ -> "char **"
1393 | RStruct (_, typ) -> sprintf "struct guestfs_%s *" typ
1394 | RStructList (_, typ) ->
1395 sprintf "struct guestfs_%s_list *" typ in
1397 (* The regular variable args function, just calls the _va variant. *)
1398 generate_prototype ~extern:false ~semicolon:false ~newline:true
1399 ~handle:"g" ~prefix:"guestfs_" shortname style;
1401 pr " va_list optargs;\n";
1403 pr " va_start (optargs, %s);\n" last_arg;
1404 pr " %sr = guestfs_%s_va " rtype shortname;
1405 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1407 pr " va_end (optargs);\n";
1412 generate_prototype ~extern:false ~semicolon:false ~newline:true
1413 ~handle:"g" ~prefix:"guestfs_" ~suffix:"_va" ~optarg_proto:VA
1416 pr " struct guestfs_%s_argv optargs_s;\n" shortname;
1417 pr " struct guestfs_%s_argv *optargs = &optargs_s;\n" shortname;
1420 pr " optargs_s.bitmask = 0;\n";
1422 pr " while ((i = va_arg (args, int)) >= 0) {\n";
1423 pr " switch (i) {\n";
1427 let n = name_of_argt argt in
1428 let uc_n = String.uppercase n in
1429 pr " case GUESTFS_%s_%s:\n" uc_shortname uc_n;
1430 pr " optargs_s.%s = va_arg (args, " n;
1432 | Bool _ | Int _ -> pr "int"
1433 | Int64 _ -> pr "int64_t"
1434 | String _ -> pr "const char *"
1442 match errcode_of_ret ret with
1443 | `CannotReturnError -> assert false
1444 | (`ErrorIsMinusOne | `ErrorIsNULL) as e -> e in
1447 pr " error (g, \"%%s: unknown option %%d (this can happen if a program is compiled against a newer version of libguestfs, then dynamically linked to an older version)\",\n";
1448 pr " \"%s\", i);\n" shortname;
1449 pr " return %s;\n" (string_of_errcode errcode);
1452 pr " uint64_t i_mask = UINT64_C(1) << i;\n";
1453 pr " if (optargs_s.bitmask & i_mask) {\n";
1454 pr " error (g, \"%%s: same optional argument specified more than once\",\n";
1455 pr " \"%s\");\n" shortname;
1456 pr " return %s;\n" (string_of_errcode errcode);
1458 pr " optargs_s.bitmask |= i_mask;\n";
1461 pr " return guestfs_%s_argv " shortname;
1462 generate_c_call_args ~handle:"g" ~implicit_size_ptr:"size_r" style;
1466 ) all_functions_sorted
1468 (* Generate the linker script which controls the visibility of
1469 * symbols in the public ABI and ensures no other symbols get
1470 * exported accidentally.
1472 and generate_linker_script () =
1473 generate_header HashStyle GPLv2plus;
1478 "guestfs_delete_event_callback";
1479 "guestfs_first_private";
1480 "guestfs_get_error_handler";
1481 "guestfs_get_out_of_memory_handler";
1482 "guestfs_get_private";
1483 "guestfs_last_errno";
1484 "guestfs_last_error";
1485 "guestfs_next_private";
1486 "guestfs_set_close_callback";
1487 "guestfs_set_error_handler";
1488 "guestfs_set_event_callback";
1489 "guestfs_set_launch_done_callback";
1490 "guestfs_set_log_message_callback";
1491 "guestfs_set_out_of_memory_handler";
1492 "guestfs_set_private";
1493 "guestfs_set_progress_callback";
1494 "guestfs_set_subprocess_quit_callback";
1495 "guestfs_user_cancel";
1497 (* Unofficial parts of the API: the bindings code use these
1498 * functions, so it is useful to export them.
1500 "guestfs_safe_calloc";
1501 "guestfs_safe_malloc";
1502 "guestfs_safe_strdup";
1503 "guestfs_safe_memdup";
1505 "guestfs___for_each_disk";
1511 | name, (_, _, []), _, _, _, _, _ -> ["guestfs_" ^ name]
1512 | name, (_, _, _), _, _, _, _, _ ->
1514 "guestfs_" ^ name ^ "_va";
1515 "guestfs_" ^ name ^ "_argv"]
1520 List.map (fun (typ, _) ->
1521 ["guestfs_free_" ^ typ; "guestfs_free_" ^ typ ^ "_list"])
1524 let globals = List.sort compare (globals @ functions @ structs) in
1528 List.iter (pr " %s;\n") globals;
1535 and generate_max_proc_nr () =
1536 pr "%d\n" max_proc_nr