diff options
author | Thomas Haller <thaller@redhat.com> | 2019-10-22 16:49:05 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-10-27 14:30:51 +0100 |
commit | 1c4acc89f1d7fa9b390f048f341b0d19f52e4ae4 (patch) | |
tree | f7cb175a911a71f7e852bd2bee5d09a9290267f7 | |
parent | a75dccad7809e7cb7da4dd16dce374fa625e8ef0 (diff) | |
download | NetworkManager-1c4acc89f1d7fa9b390f048f341b0d19f52e4ae4.tar.gz |
shared: add NM_IS_REF_STRING() helper
-rw-r--r-- | shared/nm-glib-aux/nm-ref-string.h | 19 |
1 files changed, 19 insertions, 0 deletions
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__ */ |