Improve the output by ensuring a well defined order for type switches.
* src/uniqstr.h: Style changes for macro arguments.
(UNIQSTR_CMP): Replace by...
(uniqstr_cmp): this.
* src/uniqstr.c (uniqstr_cmp): New.
Produce well defined results.
* src/output.c: Use it.
static int
symbol_type_name_cmp (const symbol **lhs, const symbol **rhs)
{
- int res = UNIQSTR_CMP((*lhs)->type_name, (*rhs)->type_name);
- if (res)
- return res;
- return (*lhs)->number - (*rhs)->number;
+ int res = uniqstr_cmp ((*lhs)->type_name, (*rhs)->type_name);
+ if (!res)
+ res = (*lhs)->number - (*rhs)->number;
+ return res;
}
return uniqstr_print (ustr);
}
-\f
+
+int
+uniqstr_cmp(uniqstr l, uniqstr r)
+{
+ return (l == r ? 0
+ : !l ? -1
+ : !r ? +1
+ : strcmp (l, r));
+}
+
+
/*-----------------------.
| A uniqstr hash table. |
`-----------------------*/
return hash_string (m, tablesize);
}
+
/*----------------------------.
| Create the uniqstrs table. |
`----------------------------*/
/* Compare two uniqstr a la strcmp: negative for <, nul for =, and
positive for >. Undefined order, relies on addresses. */
-# define UNIQSTR_CMP(USTR1, USTR2) ((USTR1) - (USTR2))
+int uniqstr_cmp(uniqstr u1, uniqstr u2);
/* Die if STR is not a uniqstr. */
void uniqstr_assert (char const *str);