[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: master is broken due to latest changes to pk-mi-json

From: Mohammad-Reza Nabipoor
Subject: Re: master is broken due to latest changes to pk-mi-json
Date: Fri, 26 Nov 2021 17:19:40 +0330

Hi, Jose

On Fri, Nov 26, 2021 at 02:24:38PM +0100, Jose E. Marchesi wrote:
> Ok I just pushed the commit below, that fixes this problem.  But then
> there is another problem in the testsuite:
> /bin/bash ../../libtool  --tag=CC   --mode=link gcc -fgnu89-inline 
> -I/usr/include/json-c -g -O2   -o mi-json mi_json-mi-json.o 
> ../../poke/mi_json-pk-mi-msg.o ../../poke/mi_json-pk-mi-json.o 
> ../../common/mi_json-pk-utils.o -ljson-c ../../gl/libgnu.la 
> ../../libpoke/libpoke.la 
> libtool: link: gcc -fgnu89-inline -I/usr/include/json-c -g -O2 -o 
> .libs/mi-json mi_json-mi-json.o ../../poke/mi_json-pk-mi-msg.o 
> ../../poke/mi_json-pk-mi-json.o ../../common/mi_json-pk-utils.o  -ljson-c 
> ../../gl/.libs/libgnu.a -lreadline -L/usr/local/lib 
> /usr/local/lib/libtextstyle.so -lm -lncurses ../../libpoke/.libs/libpoke.so 
> -pthread
> mi_json-mi-json.o: In function `test_val_to_json':
> /home/jemarch/gnu/hacks/poke/build/testsuite/poke.mi-json/../../../testsuite/poke.mi-json/mi-json.c:239:
>  undefined reference to `json_object_equal'

What about implementing `json_object_equal` ourself (by copying from the
json-c newer projects):
(The `lh_table_lookup_ex` is declared in `linkhash.h`.)

static int json_array_equal(struct json_object* jso1,
                            struct json_object* jso2)
        size_t len, i;

        len = json_object_array_length(jso1);
        if (len != json_object_array_length(jso2))
                return 0;

        for (i = 0; i < len; i++) {
                if (!json_object_equal(json_object_array_get_idx(jso1, i),
                                       json_object_array_get_idx(jso2, i)))
                        return 0;
        return 1;

static int json_object_all_values_equal(struct json_object* jso1,
                                        struct json_object* jso2)
        struct json_object_iter iter;
        struct json_object *sub;

        assert(json_object_get_type(jso1) == json_type_object);
        assert(json_object_get_type(jso2) == json_type_object);
        /* Iterate over jso1 keys and see if they exist and are equal in jso2 */
        json_object_object_foreachC(jso1, iter) {
                if (!lh_table_lookup_ex(jso2->o.c_object, (void*)iter.key,
                                        (void**)(void *)&sub))
                        return 0;
                if (!json_object_equal(iter.val, sub))
                        return 0;

        /* Iterate over jso2 keys to see if any exist that are not in jso1 */
        json_object_object_foreachC(jso2, iter) {
                if (!lh_table_lookup_ex(jso1->o.c_object, (void*)iter.key,
                                        (void**)(void *)&sub))
                        return 0;

        return 1;

int json_object_equal(struct json_object* jso1, struct json_object* jso2)
        if (jso1 == jso2)
                return 1;

        if (!jso1 || !jso2)
                return 0;

        if (jso1->o_type != jso2->o_type)
                return 0;

        switch(jso1->o_type) {
                case json_type_boolean:
                        return (jso1->o.c_boolean == jso2->o.c_boolean);

                case json_type_double:
                        return (jso1->o.c_double == jso2->o.c_double);

                case json_type_int:
                        return (jso1->o.c_int64 == jso2->o.c_int64);

                case json_type_string:
                        return (jso1->o.c_string.len == jso2->o.c_string.len &&
                                       jso1->o.c_string.len) == 0);

                case json_type_object:
                        return json_object_all_values_equal(jso1, jso2);

                case json_type_array:
                        return json_array_equal(jso1, jso2);

                case json_type_null:
                        return 1;

        return 0;


If this approach is OK, I can do this.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]