mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-06-17 09:08:28 +02:00
shared: add static assert for nm_g_slice_free_fcn() argument
This commit is contained in:
parent
9c3402aa1e
commit
974501fdcf
2 changed files with 15 additions and 2 deletions
|
|
@ -210,6 +210,10 @@ static void
|
|||
test_nm_g_slice_free_fcn (void)
|
||||
{
|
||||
gpointer p;
|
||||
struct {
|
||||
char a1;
|
||||
char a2;
|
||||
} xx;
|
||||
|
||||
p = g_slice_new (gint64);
|
||||
(nm_g_slice_free_fcn (gint64)) (p);
|
||||
|
|
@ -222,6 +226,9 @@ test_nm_g_slice_free_fcn (void)
|
|||
|
||||
p = g_slice_new (gint64);
|
||||
nm_g_slice_free_fcn_gint64 (p);
|
||||
|
||||
p = g_slice_alloc (sizeof (xx));
|
||||
(nm_g_slice_free_fcn (xx)) (p);
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
|
|
|||
|
|
@ -326,12 +326,18 @@ _nm_g_slice_free_fcn_define (16)
|
|||
/* If mem_size is a compile time constant, the compiler
|
||||
* will be able to optimize this. Hence, you don't want
|
||||
* to call this with a non-constant size argument. */ \
|
||||
switch (mem_size) { \
|
||||
G_STATIC_ASSERT_EXPR ( ((mem_size) == 1) \
|
||||
|| ((mem_size) == 2) \
|
||||
|| ((mem_size) == 4) \
|
||||
|| ((mem_size) == 8) \
|
||||
|| ((mem_size) == 12) \
|
||||
|| ((mem_size) == 16)); \
|
||||
switch ((mem_size)) { \
|
||||
case 1: _fcn = _nm_g_slice_free_fcn_1; break; \
|
||||
case 2: _fcn = _nm_g_slice_free_fcn_2; break; \
|
||||
case 4: _fcn = _nm_g_slice_free_fcn_4; break; \
|
||||
case 8: _fcn = _nm_g_slice_free_fcn_8; break; \
|
||||
case 12: _fcn = _nm_g_slice_free_fcn_12; break; \
|
||||
case 12: _fcn = _nm_g_slice_free_fcn_12; break; \
|
||||
case 16: _fcn = _nm_g_slice_free_fcn_16; break; \
|
||||
default: g_assert_not_reached (); _fcn = NULL; break; \
|
||||
} \
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue