Pino Toscano
2018-Aug-22 11:20 UTC
Re: [Libguestfs] [PATCH 4/4] mltools: JSON: unify JSON_parser type with JSON.json_t.
On Monday, 20 August 2018 18:02:06 CEST Richard W.M. Jones wrote:> - } else > - rv = Val_none; > + } > + else { > + /* Previously we had a special JSON_parser_null value we could > + * use here, making the returned type (sort of) an option. > + * This is a best effort which is better than crashing / > + * throwing an error. > + */ > + rv = caml_alloc (1, JSON_STRING_TAG); > + v = caml_copy_string (""); > + Store_field (rv, 0, v); > + }NACK, this is not correct. null is a proper type of value in JSON, and thus JSON.json_t must represent it as well. This is even used in other parts, for example the check of backing files of disks (see guestfs_impl_disk_has_backing_file). -- Pino Toscano
Richard W.M. Jones
2018-Aug-22 14:18 UTC
Re: [Libguestfs] [PATCH 4/4] mltools: JSON: unify JSON_parser type with JSON.json_t.
On Wed, Aug 22, 2018 at 01:20:55PM +0200, Pino Toscano wrote:> On Monday, 20 August 2018 18:02:06 CEST Richard W.M. Jones wrote: > > - } else > > - rv = Val_none; > > + } > > + else { > > + /* Previously we had a special JSON_parser_null value we could > > + * use here, making the returned type (sort of) an option. > > + * This is a best effort which is better than crashing / > > + * throwing an error. > > + */ > > + rv = caml_alloc (1, JSON_STRING_TAG); > > + v = caml_copy_string (""); > > + Store_field (rv, 0, v); > > + } > > NACK, this is not correct. null is a proper type of value in JSON, and > thus JSON.json_t must represent it as well. > > This is even used in other parts, for example the check of backing > files of disks (see guestfs_impl_disk_has_backing_file).Can you explain more about what a "null" JSON document looks like? Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Richard W.M. Jones
2018-Aug-22 14:21 UTC
Re: [Libguestfs] [PATCH 4/4] mltools: JSON: unify JSON_parser type with JSON.json_t.
On Wed, Aug 22, 2018 at 03:18:31PM +0100, Richard W.M. Jones wrote:> On Wed, Aug 22, 2018 at 01:20:55PM +0200, Pino Toscano wrote: > > On Monday, 20 August 2018 18:02:06 CEST Richard W.M. Jones wrote: > > > - } else > > > - rv = Val_none; > > > + } > > > + else { > > > + /* Previously we had a special JSON_parser_null value we could > > > + * use here, making the returned type (sort of) an option. > > > + * This is a best effort which is better than crashing / > > > + * throwing an error. > > > + */ > > > + rv = caml_alloc (1, JSON_STRING_TAG); > > > + v = caml_copy_string (""); > > > + Store_field (rv, 0, v); > > > + } > > > > NACK, this is not correct. null is a proper type of value in JSON, and > > thus JSON.json_t must represent it as well. > > > > This is even used in other parts, for example the check of backing > > files of disks (see guestfs_impl_disk_has_backing_file). > > Can you explain more about what a "null" JSON document looks like?Oh I see, it's actually a special value. I think I can add this. I've pushed patches 1-3. 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
Eric Blake
2018-Aug-22 14:25 UTC
Re: [Libguestfs] [PATCH 4/4] mltools: JSON: unify JSON_parser type with JSON.json_t.
On 08/22/2018 09:18 AM, Richard W.M. Jones wrote:>> NACK, this is not correct. null is a proper type of value in JSON, and >> thus JSON.json_t must represent it as well. >> >> This is even used in other parts, for example the check of backing >> files of disks (see guestfs_impl_disk_has_backing_file). > > Can you explain more about what a "null" JSON document looks like?An example: qemu will accept the following substring, as part of BlockdevOptionsGenricCOWFormat, when specifically asking qemu to ignore the backing information present in a file and instead open the file without any backing: { "backing": null } That is, JSON has "null", "true", and "false" as its three bare literals, which hold the same semantic weight as literal numbers, strings, [] arrays, and {} objects. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Apparently Analagous Threads
- Re: [PATCH 4/4] mltools: JSON: unify JSON_parser type with JSON.json_t.
- [PATCH 4/4] mltools: JSON: unify JSON_parser type with JSON.json_t.
- [PATCH v2 0/2] mltools: JSON: unify JSON & JSON parser.
- [PATCH v3 1/4] mltools: Rename Yajl module as JSON_parser and move to common/mltools.
- [PATCH 0/4] mltools: JSON unification