<soum...@nvidia.com> writes: > +/* Extract string value from JSON, returning allocated C string. */ > +char * > +extract_string (const json::value *val) > +{ > + if (auto *string_val = dyn_cast<const json::string *> (val)) > + { > + char *result = new char[string_val->get_length () + 1]; > + strcpy (result, string_val->get_string ()); > + return result;
Looks like this could use xstrdup. How is memory management handled (both here and for pointers to structures)? Do we just allocate and never free? If so, that's ok for command-line options, but I wonder whether we'll ewventually be using this on a per-function basis. (Hopefully not though...) > [...] > +/* Main routine for setting up the parsing of JSON data. */ > +void > +aarch64_load_tuning_params_from_json_string (const char *json_string, > + const char *schema_string, > + struct tune_params *tune) > +{ > + /* Try parsing the JSON string */ > + json::parser_result_t data_result > + = json::parse_utf8_string (strlen (json_string), json_string, true, > + nullptr); > + > + if (auto json_err = data_result.m_err.get ()) > + { > + error ("error parsing JSON data: %s", json_err->get_msg ()); > + return; > + } > + > + const std::unique_ptr<json::value> &root = data_result.m_val; > + if (!root) > + { > + error ("JSON parsing returned null data"); > + return; > + } > + auto *root_obj = dyn_cast<const json::object *> (root.get ()); > + if (!root_obj) > + { > + warning (0, "no JSON object found in the provided data"); > + return; > + } > + > + /* Parse the schema */ /* Parse the schema. */ > + json::parser_result_t schema_result = > + json::parse_utf8_string (strlen (schema_string), schema_string, true, > + nullptr); > + > + if (auto json_err = schema_result.m_err.get ()) > + { > + error ("error parsing JSON schema: %s", json_err->get_msg ()); > + return; > + } > + > + const std::unique_ptr<json::value> &schema_root = schema_result.m_val; > + if (!schema_root) > + { > + error ("JSON schema parsing returned null data"); > + return; > + } > + auto *schema_obj = dyn_cast<const json::object *> (schema_root.get ()); > + if (!schema_obj) > + { > + error ("no JSON object found in the provided schema"); > + return; > + } Since the schema is hard-coded, I would have expected all of these to be assertions rather than errors. Thanks, Richard