[ovs-dev] [PATCH 1/2] ovsdb-client: Refactor table code to save original json during formatting.

Ethan Jackson ethan at nicira.com
Wed Nov 3 23:02:35 UTC 2010


> +static const char *
> +cell_to_text(const struct cell *cell_)
> +{
> +    struct cell *cell = (struct cell *) cell_;
> +    if (!cell->text) {
> +        if (cell->json) {
> +            if (data_format == DF_JSON || !cell->type) {
> +                cell->text = json_to_string(cell->json, JSSF_SORT);
> +            } else if (data_format == DF_STRING) {
> +                struct ovsdb_datum datum;
> +                struct ovsdb_error *error;
> +                struct ds s;
> +
> +                error = ovsdb_datum_from_json(&datum, cell->type, cell->json,
> +                                              NULL);
> +                if (!error) {
> +                    ds_init(&s);
> +                    ovsdb_datum_to_string(&datum, cell->type, &s);
> +                    ovsdb_datum_destroy(&datum, cell->type);
> +                    cell->text = ds_steal_cstr(&s);
> +                } else {
> +                    cell->text = json_to_string(cell->json, JSSF_SORT);
> +                }
> +            } else {
> +                NOT_REACHED();
> +            }
> +        } else {
> +            cell->text = xstrdup("");
> +        }
> +    }
> +
> +    return cell->text;
> +}
> +
> +static void
> +cell_destroy(struct cell *cell)
> + {
> +    free(cell->text);
> +    json_destroy(cell->json);
> +}

cell_to_text checks if cell->text and cell->json are null so
cell_destroy probably should as well.

Other then that looks good to me.

Ethan Jackson




More information about the dev mailing list