mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-10 04:40:20 +01:00
shared: add nm_clear_g_free()
This commit is contained in:
parent
a83eb773ce
commit
b4e66c4818
2 changed files with 22 additions and 1 deletions
|
|
@ -2527,7 +2527,7 @@ test_setting_compare_wireless_cloned_mac_address (void)
|
|||
g_assert_cmpstr ("stable-bia", ==, nm_setting_wireless_get_cloned_mac_address ((NMSettingWireless *) new));
|
||||
g_object_get (new, NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS, &str1, NULL);
|
||||
g_assert_cmpstr ("stable-bia", ==, str1);
|
||||
g_clear_pointer (&str1, g_free);
|
||||
nm_clear_g_free (&str1);
|
||||
|
||||
success = nm_setting_compare (old, new, NM_SETTING_COMPARE_FLAG_EXACT);
|
||||
g_assert (!success);
|
||||
|
|
|
|||
|
|
@ -373,6 +373,27 @@ nm_g_object_unref (gpointer obj)
|
|||
g_object_unref (obj);
|
||||
}
|
||||
|
||||
/* basically, replaces
|
||||
* g_clear_pointer (&location, g_free)
|
||||
* with
|
||||
* nm_clear_g_free (&location)
|
||||
*
|
||||
* Another advantage is that by using a macro and typeof(), it is more
|
||||
* typesafe and gives you for example a compiler warning when pp is a const
|
||||
* pointer or points to a const-pointer.
|
||||
*/
|
||||
#define nm_clear_g_free(pp) \
|
||||
({ \
|
||||
typeof (*(pp)) *_pp = (pp); \
|
||||
typeof (**_pp) *_p = *_pp; \
|
||||
\
|
||||
if (_p) { \
|
||||
*_pp = NULL; \
|
||||
g_free (_p); \
|
||||
} \
|
||||
!!_p; \
|
||||
})
|
||||
|
||||
static inline gboolean
|
||||
nm_clear_g_source (guint *id)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue