Richard W.M. Jones
2014-Jul-01 15:16 UTC
[Libguestfs] [PATCH] generator: Sort the structs.
Sort the structs when generating code. Since the structs are logically indepedent of each other, this should have no effect except to make generated files list the structs in a different order. However this also fixes the following build problem: File "convert_linux.ml", line 322, characters 43-50: Error: This expression has type G.stat = Guestfs.stat but an expression was expected of type G.dirent = Guestfs.dirent It turns out the OCaml bindings don't like the fact that we have two structs with a common field name (dirent.ino and stat.ino). In OCaml < 4.01, this means that any attempt to reference stat.ino would fail because dirent.ino appears second in the file, overriding stat.ino. In OCaml >= 4.01 the compiler now uses some disambiguation rules based on the known types to resolve this problem. See: http://ocaml.org/releases/4.01.0.html http://www.lexifi.com/blog/type-based-selection-label-and-constructors http://www.lexifi.com/blog/ocaml-extensions-lexifi-overidding-record-labels-and-constructors --- generator/structs.ml | 8 ++++++-- gobject/Makefile.inc | 48 ++++++++++++++++++++++++------------------------ 2 files changed, 30 insertions(+), 26 deletions(-) diff --git a/generator/structs.ml b/generator/structs.ml index 1bc6e08..65c78b2 100644 --- a/generator/structs.ml +++ b/generator/structs.ml @@ -382,6 +382,10 @@ let camel_name_of_struct name = (lookup_struct name).s_camel_name let cols_of_struct name = (lookup_struct name).s_cols -let external_structs = List.filter (fun x -> not x.s_internal) structs +let compare_structs { s_name = n1 } { s_name = n2 } = compare n1 n2 -let internal_structs = List.filter (fun x -> x.s_internal) structs +let external_structs + List.sort compare_structs (List.filter (fun x -> not x.s_internal) structs) + +let internal_structs + List.sort compare_structs (List.filter (fun x -> x.s_internal) structs) diff --git a/gobject/Makefile.inc b/gobject/Makefile.inc index 3b567a2..ed1ff3b 100644 --- a/gobject/Makefile.inc +++ b/gobject/Makefile.inc @@ -23,26 +23,26 @@ guestfs_gobject_headers= \ include/guestfs-gobject.h \ include/guestfs-gobject/session.h \ include/guestfs-gobject/tristate.h \ + include/guestfs-gobject/struct-application.h \ + include/guestfs-gobject/struct-application2.h \ + include/guestfs-gobject/struct-btrfssubvolume.h \ + include/guestfs-gobject/struct-dirent.h \ + include/guestfs-gobject/struct-hivex_node.h \ + include/guestfs-gobject/struct-hivex_value.h \ + include/guestfs-gobject/struct-inotify_event.h \ include/guestfs-gobject/struct-int_bool.h \ + include/guestfs-gobject/struct-isoinfo.h \ + include/guestfs-gobject/struct-lvm_lv.h \ include/guestfs-gobject/struct-lvm_pv.h \ include/guestfs-gobject/struct-lvm_vg.h \ - include/guestfs-gobject/struct-lvm_lv.h \ + include/guestfs-gobject/struct-mdstat.h \ + include/guestfs-gobject/struct-partition.h \ include/guestfs-gobject/struct-stat.h \ include/guestfs-gobject/struct-statvfs.h \ - include/guestfs-gobject/struct-dirent.h \ + include/guestfs-gobject/struct-utsname.h \ include/guestfs-gobject/struct-version.h \ include/guestfs-gobject/struct-xattr.h \ - include/guestfs-gobject/struct-inotify_event.h \ - include/guestfs-gobject/struct-partition.h \ - include/guestfs-gobject/struct-application.h \ - include/guestfs-gobject/struct-application2.h \ - include/guestfs-gobject/struct-isoinfo.h \ - include/guestfs-gobject/struct-mdstat.h \ - include/guestfs-gobject/struct-btrfssubvolume.h \ include/guestfs-gobject/struct-xfsinfo.h \ - include/guestfs-gobject/struct-utsname.h \ - include/guestfs-gobject/struct-hivex_node.h \ - include/guestfs-gobject/struct-hivex_value.h \ include/guestfs-gobject/optargs-add_domain.h \ include/guestfs-gobject/optargs-add_drive.h \ include/guestfs-gobject/optargs-add_drive_scratch.h \ @@ -100,26 +100,26 @@ guestfs_gobject_headers= \ guestfs_gobject_sources= \ src/session.c \ src/tristate.c \ + src/struct-application.c \ + src/struct-application2.c \ + src/struct-btrfssubvolume.c \ + src/struct-dirent.c \ + src/struct-hivex_node.c \ + src/struct-hivex_value.c \ + src/struct-inotify_event.c \ src/struct-int_bool.c \ + src/struct-isoinfo.c \ + src/struct-lvm_lv.c \ src/struct-lvm_pv.c \ src/struct-lvm_vg.c \ - src/struct-lvm_lv.c \ + src/struct-mdstat.c \ + src/struct-partition.c \ src/struct-stat.c \ src/struct-statvfs.c \ - src/struct-dirent.c \ + src/struct-utsname.c \ src/struct-version.c \ src/struct-xattr.c \ - src/struct-inotify_event.c \ - src/struct-partition.c \ - src/struct-application.c \ - src/struct-application2.c \ - src/struct-isoinfo.c \ - src/struct-mdstat.c \ - src/struct-btrfssubvolume.c \ src/struct-xfsinfo.c \ - src/struct-utsname.c \ - src/struct-hivex_node.c \ - src/struct-hivex_value.c \ src/optargs-add_domain.c \ src/optargs-add_drive.c \ src/optargs-add_drive_scratch.c \ -- 1.9.0
On Tuesday 01 July 2014 16:16:18 Richard W.M. Jones wrote:> Sort the structs when generating code. Since the structs are > logically indepedent of each other, this should have no effect except > to make generated files list the structs in a different order. > > However this also fixes the following build problem: > > File "convert_linux.ml", line 322, characters 43-50: > Error: This expression has type G.stat = Guestfs.stat > but an expression was expected of type G.dirent = Guestfs.dirent > > It turns out the OCaml bindings don't like the fact that we have > two structs with a common field name (dirent.ino and stat.ino). > > In OCaml < 4.01, this means that any attempt to reference stat.ino > would fail because dirent.ino appears second in the file, overriding > stat.ino.So that means that with such OCaml versions both the .ino members cannot be used at the same time?> In OCaml >= 4.01 the compiler now uses some disambiguation rules based > on the known types to resolve this problem.Patch seems good to me. Thanks, -- Pino Toscano
Richard W.M. Jones
2014-Jul-01 15:52 UTC
Re: [Libguestfs] [PATCH] generator: Sort the structs.
On Tue, Jul 01, 2014 at 05:27:42PM +0200, Pino Toscano wrote:> On Tuesday 01 July 2014 16:16:18 Richard W.M. Jones wrote: > > Sort the structs when generating code. Since the structs are > > logically indepedent of each other, this should have no effect except > > to make generated files list the structs in a different order. > > > > However this also fixes the following build problem: > > > > File "convert_linux.ml", line 322, characters 43-50: > > Error: This expression has type G.stat = Guestfs.stat > > but an expression was expected of type G.dirent = Guestfs.dirent > > > > It turns out the OCaml bindings don't like the fact that we have > > two structs with a common field name (dirent.ino and stat.ino). > > > > In OCaml < 4.01, this means that any attempt to reference stat.ino > > would fail because dirent.ino appears second in the file, overriding > > stat.ino. > > So that means that with such OCaml versions both the .ino members cannot > be used at the same time?Yup. Luckily we don't use `dirent.ino'.> > In OCaml >= 4.01 the compiler now uses some disambiguation rules based > > on the known types to resolve this problem. > > Patch seems good to me.Thanks - I will push it in a moment. 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