Commit 48bb4773 authored by Philipp Schafft's avatar Philipp Schafft

Feature: Added REFOBJECT_DEFINE_TYPE_NEW_NOOP()

parent 491c4ab2
......@@ -19,14 +19,14 @@
#define TO_BASE(x) REFOBJECT_TO_TYPE((x), refobject_base_t *)
static int return_zero(refobject_t self, const refobject_type_t *type, va_list ap)
int refobject_new__return_zero(refobject_t self, const refobject_type_t *type, va_list ap)
{
(void)self, (void)type, (void)ap;
return 0;
}
REFOBJECT_DEFINE_TYPE(refobject_base_t,
REFOBJECT_DEFINE_TYPE_NEW(return_zero)
REFOBJECT_DEFINE_TYPE_NEW_NOOP()
);
static inline int check_type(const refobject_type_t *type)
......
......@@ -72,8 +72,10 @@ static const refobject_type_t 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)
#define REFOBJECT_DEFINE_TYPE_NEW(cb) .type_newcb = (cb)
#define REFOBJECT_DEFINE_TYPE_NEW_NOOP() .type_newcb = refobject_new__return_zero
typedef struct refobject_type_tag refobject_type_t;
int refobject_new__return_zero(refobject_t self, const refobject_type_t *type, va_list ap);
/* Type used for callback called then the object is actually freed
* That is once all references to it are gone.
......
......@@ -16,12 +16,6 @@
#include "../refobject.h"
static int return_zero(refobject_t self, const refobject_type_t *type, va_list ap)
{
(void)self, (void)type, (void)ap;
return 0;
}
static void test_ptr(void)
{
refobject_t a;
......@@ -90,7 +84,7 @@ static void test_sizes(void)
char padding[1024];
} ctest_test_type_a_t;
REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_a_t,
REFOBJECT_DEFINE_TYPE_NEW(return_zero)
REFOBJECT_DEFINE_TYPE_NEW_NOOP()
);
typedef struct {
......@@ -98,21 +92,21 @@ static void test_sizes(void)
char padding[131072];
} ctest_test_type_b_t;
REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_b_t,
REFOBJECT_DEFINE_TYPE_NEW(return_zero)
REFOBJECT_DEFINE_TYPE_NEW_NOOP()
);
typedef struct {
char padding[sizeof(refobject_base_t) - 1];
} ctest_test_type_c_t;
REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_c_t,
REFOBJECT_DEFINE_TYPE_NEW(return_zero)
REFOBJECT_DEFINE_TYPE_NEW_NOOP()
);
typedef struct {
char padding[0];
} ctest_test_type_d_t;
REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_d_t,
REFOBJECT_DEFINE_TYPE_NEW(return_zero)
REFOBJECT_DEFINE_TYPE_NEW_NOOP()
);
a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_a_t));
......@@ -212,7 +206,7 @@ static void test_freecb(void)
REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_t,
REFOBJECT_DEFINE_TYPE_FREE(test_freecb__freecb),
REFOBJECT_DEFINE_TYPE_NEW(return_zero)
REFOBJECT_DEFINE_TYPE_NEW_NOOP()
);
test_freecb__called = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment