Re: [Libguestfs] [PATCH v3 06/10] mllib: ocaml wrapper for lib/osinfo

2017-02-14 Thread Richard W.M. Jones
On Fri, Feb 10, 2017 at 04:06:01PM +0100, Cédric Bosdonnat wrote:
> Provide osinfo database parsing API in OCAML.

This commit looks OK too.

I reviewed up to and including this commit.

I pushed commits 1, 2 and 3.

Thanks,

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
libguestfs lets you edit virtual machines.  Supports shell scripting,
bindings from many languages.  http://libguestfs.org

___
Libguestfs mailing list
Libguestfs@redhat.com
https://www.redhat.com/mailman/listinfo/libguestfs


[Libguestfs] [PATCH v3 06/10] mllib: ocaml wrapper for lib/osinfo

2017-02-10 Thread Cédric Bosdonnat
Provide osinfo database parsing API in OCAML.
---
 mllib/Makefile.am |  11 --
 mllib/osinfo-c.c  | 100 ++
 mllib/osinfo.ml   |  26 ++
 mllib/osinfo.mli  |  31 +
 4 files changed, 166 insertions(+), 2 deletions(-)
 create mode 100644 mllib/osinfo-c.c
 create mode 100644 mllib/osinfo.ml
 create mode 100644 mllib/osinfo.mli

diff --git a/mllib/Makefile.am b/mllib/Makefile.am
index aa5472ade..2541ce280 100644
--- a/mllib/Makefile.am
+++ b/mllib/Makefile.am
@@ -40,6 +40,7 @@ SOURCES_MLI = \
getopt.mli \
JSON.mli \
mkdtemp.mli \
+   osinfo.mli \
planner.mli \
progress.mli \
regedit.mli \
@@ -71,7 +72,8 @@ SOURCES_ML = \
exit.ml \
checksums.ml \
xml.ml \
-   xpath_helpers.ml
+   xpath_helpers.ml \
+   osinfo.ml
 
 SOURCES_C = \
../common/visit/visit.c \
@@ -79,6 +81,9 @@ SOURCES_C = \
../common/options/keys.c \
../common/options/uri.c \
../common/progress/progress.c \
+   ../lib/alloc.c \
+   ../lib/osinfo.c \
+   ../lib/osinfo.h \
common_utils-c.c \
dev_t-c.c \
exit-c.c \
@@ -86,6 +91,7 @@ SOURCES_C = \
fsync-c.c \
getopt-c.c \
mkdtemp-c.c \
+   osinfo-c.c \
progress-c.c \
statvfs-c.c \
uri-c.c \
@@ -119,7 +125,8 @@ libmllib_a_CPPFLAGS = \
-I$(top_srcdir)/lib \
-I$(top_srcdir)/common/visit \
-I$(top_srcdir)/common/options \
-   -I$(top_srcdir)/common/progress
+   -I$(top_srcdir)/common/progress \
+   -DLIBOSINFO_DB_PATH='"$(datadir)/libosinfo/db"'
 libmllib_a_CFLAGS = \
$(WARN_CFLAGS) $(WERROR_CFLAGS) \
$(LIBVIRT_CFLAGS) $(LIBXML2_CFLAGS) \
diff --git a/mllib/osinfo-c.c b/mllib/osinfo-c.c
new file mode 100644
index 0..9546c5984
--- /dev/null
+++ b/mllib/osinfo-c.c
@@ -0,0 +1,100 @@
+/* Bindings for osinfo db reading function.
+ * Copyright (C) 2017 SUSE 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 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "guestfs.h"
+#include "guestfs-internal.h"
+#include "osinfo.h"
+
+#pragma GCC diagnostic ignored "-Wmissing-prototypes"
+
+struct callback_wrapper_args {
+  /* In both case we are pointing to local roots, hence why these are
+   * value* not value.
+   */
+  value *exnp;  /* Safe place to store any exception
+   raised by callback */
+  value *fvp;   /* callback. */
+};
+
+static int read_osinfo_db_callback_wrapper (guestfs_h *g, const char *path, 
void *opaque);
+
+value
+guestfs_int_mllib_read_osinfo_db (value gv, value fv)
+{
+  CAMLparam2 (gv, fv);
+  guestfs_h *g = (guestfs_h *) Int64_val (gv);
+  struct callback_wrapper_args args;
+
+  /* This stack address is used to point to the exception, if one is
+   * raised in the visitor_function.  Note that the macro initializes
+   * this to Val_unit, which is how we know if an exception was set.
+   */
+  CAMLlocal1 (exn);
+
+  args.exnp = 
+  args.fvp = 
+
+  if (read_osinfo_db (g, read_osinfo_db_callback_wrapper, ) == -1) {
+if (exn != Val_unit) {
+  /* The failure was caused by the callback raising an
+   * exception.  Re-raise it here.
+   */
+  caml_raise (exn);
+}
+
+caml_failwith ("read_osinfo_db");
+}
+
+  CAMLreturn (Val_unit);
+}
+
+static int
+read_osinfo_db_callback_wrapper (guestfs_h *g, const char *path, void *opaque)
+{
+  CAMLparam0 ();
+  CAMLlocal2 (pathv, v);
+  struct callback_wrapper_args *args = opaque;
+
+  assert (path != NULL);
+  assert (args != NULL);
+
+  pathv = caml_copy_string (path);
+
+  v = caml_callback_exn (*args->fvp, pathv);
+
+  if (Is_exception_result (v)) {
+*args->exnp = Extract_exception (v);
+CAMLreturnT (int, -1);
+  }
+
+  /* No error, return normally. */
+  CAMLreturnT (int, 0);
+}
diff --git a/mllib/osinfo.ml b/mllib/osinfo.ml
new file mode 100644
index 0..f5afbd889
--- /dev/null
+++ b/mllib/osinfo.ml
@@ -0,0 +1,26 @@
+(* virt-builder
+ * Copyright (C) 2016 - SUSE Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ *