Skip to content

Commit d07e4ac

Browse files
committed
utils/annotate: reimplement info operations using hwloc_modify_infos()
It was relying on non-official/non-documentation manual changes to the info attr arrays. Signed-off-by: Brice Goglin <[email protected]>
1 parent 749e22a commit d07e4ac

File tree

1 file changed

+6
-36
lines changed

1 file changed

+6
-36
lines changed

utils/hwloc/hwloc-annotate.c

Lines changed: 6 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -81,46 +81,16 @@ static char *distances_transform_replace_newtype = NULL;
8181

8282
static void apply_infos(struct hwloc_infos_s *infos)
8383
{
84-
unsigned i, j;
8584
if (clearinfos) {
86-
/* this may be considered dangerous, applications should not modify objects directly */
87-
for(i=0; i<infos->count; i++) {
88-
struct hwloc_info_s *info = &infos->array[i];
89-
free(info->name);
90-
free(info->value);
91-
}
92-
free(infos->array);
93-
infos->array = NULL;
94-
infos->count = 0;
95-
infos->allocated = 0;
85+
hwloc_modify_infos(infos, HWLOC_MODIFY_INFOS_OP_REMOVE, NULL, NULL);
9686
}
9787
if (infoname) {
9888
if (replaceinfos) {
99-
/* this may be considered dangerous, applications should not modify objects directly */
100-
for(i=0, j=0; i<infos->count; i++) {
101-
struct hwloc_info_s *info = &infos->array[i];
102-
if (!strcmp(infoname, info->name)) {
103-
/* remove info */
104-
free(info->name);
105-
info->name = NULL;
106-
free(info->value);
107-
} else {
108-
if (i != j) {
109-
/* shift info to where it belongs */
110-
infos->array[j].name = info->name;
111-
infos->array[j].value = info->value;
112-
}
113-
j++;
114-
}
115-
}
116-
infos->count = j;
117-
if (!j) {
118-
free(infos->array);
119-
infos->array = NULL;
120-
infos->allocated = 0;
121-
}
122-
}
123-
if (infovalue)
89+
if (infovalue)
90+
hwloc_modify_infos(infos, HWLOC_MODIFY_INFOS_OP_REPLACE, infoname, infovalue);
91+
else
92+
hwloc_modify_infos(infos, HWLOC_MODIFY_INFOS_OP_REMOVE, infoname, NULL);
93+
} else
12494
hwloc_modify_infos(infos, HWLOC_MODIFY_INFOS_OP_ADD, infoname, infovalue);
12595
}
12696
}

0 commit comments

Comments
 (0)