From 2dd9045842536abf17cba4f21765e82aa0519d08 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 10 Oct 2018 14:11:24 +0000 Subject: [PATCH] Fix: Corrected structure of how refobject_type*__* is generated. --- src/refobject.h | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/refobject.h b/src/refobject.h index 21fcb594..7e375e4c 100644 --- a/src/refobject.h +++ b/src/refobject.h @@ -53,19 +53,22 @@ #define REFOBJECT_GET_TYPE(x) (REFOBJECT_GET_BASE((x)) == NULL ? NULL : REFOBJECT_GET_BASE((x))->type) #define REFOBJECT_GET_TYPENAME(x) (REFOBJECT_GET_TYPE((x)) == NULL ? NULL : REFOBJECT_GET_TYPE((x))->type_name) -#define REFOBJECT_IS_VALID(x,type) (!REFOBJECT_IS_NULL((x)) && REFOBJECT_GET_TYPE((x)) == &(refobject_type__ ## type)) +#define REFOBJECT_IS_VALID(x,type) (!REFOBJECT_IS_NULL((x)) && REFOBJECT_GET_TYPE((x)) == (refobject_type__ ## type)) -#define REFOBJECT_CONTROL_VERSION 0 -#define REFOBJECT_FORWARD_TYPE(type) extern const refobject_type_t refobject_type__ ## type; -#define REFOBJECT_DEFINE_TYPE(type, extra) const refobject_type_t refobject_type__ ## type = { \ +#define REFOBJECT_CONTROL_VERSION 1 +#define REFOBJECT_FORWARD_TYPE(type) extern const refobject_type_t * refobject_type__ ## type; +#define REFOBJECT_DEFINE_TYPE__RAW(type, ...) \ +static const refobject_type_t refobject_typedef__ ## type = \ +{ \ .control_length = sizeof(refobject_type_t), \ .control_version = REFOBJECT_CONTROL_VERSION, \ .type_length = sizeof(type), \ - .type_name = # type, \ - extra \ + .type_name = # type \ + , ## __VA_ARGS__ \ } -#define REFOBJECT_DEFINE_PRIVATE_TYPE(type, extra) static REFOBJECT_DEFINE_TYPE(type, extra) -#define REFOBJECT_DEFINE_TYPE_FREE(cb) .type_freecb = (cb) +#define REFOBJECT_DEFINE_TYPE(type, ...) REFOBJECT_DEFINE_TYPE__RAW(type, ## __VA_ARGS__); const refobject_type_t * refobject_type__ ## type = &refobject_typedef__ ## type +#define REFOBJECT_DEFINE_PRIVATE_TYPE(type, ...) REFOBJECT_DEFINE_TYPE__RAW(type, ## __VA_ARGS__); static const refobject_type_t * refobject_type__ ## type = &refobject_typedef__ ## type +#define REFOBJECT_DEFINE_TYPE_FREE(cb) .type_freecb = (cb) /* Type used for callback called then the object is actually freed * That is once all references to it are gone. @@ -119,7 +122,7 @@ REFOBJECT_FORWARD_TYPE(refobject_base_t); * All parameters beside len are optional and can be NULL/REFOBJECT_NULL. * If no freecb is given the userdata is freed (see refobject_free_t above). */ -#define refobject_new__new(type, userdata, name, associated) REFOBJECT_TO_TYPE(refobject_new__real(&(refobject_type__ ## type), (userdata), (name), (associated)), type*) +#define refobject_new__new(type, userdata, name, associated) REFOBJECT_TO_TYPE(refobject_new__real((refobject_type__ ## type), (userdata), (name), (associated)), type*) refobject_t refobject_new__real(const refobject_type_t *type, void *userdata, const char *name, refobject_t associated); /* This increases the reference counter of the object */ -- GitLab