diff options
author | hunt <hunt> | 2005-10-28 19:44:58 +0000 |
---|---|---|
committer | hunt <hunt> | 2005-10-28 19:44:58 +0000 |
commit | 063b69fe3f1109ec81b5e4c1f1333a442ccb3734 (patch) | |
tree | 7e2a0bffafb5e606eabc7f5da73d580451fb6d5e /runtime/map.c | |
parent | 052d76119736a4b1d90190e37f45439ca1e57393 (diff) | |
download | systemtap-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_*().
Diffstat (limited to 'runtime/map.c')
-rw-r--r-- | runtime/map.c | 55 |
1 files changed, 27 insertions, 28 deletions
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; |