[libvirt] [ocaml PATCH 2/6] Turn libvirt_c.h as proper header

Pino Toscano ptoscano at redhat.com
Tue Sep 3 08:43:02 UTC 2019


- 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 at 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




More information about the libvir-list mailing list