diff options
author | Guilherme Iscaro <iscaro@profusion.mobi> | 2016-12-02 11:16:33 -0200 |
---|---|---|
committer | Bruno Dilly <bdilly@profusion.mobi> | 2016-12-02 15:12:56 -0200 |
commit | 81782414dfba9a8a69ea42a4dd5b01fc19170d88 (patch) | |
tree | 52679cba647cf38eef9d7efb1b6e5bdb198e4c3c | |
parent | 826cd7cb5e6e6a0a53dbe1c687de072dd8fd2f6c (diff) | |
download | efl-81782414dfba9a8a69ea42a4dd5b01fc19170d88.tar.gz |
Eo: Add efl_replace() function.
This new function adds a new way to safely replace Eo pointer values.
-rw-r--r-- | src/lib/eo/Eo.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/lib/eo/Eo.h b/src/lib/eo/Eo.h index 8c815447c3..244478b0ae 100644 --- a/src/lib/eo/Eo.h +++ b/src/lib/eo/Eo.h @@ -1334,6 +1334,28 @@ EAPI int efl_callbacks_cmp(const Efl_Callback_Array_Item *a, const Efl_Callback_ EFL_CALLBACK_PRIORITY_DEFAULT, data) /** + * @def Replace the previously Eo pointer with new content. + * + * @param storage The object to replace the old reference. It can not be @c NULL. + * @param new_obj The new object. It may be @c NULL. + * + * The string pointed by @c storage must be previously an Eo or + * @c NULL and it will be efl_unref(). The @a new_obj will be passed + * to efl_ref() and then assigned to @c *storage. + * + * @see efl_ref() + * @see efl_unref() + */ +static inline void +efl_replace(Eo **storage, Eo *new_obj) +{ + if (!storage || *storage == new_obj) return; + efl_ref(new_obj); + efl_unref(*storage); + *storage = new_obj; +} + +/** * @} */ |