You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by nw...@apache.org on 2015/05/04 18:46:23 UTC

[4/4] lucy git commit: Fix dumping of Nums

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

Branch: refs/heads/master
Commit: 78889bcdcfea5f8f7d999cd8da0a74a9036353b4
Parents: be1b383
Author: Nick Wellnhofer <we...@aevum.de>
Authored: Mon May 4 17:10:28 2015 +0200
Committer: Nick Wellnhofer <we...@aevum.de>
Committed: Mon May 4 18:45:56 2015 +0200

----------------------------------------------------------------------
 core/Lucy/Util/Freezer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


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);
     }
 }
 


[lucy-dev] Re: [4/4] lucy git commit: Fix dumping of Nums

Posted by Marvin Humphrey <ma...@rectangular.com>.
On Mon, May 4, 2015 at 9:46 AM,  <nw...@apache.org> 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