On Mon, May 4, 2015 at 9:46 AM,  <[email protected]> wrote:
> Fix dumping of Nums
>
> Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
> Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/78889bcd
> Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/78889bcd
> Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/78889bcd


> http://git-wip-us.apache.org/repos/asf/lucy/blob/78889bcd/core/Lucy/Util/Freezer.c
> ----------------------------------------------------------------------
> diff --git a/core/Lucy/Util/Freezer.c b/core/Lucy/Util/Freezer.c
> index c427d55..7e053fd 100644
> --- a/core/Lucy/Util/Freezer.c
> +++ b/core/Lucy/Util/Freezer.c
> @@ -384,7 +384,7 @@ Freezer_dump(Obj *obj) {
>          return Query_Dump((Query*)obj);
>      }
>      else {
> -        return (Obj*)Obj_To_String(obj);
> +        return (Obj*)Obj_Clone(obj);
>      }
>  }

This might be a reasonable design, but it doesn't match the API documentation:

    /** Return a representation of the object using only scalars, hashes, and
     * arrays.  Some classes support JSON serialization via dump() and its
     * companion, load(); for others, dump() is only a debugging aid.
     * The default simply calls [](cfish:.To_String).
     */
    inert incremented Obj*
    dump(Obj *obj);

Perhaps consider adding another conditional branch:

    else if (Obj_Is_A(obj, NUM)) {
        return Obj_Clone(obj);
    }
    else {
        return Obj_To_String(obj);
    }

This maintains the guarantee that `Freezer_dump` will always produce a
JSON-izable data structure, even if it means stringifying unsupported types.

Marvin Humphrey

Reply via email to