From 1c4acc89f1d7fa9b390f048f341b0d19f52e4ae4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 22 Oct 2019 16:49:05 +0200 Subject: [PATCH] shared: add NM_IS_REF_STRING() helper --- shared/nm-glib-aux/nm-ref-string.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/shared/nm-glib-aux/nm-ref-string.h b/shared/nm-glib-aux/nm-ref-string.h index b4652d8443..c80b75eab9 100644 --- a/shared/nm-glib-aux/nm-ref-string.h +++ b/shared/nm-glib-aux/nm-ref-string.h @@ -49,4 +49,23 @@ nm_ref_string_get_len (NMRefString *rstr) return rstr ? rstr->len : 0u; } +static inline gboolean +NM_IS_REF_STRING (const NMRefString *rstr) +{ +#if NM_MORE_ASSERTS > 10 + if (rstr) { + nm_auto_ref_string NMRefString *r2 = NULL; + + r2 = nm_ref_string_new_len (rstr->str, rstr->len); + nm_assert (rstr == r2); + } +#endif + + /* Technically, %NULL is also a valid NMRefString (according to nm_ref_string_new(), + * nm_ref_string_get_str() and nm_ref_string_unref()). However, NM_IS_REF_STRING() + * does not think so. If callers want to allow %NULL, they need to check + * separately. */ + return !!rstr; +} + #endif /* __NM_REF_STRING_H__ */