summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: df33553)
raw | patch | inline | side by side (parent: df33553)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 31 Mar 2014 20:41:37 +0000 (22:41 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 31 Mar 2014 20:41:37 +0000 (22:41 +0200) |
This is still simple but it allows for some more dynamic.
src/core/object.c | patch | blob | history | |
src/include/core/object.h | patch | blob | history | |
t/core/object_test.c | patch | blob | history |
diff --git a/src/core/object.c b/src/core/object.c
index 9d10f9831720ba8eaf310d3f83227c8572025df1..177ac4c3ada9a76009805187d0a0cd4eda322b9e 100644 (file)
--- a/src/core/object.c
+++ b/src/core/object.c
} /* 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 */
index 2f6470e01c8ee5350b75a7300029e88162b759a3..25e37d18b7c4a2817a438f4624a3bdf2b3c9e93a 100644 (file)
/*
* 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 844dbc19982678484d46ff701011f5ba70250025..85e95c3a8b121cf590f6eee1e0de55a70ed703da 100644 (file)
--- a/t/core/object_test.c
+++ b/t/core/object_test.c
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: <obj>");
fail_unless(obj->type.size == sizeof(struct noop),