@@ -66,7 +66,8 @@ static int hwloc_append_diff_too_complex(hwloc_obj_t obj1,
6666 return 0 ;
6767}
6868
69- static int hwloc_append_diff_obj_attr_string (hwloc_obj_t obj ,
69+ static int hwloc_append_diff_obj_attr_string (hwloc_topology_t topology ,
70+ hwloc_obj_t obj ,
7071 hwloc_topology_diff_obj_attr_type_t type ,
7172 const char * name ,
7273 const char * oldvalue ,
@@ -80,8 +81,8 @@ static int hwloc_append_diff_obj_attr_string(hwloc_obj_t obj,
8081 return -1 ;
8182
8283 newdiff -> obj_attr .type = HWLOC_TOPOLOGY_DIFF_OBJ_ATTR ;
83- newdiff -> obj_attr .obj_depth = obj -> depth ;
84- newdiff -> obj_attr .obj_index = obj -> logical_index ;
84+ newdiff -> obj_attr .obj_depth = obj ? obj -> depth : ( int ) topology -> nb_levels ;
85+ newdiff -> obj_attr .obj_index = obj ? obj -> logical_index : 0 ;
8586 newdiff -> obj_attr .diff .string .type = type ;
8687 newdiff -> obj_attr .diff .string .name = name ? strdup (name ) : NULL ;
8788 newdiff -> obj_attr .diff .string .oldvalue = oldvalue ? strdup (oldvalue ) : NULL ;
@@ -155,7 +156,7 @@ hwloc_diff_trees(hwloc_topology_t topo1, hwloc_obj_t obj1,
155156
156157 if ((!obj1 -> name ) != (!obj2 -> name )
157158 || (obj1 -> name && strcmp (obj1 -> name , obj2 -> name ))) {
158- err = hwloc_append_diff_obj_attr_string (obj1 ,
159+ err = hwloc_append_diff_obj_attr_string (topo1 , obj1 ,
159160 HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_NAME ,
160161 NULL ,
161162 obj1 -> name ,
@@ -219,7 +220,7 @@ hwloc_diff_trees(hwloc_topology_t topo1, hwloc_obj_t obj1,
219220 if (strcmp (info1 -> name , info2 -> name ))
220221 goto out_too_complex ;
221222 if (strcmp (info1 -> value , info2 -> value )) {
222- err = hwloc_append_diff_obj_attr_string (obj1 ,
223+ err = hwloc_append_diff_obj_attr_string (topo1 , obj1 ,
223224 HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_INFO ,
224225 info1 -> name ,
225226 info1 -> value ,
@@ -338,6 +339,27 @@ int hwloc_topology_diff_build(hwloc_topology_t topo1,
338339 goto roottoocomplex ;
339340 }
340341
342+ /* topology infos */
343+ if (!err ) {
344+ if (topo1 -> infos .count != topo2 -> infos .count )
345+ goto roottoocomplex ;
346+ for (i = 0 ; i < topo1 -> infos .count ; i ++ ) {
347+ struct hwloc_info_s * info1 = & topo1 -> infos .array [i ], * info2 = & topo2 -> infos .array [i ];
348+ if (strcmp (info1 -> name , info2 -> name ))
349+ goto roottoocomplex ;
350+ if (strcmp (info1 -> value , info2 -> value )) {
351+ err = hwloc_append_diff_obj_attr_string (topo1 , NULL ,
352+ HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_INFO ,
353+ info1 -> name ,
354+ info1 -> value ,
355+ info2 -> value ,
356+ diffp , & lastdiff );
357+ if (err < 0 )
358+ return err ;
359+ }
360+ }
361+ }
362+
341363 if (!err ) {
342364 /* distances */
343365 hwloc_internal_distances_refresh (topo1 );
@@ -458,15 +480,22 @@ hwloc_apply_diff_one(hwloc_topology_t topology,
458480 case HWLOC_TOPOLOGY_DIFF_OBJ_ATTR : {
459481 struct hwloc_topology_diff_obj_attr_s * obj_attr = & diff -> obj_attr ;
460482 hwloc_obj_t obj = hwloc_get_obj_by_depth (topology , obj_attr -> obj_depth , obj_attr -> obj_index );
461- if (!obj )
462- return -1 ;
483+ struct hwloc_infos_s * infos ;
484+ if (obj )
485+ infos = & obj -> infos ;
486+ else if (obj_attr -> obj_depth == (int ) topology -> nb_levels )
487+ infos = & topology -> infos ;
488+ else
489+ return -1 ;
463490
464491 switch (obj_attr -> diff .generic .type ) {
465492 case HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_SIZE : {
466493 hwloc_obj_t tmpobj ;
467494 hwloc_uint64_t oldvalue = reverse ? obj_attr -> diff .uint64 .newvalue : obj_attr -> diff .uint64 .oldvalue ;
468495 hwloc_uint64_t newvalue = reverse ? obj_attr -> diff .uint64 .oldvalue : obj_attr -> diff .uint64 .newvalue ;
469496 hwloc_uint64_t valuediff = newvalue - oldvalue ;
497+ if (!obj )
498+ return -1 ;
470499 if (obj -> type != HWLOC_OBJ_NUMANODE )
471500 return -1 ;
472501 if (obj -> attr -> numanode .local_memory != oldvalue )
@@ -482,7 +511,9 @@ hwloc_apply_diff_one(hwloc_topology_t topology,
482511 case HWLOC_TOPOLOGY_DIFF_OBJ_ATTR_NAME : {
483512 const char * oldvalue = reverse ? obj_attr -> diff .string .newvalue : obj_attr -> diff .string .oldvalue ;
484513 const char * newvalue = reverse ? obj_attr -> diff .string .oldvalue : obj_attr -> diff .string .newvalue ;
485- if (!obj -> name || strcmp (obj -> name , oldvalue ))
514+ if (!obj )
515+ return -1 ;
516+ if (!obj -> name || strcmp (obj -> name , oldvalue ))
486517 return -1 ;
487518 free (obj -> name );
488519 obj -> name = strdup (newvalue );
@@ -494,8 +525,8 @@ hwloc_apply_diff_one(hwloc_topology_t topology,
494525 const char * newvalue = reverse ? obj_attr -> diff .string .oldvalue : obj_attr -> diff .string .newvalue ;
495526 unsigned i ;
496527 int found = 0 ;
497- for (i = 0 ; i < obj -> infos . count ; i ++ ) {
498- struct hwloc_info_s * info = & obj -> infos . array [i ];
528+ for (i = 0 ; i < infos -> count ; i ++ ) {
529+ struct hwloc_info_s * info = & infos -> array [i ];
499530 if (!strcmp (info -> name , name )
500531 && !strcmp (info -> value , oldvalue )) {
501532 free (info -> value );
0 commit comments