|
From: Jeremy F. <je...@go...> - 2005-02-28 01:08:36
|
CVS commit by fitzhardinge:
A little refactoring to add a standard set of comparison functions for
skiplists, since many lists are using the same key types.
M +1 -15 coregrind/vg_memory.c 1.93
M +3 -17 coregrind/vg_redir.c 1.6
M +63 -2 coregrind/vg_skiplist.c 1.9
M +2 -15 coregrind/vg_threadmodel.c 1.2
M +8 -2 include/tool.h.base 1.27
--- valgrind/coregrind/vg_skiplist.c #1.8:1.9
@@ -4,6 +4,6 @@
emulator for monitoring program execution on x86-Unixes.
- Copyright (C) 2002-2004 Nicholas Nethercote
- nj...@ca...
+ Copyright (C) 2002-2004 Jeremy Fitzhardinge
+ je...@go...
This program is free software; you can redistribute it and/or
@@ -450,2 +450,63 @@ void *VG_(SkipList_Remove)(SkipList *l,
return data_of_node(l, n);
}
+
+void VG_(SkipList_for_each_node)(const SkipList *l,
+ void (*fn)(void *node, void *arg), void *arg)
+{
+ void *n;
+
+ for(n = VG_(SkipNode_First)(l);
+ n != NULL;
+ n = VG_(SkipNode_Next)(l, n))
+ (*fn)(n, arg);
+}
+
+
+/* --------------------------------------------------
+ Comparison functions
+ -------------------------------------------------- */
+Int VG_(cmp_Int)(const void *v1, const void *v2)
+{
+ Int a = *(const Int *)v1;
+ Int b = *(const Int *)v2;
+
+ if (a < b)
+ return -1;
+ if (a == b)
+ return 0;
+ return 1;
+}
+
+Int VG_(cmp_UInt)(const void *v1, const void *v2)
+{
+ UInt a = *(const UInt *)v1;
+ UInt b = *(const UInt *)v2;
+
+ if (a < b)
+ return -1;
+ if (a == b)
+ return 0;
+ return 1;
+}
+
+Int VG_(cmp_Addr)(const void *v1, const void *v2)
+{
+ Addr a = *(const Addr *)v1;
+ Addr b = *(const Addr *)v2;
+
+ if (a < b)
+ return -1;
+ if (a == b)
+ return 0;
+ return 1;
+}
+
+Int VG_(cmp_string)(const void *v1, const void *v2)
+{
+ const Char *a = *(const Char **)v1;
+ const Char *b = *(const Char **)v2;
+
+ return VG_(strcmp)(a, b);
+}
+
+
--- valgrind/coregrind/vg_threadmodel.c #1.1:1.2
@@ -239,10 +239,5 @@ static void do_thread_dead(struct thread
}
-static Int tidcmp(const void *v1, const void *v2)
-{
- return *(Int *)v1 - *(Int *)v2;
-}
-
-static SkipList sk_threads = SKIPLIST_INIT(struct thread, tid, tidcmp, NULL, VG_AR_CORE);
+static SkipList sk_threads = SKIPLIST_INIT(struct thread, tid, VG_(cmp_UInt), NULL, VG_AR_CORE);
static struct thread *thread_get(ThreadId tid)
@@ -610,13 +605,5 @@ static void mutex_report(ThreadId tid, A
}
-static Int mutexcmp(const void *v1, const void *v2)
-{
- Addr a = *(Addr *)v1;
- Addr b = *(Addr *)v2;
-
- return (a < b) ? -1 : (a == b ? 0 : 1);
-}
-
-static SkipList sk_mutex = SKIPLIST_INIT(struct mutex, mutex, mutexcmp, NULL, VG_AR_CORE);
+static SkipList sk_mutex = SKIPLIST_INIT(struct mutex, mutex, VG_(cmp_Addr), NULL, VG_AR_CORE);
static struct mutex *mx_get(Addr mutexp)
--- valgrind/coregrind/vg_memory.c #1.92:1.93
@@ -38,18 +38,4 @@
static const Bool mem_debug = False;
-static Int addrcmp(const void *ap, const void *bp)
-{
- Addr a = *(Addr *)ap;
- Addr b = *(Addr *)bp;
- Int ret;
-
- if (a == b)
- ret = 0;
- else
- ret = (a < b) ? -1 : 1;
-
- return ret;
-}
-
static Char *straddr(void *p)
{
@@ -61,5 +47,5 @@ static Char *straddr(void *p)
}
-static SkipList sk_segments = SKIPLIST_INIT(Segment, addr, addrcmp, straddr, VG_AR_CORE);
+static SkipList sk_segments = SKIPLIST_INIT(Segment, addr, VG_(cmp_Addr), straddr, VG_AR_CORE);
/*--------------------------------------------------------------*/
--- valgrind/coregrind/vg_redir.c #1.5:1.6
@@ -76,18 +76,4 @@ struct _CodeRedirect {
};
-static Int cmp_addrp(const void *ap, const void *bp)
-{
- Addr a = *(Addr *)ap;
- Addr b = *(Addr *)bp;
- Int ret;
-
- if (a == b)
- ret = 0;
- else
- ret = (a < b) ? -1 : 1;
-
- return ret;
-}
-
static Char *straddr(void *p)
{
@@ -100,5 +86,5 @@ static Char *straddr(void *p)
static SkipList sk_resolved_redir = SKIPLIST_INIT(CodeRedirect, from_addr,
- cmp_addrp, straddr, VG_AR_SYMTAB);
+ VG_(cmp_Addr), straddr, VG_AR_SYMTAB);
static CodeRedirect *unresolved_redir = NULL;
@@ -574,9 +560,9 @@ struct wrapper_return {
/* A mapping from eip of wrapped function entrypoints to actual wrappers */
-static SkipList wrapped_functions = SKIPLIST_INIT(struct wrapped_function, eip, cmp_addrp,
+static SkipList wrapped_functions = SKIPLIST_INIT(struct wrapped_function, eip, VG_(cmp_Addr),
NULL, VG_AR_SYMTAB);
/* A set of EIPs which are return addresses for wrapped functions */
-static SkipList wrapper_returns = SKIPLIST_INIT(struct wrapper_return, eip, cmp_addrp,
+static SkipList wrapper_returns = SKIPLIST_INIT(struct wrapper_return, eip, VG_(cmp_Addr),
NULL, VG_AR_SYMTAB);
--- valgrind/include/tool.h.base #1.26:1.27
@@ -1690,6 +1690,12 @@
extern void *VG_(SkipList_Find_Exact) (const SkipList *l, void *key);
extern void *VG_(SkipList_Find_After) (const SkipList *l, void *key);
-extern void VG_(SkipList_Insert)( SkipList *l, void *data);
-extern void *VG_(SkipList_Remove)( SkipList *l, void *key);
+extern void VG_(SkipList_Insert) ( SkipList *l, void *data);
+extern void *VG_(SkipList_Remove) ( SkipList *l, void *key);
+
+/* Some useful standard comparisons */
+extern Int VG_(cmp_Addr) (const void *a, const void *b);
+extern Int VG_(cmp_Int) (const void *a, const void *b);
+extern Int VG_(cmp_UInt) (const void *a, const void *b);
+extern Int VG_(cmp_string)(const void *a, const void *b);
/* Node (element) operations:
|