aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2012-11-24 00:40:40 +0100
committerPetr Machata <pmachata@redhat.com>2013-03-08 22:55:26 +0100
commit3ac9b91974678878889776221c390f39f5c2ffcf (patch)
tree9257cb726e0ca50f83c7f7cc7622bc6779fb2af2
parent58f6487bba4be7da18752e3ce9065723fd9be71f (diff)
downloadltrace-3ac9b91974678878889776221c390f39f5c2ffcf.tar.gz
Implement more of prototype.{c,h}
-rw-r--r--prototype.c51
-rw-r--r--prototype.h9
2 files changed, 49 insertions, 11 deletions
diff --git a/prototype.c b/prototype.c
index 0575dd3..e123394 100644
--- a/prototype.c
+++ b/prototype.c
@@ -108,9 +108,18 @@ prototype_each_param(struct prototype *proto, struct param *start_after,
}
void
+named_type_init(struct named_type *named,
+ struct arg_type_info *info, int own_type)
+{
+ named->info = info;
+ named->own_type = own_type;
+ named->forward = 0;
+}
+
+void
named_type_destroy(struct named_type *named)
{
- if (named->owned) {
+ if (named->own_type) {
type_destroy(named->info);
free(named->info);
}
@@ -229,18 +238,32 @@ protolib_add_named_type(struct protolib *plib, const char *name, int own_name,
struct lookup {
const char *name;
void *result;
+ struct dict *(*getter)(struct protolib *plib);
};
+static struct dict *
+get_prototypes(struct protolib *plib)
+{
+ return plib->prototypes;
+}
+
+static struct dict *
+get_named_types(struct protolib *plib)
+{
+ return plib->named_types;
+}
+
static enum callback_status
-lookup_prototype_rec(struct protolib **plibp, void *data)
+protolib_lookup_rec(struct protolib **plibp, void *data)
{
struct lookup *lookup = data;
+ struct dict *dict = (*lookup->getter)(*plibp);
- lookup->result = dict_find_entry((*plibp)->prototypes, lookup->name);
+ lookup->result = dict_find_entry(dict, lookup->name);
if (lookup->result != NULL)
return CBS_STOP;
- if (each_import(*plibp, NULL, &lookup_prototype_rec, lookup) != NULL) {
+ if (each_import(*plibp, NULL, &protolib_lookup_rec, lookup) != NULL) {
assert(lookup->result != NULL);
return CBS_STOP;
}
@@ -248,16 +271,26 @@ lookup_prototype_rec(struct protolib **plibp, void *data)
return CBS_CONT;
}
-struct prototype *
-protolib_lookup_prototype(struct protolib *plib, const char *name)
+static void *
+protolib_lookup(struct protolib *plib, const char *name,
+ struct dict *(*getter)(struct protolib *))
{
- struct lookup lookup = { name, NULL };
- if (lookup_prototype_rec(&plib, &lookup) == CBS_STOP)
+ struct lookup lookup = { name, NULL, getter };
+ if (protolib_lookup_rec(&plib, &lookup) == CBS_STOP)
assert(lookup.result != NULL);
else
assert(lookup.result == NULL);
return lookup.result;
}
+struct prototype *
+protolib_lookup_prototype(struct protolib *plib, const char *name)
+{
+ return protolib_lookup(plib, name, &get_prototypes);
+}
+
struct named_type *
-protolib_lookup_type(struct protolib *plib, const char *name);
+protolib_lookup_type(struct protolib *plib, const char *name)
+{
+ return protolib_lookup(plib, name, &get_named_types);
+}
diff --git a/prototype.h b/prototype.h
index 7a75e2f..0181f32 100644
--- a/prototype.h
+++ b/prototype.h
@@ -69,9 +69,14 @@ struct param *prototype_each_param
struct named_type {
struct arg_type_info *info;
int forward : 1;
- int owned : 1;
+ int own_type : 1;
};
+/* Initialize a named type INFO, which, if OWN_TYPE, is destroyed when
+ * named_type_destroy is called. */
+void named_type_init(struct named_type *named,
+ struct arg_type_info *info, int own_type);
+
void named_type_destroy(struct named_type *named);
/* One prototype library. */
@@ -110,7 +115,7 @@ int protolib_add_prototype(struct protolib *plib,
/* Add a named type NAMED to PLIB. Returns 0 on success or a negative
* value on failure. NAME is owned and released on PLIB destruction
- * if OWN_NAME. */
+ * if OWN_NAME. NAMED _pointer_ is copied to PLIB. */
int protolib_add_named_type(struct protolib *plib,
const char *name, int own_name,
struct named_type *named);