const char *module_name;
JsonVariant *module_json;
- /* Cannot nest two JSON_VARIANT_OBJECT_FOREACH as they define the same
- * iterator variable '_state' */
- for (struct json_variant_foreach_state _state2 = { (v), 0 }; \
- json_variant_is_object(_state2.variant) && \
- _state2.idx < json_variant_elements(_state2.variant) && \
- ({ module_name = json_variant_string(json_variant_by_index(_state2.variant, _state2.idx)); \
- module_json = json_variant_by_index(_state2.variant, _state2.idx + 1); \
- true; }); \
- _state2.idx += 2) {
+ JSON_VARIANT_OBJECT_FOREACH(module_name, module_json, v) {
_cleanup_free_ char *module_basename = NULL, *exe_basename = NULL;
- const char *key;
- JsonVariant *w;
+ JsonVariant *build_id;
/* The module name, most likely parsed from the ELF core file,
* sometimes contains the full path and sometimes does not. */
if (!streq(module_basename, exe_basename))
continue;
- JSON_VARIANT_OBJECT_FOREACH(key, w, module_json) {
- if (!json_variant_is_string(w))
- continue;
-
- if (!streq(key, "buildId"))
- continue;
-
- fprintf(file, " build-id: %s\n", json_variant_string(w));
-
- break;
- }
+ build_id = json_variant_by_key(module_json, "buildId");
+ if (build_id)
+ fprintf(file, " build-id: %s\n", json_variant_string(build_id));
break;
}