all: use _NM_ENSURE_POINTER() macro

This commit is contained in:
Thomas Haller 2021-07-30 10:48:59 +02:00
parent 4484363df0
commit 3a6eb5920e
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 27 additions and 30 deletions

View file

@ -411,14 +411,15 @@ _nm_g_hash_table_get_keys_as_array(GHashTable *hash_table, guint *length)
#undef g_steal_pointer
#endif
#define g_steal_pointer(pp) \
({ \
typeof(*(pp)) *const _pp = (pp); \
typeof(*_pp) _p = *_pp; \
_nm_unused const void *const _p_type_check = _p; \
\
*_pp = NULL; \
_p; \
#define g_steal_pointer(pp) \
({ \
typeof(*(pp)) *const _pp = (pp); \
typeof(*_pp) _p = *_pp; \
\
_NM_ENSURE_POINTER(_p); \
\
*_pp = NULL; \
_p; \
})
/*****************************************************************************/

View file

@ -349,13 +349,10 @@ NM_G_ERROR_MSG(GError *error)
* The only purpose of this macro is some additional compile time safety,
* that the argument is a pointer to pointer. But then it will C cast any kind
* of such argument. */
#define NM_CAST_PPTR(type, arg) \
({ \
typeof(*(arg)) *const _arg = (arg); \
typeof(*_arg) _arg2 = _arg ? *_arg : NULL; \
_nm_unused const void *const _arg3 = _arg2; \
\
(type **) _arg; \
#define NM_CAST_PPTR(type, arg) \
({ \
_NM_ENSURE_POINTER(*(arg)); \
(type **) (arg); \
})
#if _NM_CC_SUPPORT_GENERIC

View file

@ -410,12 +410,10 @@ _nm_ptrarray_len_impl(const void *const *array)
* like g_strv_length() does. The difference is:
* - it operates on arrays of pointers (of any kind, requiring no cast).
* - it accepts NULL to return zero. */
#define NM_PTRARRAY_LEN(array) \
({ \
typeof(*(array)) *const _array = (array); \
_nm_unused const void * _type_check_is_pointer = 0 ? _array[0] : NULL; \
\
_nm_ptrarray_len_impl((const void *const *) _array); \
#define NM_PTRARRAY_LEN(array) \
({ \
_NM_ENSURE_POINTER((array)[0]); \
_nm_ptrarray_len_impl((const void *const *) (array)); \
})
/*****************************************************************************/
@ -944,7 +942,7 @@ _nm_auto_fclose(FILE **pfd)
int _changed = false; \
\
if (_pp && (_p = *_pp)) { \
_nm_unused const void *_p_check_is_pointer = _p; \
_NM_ENSURE_POINTER(_p); \
\
*_pp = NULL; \
\
@ -967,14 +965,15 @@ _nm_auto_fclose(FILE **pfd)
/*****************************************************************************/
#define nm_steal_pointer(pp) \
({ \
typeof(*(pp)) *const _pp = (pp); \
typeof(*_pp) _p = *_pp; \
_nm_unused const void *const _p_type_check = _p; \
\
*_pp = NULL; \
_p; \
#define nm_steal_pointer(pp) \
({ \
typeof(*(pp)) *const _pp = (pp); \
typeof(*_pp) _p = *_pp; \
\
_NM_ENSURE_POINTER(_p); \
\
*_pp = NULL; \
_p; \
})
/**