Commit b6acec0f authored by Thomas Haller's avatar Thomas Haller

shared: add compat macro for G_PID_FORMAT

Having G_PID_FORMAT macro is useful, but it's only available in
recent glib versions. Add a compat implementation and a test that
our assumptions hold.
parent e2846081
......@@ -556,6 +556,17 @@ _nm_g_value_unset (GValue *value)
#define g_value_unset _nm_g_value_unset
#endif
/* G_PID_FORMAT was added only in 2.53.5. Define it ourself.
*
* If this was about "pid_t", we would check SIZEOF_PID_T, and set
* PRIi32/PRIi16, like systemd does. But it's actually about
* GPid, which glib typedefs as an "int".
*
* There is a test_gpid() that check that GPid is really a typedef
* for int. */
#undef G_PID_FORMAT
#define G_PID_FORMAT "i"
/*****************************************************************************/
#endif /* __NM_GLIB_H__ */
......@@ -15,6 +15,31 @@
/*****************************************************************************/
static void
test_gpid (void)
{
const int *int_ptr;
GPid pid = 42;
/* We redefine G_PID_FORMAT, because it's only available since glib 2.53.5.
*
* Also, this is the format for GPid, which for glib is always a typedef
* for "int". Add a check for that here.
*
* G_PID_FORMAT is not about pid_t, which might be a smaller int, and which we would
* check with SIZEOF_PID_T. */
G_STATIC_ASSERT (sizeof (GPid) == sizeof (int));
g_assert_cmpstr (""G_PID_FORMAT, ==, "i");
/* check that it's really "int". We will get a compiler warning, if that's not
* the case. */
int_ptr = &pid;
g_assert_cmpint (*int_ptr, ==, 42);
}
/*****************************************************************************/
static void
test_monotonic_timestamp (void)
{
......@@ -502,6 +527,7 @@ int main (int argc, char **argv)
{
nmtst_init (&argc, &argv, TRUE);
g_test_add_func ("/general/test_gpid", test_gpid);
g_test_add_func ("/general/test_monotonic_timestamp", test_monotonic_timestamp);
g_test_add_func ("/general/test_nmhash", test_nmhash);
g_test_add_func ("/general/test_nm_make_strv", test_make_strv);
......
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