[libvirt] [ocaml PATCH 0/6] Split/reorganize sources

This series splits the sources in the 3 parts built on their own (instead of a whole source including everything), so it is easier to rebuild on changes. Also, improve their file names. Pino Toscano (6): Rename libvirt_c_prologue.c to libvirt_c.h Turn libvirt_c.h as proper header Build C sources separately Rename the generated libvirt_c.c to libvirt_generated.c Build libvirt_generated.c with -Wmissing-prototypes Rename libvirt_c_epilogue.c to libvirt_c_common.c .gitignore | 2 +- MANIFEST | 4 +- Makefile.in | 2 +- libvirt/Makefile.in | 22 +++---- libvirt/README | 40 ++++--------- libvirt/generator.pl | 29 ++------- libvirt/libvirt.mli | 6 +- libvirt/{libvirt_c_prologue.c => libvirt_c.h} | 60 +++++++++++++------ ...ibvirt_c_epilogue.c => libvirt_c_common.c} | 40 +++++++------ libvirt/libvirt_c_oneoffs.c | 2 + 10 files changed, 99 insertions(+), 108 deletions(-) rename libvirt/{libvirt_c_prologue.c => libvirt_c.h} (79%) rename libvirt/{libvirt_c_epilogue.c => libvirt_c_common.c} (97%) -- 2.21.0

Since it contains prototypes of functions and common macros, just rename it so it will be used as proper general header for multiple sources in the future. Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- MANIFEST | 2 +- libvirt/Makefile.in | 2 +- libvirt/README | 8 +++----- libvirt/generator.pl | 2 +- libvirt/{libvirt_c_prologue.c => libvirt_c.h} | 0 5 files changed, 6 insertions(+), 8 deletions(-) rename libvirt/{libvirt_c_prologue.c => libvirt_c.h} (100%) diff --git a/MANIFEST b/MANIFEST index e969dd5..c026fef 100644 --- a/MANIFEST +++ b/MANIFEST @@ -19,9 +19,9 @@ gitlog-to-changelog install-sh libvirt/.depend libvirt/generator.pl +libvirt/libvirt_c.h libvirt/libvirt_c_epilogue.c libvirt/libvirt_c_oneoffs.c -libvirt/libvirt_c_prologue.c libvirt/libvirt.ml libvirt/libvirt.mli libvirt/libvirt_version.ml.in diff --git a/libvirt/Makefile.in b/libvirt/Makefile.in index f255ee2..8451c5d 100644 --- a/libvirt/Makefile.in +++ b/libvirt/Makefile.in @@ -104,7 +104,7 @@ libvirt_c.c: generator.pl $(PERL) -w $< # Extra dependencies. -libvirt_c.c: libvirt_c_prologue.c +libvirt_c.c: libvirt_c.h libvirt_c.c: libvirt_c_oneoffs.c libvirt_c.c: libvirt_c_epilogue.c diff --git a/libvirt/README b/libvirt/README index be8300d..0109940 100644 --- a/libvirt/README +++ b/libvirt/README @@ -10,6 +10,9 @@ documentation starting at html/index.html. 'libvirt_c*.c' are the C functions which map OCaml objects to C objects and vice versa (see next section). +'libvirt_c.h' contains prototypes of common functions defined +in the epilogue (see below), and provides some general macros. + Generated code -------------- @@ -27,11 +30,6 @@ directory to find out how we're doing. The generated 'libvirt_c.c' #includes some other C files in this directory: - #include "libvirt_c_prologue.c" - - A prologue that prototypes some static functions which are defined - in the epilogue (see below), and provides some general macros. - #include "libvirt_c_oneoffs.c" One-off bindings: Bindings which are too specialised or one-of-a-kind diff --git a/libvirt/generator.pl b/libvirt/generator.pl index 279331a..92d5a64 100755 --- a/libvirt/generator.pl +++ b/libvirt/generator.pl @@ -249,7 +249,7 @@ print F <<'END'; #include <caml/mlvalues.h> #include <caml/signals.h> -#include "libvirt_c_prologue.c" +#include "libvirt_c.h" #include "libvirt_c_oneoffs.c" diff --git a/libvirt/libvirt_c_prologue.c b/libvirt/libvirt_c.h similarity index 100% rename from libvirt/libvirt_c_prologue.c rename to libvirt/libvirt_c.h -- 2.21.0

- make sure that all the function declarations are non-static, so the header can be included by more than one C source - move all the common includes there from the generated file from generator.pl - add include guard for it, even if it will not be used in practice Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- libvirt/generator.pl | 17 ---------- libvirt/libvirt_c.h | 60 ++++++++++++++++++++++++------------ libvirt/libvirt_c_epilogue.c | 38 +++++++++++------------ 3 files changed, 60 insertions(+), 55 deletions(-) diff --git a/libvirt/generator.pl b/libvirt/generator.pl index 92d5a64..61526c0 100755 --- a/libvirt/generator.pl +++ b/libvirt/generator.pl @@ -232,23 +232,6 @@ print F <<'END'; * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <libvirt/libvirt.h> -#include <libvirt/virterror.h> - -#include <caml/config.h> -#include <caml/alloc.h> -#include <caml/callback.h> -#include <caml/custom.h> -#include <caml/fail.h> -#include <caml/memory.h> -#include <caml/misc.h> -#include <caml/mlvalues.h> -#include <caml/signals.h> - #include "libvirt_c.h" #include "libvirt_c_oneoffs.c" diff --git a/libvirt/libvirt_c.h b/libvirt/libvirt_c.h index 8533618..541d8e3 100644 --- a/libvirt/libvirt_c.h +++ b/libvirt/libvirt_c.h @@ -18,18 +18,38 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifndef LIBVIRT_C_H +#define LIBVIRT_C_H + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <libvirt/libvirt.h> +#include <libvirt/virterror.h> + +#include <caml/config.h> +#include <caml/alloc.h> +#include <caml/callback.h> +#include <caml/custom.h> +#include <caml/fail.h> +#include <caml/memory.h> +#include <caml/misc.h> +#include <caml/mlvalues.h> +#include <caml/signals.h> + /* Please read libvirt/README file. */ -static const char *Optstring_val (value strv); +const char *Optstring_val (value strv); typedef value (*Val_ptr_t) (void *); -static value Val_opt (void *ptr, Val_ptr_t Val_ptr); +value Val_opt (void *ptr, Val_ptr_t Val_ptr); typedef value (*Val_const_ptr_t) (const void *); -static value Val_opt_const (const void *ptr, Val_const_ptr_t Val_ptr); -/*static value option_default (value option, value deflt);*/ -static void _raise_virterror (const char *fn) Noreturn; -static value Val_virterror (virErrorPtr err); -static int _list_length (value listv); -static value Val_virconnectcredential (const virConnectCredentialPtr cred); +value Val_opt_const (const void *ptr, Val_const_ptr_t Val_ptr); +/*value option_default (value option, value deflt);*/ +void _raise_virterror (const char *fn) Noreturn; +value Val_virterror (virErrorPtr err); +int _list_length (value listv); +value Val_virconnectcredential (const virConnectCredentialPtr cred); /* Use this around synchronous libvirt API calls to release the OCaml * lock, allowing other threads to run simultaneously. 'code' must not @@ -106,12 +126,12 @@ static value Val_virconnectcredential (const virConnectCredentialPtr cred); #define Sec_val(rv) (*((virSecretPtr *)Data_custom_val(rv))) /* Wrap up a pointer to something in a custom block. */ -static value Val_connect (virConnectPtr conn); -static value Val_dom (virDomainPtr dom); -static value Val_net (virNetworkPtr net); -static value Val_pol (virStoragePoolPtr pool); -static value Val_vol (virStorageVolPtr vol); -static value Val_sec (virSecretPtr sec); +value Val_connect (virConnectPtr conn); +value Val_dom (virDomainPtr dom); +value Val_net (virNetworkPtr net); +value Val_pol (virStoragePoolPtr pool); +value Val_vol (virStorageVolPtr vol); +value Val_sec (virSecretPtr sec); /* Domains and networks are stored as pairs (dom/net, conn), so have * some convenience functions for unwrapping and wrapping them. @@ -127,8 +147,10 @@ static value Val_sec (virSecretPtr sec); #define Connect_volv(rv) (Connect_val(Field((rv),1))) #define Connect_secv(rv) (Connect_val(Field((rv),1))) -static value Val_domain (virDomainPtr dom, value connv); -static value Val_network (virNetworkPtr net, value connv); -static value Val_pool (virStoragePoolPtr pol, value connv); -static value Val_volume (virStorageVolPtr vol, value connv); -static value Val_secret (virSecretPtr sec, value connv); +value Val_domain (virDomainPtr dom, value connv); +value Val_network (virNetworkPtr net, value connv); +value Val_pool (virStoragePoolPtr pol, value connv); +value Val_volume (virStorageVolPtr vol, value connv); +value Val_secret (virSecretPtr sec, value connv); + +#endif diff --git a/libvirt/libvirt_c_epilogue.c b/libvirt/libvirt_c_epilogue.c index 37efc43..e58f7bb 100644 --- a/libvirt/libvirt_c_epilogue.c +++ b/libvirt/libvirt_c_epilogue.c @@ -20,7 +20,7 @@ /* Please read libvirt/README file. */ -static const char * +const char * Optstring_val (value strv) { if (strv == Val_int (0)) /* None */ @@ -29,7 +29,7 @@ Optstring_val (value strv) return String_val (Field (strv, 0)); } -static value +value Val_opt (void *ptr, Val_ptr_t Val_ptr) { CAMLparam0 (); @@ -45,7 +45,7 @@ Val_opt (void *ptr, Val_ptr_t Val_ptr) CAMLreturn (optv); } -static value +value Val_opt_const (const void *ptr, Val_const_ptr_t Val_ptr) { CAMLparam0 (); @@ -62,7 +62,7 @@ Val_opt_const (const void *ptr, Val_const_ptr_t Val_ptr) } #if 0 -static value +value option_default (value option, value deflt) { if (option == Val_int (0)) /* "None" */ @@ -72,7 +72,7 @@ option_default (value option, value deflt) } #endif -static void +void _raise_virterror (const char *fn) { CAMLparam0 (); @@ -100,7 +100,7 @@ _raise_virterror (const char *fn) (void) caml__frame; } -static int +int _list_length (value listv) { CAMLparam1 (listv); @@ -111,7 +111,7 @@ _list_length (value listv) CAMLreturnT (int, len); } -static value +value Val_virconnectcredential (const virConnectCredentialPtr cred) { CAMLparam0 (); @@ -196,7 +196,7 @@ Val_err_level (virErrorLevel code) } /* Convert a virterror to a value. */ -static value +value Val_virterror (virErrorPtr err) { CAMLparam0 (); @@ -283,7 +283,7 @@ static struct custom_operations sec_custom_operations = { custom_deserialize_default }; -static value +value Val_connect (virConnectPtr conn) { CAMLparam0 (); @@ -294,7 +294,7 @@ Val_connect (virConnectPtr conn) CAMLreturn (rv); } -static value +value Val_dom (virDomainPtr dom) { CAMLparam0 (); @@ -305,7 +305,7 @@ Val_dom (virDomainPtr dom) CAMLreturn (rv); } -static value +value Val_net (virNetworkPtr net) { CAMLparam0 (); @@ -316,7 +316,7 @@ Val_net (virNetworkPtr net) CAMLreturn (rv); } -static value +value Val_pol (virStoragePoolPtr pol) { CAMLparam0 (); @@ -327,7 +327,7 @@ Val_pol (virStoragePoolPtr pol) CAMLreturn (rv); } -static value +value Val_vol (virStorageVolPtr vol) { CAMLparam0 (); @@ -338,7 +338,7 @@ Val_vol (virStorageVolPtr vol) CAMLreturn (rv); } -static value +value Val_sec (virSecretPtr sec) { CAMLparam0 (); @@ -350,7 +350,7 @@ Val_sec (virSecretPtr sec) } /* This wraps up the (dom, conn) pair (Domain.t). */ -static value +value Val_domain (virDomainPtr dom, value connv) { CAMLparam1 (connv); @@ -364,7 +364,7 @@ Val_domain (virDomainPtr dom, value connv) } /* This wraps up the (net, conn) pair (Network.t). */ -static value +value Val_network (virNetworkPtr net, value connv) { CAMLparam1 (connv); @@ -378,7 +378,7 @@ Val_network (virNetworkPtr net, value connv) } /* This wraps up the (pol, conn) pair (Pool.t). */ -static value +value Val_pool (virStoragePoolPtr pol, value connv) { CAMLparam1 (connv); @@ -392,7 +392,7 @@ Val_pool (virStoragePoolPtr pol, value connv) } /* This wraps up the (vol, conn) pair (Volume.t). */ -static value +value Val_volume (virStorageVolPtr vol, value connv) { CAMLparam1 (connv); @@ -406,7 +406,7 @@ Val_volume (virStorageVolPtr vol, value connv) } /* This wraps up the (sec, conn) pair (Secret.t). */ -static value +value Val_secret (virSecretPtr sec, value connv) { CAMLparam1 (connv); -- 2.21.0

Instead of including everything in a single C source, build all the 3 C sources separately. Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- libvirt/Makefile.in | 14 +++++++------- libvirt/README | 28 ++++++---------------------- libvirt/generator.pl | 4 ---- libvirt/libvirt_c_epilogue.c | 2 ++ libvirt/libvirt_c_oneoffs.c | 2 ++ 5 files changed, 17 insertions(+), 33 deletions(-) diff --git a/libvirt/Makefile.in b/libvirt/Makefile.in index 8451c5d..ad56bb5 100644 --- a/libvirt/Makefile.in +++ b/libvirt/Makefile.in @@ -64,10 +64,10 @@ OPTOBJS := libvirt.cmx libvirt_version.cmx ifneq ($(OCAMLMKLIB),) # Good, we can just use ocamlmklib -mllibvirt.cma: libvirt_c.o $(COBJS) +mllibvirt.cma: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(COBJS) $(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) -mllibvirt.cmxa: libvirt_c.o $(OPTOBJS) +mllibvirt.cmxa: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(OPTOBJS) $(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) else @@ -83,11 +83,11 @@ mllibvirt.cmxa: libmllibvirt.a $(OPTOBJS) $(OCAMLOPT) -a -linkall -o $@ $(OPTOBJS) \ -cclib -lmllibvirt -cclib "$(LDFLAGS)" -dllmllibvirt.dll: libvirt_c.o +dllmllibvirt.dll: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(CC) -shared -o $@ $^ \ $(LDFLAGS) "$(shell ocamlc -where)"/ocamlrun.a -libmllibvirt.a: libvirt_c.o +libmllibvirt.a: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o ar rc $@ $^ ranlib $@ @@ -104,9 +104,9 @@ libvirt_c.c: generator.pl $(PERL) -w $< # Extra dependencies. -libvirt_c.c: libvirt_c.h -libvirt_c.c: libvirt_c_oneoffs.c -libvirt_c.c: libvirt_c_epilogue.c +libvirt_c.o: libvirt_c.h +libvirt_c_oneoffs.o: libvirt_c.h +libvirt_c_epilogue.o: libvirt_c.h # Status of automatically generated bindings. autostatus: libvirt_c.c diff --git a/libvirt/README b/libvirt/README index 0109940..3fb8f53 100644 --- a/libvirt/README +++ b/libvirt/README @@ -7,12 +7,15 @@ documentation starting at html/index.html. 'libvirt.ml' describes how OCaml functions map to C functions. -'libvirt_c*.c' are the C functions which map OCaml objects to C -objects and vice versa (see next section). - 'libvirt_c.h' contains prototypes of common functions defined in the epilogue (see below), and provides some general macros. +'libvirt_c_epilogue.c' contains some standard functions (eg.) for +wrapping and unwrapping libvirt objects. + +'libvirt_c_oneoffs.c' contains bindings which are too specialised or +one-of-a-kind to be worth generating automatically. + Generated code -------------- @@ -26,22 +29,3 @@ there are a few one-off bindings (eg. one-of-a-type functions, functions with particularly complex mappings). Our eventual aim to is autogenerate as much as possible. Use 'make autostatus' in this directory to find out how we're doing. - -The generated 'libvirt_c.c' #includes some other C files in this -directory: - - #include "libvirt_c_oneoffs.c" - - One-off bindings: Bindings which are too specialised or one-of-a-kind - to be worth generating automatically. - - [Followed by generated bindings, then ...] - - #include "libvirt_c_epilogue.c" - - An epilogue which defines some standard static functions (eg.) for - wrapping and unwrapping libvirt objects. - -The key to understanding the generator is to look at the generated -code (libvirt_c.c) first, and go from there back to parts of the -generator script. diff --git a/libvirt/generator.pl b/libvirt/generator.pl index 61526c0..eb329a0 100755 --- a/libvirt/generator.pl +++ b/libvirt/generator.pl @@ -234,8 +234,6 @@ print F <<'END'; #include "libvirt_c.h" -#include "libvirt_c_oneoffs.c" - END #---------------------------------------------------------------------- @@ -880,8 +878,6 @@ END # Write the epilogue. print F <<'END'; -#include "libvirt_c_epilogue.c" - /* EOF */ END diff --git a/libvirt/libvirt_c_epilogue.c b/libvirt/libvirt_c_epilogue.c index e58f7bb..3baf290 100644 --- a/libvirt/libvirt_c_epilogue.c +++ b/libvirt/libvirt_c_epilogue.c @@ -20,6 +20,8 @@ /* Please read libvirt/README file. */ +#include "libvirt_c.h" + const char * Optstring_val (value strv) { diff --git a/libvirt/libvirt_c_oneoffs.c b/libvirt/libvirt_c_oneoffs.c index 0a9e485..6f56f10 100644 --- a/libvirt/libvirt_c_oneoffs.c +++ b/libvirt/libvirt_c_oneoffs.c @@ -19,6 +19,8 @@ /* Please read libvirt/README file. */ +#include "libvirt_c.h" + #ifdef __GNUC__ #pragma GCC diagnostic ignored "-Wmissing-prototypes" #endif -- 2.21.0

Make it clear it is a generated source. Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- .gitignore | 2 +- Makefile.in | 2 +- libvirt/Makefile.in | 18 +++++++++--------- libvirt/README | 6 +++--- libvirt/generator.pl | 4 ++-- libvirt/libvirt.mli | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/.gitignore b/.gitignore index 840c0c4..c52c1b8 100644 --- a/.gitignore +++ b/.gitignore @@ -28,7 +28,7 @@ core.* /examples/list_secrets /examples/node_info /html/ -/libvirt/libvirt_c.c +/libvirt/libvirt_generated.c /libvirt/libvirt_version.ml /ocaml-libvirt-*.exe /ocaml-libvirt-*.tar.gz diff --git a/Makefile.in b/Makefile.in index e50600a..4357ba6 100644 --- a/Makefile.in +++ b/Makefile.in @@ -35,7 +35,7 @@ clean: for d in . $(SUBDIRS); do \ (cd $$d; rm -f *.cmi *.cmo *.cmx *.cma *.cmxa *.o *.a *.so *.opt *~ *.dll *.exe core); \ done - rm -f libvirt/libvirt_c.c + rm -f libvirt/libvirt_generated.c rm -f examples/list_domains rm -f examples/node_info rm -f examples/get_cpu_stats diff --git a/libvirt/Makefile.in b/libvirt/Makefile.in index ad56bb5..d78056b 100644 --- a/libvirt/Makefile.in +++ b/libvirt/Makefile.in @@ -64,10 +64,10 @@ OPTOBJS := libvirt.cmx libvirt_version.cmx ifneq ($(OCAMLMKLIB),) # Good, we can just use ocamlmklib -mllibvirt.cma: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(COBJS) +mllibvirt.cma: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(COBJS) $(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) -mllibvirt.cmxa: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(OPTOBJS) +mllibvirt.cmxa: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(OPTOBJS) $(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) else @@ -83,11 +83,11 @@ mllibvirt.cmxa: libmllibvirt.a $(OPTOBJS) $(OCAMLOPT) -a -linkall -o $@ $(OPTOBJS) \ -cclib -lmllibvirt -cclib "$(LDFLAGS)" -dllmllibvirt.dll: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o +dllmllibvirt.dll: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(CC) -shared -o $@ $^ \ $(LDFLAGS) "$(shell ocamlc -where)"/ocamlrun.a -libmllibvirt.a: libvirt_c.o libvirt_c_oneoffs.o libvirt_c_epilogue.o +libmllibvirt.a: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_epilogue.o ar rc $@ $^ ranlib $@ @@ -100,24 +100,24 @@ endif endif # Automatically generate the C code from a Perl script 'generator.pl'. -libvirt_c.c: generator.pl +libvirt_generated.c: generator.pl $(PERL) -w $< # Extra dependencies. -libvirt_c.o: libvirt_c.h +libvirt_generated.o: libvirt_c.h libvirt_c_oneoffs.o: libvirt_c.h libvirt_c_epilogue.o: libvirt_c.h # Status of automatically generated bindings. -autostatus: libvirt_c.c +autostatus: libvirt_generated.c @echo -n "Functions which have manual bindings: " @grep ^ocaml_libvirt_ libvirt_c_oneoffs.c | wc -l @echo -n "Functions which have automatic bindings: " - @grep ^ocaml_libvirt_ libvirt_c.c | wc -l + @grep ^ocaml_libvirt_ libvirt_generated.c | wc -l @echo -n "LOC in manual bindings: " @wc -l < libvirt_c_oneoffs.c @echo -n "LOC in automatic bindings: " - @wc -l < libvirt_c.c + @wc -l < libvirt_generated.c install-byte: diff --git a/libvirt/README b/libvirt/README index 3fb8f53..197a07a 100644 --- a/libvirt/README +++ b/libvirt/README @@ -19,9 +19,9 @@ one-of-a-kind to be worth generating automatically. Generated code -------------- -The C bindings in 'libvirt_c.c' are now generated automatically by a -Perl script called 'generator.pl'. You do not normally need to run -this script, but you may need to if you want to extend libvirt +The C bindings in 'libvirt_generated.c' are now generated automatically +by a Perl script called 'generator.pl'. You do not normally need to +run this script, but you may need to if you want to extend libvirt coverage. The majority of the functions are now generated automatically, but diff --git a/libvirt/generator.pl b/libvirt/generator.pl index eb329a0..cb2b845 100755 --- a/libvirt/generator.pl +++ b/libvirt/generator.pl @@ -19,7 +19,7 @@ # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA -# This generates libvirt_c.c (the core of the bindings). You don't +# This generates libvirt_generated.c (the core of the bindings). You don't # need to run this program unless you are extending the bindings # themselves (eg. because libvirt has been extended). # @@ -199,7 +199,7 @@ my @unimplemented = ( # Open the output file. -my $filename = "libvirt_c.c"; +my $filename = "libvirt_generated.c"; open F, ">$filename" or die "$filename: $!"; # Write the prologue. diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli index 72e83f9..0739702 100644 --- a/libvirt/libvirt.mli +++ b/libvirt/libvirt.mli @@ -1574,7 +1574,7 @@ sig | VIR_ERR_NONE | VIR_ERR_WARNING | VIR_ERR_ERROR - (* ^^ NB: If you add a variant you MUST edit libvirt_c.c: MAX_VIR_* *) + (* ^^ NB: If you add a variant you MUST edit libvirt_generated.c: MAX_VIR_* *) | VIR_ERR_UNKNOWN_LEVEL of int (** Other level, not handled with existing values. *) (** No error, a warning or an error. *) -- 2.21.0

There are no prototypes for the autogenerated C functions, so build this source with that too. Previously it was pulled in when all the sources were built as one. Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- libvirt/generator.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libvirt/generator.pl b/libvirt/generator.pl index cb2b845..ac3dd65 100755 --- a/libvirt/generator.pl +++ b/libvirt/generator.pl @@ -234,6 +234,10 @@ print F <<'END'; #include "libvirt_c.h" +#ifdef __GNUC__ +#pragma GCC diagnostic ignored "-Wmissing-prototypes" +#endif + END #---------------------------------------------------------------------- -- 2.21.0

Make it clear it contains common code, and it is no more the final part of some other source. Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- MANIFEST | 2 +- libvirt/Makefile.in | 10 +++++----- libvirt/README | 2 +- libvirt/libvirt.mli | 4 ++-- libvirt/{libvirt_c_epilogue.c => libvirt_c_common.c} | 0 5 files changed, 9 insertions(+), 9 deletions(-) rename libvirt/{libvirt_c_epilogue.c => libvirt_c_common.c} (100%) diff --git a/MANIFEST b/MANIFEST index c026fef..b6a7707 100644 --- a/MANIFEST +++ b/MANIFEST @@ -20,7 +20,7 @@ install-sh libvirt/.depend libvirt/generator.pl libvirt/libvirt_c.h -libvirt/libvirt_c_epilogue.c +libvirt/libvirt_c_common.c libvirt/libvirt_c_oneoffs.c libvirt/libvirt.ml libvirt/libvirt.mli diff --git a/libvirt/Makefile.in b/libvirt/Makefile.in index d78056b..2fa445b 100644 --- a/libvirt/Makefile.in +++ b/libvirt/Makefile.in @@ -64,10 +64,10 @@ OPTOBJS := libvirt.cmx libvirt_version.cmx ifneq ($(OCAMLMKLIB),) # Good, we can just use ocamlmklib -mllibvirt.cma: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(COBJS) +mllibvirt.cma: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_common.o $(COBJS) $(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) -mllibvirt.cmxa: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_epilogue.o $(OPTOBJS) +mllibvirt.cmxa: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_common.o $(OPTOBJS) $(OCAMLMKLIB) -o mllibvirt $^ $(LDFLAGS) else @@ -83,11 +83,11 @@ mllibvirt.cmxa: libmllibvirt.a $(OPTOBJS) $(OCAMLOPT) -a -linkall -o $@ $(OPTOBJS) \ -cclib -lmllibvirt -cclib "$(LDFLAGS)" -dllmllibvirt.dll: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_epilogue.o +dllmllibvirt.dll: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_common.o $(CC) -shared -o $@ $^ \ $(LDFLAGS) "$(shell ocamlc -where)"/ocamlrun.a -libmllibvirt.a: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_epilogue.o +libmllibvirt.a: libvirt_generated.o libvirt_c_oneoffs.o libvirt_c_common.o ar rc $@ $^ ranlib $@ @@ -106,7 +106,7 @@ libvirt_generated.c: generator.pl # Extra dependencies. libvirt_generated.o: libvirt_c.h libvirt_c_oneoffs.o: libvirt_c.h -libvirt_c_epilogue.o: libvirt_c.h +libvirt_c_common.o: libvirt_c.h # Status of automatically generated bindings. autostatus: libvirt_generated.c diff --git a/libvirt/README b/libvirt/README index 197a07a..fb8e7f5 100644 --- a/libvirt/README +++ b/libvirt/README @@ -10,7 +10,7 @@ documentation starting at html/index.html. 'libvirt_c.h' contains prototypes of common functions defined in the epilogue (see below), and provides some general macros. -'libvirt_c_epilogue.c' contains some standard functions (eg.) for +'libvirt_c_common.c' contains some standard functions (eg.) for wrapping and unwrapping libvirt objects. 'libvirt_c_oneoffs.c' contains bindings which are too specialised or diff --git a/libvirt/libvirt.mli b/libvirt/libvirt.mli index 0739702..cbcf616 100644 --- a/libvirt/libvirt.mli +++ b/libvirt/libvirt.mli @@ -1485,7 +1485,7 @@ sig | VIR_ERR_NETWORK_PORT_EXIST | VIR_ERR_NO_NETWORK_PORT (* ^^ NB: If you add a variant you MUST edit - libvirt_c_epilogue.c:MAX_VIR_* *) + libvirt_c_common.c:MAX_VIR_* *) | VIR_ERR_UNKNOWN of int (** Other error, not handled with existing values. *) (** See [<libvirt/virterror.h>] for meaning of these codes. *) @@ -1564,7 +1564,7 @@ sig | VIR_FROM_DOMAIN_CHECKPOINT | VIR_FROM_TPM (* ^^ NB: If you add a variant you MUST edit - libvirt_c_epilogue.c: MAX_VIR_* *) + libvirt_c_common.c: MAX_VIR_* *) | VIR_FROM_UNKNOWN of int (** Other domain, not handled with existing values. *) (** Subsystem / driver which produced the error. *) diff --git a/libvirt/libvirt_c_epilogue.c b/libvirt/libvirt_c_common.c similarity index 100% rename from libvirt/libvirt_c_epilogue.c rename to libvirt/libvirt_c_common.c -- 2.21.0

This is all fine. Should we try to use a linker script to hide the public symbols from patch 2? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top

On Tuesday, 3 September 2019 13:04:14 CEST Richard W.M. Jones wrote:
This is all fine. Should we try to use a linker script to hide the public symbols from patch 2?
Makes sense -- let me post a followup. Thanks, -- Pino Toscano

Use a GCC pragma to hide all the internal helpers, so they are not exposed as public symbols of the stub library. Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- libvirt/libvirt_c.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/libvirt/libvirt_c.h b/libvirt/libvirt_c.h index 541d8e3..45937f6 100644 --- a/libvirt/libvirt_c.h +++ b/libvirt/libvirt_c.h @@ -40,6 +40,13 @@ /* Please read libvirt/README file. */ +/* Make sure to not expose our internal helpers as public symbols. + * https://gcc.gnu.org/wiki/Visibility + */ +#ifdef __GNUC__ +#pragma GCC visibility push(hidden) +#endif + const char *Optstring_val (value strv); typedef value (*Val_ptr_t) (void *); value Val_opt (void *ptr, Val_ptr_t Val_ptr); @@ -153,4 +160,8 @@ value Val_pool (virStoragePoolPtr pol, value connv); value Val_volume (virStorageVolPtr vol, value connv); value Val_secret (virSecretPtr sec, value connv); +#ifdef __GNUC__ +#pragma GCC visibility pop +#endif + #endif -- 2.21.0

On Tue, Sep 03, 2019 at 01:41:16PM +0200, Pino Toscano wrote:
Use a GCC pragma to hide all the internal helpers, so they are not exposed as public symbols of the stub library.
Signed-off-by: Pino Toscano <ptoscano@redhat.com> --- libvirt/libvirt_c.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
diff --git a/libvirt/libvirt_c.h b/libvirt/libvirt_c.h index 541d8e3..45937f6 100644 --- a/libvirt/libvirt_c.h +++ b/libvirt/libvirt_c.h @@ -40,6 +40,13 @@
/* Please read libvirt/README file. */
+/* Make sure to not expose our internal helpers as public symbols. + * https://gcc.gnu.org/wiki/Visibility + */ +#ifdef __GNUC__ +#pragma GCC visibility push(hidden) +#endif + const char *Optstring_val (value strv); typedef value (*Val_ptr_t) (void *); value Val_opt (void *ptr, Val_ptr_t Val_ptr); @@ -153,4 +160,8 @@ value Val_pool (virStoragePoolPtr pol, value connv); value Val_volume (virStorageVolPtr vol, value connv); value Val_secret (virSecretPtr sec, value connv);
+#ifdef __GNUC__ +#pragma GCC visibility pop +#endif + #endif
Even better :-) ACK series. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-df lists disk usage of guests without needing to install any software inside the virtual machine. Supports Linux and Windows. http://people.redhat.com/~rjones/virt-df/
participants (2)
-
Pino Toscano
-
Richard W.M. Jones