why does the int_value of the pa_json_object structure need to be declared as int64_t?

赵成义 zhaochengyi at uniontech.com
Mon Jul 8 07:41:21 UTC 2024


Hi guys,


Please help explain why the int_value of the pa_json_object structure needs to be declared as int64_t.


./src/pulsecore/json.c:


struct pa_json_object {
    pa_json_type type;


    union {
        int64_t int_value;
        double double_value;
        bool bool_value;
        char *string_value;
        pa_hashmap *object_values; /* name -> object */
        pa_idxset *array_values; /* objects */
    };
};



Can I change "int64_t int_value;" to "int int_value;"?
In the ./src/pulse/format.c file, the function pa_json_object_get_int
is called multiple times, converting int64_t to int.



./src/pulse/format.c:


int pa_format_info_get_prop_int(const pa_format_info *f, const char *key, int *v) {
    const char *str;
    pa_json_object *o;


    pa_assert(f);
    pa_assert(key);
    pa_assert(v);


    str = pa_proplist_gets(f->plist, key);
    if (!str)
        return -PA_ERR_NOENTITY;


    o = pa_json_parse(str);
    if (!o) {
        pa_log_debug("Failed to parse format info property '%s'.", key);
        return -PA_ERR_INVALID;
    }


    if (pa_json_object_get_type(o) != PA_JSON_TYPE_INT) {
        pa_log_debug("Format info property '%s' type is not int.", key);
        pa_json_object_free(o);
        return -PA_ERR_INVALID;
    }


    *v = pa_json_object_get_int(o);
    pa_json_object_free(o);


    return 0;
}


Thanks,
Chengyi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/pulseaudio-discuss/attachments/20240708/3d8751a4/attachment.htm>


More information about the pulseaudio-discuss mailing list