1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-11-03 04:17:20 -05:00

Update: Updated igloo_ro_ref() to use igloo_error_t

This commit is contained in:
Philipp Schafft 2019-09-14 11:16:52 +00:00
parent b8ce49e64e
commit 454b57449f
8 changed files with 34 additions and 30 deletions

View File

@ -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.
*/

View File

@ -14,6 +14,7 @@
#include <igloo/ro.h>
#include <igloo/io.h>
#include <igloo/error.h>
#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;
}

View File

@ -25,6 +25,7 @@
#include <igloo/list.h>
#include <igloo/objecthandler.h>
#include <igloo/error.h>
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++;

View File

@ -19,6 +19,7 @@
#include <igloo/objecthandler.h>
#include <igloo/filter.h>
#include <igloo/io.h>
#include <igloo/error.h>
#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;

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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);

View File

@ -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);