diff --git a/include/libbase/plist/model.h b/include/libbase/plist/model.h index 5765214..844bb09 100644 --- a/include/libbase/plist/model.h +++ b/include/libbase/plist/model.h @@ -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) { @@ -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)); diff --git a/src/plist/model.c b/src/plist/model.c index df2d4ff..1abcbfa 100644 --- a/src/plist/model.c +++ b/src/plist/model.c @@ -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; } @@ -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); @@ -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( @@ -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(