[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/6] variant: produce stable results
From: |
Akim Demaille |
Subject: |
[PATCH 6/6] variant: produce stable results |
Date: |
Sun, 23 Dec 2012 10:27:06 +0100 |
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.
---
src/output.c | 8 ++++----
src/uniqstr.c | 13 ++++++++++++-
src/uniqstr.h | 2 +-
3 files changed, 17 insertions(+), 6 deletions(-)
diff --git a/src/output.c b/src/output.c
index c64c7aa..7e552dc 100644
--- a/src/output.c
+++ b/src/output.c
@@ -284,10 +284,10 @@ prepare_states (void)
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;
}
diff --git a/src/uniqstr.c b/src/uniqstr.c
index f295444..9917121 100644
--- a/src/uniqstr.c
+++ b/src/uniqstr.c
@@ -103,7 +103,17 @@ uniqstr_print_processor (void *ustr, void *null
ATTRIBUTE_UNUSED)
return uniqstr_print (ustr);
}
-
+
+int
+uniqstr_cmp(uniqstr l, uniqstr r)
+{
+ return (l == r ? 0
+ : !l ? -1
+ : !r ? +1
+ : strcmp (l, r));
+}
+
+
/*-----------------------.
| A uniqstr hash table. |
`-----------------------*/
@@ -120,6 +130,7 @@ hash_uniqstr (void const *m, size_t tablesize)
return hash_string (m, tablesize);
}
+
/*----------------------------.
| Create the uniqstrs table. |
`----------------------------*/
diff --git a/src/uniqstr.h b/src/uniqstr.h
index ba27322..9990446 100644
--- a/src/uniqstr.h
+++ b/src/uniqstr.h
@@ -40,7 +40,7 @@ uniqstr uniqstr_vsprintf (char const *format, ...)
/* 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);
--
1.8.0.2
- [PATCH 0/6] {master} minor improvements, Akim Demaille, 2012/12/26
- [PATCH 1/6] c++: use // comments in the output, Akim Demaille, 2012/12/26
- [PATCH 4/6] skeletons: fix an error message, Akim Demaille, 2012/12/26
- [PATCH 2/6] c++: comment changes, Akim Demaille, 2012/12/26
- [PATCH 5/6] uniqstr: formatting changes, Akim Demaille, 2012/12/26
- [PATCH 3/6] tests: improve titles, Akim Demaille, 2012/12/26
- [PATCH 6/6] variant: produce stable results,
Akim Demaille <=