[Libguestfs] [PATCH 02/10] gobject: Add GObject bindings

Richard W.M. Jones rjones at redhat.com
Fri Jan 20 12:37:27 UTC 2012


On Fri, Jan 20, 2012 at 11:07:45AM +0000, Matthew Booth wrote:
> ---
>  .gitignore                     |    4 +
>  Makefile.am                    |    3 +
>  configure.ac                   |   37 ++
>  generator/Makefile.am          |    1 +
>  generator/generator_gobject.ml |  878 ++++++++++++++++++++++++++++++++++++++++
>  generator/generator_main.ml    |    3 +
>  gobject/Makefile.am            |   41 ++
>  m4/introspection.m4            |   94 +++++
>  po/POTFILES.in                 |    1 +
>  9 files changed, 1062 insertions(+), 0 deletions(-)
>  create mode 100644 generator/generator_gobject.ml
>  create mode 100644 gobject/Makefile.am
>  create mode 100644 m4/introspection.m4
> 
> diff --git a/.gitignore b/.gitignore
> index 36411aa..b970108 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -120,6 +120,10 @@ generator/stamp-generator
>  .git-module-status
>  /gnulib
>  /GNUmakefile
> +gobject/Guestfs-1.0.gir
> +gobject/Guestfs-1.0.typelib
> +gobject/guestfs-gobject.c
> +gobject/guestfs-gobject.h
>  .guestfs-*
>  guestfs.*
>  guestfsd-in-wine.log
> diff --git a/Makefile.am b/Makefile.am
> index f925529..839379a 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -79,6 +79,9 @@ endif
>  if HAVE_ERLANG
>  SUBDIRS += erlang erlang/examples
>  endif
> +if HAVE_GOBJECT
> +SUBDIRS += gobject
> +endif
>  
>  # Unconditional because nothing is built yet.
>  SUBDIRS += csharp
> diff --git a/configure.ac b/configure.ac
> index ce0f6e8..2ca0c47 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -996,6 +996,38 @@ AS_IF([test "x$PERL" != "xno"],
>  AM_CONDITIONAL([HAVE_TOOLS],
>      [test "x$PERL" != "xno" && test "x$missing_perl_modules" != "xyes"])
>  
> +dnl gobject library
> +AC_ARG_ENABLE([gobject],
> +    AS_HELP_STRING([--disable-gobject], [Disable GObject bindings]),
> +    [],
> +    [enable_gobject=yes])
> +AS_IF(
> +  [test "x$enable_gobject" != "xno"],
> +  [
> +    PKG_CHECK_MODULES([GOBJECT], [gobject-2.0],
> +      [
> +        AC_SUBST([GOBJECT_CFLAGS])
> +        AC_SUBST([GOBJECT_LIBS])
> +        AC_DEFINE([HAVE_GOBJECT],[1],
> +                  [gobject library found at compile time.])
> +      ],
> +      [AC_MSG_WARN([gobject library not found, gobject binding will be disabled])]
> +    )
> +  ]
> +)
> +AM_CONDITIONAL([HAVE_GOBJECT],[test "x$GOBJECT_LIBS" != "x"])
> +
> +dnl gobject introspection
> +GOBJECT_INTROSPECTION_CHECK([1.30.0])

./autogen.sh gives me the following hard error:

  ./configure: line 51409: syntax error near unexpected token `1.30.0'
  ./configure: line 51409: `GOBJECT_INTROSPECTION_CHECK(1.30.0)'

I had to comment out this line in order to continue with my tests.

> +dnl The above check automatically sets HAVE_INTROSPECTION, but we want this to
> +dnl be conditional on gobject also being available. We can't move the above
> +dnl check inside the gobject if block above or HAVE_INTROSPECTION ends up
> +dnl undefined, so we recheck it here.
> +AM_CONDITIONAL([HAVE_INTROSPECTION],
> +               [test "x$HAVE_INTROSPECTION_TRUE" = "x" &&
> +                test "x$HAVE_GOBJECT_TRUE" = "x"])

Is it not possible to put AM_CONDITIONAL([HAVE_INTROSPECTION],[false])
in the else-clause of the conditional?  I know that automake
conditionals are a hack though so this might not work ...

Unless 'gjs' is a dependency of GObject (everywhere, including on
Debian etc), we need to check inside the conditional that gjs is
installed, because it is used in the tests.

> diff --git a/generator/generator_gobject.ml b/generator/generator_gobject.ml
> new file mode 100644
> index 0000000..b01cdb3
> --- /dev/null
> +++ b/generator/generator_gobject.ml
> @@ -0,0 +1,878 @@
> +(* libguestfs
> + * Copyright (C) 2012 Red Hat 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
> + *)
> +
> +(* Please read generator/README first. *)
> +
> +open Str
> +
> +open Generator_actions
> +open Generator_docstrings
> +open Generator_pr
> +open Generator_structs
> +open Generator_types
> +open Generator_utils
> +
> +let rec camel_of_name flags name =
> +  "Guestfs" ^
> +  try
> +    find_map (function CamelName n -> Some n | _ -> None) flags
> +  with Not_found ->
> +    List.fold_left (
> +      fun a b ->
> +        a ^ String.uppercase (Str.first_chars b 1) ^ Str.string_after b 1
> +    ) "" (Str.split (regexp "_") name)

This function isn't recursive, so you can just use 'let' here.  (I
know that the whole file is one large 'let rec ... and' but that's not
good style).

> +and returns_error (ret:Generator_types.ret) = match ret with
> +  | RConstOptString _ -> false
> +  | _ -> true

You can write this as:

  let returns_error = function
  | RConstOptString _ -> false
  | _ -> true

There shouldn't be any need for a type annotation, but if there was,
since Generator_types is 'open', you could have written (ret : ret).

> diff --git a/gobject/Makefile.am b/gobject/Makefile.am
> new file mode 100644
> index 0000000..6543ca8
> --- /dev/null
> +++ b/gobject/Makefile.am
> @@ -0,0 +1,41 @@

This Makefile.am (and every file) needs a copyright header.  See
*/Makefile.am for an example to copy.

> diff --git a/m4/introspection.m4 b/m4/introspection.m4
> new file mode 100644
> index 0000000..bfc52be
> --- /dev/null
> +++ b/m4/introspection.m4

I'm guessing this bit is supposed to define GOBJECT_INTROSPECTION_CHECK
but for some reason it didn't work for me ...

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list