aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPetr Machata <pmachata@redhat.com>2013-10-16 14:24:27 +0200
committerPetr Machata <pmachata@redhat.com>2013-10-23 01:00:03 +0200
commitc65c24a7e4645559a0fb050ff5a96ec248827562 (patch)
tree4fc2a183b0d2968a47654fbc610d3e9df627212d
parenta186b0e5c469156b9af66e88dca12d208418195c (diff)
downloadltrace-c65c24a7e4645559a0fb050ff5a96ec248827562.tar.gz
Extract the logic for creating void* type to type_get_voidptr
-rw-r--r--prototype.c6
-rw-r--r--type.c13
-rw-r--r--type.h1
3 files changed, 16 insertions, 4 deletions
diff --git a/prototype.c b/prototype.c
index 92f7509..319b7a2 100644
--- a/prototype.c
+++ b/prototype.c
@@ -645,12 +645,10 @@ void
init_global_config(void)
{
protolib_init(&legacy_typedefs);
- struct arg_type_info *void_info = type_get_simple(ARGTYPE_VOID);
- static struct arg_type_info ptr_info;
- type_init_pointer(&ptr_info, void_info, 0);
+ struct arg_type_info *ptr_info = type_get_voidptr();
static struct named_type voidptr_type;
- named_type_init(&voidptr_type, &ptr_info, 0);
+ named_type_init(&voidptr_type, ptr_info, 0);
/* Build legacy typedefs first. This is used by
* protolib_cache_init call below. */
diff --git a/type.c b/type.c
index 458da4b..6128085 100644
--- a/type.c
+++ b/type.c
@@ -59,6 +59,19 @@ type_get_simple(enum arg_type type)
abort();
}
+struct arg_type_info *
+type_get_voidptr(void)
+{
+ struct arg_type_info *void_info = type_get_simple(ARGTYPE_VOID);
+ static struct arg_type_info *ret;
+ if (ret == NULL) {
+ static struct arg_type_info ptr_info;
+ type_init_pointer(&ptr_info, void_info, 0);
+ ret = &ptr_info;
+ }
+ return ret;
+}
+
static void
type_init_common(struct arg_type_info *info, enum arg_type type)
{
diff --git a/type.h b/type.h
index 0ffbd98..9ddaa34 100644
--- a/type.h
+++ b/type.h
@@ -70,6 +70,7 @@ struct arg_type_info {
* struct, or pointer. Each call with the same TYPE yields the same
* arg_type_info pointer. */
struct arg_type_info *type_get_simple(enum arg_type type);
+struct arg_type_info *type_get_voidptr(void);
/* Initialize INFO so it becomes ARGTYPE_STRUCT. The created
* structure contains no fields. Use type_struct_add to populate the