[SATYR PATCH 3/9] Factor out qsort wrapper for strcmp
Martin Milata
mmilata at redhat.com
Wed Jun 26 20:14:07 UTC 2013
Signed-off-by: Martin Milata <mmilata at redhat.com>
---
include/utils.h | 7 +++++++
lib/core_fingerprint.c | 10 ++--------
lib/normalize.c | 8 +-------
lib/utils.c | 6 ++++++
4 files changed, 16 insertions(+), 15 deletions(-)
diff --git a/include/utils.h b/include/utils.h
index 68e763b..5684620 100644
--- a/include/utils.h
+++ b/include/utils.h
@@ -106,6 +106,13 @@ int
sr_strcmp0(const char *s1, const char *s2);
/**
+ * A wrapper around sr_strcmp0 that takes pointers to strings. Can be used as a
+ * paramter to qsort or bsearch.
+ */
+int
+sr_ptrstrcmp(const void *s1, const void *s2);
+
+/**
* A strchr() variant providing line and column in the string s
* indicating where the char c was found.
* @param line
diff --git a/lib/core_fingerprint.c b/lib/core_fingerprint.c
index aeea837..af33a93 100644
--- a/lib/core_fingerprint.c
+++ b/lib/core_fingerprint.c
@@ -280,12 +280,6 @@ get_libcalls(char ***symbol_list,
return true;
}
-static int
-strcmp_wrapper(const char **s1, const char **s2)
-{
- return strcmp(*s1, *s2);
-}
-
static bool
fp_libcalls(struct sr_strbuf *fingerprint,
uint64_t function_start_address,
@@ -310,7 +304,7 @@ fp_libcalls(struct sr_strbuf *fingerprint,
return false;
qsort(symbol_list, symbol_list_size,
- sizeof(char*), (comparison_fn_t)strcmp_wrapper);
+ sizeof(char*), (comparison_fn_t)sr_ptrstrcmp);
/* Make it unique. */
sr_struniq(symbol_list, &symbol_list_size);
@@ -349,7 +343,7 @@ fp_calltree_leaves(struct sr_strbuf *fingerprint,
return false;
qsort(symbol_list, symbol_list_size,
- sizeof(char*), (comparison_fn_t)strcmp_wrapper);
+ sizeof(char*), (comparison_fn_t)sr_ptrstrcmp);
/* Make it unique. */
sr_struniq(symbol_list, &symbol_list_size);
diff --git a/lib/normalize.c b/lib/normalize.c
index 9582a5f..7cd8144 100644
--- a/lib/normalize.c
+++ b/lib/normalize.c
@@ -380,12 +380,6 @@ sr_normalize_gdb_stacktrace(struct sr_gdb_stacktrace *stacktrace)
}
}
-static int
-ptrstrcmp(const void *s1, const void *s2)
-{
- return sr_strcmp0(*(const char**)s1, *(const char**)s2);
-}
-
void
sr_normalize_koops_stacktrace(struct sr_koops_stacktrace *stacktrace)
{
@@ -433,7 +427,7 @@ sr_normalize_koops_stacktrace(struct sr_koops_stacktrace *stacktrace)
blacklist,
sizeof(blacklist) / sizeof(blacklist[0]),
sizeof(blacklist[0]),
- ptrstrcmp);
+ sr_ptrstrcmp);
/* do not drop frames belonging to a module */
if (!frame->module_name && in_blacklist)
diff --git a/lib/utils.c b/lib/utils.c
index 1b9d982..ac56c7e 100644
--- a/lib/utils.c
+++ b/lib/utils.c
@@ -157,6 +157,12 @@ sr_strcmp0(const char *s1, const char *s2)
return s2 ? -1 : 0;
}
+int
+sr_ptrstrcmp(const void *s1, const void *s2)
+{
+ return sr_strcmp0(*(const char**)s1, *(const char**)s2);
+}
+
char *
sr_strchr_location(const char *s, int c, int *line, int *column)
{
--
1.7.11.7
More information about the Crash-catcher
mailing list