Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/libbase/plist/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,13 @@ bspl_object_t *bspl_array_at(

/* -- Static & inlined methods: Convenience wrappers ----------------------- */

/** Gets a reference to `string_ptr`. */
static inline bspl_string_t *bspl_string_ref(bspl_string_t *string_ptr)
{
return bspl_string_from_object(
bspl_object_ref(bspl_object_from_string(string_ptr)));
}

/** Unreferences the string. Wraps to @ref bspl_object_unref. */
static inline void bspl_string_unref(bspl_string_t *string_ptr)
{
Expand Down Expand Up @@ -263,6 +270,12 @@ static inline const char *bspl_dict_get_string_value(
bspl_string_from_object(bspl_dict_get(dict_ptr, key_ptr)));
}

/** Gets a reference to `array_ptr`. */
static inline bspl_array_t *bspl_array_ref(bspl_array_t *array_ptr)
{
return bspl_array_from_object(
bspl_object_ref(bspl_object_from_array(array_ptr)));
}
/** Unreferences the array. Wraps to @ref bspl_object_unref. */
static inline void bspl_array_unref(bspl_array_t *array_ptr) {
bspl_object_unref(bspl_object_from_array(array_ptr));
Expand Down
6 changes: 6 additions & 0 deletions src/plist/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ static void _bspl_dict_item_node_destroy(
/* ------------------------------------------------------------------------- */
bspl_object_t *bspl_object_ref(bspl_object_t *object_ptr)
{
if (NULL == object_ptr) return NULL;
++object_ptr->references;
return object_ptr;
}
Expand Down Expand Up @@ -794,6 +795,7 @@ void test_string(bs_test_t *test_ptr)
bspl_string_t *string_ptr;

BS_TEST_VERIFY_EQ(test_ptr, NULL, bspl_string_create(NULL));
BS_TEST_VERIFY_EQ(test_ptr, NULL, bspl_string_ref(NULL));

string_ptr = bspl_string_create("a test");
BS_TEST_VERIFY_NEQ(test_ptr, NULL, string_ptr);
Expand Down Expand Up @@ -827,6 +829,8 @@ void test_string(bs_test_t *test_ptr)
/** Tests the bspl_dict_t methods. */
void test_dict(bs_test_t *test_ptr)
{
BS_TEST_VERIFY_EQ(test_ptr, NULL, bspl_dict_ref(NULL));

bspl_dict_t *dict_ptr = bspl_dict_create();

bspl_object_t *obj0_ptr = BS_ASSERT_NOTNULL(
Expand Down Expand Up @@ -875,6 +879,8 @@ void test_dict(bs_test_t *test_ptr)
/** Tests the bspl_array_t methods. */
void test_array(bs_test_t *test_ptr)
{
BS_TEST_VERIFY_EQ(test_ptr, NULL, bspl_array_ref(NULL));

bspl_array_t *array_ptr = bspl_array_create();

bspl_object_t *obj0_ptr = BS_ASSERT_NOTNULL(
Expand Down