From: Sebastian Harl Date: Mon, 31 Mar 2014 20:41:37 +0000 (+0200) Subject: object: Let create_simple() accept an optional destructor. X-Git-Tag: sysdb-0.1.0~170 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=a6aba8073470766a456ee417cd948fe56c1e4f2c;p=sysdb.git object: Let create_simple() accept an optional destructor. This is still simple but it allows for some more dynamic. --- diff --git a/src/core/object.c b/src/core/object.c index 9d10f98..177ac4c 100644 --- a/src/core/object.c +++ b/src/core/object.c @@ -125,9 +125,10 @@ sdb_object_create(const char *name, sdb_type_t type, ...) } /* sdb_object_create */ sdb_object_t * -sdb_object_create_simple(const char *name, size_t size) +sdb_object_create_simple(const char *name, size_t size, + void (*destructor)(sdb_object_t *)) { - sdb_type_t t = { size, NULL, NULL }; + sdb_type_t t = { size, NULL, destructor }; return sdb_object_create(name, t); } /* sdb_object_create_simple */ diff --git a/src/include/core/object.h b/src/include/core/object.h index 2f6470e..25e37d1 100644 --- a/src/include/core/object.h +++ b/src/include/core/object.h @@ -95,17 +95,19 @@ sdb_object_vcreate(const char *name, sdb_type_t type, va_list ap); /* * sdb_object_create_simple: - * Create a "simple" object without custom initialization and destructor. - * See the description of sdb_object_create for more details. + * Create a "simple" object without custom initialization and optional + * destructor. See the description of sdb_object_create for more details. */ sdb_object_t * -sdb_object_create_simple(const char *name, size_t size); +sdb_object_create_simple(const char *name, size_t size, + void (*destructor)(sdb_object_t *)); /* * sdb_object_create_T: * Create a simple object of type 't'. */ -#define sdb_object_create_T(n,t) sdb_object_create_simple((n), sizeof(t)) +#define sdb_object_create_T(n,t) \ + sdb_object_create_simple((n), sizeof(t), NULL) /* * sdb_object_create_wrapper: diff --git a/t/core/object_test.c b/t/core/object_test.c index 844dbc1..85e95c3 100644 --- a/t/core/object_test.c +++ b/t/core/object_test.c @@ -159,7 +159,7 @@ START_TEST(test_obj_create) sdb_object_deref(obj); init_noop_called = 0; - obj = sdb_object_create_simple(name, sizeof(struct noop)); + obj = sdb_object_create_simple(name, sizeof(struct noop), NULL); fail_unless(obj != NULL, "sdb_object_create_simple() = NULL; expected: "); fail_unless(obj->type.size == sizeof(struct noop),