summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2007-01-10 15:07:25 +0000
committerhunt <hunt>2007-01-10 15:07:25 +0000
commit3c2a749a7ef6df845063867ff69b12276ba09800 (patch)
tree76ccc779ffa9e250d0f6995594677ba8144f1ec2
parent4f723326777390f7ac0b949046e4adbf67a3f3cd (diff)
downloadsystemtap-steved-3c2a749a7ef6df845063867ff69b12276ba09800.tar.gz
systemtap-steved-3c2a749a7ef6df845063867ff69b12276ba09800.tar.xz
systemtap-steved-3c2a749a7ef6df845063867ff69b12276ba09800.zip
2007-01-10 Martin Hunt <hunt@redhat.com>
PR 3708 * map.c (str_copy): Check for NULL pointers. (_new_map_set_int64): Don't check val for 0. (_new_map_set_str): Don't check val for NULL. * map-gen.c (VAL_IS_ZERO): Removed. (_stp_map_del): New. (__stp_map_set): Don't check for zero. * pmap-gen.c (VAL_IS_ZERO): Removed. (_stp_pmap_del): New. (__stp_pmap_set): Don't check for zero.
-rw-r--r--runtime/ChangeLog14
-rw-r--r--runtime/map-gen.c49
-rw-r--r--runtime/map.c33
-rw-r--r--runtime/pmap-gen.c67
4 files changed, 122 insertions, 41 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog
index 450ac493..500dd25b 100644
--- a/runtime/ChangeLog
+++ b/runtime/ChangeLog
@@ -1,3 +1,17 @@
+2007-01-10 Martin Hunt <hunt@redhat.com>
+ PR 3708
+ * map.c (str_copy): Check for NULL pointers.
+ (_new_map_set_int64): Don't check val for 0.
+ (_new_map_set_str): Don't check val for NULL.
+
+ * map-gen.c (VAL_IS_ZERO): Removed.
+ (_stp_map_del): New.
+ (__stp_map_set): Don't check for zero.
+
+ * pmap-gen.c (VAL_IS_ZERO): Removed.
+ (_stp_pmap_del): New.
+ (__stp_pmap_set): Don't check for zero.
+
2006-12-20 Martin Hunt <hunt@redhat.com>
* runtime.h: Include mm.h.
diff --git a/runtime/map-gen.c b/runtime/map-gen.c
index 66654913..f2b39d40 100644
--- a/runtime/map-gen.c
+++ b/runtime/map-gen.c
@@ -40,7 +40,6 @@
#define VALN s
#define MAP_SET_VAL(a,b,c,d) _new_map_set_str(a,b,c,d)
#define MAP_GET_VAL(n) _stp_get_str(n)
-#define VAL_IS_ZERO(val,add) (val == 0 || *val == 0)
#define NULLRET ""
#elif VALUE_TYPE == INT64
#define VALTYPE int64_t
@@ -49,7 +48,6 @@
#define VALN i
#define MAP_SET_VAL(a,b,c,d) _new_map_set_int64(a,b,c,d)
#define MAP_GET_VAL(n) _stp_get_int64(n)
-#define VAL_IS_ZERO(val,add) (val == 0)
#define NULLRET (int64_t)0
#elif VALUE_TYPE == STAT
#define VALTYPE stat*
@@ -58,7 +56,6 @@
#define VALN x
#define MAP_SET_VAL(a,b,c,d) _new_map_set_stat(a,b,c,d)
#define MAP_GET_VAL(n) _stp_get_stat(n)
-#define VAL_IS_ZERO(val,add) (val == 0 && !add)
#define NULLRET (stat*)0
#else
#error Need to define VALUE_TYPE as STRING, STAT, or INT64
@@ -429,19 +426,11 @@ int KEYSYM(__stp_map_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add)
#endif
#endif
) {
- if VAL_IS_ZERO(val,add) {
- if (!add)
- _new_map_del_node(map,(struct map_node *)n);
- return 0;
-
- }
return MAP_SET_VAL(map,(struct map_node *)n, val, add);
}
}
/* key not found */
dbug("key not found\n");
- if VAL_IS_ZERO(val,add)
- return 0;
n = (struct KEYSYM(map_node)*)_new_map_create (map, head);
if (n == NULL)
@@ -498,6 +487,43 @@ VALTYPE KEYSYM(_stp_map_get) (MAP map, ALLKEYSD(key))
return NULLRET;
}
+int KEYSYM(_stp_map_del) (MAP map, ALLKEYSD(key))
+{
+ unsigned int hv;
+ struct hlist_head *head;
+ struct hlist_node *e;
+ struct KEYSYM(map_node) *n;
+
+ if (map == NULL)
+ return -1;
+
+ hv = KEYSYM(hash) (ALLKEYS(key));
+ head = &map->hashes[hv];
+
+ hlist_for_each(e, head) {
+ n = (struct KEYSYM(map_node) *)((long)e - sizeof(struct list_head));
+ if (KEY1_EQ_P(n->key1, key1)
+#if KEY_ARITY > 1
+ && KEY2_EQ_P(n->key2, key2)
+#if KEY_ARITY > 2
+ && KEY3_EQ_P(n->key3, key3)
+#if KEY_ARITY > 3
+ && KEY4_EQ_P(n->key4, key4)
+#if KEY_ARITY > 4
+ && KEY5_EQ_P(n->key5, key5)
+#endif
+#endif
+#endif
+#endif
+ ) {
+ _new_map_del_node(map,(struct map_node *)n);
+ return 0;
+ }
+ }
+ /* key not found */
+ return 0;
+}
+
#undef KEY1NAME
#undef KEY1N
@@ -548,5 +574,4 @@ VALTYPE KEYSYM(_stp_map_get) (MAP map, ALLKEYSD(key))
#undef MAP_SET_VAL
#undef MAP_GET_VAL
-#undef VAL_IS_ZERO
#undef NULLRET
diff --git a/runtime/map.c b/runtime/map.c
index 843a8543..cb866ffe 100644
--- a/runtime/map.c
+++ b/runtime/map.c
@@ -39,10 +39,13 @@ int int64_eq_p (int64_t key1, int64_t key2)
void str_copy(char *dest, char *src)
{
- int len = strlen(src);
- if (len > MAP_STRING_LENGTH - 1)
- len = MAP_STRING_LENGTH - 1;
- memcpy (dest, src, len);
+ int len = 0;
+ if (src) {
+ len = strlen(src);
+ if (len > MAP_STRING_LENGTH - 1)
+ len = MAP_STRING_LENGTH - 1;
+ memcpy (dest, src, len);
+ }
dest[len] = 0;
}
@@ -974,12 +977,11 @@ static int _new_map_set_int64 (MAP map, struct map_node *n, int64_t val, int add
if (map == NULL || n == NULL)
return -2;
- if (val || map->list) {
- if (add)
- *(int64_t *)((long)n + map->data_offset) += val;
- else
- *(int64_t *)((long)n + map->data_offset) = val;
- }
+ if (add)
+ *(int64_t *)((long)n + map->data_offset) += val;
+ else
+ *(int64_t *)((long)n + map->data_offset) = val;
+
return 0;
}
@@ -988,12 +990,11 @@ static int _new_map_set_str (MAP map, struct map_node *n, char *val, int add)
if (map == NULL || n == NULL)
return -2;
- if ((val && *val)|| map->list) {
- if (add)
- str_add((void *)((long)n + map->data_offset), val);
- else
- str_copy((void *)((long)n + map->data_offset), val);
- }
+ if (add)
+ str_add((void *)((long)n + map->data_offset), val);
+ else
+ str_copy((void *)((long)n + map->data_offset), val);
+
return 0;
}
diff --git a/runtime/pmap-gen.c b/runtime/pmap-gen.c
index 21a0aef4..ddae87ab 100644
--- a/runtime/pmap-gen.c
+++ b/runtime/pmap-gen.c
@@ -40,7 +40,6 @@
#define VALN s
#define MAP_SET_VAL(a,b,c,d) _new_map_set_str(a,b,c,d)
#define MAP_GET_VAL(n) _stp_get_str(n)
-#define VAL_IS_ZERO(val,add) (val == 0 || *val == 0)
#define NULLRET ""
#elif VALUE_TYPE == INT64
#define VALTYPE int64_t
@@ -49,7 +48,6 @@
#define VALN i
#define MAP_SET_VAL(a,b,c,d) _new_map_set_int64(a,b,c,d)
#define MAP_GET_VAL(n) _stp_get_int64(n)
-#define VAL_IS_ZERO(val,add) (val == 0)
#define NULLRET (int64_t)0
#elif VALUE_TYPE == STAT
#define VALTYPE stat*
@@ -58,7 +56,6 @@
#define VALN x
#define MAP_SET_VAL(a,b,c,d) _new_map_set_stat(a,b,c,d)
#define MAP_GET_VAL(n) _stp_get_stat(n)
-#define VAL_IS_ZERO(val,add) (val == 0 && !add)
#define NULLRET (stat*)0
#else
#error Need to define VALUE_TYPE as STRING, STAT, or INT64
@@ -516,12 +513,6 @@ int KEYSYM(__stp_pmap_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add)
#endif
#endif
) {
- if VAL_IS_ZERO(val,add) {
- if (!add)
- _new_map_del_node(map,(struct map_node *)n);
- return 0;
-
- }
return MAP_SET_VAL(map,(struct map_node *)n, val, add);
}
}
@@ -529,9 +520,6 @@ int KEYSYM(__stp_pmap_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add)
/* key not found */
dbug("key not found\n");
- if VAL_IS_ZERO(val,add)
- return 0;
-
n = (struct KEYSYM(pmap_node)*)_new_map_create (map, head);
if (n == NULL)
return -1;
@@ -699,6 +687,60 @@ VALTYPE KEYSYM(_stp_pmap_get) (PMAP pmap, ALLKEYSD(key))
return NULLRET;
}
+int KEYSYM(__stp_pmap_del) (MAP map, ALLKEYSD(key))
+{
+ unsigned int hv;
+ struct hlist_head *head;
+ struct hlist_node *e;
+ struct KEYSYM(pmap_node) *n;
+
+ if (map == NULL)
+ return -1;
+
+ if (KEYSYM(pkeycheck) (ALLKEYS(key)) == 0)
+ return -1;
+
+ hv = KEYSYM(phash) (ALLKEYS(key));
+ head = &map->hashes[hv];
+
+ hlist_for_each(e, head) {
+ n = (struct KEYSYM(pmap_node) *)((long)e - sizeof(struct list_head));
+ if (KEY1_EQ_P(n->key1, key1)
+#if KEY_ARITY > 1
+ && KEY2_EQ_P(n->key2, key2)
+#if KEY_ARITY > 2
+ && KEY3_EQ_P(n->key3, key3)
+#if KEY_ARITY > 3
+ && KEY4_EQ_P(n->key4, key4)
+#if KEY_ARITY > 4
+ && KEY5_EQ_P(n->key5, key5)
+#endif
+#endif
+#endif
+#endif
+ ) {
+ _new_map_del_node(map,(struct map_node *)n);
+ return 0;
+ }
+ }
+
+ /* key not found */
+ dbug("key not found\n");
+ return 0;
+}
+
+int KEYSYM(_stp_pmap_del) (PMAP pmap, ALLKEYSD(key))
+{
+ int res;
+ MAP m = per_cpu_ptr (pmap->map, get_cpu());
+ if (!spin_trylock(&m->lock))
+ return -1;
+ res = KEYSYM(__stp_pmap_del) (m, ALLKEYS(key));
+ spin_unlock(&m->lock);
+ put_cpu();
+ return res;
+}
+
#undef KEY1NAME
#undef KEY1N
#undef KEY1TYPE
@@ -748,5 +790,4 @@ VALTYPE KEYSYM(_stp_pmap_get) (PMAP pmap, ALLKEYSD(key))
#undef MAP_SET_VAL
#undef MAP_GET_VAL
-#undef VAL_IS_ZERO
#undef NULLRET