diff --git a/include/igloo/ro.h b/include/igloo/ro.h index feed150..2e8facf 100644 --- a/include/igloo/ro.h +++ b/include/igloo/ro.h @@ -295,7 +295,7 @@ igloo_ro_t igloo_ro_new__simple(const igloo_ro_type_t *type, const char *na #define igloo_ro_new_ext(type, name, associated, ...) igloo_RO_TO_TYPE(igloo_ro_new__simple(igloo_RO_GET_TYPE_BY_SYMBOL(type), (name), (associated), ## __VA_ARGS__), type) /* This increases the reference counter of the object */ -int igloo_ro_ref(igloo_ro_t self); +igloo_error_t igloo_ro_ref(igloo_ro_t self); /* This decreases the reference counter of the object. * If the object's reference counter reaches zero the object is freed. */ diff --git a/src/interface.c b/src/interface.c index 0a57aef..13622d1 100644 --- a/src/interface.c +++ b/src/interface.c @@ -14,6 +14,7 @@ #include #include +#include #include "private.h" void igloo_interface_base_free(igloo_ro_t self) @@ -48,7 +49,7 @@ igloo_ro_t igloo_interface_base_new_real(const igloo_ro_type_t *type, size_t des return igloo_RO_NULL; if (!igloo_RO_IS_NULL(backend_object)) { - if (igloo_ro_ref(backend_object) != 0) { + if (igloo_ro_ref(backend_object) != igloo_ERROR_NONE) { igloo_ro_unref(self); return igloo_RO_NULL; } diff --git a/src/list.c b/src/list.c index 2cb9217..dc5a89d 100644 --- a/src/list.c +++ b/src/list.c @@ -25,6 +25,7 @@ #include #include +#include struct igloo_list_tag { igloo_ro_base_t __base; @@ -216,7 +217,7 @@ int igloo_list_push(igloo_list_t *list, igloo_ro_t element) return -1; } - if (igloo_ro_ref(element) != 0) + if (igloo_ro_ref(element) != igloo_ERROR_NONE) return -1; list->elements[list->fill++] = element; @@ -263,7 +264,7 @@ int igloo_list_unshift(igloo_list_t *list, igloo_ro_t elemen if (!list->offset) return -1; - if (igloo_ro_ref(element) != 0) + if (igloo_ro_ref(element) != igloo_ERROR_NONE) return -1; list->elements[--list->offset] = element; @@ -317,7 +318,7 @@ static inline int igloo_list_copy_elements(igloo_list_t *list, igloo_list_t *ele return -1; } - if (igloo_ro_ref(elements->elements[i]) != 0) + if (igloo_ro_ref(elements->elements[i]) != igloo_ERROR_NONE) return -1; list->elements[list->fill++] = elements->elements[i]; @@ -441,7 +442,7 @@ igloo_list_iterator_t * igloo_list_iterator_start(igloo_list_t *list, void *stor iterator = storage; memset(iterator, 0, sizeof(*iterator)); - if (igloo_ro_ref(list) != 0) + if (igloo_ro_ref(list) != igloo_ERROR_NONE) return NULL; iterator->list = list; @@ -463,7 +464,7 @@ igloo_ro_t igloo_list_iterator_next(igloo_list_iterator_t *iterator if (physical >= iterator->list->fill) return igloo_RO_NULL; - if (igloo_ro_ref(iterator->list->elements[physical]) != 0) + if (igloo_ro_ref(iterator->list->elements[physical]) != igloo_ERROR_NONE) return igloo_RO_NULL; iterator->idx++; diff --git a/src/logmsg.c b/src/logmsg.c index 6201031..b248997 100644 --- a/src/logmsg.c +++ b/src/logmsg.c @@ -19,6 +19,7 @@ #include #include #include +#include #include "private.h" #define LOG_MAXLINELEN 1024 @@ -103,7 +104,7 @@ igloo_logmsg_t * igloo_logmsg_new(const char *name, igloo_ro_t associated, if (referenced) { - if (igloo_ro_ref(referenced) != 0) + if (igloo_ro_ref(referenced) != igloo_ERROR_NONE) break; logmsg->referenced = referenced; @@ -160,7 +161,7 @@ int igloo_logmsg_get_extra(igloo_logmsg_t *msg, igloo_logmsg_opt_t *options, igl if (referenced) { if (msg->referenced) { - if (igloo_ro_ref(msg->referenced) != 0) + if (igloo_ro_ref(msg->referenced) != igloo_ERROR_NONE) return -1; *referenced = msg->referenced; diff --git a/src/reportxml.c b/src/reportxml.c index ab16932..ca3b0c7 100644 --- a/src/reportxml.c +++ b/src/reportxml.c @@ -288,7 +288,7 @@ igloo_reportxml_node_t * igloo_reportxml_get_root_node(igloo_reportxml_t *r if (!report) return NULL; - if (igloo_ro_ref(report->root) != 0) + if (igloo_ro_ref(report->root) != igloo_ERROR_NONE) return NULL; return report->root; @@ -778,7 +778,7 @@ int igloo_reportxml_node_add_child(igloo_reportxml_node_t *n node->childs = n; - if (igloo_ro_ref(child) != 0) + if (igloo_ro_ref(child) != igloo_ERROR_NONE) return -1; node->childs[node->childs_len++] = child; @@ -802,7 +802,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_get_child(igloo_reportxml_nod if (idx >= node->childs_len) return NULL; - if (igloo_ro_ref(node->childs[idx]) != 0) + if (igloo_ro_ref(node->childs[idx]) != igloo_ERROR_NONE) return NULL; return node->childs[idx]; @@ -822,7 +822,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_get_child_by_attribute(igloo_ if (strcmp((const char*)k, value) == 0) { xmlFree(k); - if (igloo_ro_ref(node) != 0) + if (igloo_ro_ref(node) != igloo_ERROR_NONE) return NULL; return node; @@ -850,7 +850,7 @@ igloo_reportxml_node_t * igloo_reportxml_node_get_child_by_type(igloo_repor return NULL; if (node->type == type) { - if (igloo_ro_ref(node) != 0) + if (igloo_ro_ref(node) != igloo_ERROR_NONE) return NULL; return node; } @@ -1151,7 +1151,7 @@ static igloo_reportxml_node_t * __reportxml_database_build_node_ext(igloo_r igloo_ro_unref(search); - if (igloo_ro_ref(found) != 0) { + if (igloo_ro_ref(found) != igloo_ERROR_NONE) { igloo_thread_mutex_unlock(&(db->lock)); return NULL; } diff --git a/src/ro.c b/src/ro.c index 9aa0580..937b81b 100644 --- a/src/ro.c +++ b/src/ro.c @@ -94,7 +94,7 @@ igloo_ro_t igloo_ro_new__raw(const igloo_ro_type_t *type, const char *name, } if (!igloo_RO_IS_NULL(associated)) { - if (igloo_ro_ref(associated) != 0) { + if (igloo_ro_ref(associated) != igloo_ERROR_NONE) { igloo_ro_unref(base); return igloo_RO_NULL; } @@ -133,22 +133,22 @@ igloo_ro_t igloo_ro_new__simple(const igloo_ro_type_t *type, const char *na return ret; } -int igloo_ro_ref(igloo_ro_t self) +igloo_error_t igloo_ro_ref(igloo_ro_t self) { igloo_ro_base_t *base = igloo_RO__GETBASE(self); if (!base) - return -1; + return igloo_ERROR_FAULT; igloo_thread_mutex_lock(&(base->lock)); if (!base->refc) { igloo_thread_mutex_unlock(&(base->lock)); - return -1; + return igloo_ERROR_GENERIC; } base->refc++; igloo_thread_mutex_unlock(&(base->lock)); - return 0; + return igloo_ERROR_NONE; } static inline void igloo_ro__destory(igloo_ro_base_t *base) @@ -269,7 +269,7 @@ igloo_ro_t igloo_ro_get_associated(igloo_ro_t self) } ret = base->associated; if (!igloo_RO_IS_NULL(ret)) { - if (igloo_ro_ref(ret) != 0) { + if (igloo_ro_ref(ret) != igloo_ERROR_NONE) { igloo_thread_mutex_unlock(&(base->lock)); return igloo_RO_NULL; } @@ -283,18 +283,19 @@ igloo_error_t igloo_ro_set_associated(igloo_ro_t self, igloo_ro_t associated) { igloo_ro_base_t *base = igloo_RO__GETBASE(self); igloo_ro_t old; + igloo_error_t ret; if (!base) - return 0; + return igloo_ERROR_FAULT; /* We can not set ourself to be our associated. */ if (base == igloo_RO__GETBASE(associated)) return igloo_ERROR_GENERIC; if (!igloo_RO_IS_NULL(associated)) { - if (igloo_ro_ref(associated) != 0) { + if ((ret = igloo_ro_ref(associated)) != igloo_ERROR_NONE) { /* Could not get a reference on the new associated object. */ - return igloo_ERROR_GENERIC; + return ret; } } diff --git a/src/tests/ctest_list.c b/src/tests/ctest_list.c index e6905fc..452114e 100644 --- a/src/tests/ctest_list.c +++ b/src/tests/ctest_list.c @@ -470,7 +470,7 @@ static void test_list_policy_fixed_pipe_push(void) { if (i == 1) { second_element = element; - ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == 0); + ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == igloo_ERROR_NONE); } ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE); @@ -504,7 +504,7 @@ static void test_list_policy_fixed_pipe_unshift(void) { if (i == 1) { second_element = element; - ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == 0); + ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == igloo_ERROR_NONE); } ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE); @@ -568,7 +568,7 @@ static void test_list_remove(void) { if (i == 1) { second_element = element; - ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == 0); + ctest_test("referenced 2nd test object", igloo_ro_ref(second_element) == igloo_ERROR_NONE); } ctest_test("un-referenced test object", igloo_ro_unref(element) == igloo_ERROR_NONE); diff --git a/src/tests/ctest_refobject.c b/src/tests/ctest_refobject.c index 803da00..a5ce008 100644 --- a/src/tests/ctest_refobject.c +++ b/src/tests/ctest_refobject.c @@ -100,7 +100,7 @@ static void test_create_ref_unref(void) a = igloo_ro_new(igloo_ro_base_t); ctest_test("refobject created", !igloo_RO_IS_NULL(a)); - ctest_test("referenced", igloo_ro_ref(a) == 0); + ctest_test("referenced", igloo_ro_ref(a) == igloo_ERROR_NONE); ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE); ctest_test("un-referenced (2 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE); } @@ -114,7 +114,7 @@ static void test_create_weak_ref_unref(void) ctest_test("weak referenced", igloo_ro_weak_ref(a) == 0); ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE); - ctest_test("referencing failed", igloo_ro_ref(a) != 0); + ctest_test("referencing failed", igloo_ro_ref(a) != igloo_ERROR_NONE); ctest_test("un-referencing (2 of 2) failed", igloo_ro_unref(a) != igloo_ERROR_NONE); ctest_test("weak un-referenced", igloo_ro_weak_unref(a) == 0); } @@ -223,7 +223,7 @@ static void test_freecb(void) test_freecb__called = 0; a = igloo_ro_new(ctest_test_type_free_t); ctest_test("refobject created", a != NULL); - ctest_test("referenced", igloo_ro_ref(a) == 0); + ctest_test("referenced", igloo_ro_ref(a) == igloo_ERROR_NONE); ctest_test("freecb uncalled", test_freecb__called == 0); ctest_test("un-referenced (1 of 2)", igloo_ro_unref(a) == igloo_ERROR_NONE); ctest_test("freecb uncalled", test_freecb__called == 0);