summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorhunt <hunt>2005-10-28 19:44:58 +0000
committerhunt <hunt>2005-10-28 19:44:58 +0000
commit063b69fe3f1109ec81b5e4c1f1333a442ccb3734 (patch)
tree7e2a0bffafb5e606eabc7f5da73d580451fb6d5e
parent052d76119736a4b1d90190e37f45439ca1e57393 (diff)
downloadsystemtap-steved-063b69fe3f1109ec81b5e4c1f1333a442ccb3734.tar.gz
systemtap-steved-063b69fe3f1109ec81b5e4c1f1333a442ccb3734.tar.xz
systemtap-steved-063b69fe3f1109ec81b5e4c1f1333a442ccb3734.zip
2005-10-28 Martin Hunt <hunt@redhat.com>
* map-gen.c (MAP_GET_VAL): Use the _stp_get_*() functions. (_stp_map_set_*): When setting to "", don't create node if key not found. (_stp_map_get_*): Use new MAP_GET_VAL. Return "" when string lookups not found. * map.c (_stp_get_int64): Check args and return 0 on bad args or wrong type. (_stp_get_stat): Ditto. (_stp_key_get_int64): Ditto. (_stp_get_str): Check args and return "bad type" on bad args or wrong type. (_stp_key_get_str): Ditto. (_new_map_set_str): If setting to "", delete node. (_new_map_get_*): Delete. Use _stp_get_*().
-rw-r--r--runtime/ChangeLog19
-rw-r--r--runtime/map-gen.c20
-rw-r--r--runtime/map.c55
3 files changed, 61 insertions, 33 deletions
diff --git a/runtime/ChangeLog b/runtime/ChangeLog
index e80b225e..9f85601a 100644
--- a/runtime/ChangeLog
+++ b/runtime/ChangeLog
@@ -1,3 +1,22 @@
+2005-10-28 Martin Hunt <hunt@redhat.com>
+
+ * map-gen.c (MAP_GET_VAL): Use the _stp_get_*() functions.
+ (_stp_map_set_*): When setting to "", don't create
+ node if key not found.
+ (_stp_map_get_*): Use new MAP_GET_VAL. Return "" when
+ string lookups not found.
+
+ * map.c (_stp_get_int64): Check args and return
+ 0 on bad args or wrong type.
+ (_stp_get_stat): Ditto.
+ (_stp_key_get_int64): Ditto.
+ (_stp_get_str): Check args and return
+ "bad type" on bad args or wrong type.
+ (_stp_key_get_str): Ditto.
+ (_new_map_set_str): If setting to "", delete node.
+ (_new_map_get_*): Delete. Use _stp_get_*().
+
+
2005-10-26 Martin Hunt <hunt@redhat.com>
* map-gen.c (KEY4CPY): Fix typo.
diff --git a/runtime/map-gen.c b/runtime/map-gen.c
index ffb77660..1034b5fb 100644
--- a/runtime/map-gen.c
+++ b/runtime/map-gen.c
@@ -39,21 +39,21 @@
#define VALNAME str
#define VALN s
#define MAP_SET_VAL(a,b,c,d) _new_map_set_str(a,b,c,d)
-#define MAP_GET_VAL(a,b) _new_map_get_str(a,b)
+#define MAP_GET_VAL(n) _stp_get_str(n)
#elif VALUE_TYPE == INT64
#define VALTYPE int64_t
#define VSTYPE int64_t
#define VALNAME int64
#define VALN i
#define MAP_SET_VAL(a,b,c,d) _new_map_set_int64(a,b,c,d)
-#define MAP_GET_VAL(a,b) _new_map_get_int64(a,b)
+#define MAP_GET_VAL(n) _stp_get_int64(n)
#elif VALUE_TYPE == STAT
#define VALTYPE stat*
#define VSTYPE int64_t
#define VALNAME stat
#define VALN x
#define MAP_SET_VAL(a,b,c,d) _new_map_set_stat(a,b,c,d)
-#define MAP_GET_VAL(a,b) _new_map_get_stat(a,b)
+#define MAP_GET_VAL(n) _stp_get_stat(n)
#else
#error Need to define VALUE_TYPE as STRING, STAT, or INT64
#endif /* VALUE_TYPE */
@@ -226,7 +226,7 @@ static key_data KEYSYM(map_get_key) (struct map_node *mn, int n, int *type)
key_data ptr;
struct KEYSYM(map_node) *m = (struct KEYSYM(map_node) *)mn;
- // dbug ("m=%lx\n", (long)m);
+ dbug ("n = %d type=%lx\n", n, type);
if (n > KEY_ARITY || n < 1) {
if (type)
*type = END;
@@ -440,8 +440,14 @@ int KEYSYM(__stp_map_set) (MAP map, ALLKEYSD(key), VSTYPE val, int add)
}
/* key not found */
dbug("key not found\n");
+#if VALUE_TYPE == STRING
+ if ((val == 0 || *val == 0) && !add)
+ return 0;
+#else
if (val == 0 && !add)
return 0;
+#endif
+
n = (struct KEYSYM(map_node)*)_new_map_create (map, head);
if (n == NULL)
return -1;
@@ -494,11 +500,15 @@ VALTYPE KEYSYM(_stp_map_get) (MAP map, ALLKEYSD(key))
#endif
#endif
) {
- return MAP_GET_VAL(map,(struct map_node *)n);
+ return MAP_GET_VAL((struct map_node *)n);
}
}
/* key not found */
+#if VALUE_TYPE == STRING
+ return "";
+#else
return (VALTYPE)0;
+#endif
}
diff --git a/runtime/map.c b/runtime/map.c
index 9bf143e6..6da366e5 100644
--- a/runtime/map.c
+++ b/runtime/map.c
@@ -64,6 +64,8 @@ unsigned int str_hash(const char *key1)
*/
int64_t _stp_get_int64(struct map_node *m)
{
+ if (!m || m->map->type != INT64)
+ return 0;
return *(int64_t *)((long)m + m->map->data_offset);
}
@@ -76,6 +78,8 @@ int64_t _stp_get_int64(struct map_node *m)
*/
char *_stp_get_str(struct map_node *m)
{
+ if (!m || m->map->type != STRING)
+ return "bad type";
return (char *)((long)m + m->map->data_offset);
}
@@ -88,6 +92,8 @@ char *_stp_get_str(struct map_node *m)
*/
stat *_stp_get_stat(struct map_node *m)
{
+ if (!m || m->map->type != STAT)
+ return 0;
return (stat *)((long)m + m->map->data_offset);
}
@@ -100,9 +106,16 @@ stat *_stp_get_stat(struct map_node *m)
*/
int64_t _stp_key_get_int64 (struct map_node *mn, int n)
{
- if (mn)
- return (*mn->map->get_key)(mn, n, NULL).val;
- return 0;
+ int type;
+ int64_t res = 0;
+
+ if (mn) {
+ res = (*mn->map->get_key)(mn, n, &type).val;
+ dbug("type=%d\n", type);
+ if (type != INT64)
+ res = 0;
+ }
+ return res;
}
/** Return a string key from a map node.
@@ -114,9 +127,16 @@ int64_t _stp_key_get_int64 (struct map_node *mn, int n)
*/
char *_stp_key_get_str (struct map_node *mn, int n)
{
- if (mn)
- return (*mn->map->get_key)(mn, n, NULL).strp;
- return "";
+ int type;
+ char *str = "";
+
+ if (mn) {
+ str = (*mn->map->get_key)(mn, n, &type).strp;
+ dbug("type=%d\n", type);
+ if (type != STRING)
+ str = "bad type";
+ }
+ return str;
}
/** Create a new map.
@@ -677,7 +697,7 @@ 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 || map->list) {
+ if ((val && *val)|| map->list) {
if (add)
str_add((void *)((long)n + map->data_offset), val);
else
@@ -689,27 +709,6 @@ static int _new_map_set_str (MAP map, struct map_node *n, char *val, int add)
return 0;
}
-static int64_t _new_map_get_int64 (MAP map, struct map_node *n)
-{
- if (map == NULL || n == NULL)
- return 0;
- return *(int64_t *)((long)n + map->data_offset);
-}
-
-static char *_new_map_get_str (MAP map, struct map_node *n)
-{
- if (map == NULL || n == NULL)
- return 0;
- return (char *)((long)n + map->data_offset);
-}
-
-static stat *_new_map_get_stat (MAP map, struct map_node *n)
-{
- if (map == NULL || n == NULL)
- return 0;
- return (stat *)((long)n + map->data_offset);
-}
-
static int _new_map_set_stat (MAP map, struct map_node *n, int64_t val, int add, int new)
{
stat *sd;