diff options
author | Petr Machata <pmachata@redhat.com> | 2013-10-16 14:24:27 +0200 |
---|---|---|
committer | Petr Machata <pmachata@redhat.com> | 2013-10-23 01:00:03 +0200 |
commit | c65c24a7e4645559a0fb050ff5a96ec248827562 (patch) | |
tree | 4fc2a183b0d2968a47654fbc610d3e9df627212d | |
parent | a186b0e5c469156b9af66e88dca12d208418195c (diff) | |
download | ltrace-c65c24a7e4645559a0fb050ff5a96ec248827562.tar.gz |
Extract the logic for creating void* type to type_get_voidptr
-rw-r--r-- | prototype.c | 6 | ||||
-rw-r--r-- | type.c | 13 | ||||
-rw-r--r-- | type.h | 1 |
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. */ @@ -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) { @@ -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 |