From 2b6b7185687b90f6e20a3d8ded11186249e47fea Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Thu, 1 Nov 2018 08:09:07 +0000 Subject: [PATCH] Feature: Added support to actually define types --- include/igloo/ro.h | 1 - include/igloo/typedef.h | 21 +++++++++++++++++++-- src/ro.c | 11 +++++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/include/igloo/ro.h b/include/igloo/ro.h index 2d90dc4..86560cf 100644 --- a/include/igloo/ro.h +++ b/include/igloo/ro.h @@ -61,7 +61,6 @@ struct igloo_ro_type_tag { /* Size of this control structure */ size_t control_length; /* ABI version of this structure */ -#define igloo_RO__CONTROL_VERSION 1 int control_version; /* Total length of the objects to be created */ diff --git a/include/igloo/typedef.h b/include/igloo/typedef.h index 5c07194..d5372ff 100644 --- a/include/igloo/typedef.h +++ b/include/igloo/typedef.h @@ -28,8 +28,25 @@ extern "C" { * This header must be included before "types.h" and "ro.h" if used. */ -#define igloo_RO_TYPE(type) type * subtype__ ## type; -#define igloo_RO_FORWARD_TYPE(type) extern const igloo_ro_type_t *igloo_ro__type__ ## type +#define igloo_RO_TYPE(type) type * subtype__ ## type; + +#define igloo_RO__CONTROL_VERSION 1 +#define igloo_RO__DEFINE_TYPE(type, suffix, ...) \ +static const igloo_ro_type_t igloo_ro__typedef__ ## type = \ +{ \ + .control_length = sizeof(igloo_ro_type_t), \ + .control_version = igloo_RO__CONTROL_VERSION, \ + .type_length = sizeof(type), \ + .type_name = # type suffix \ + , ## __VA_ARGS__ \ +} + +#define igloo_RO_FORWARD_TYPE(type) extern const igloo_ro_type_t *igloo_ro__type__ ## type +#define igloo_RO_PUBLIC_TYPE(type, ...) igloo_RO__DEFINE_TYPE(type, "", ## __VA_ARGS__); const igloo_ro_type_t * igloo_ro__type__ ## type = &igloo_ro__typedef__ ## type +#define igloo_RO_PRIVATE_TYPE(type, ...) igloo_RO__DEFINE_TYPE(type, " (private)", ## __VA_ARGS__); static const igloo_ro_type_t * igloo_ro__type__ ## type = &igloo_ro__typedef__ ## type +#define igloo_RO_TYPEDECL_FREE(cb) .type_freecb = (cb) +#define igloo_RO_TYPEDECL_NEW(cb) .type_newcb = (cb) +#define igloo_RO_TYPEDECL_NEW_NOOP() .type_newcb = igloo_ro_new__return_zero #ifdef __cplusplus } diff --git a/src/ro.c b/src/ro.c index 6e09a94..675d647 100644 --- a/src/ro.c +++ b/src/ro.c @@ -26,6 +26,17 @@ #include +/* This is not static as it is used by igloo_RO_TYPEDECL_NEW_NOOP() */ +int igloo_ro_new__return_zero(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap) +{ + (void)self, (void)type, (void)ap; + return 0; +} + +igloo_RO_PUBLIC_TYPE(igloo_ro_base_t, + igloo_RO_TYPEDECL_NEW_NOOP() + ); + static inline int check_type(const igloo_ro_type_t *type) { return type->control_length == sizeof(igloo_ro_type_t) && type->control_version == igloo_RO__CONTROL_VERSION &&