Commit 974501fd authored by Thomas Haller's avatar Thomas Haller

shared: add static assert for nm_g_slice_free_fcn() argument

parent 9c3402aa
...@@ -210,6 +210,10 @@ static void ...@@ -210,6 +210,10 @@ static void
test_nm_g_slice_free_fcn (void) test_nm_g_slice_free_fcn (void)
{ {
gpointer p; gpointer p;
struct {
char a1;
char a2;
} xx;
p = g_slice_new (gint64); p = g_slice_new (gint64);
(nm_g_slice_free_fcn (gint64)) (p); (nm_g_slice_free_fcn (gint64)) (p);
...@@ -222,6 +226,9 @@ test_nm_g_slice_free_fcn (void) ...@@ -222,6 +226,9 @@ test_nm_g_slice_free_fcn (void)
p = g_slice_new (gint64); p = g_slice_new (gint64);
nm_g_slice_free_fcn_gint64 (p); 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) ...@@ -326,12 +326,18 @@ _nm_g_slice_free_fcn_define (16)
/* If mem_size is a compile time constant, the compiler /* If mem_size is a compile time constant, the compiler
* will be able to optimize this. Hence, you don't want * will be able to optimize this. Hence, you don't want
* to call this with a non-constant size argument. */ \ * 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 1: _fcn = _nm_g_slice_free_fcn_1; break; \
case 2: _fcn = _nm_g_slice_free_fcn_2; break; \ case 2: _fcn = _nm_g_slice_free_fcn_2; break; \
case 4: _fcn = _nm_g_slice_free_fcn_4; break; \ case 4: _fcn = _nm_g_slice_free_fcn_4; break; \
case 8: _fcn = _nm_g_slice_free_fcn_8; 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; \ case 16: _fcn = _nm_g_slice_free_fcn_16; break; \
default: g_assert_not_reached (); _fcn = NULL; break; \ default: g_assert_not_reached (); _fcn = NULL; break; \
} \ } \
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment