2020-09-29 16:42:22 +02:00
|
|
|
/* SPDX-License-Identifier: LGPL-2.1+ */
|
2014-07-04 13:33:18 -04:00
|
|
|
/*
|
2019-10-01 09:20:35 +02:00
|
|
|
* Copyright (C) 2008 - 2018 Red Hat, Inc.
|
2008-12-31 18:57:36 -05:00
|
|
|
*/
|
|
|
|
|
|
2015-04-06 16:42:31 -04:00
|
|
|
#ifndef __NM_GLIB_H__
|
|
|
|
|
#define __NM_GLIB_H__
|
2008-12-31 18:57:36 -05:00
|
|
|
|
shared: ensure "nm-glib.h" is not used without "nm-macros-internal.h"
Note how "nm-glib.h" uses _nm_printf() macro, which is defined in
"nm-macros-internal.h". There are many ways how to solve that
problem.
For example, we could define certain _nm_*() macros in "nm-glib.h"
itself. However, that is a bit awkward, because optimally "nm-glib.h"
only provides functions that are strictly related to glib compatiblity.
_nm_printf() is used by "nm-glib.h" for its own implementation, it should
not provide (or reimplement) this macro.
We solve this instead by enforcing what NetworkManager already does.
NetworkManager never includes "nm-glib.h" directly, instead
"nm-macros-internal.h" is the only place that includes the glib compat
header. It means, you cannot use "nm-glib.h" without
"nm-macros-internal.h". But that is a reasonable compromise, with
respect to granularity. The granularity at the moment is: if you use
anything from "shared/nm-utils", you almost always need at least
"nm-macros-internal.h" header (and automatically also get "nm-glib.h"
and "gsystem-local-alloc.h"). It's not intended, to use "nm-glib.h"
directly.
This makes "nm-glib.h" an implementation detail of "nm-macros-internal.h"
and it only exists to separate code that is related to glib compatibility to
its own header.
2018-07-09 13:46:47 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef __NM_MACROS_INTERNAL_H__
|
|
|
|
|
#error "nm-glib.h requires nm-macros-internal.h. Do not include this directly"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2014-07-26 21:13:52 +02:00
|
|
|
#ifdef __clang__
|
|
|
|
|
|
|
|
|
|
#undef G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
#undef G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
|
|
|
|
|
#define G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
|
|
|
|
|
_Pragma("clang diagnostic push") \
|
|
|
|
|
_Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
|
|
|
|
|
|
|
|
|
|
#define G_GNUC_END_IGNORE_DEPRECATIONS _Pragma("clang diagnostic pop")
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
static inline void
|
|
|
|
|
__g_type_ensure(GType type)
|
|
|
|
|
{
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 34, 0)
|
|
|
|
|
if (G_UNLIKELY(type == (GType) -1))
|
|
|
|
|
g_error("can't happen");
|
|
|
|
|
#else
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS;
|
|
|
|
|
g_type_ensure(type);
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#define g_type_ensure __g_type_ensure
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 34, 0)
|
2020-09-28 16:03:33 +02:00
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
#define g_clear_pointer(pp, destroy) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
G_STATIC_ASSERT(sizeof *(pp) == sizeof(gpointer)); \
|
|
|
|
|
/* Only one access, please */ \
|
|
|
|
|
gpointer *_pp = (gpointer *) (pp); \
|
|
|
|
|
gpointer _p; \
|
|
|
|
|
/* This assignment is needed to avoid a gcc warning */ \
|
|
|
|
|
GDestroyNotify _destroy = (GDestroyNotify)(destroy); \
|
|
|
|
|
\
|
|
|
|
|
_p = *_pp; \
|
|
|
|
|
if (_p) { \
|
|
|
|
|
*_pp = NULL; \
|
|
|
|
|
_destroy(_p); \
|
2020-09-28 16:03:33 +02:00
|
|
|
} \
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 34, 0)
|
|
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
/* These are used to clean up the output of test programs; we can just let
|
|
|
|
|
* them no-op in older glib.
|
|
|
|
|
*/
|
|
|
|
|
#define g_test_expect_message(log_domain, log_level, pattern)
|
|
|
|
|
#define g_test_assert_expected_messages()
|
|
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
|
|
/* We build with -DGLIB_MAX_ALLOWED_VERSION set to 2.32 to make sure we don't
|
|
|
|
|
* accidentally use new API that we shouldn't. But we don't want warnings for
|
|
|
|
|
* the APIs that we emulate above.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define g_test_expect_message(domain, level, format...) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
|
|
|
|
|
g_test_expect_message(domain, level, format); \
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
2020-09-28 16:03:33 +02:00
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
#define g_test_assert_expected_messages_internal(domain, file, line, func) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
|
|
|
|
|
g_test_assert_expected_messages_internal(domain, file, line, func); \
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
|
|
|
|
|
#if GLIB_CHECK_VERSION(2, 35, 0)
|
|
|
|
|
/* For glib >= 2.36, g_type_init() is deprecated.
|
|
|
|
|
* But since 2.35.1 (7c42ab23b55c43ab96d0ac2124b550bf1f49c1ec) this function
|
|
|
|
|
* does nothing. Replace the call with empty statement. */
|
|
|
|
|
#define nm_g_type_init() \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
(void) 0; \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
#else
|
|
|
|
|
#define nm_g_type_init() \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
g_type_init(); \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
|
|
|
|
|
/* g_test_initialized() is only available since glib 2.36. */
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 36, 0)
|
|
|
|
|
#define g_test_initialized() (g_test_config_vars->test_initialized)
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-02-11 12:39:42 -06:00
|
|
|
/* g_assert_cmpmem() is only available since glib 2.46. */
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 45, 7)
|
|
|
|
|
#define g_assert_cmpmem(m1, l1, m2, l2) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
gconstpointer __m1 = m1, __m2 = m2; \
|
|
|
|
|
int __l1 = l1, __l2 = l2; \
|
|
|
|
|
if (__l1 != __l2) \
|
|
|
|
|
g_assertion_message_cmpnum(G_LOG_DOMAIN, \
|
|
|
|
|
__FILE__, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
G_STRFUNC, \
|
|
|
|
|
#l1 " (len(" #m1 ")) == " #l2 " (len(" #m2 "))", \
|
|
|
|
|
__l1, \
|
|
|
|
|
"==", \
|
|
|
|
|
__l2, \
|
|
|
|
|
'i'); \
|
|
|
|
|
else if (memcmp(__m1, __m2, __l1) != 0) \
|
|
|
|
|
g_assertion_message(G_LOG_DOMAIN, \
|
|
|
|
|
__FILE__, \
|
|
|
|
|
__LINE__, \
|
|
|
|
|
G_STRFUNC, \
|
|
|
|
|
"assertion failed (" #m1 " == " #m2 ")"); \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-11-25 10:28:33 +01:00
|
|
|
/* Rumtime check for glib version. First do a compile time check which
|
|
|
|
|
* (if satisfied) shortcuts the runtime check. */
|
2017-02-23 15:24:18 +01:00
|
|
|
static inline gboolean
|
2017-02-06 18:58:44 +01:00
|
|
|
nm_glib_check_version(guint major, guint minor, guint micro)
|
|
|
|
|
{
|
|
|
|
|
return GLIB_CHECK_VERSION(major, minor, micro)
|
|
|
|
|
|| ((glib_major_version > major)
|
|
|
|
|
|| (glib_major_version == major && glib_minor_version > minor)
|
|
|
|
|
|| (glib_major_version == major && glib_minor_version == minor
|
|
|
|
|
&& glib_micro_version < micro));
|
|
|
|
|
}
|
2015-11-25 10:28:33 +01:00
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
/* g_test_skip() is only available since glib 2.38. Add a compatibility wrapper. */
|
|
|
|
|
static inline void
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
__nmtst_g_test_skip(const char *msg)
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
{
|
|
|
|
|
#if GLIB_CHECK_VERSION(2, 38, 0)
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
g_test_skip(msg);
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
#else
|
|
|
|
|
g_debug("%s", msg);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#define g_test_skip __nmtst_g_test_skip
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
|
|
|
|
|
/* g_test_add_data_func_full() is only available since glib 2.34. Add a compatibility wrapper. */
|
|
|
|
|
static inline void
|
|
|
|
|
__g_test_add_data_func_full(const char * testpath,
|
|
|
|
|
gpointer test_data,
|
|
|
|
|
GTestDataFunc test_func,
|
|
|
|
|
GDestroyNotify data_free_func)
|
|
|
|
|
{
|
|
|
|
|
#if GLIB_CHECK_VERSION(2, 34, 0)
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
g_test_add_data_func_full(testpath, test_data, test_func, data_free_func);
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
#else
|
|
|
|
|
g_return_if_fail(testpath != NULL);
|
|
|
|
|
g_return_if_fail(testpath[0] == '/');
|
|
|
|
|
g_return_if_fail(test_func != NULL);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
g_test_add_vtable(testpath,
|
|
|
|
|
0,
|
|
|
|
|
test_data,
|
|
|
|
|
NULL,
|
|
|
|
|
(GTestFixtureFunc) test_func,
|
|
|
|
|
(GTestFixtureFunc) data_free_func);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#define g_test_add_data_func_full __g_test_add_data_func_full
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
nm_g_hash_table_replace(GHashTable *hash, gpointer key, gpointer value)
|
|
|
|
|
{
|
|
|
|
|
/* glib 2.40 added a return value indicating whether the key already existed
|
|
|
|
|
* (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */
|
|
|
|
|
#if GLIB_CHECK_VERSION(2, 40, 0)
|
|
|
|
|
return g_hash_table_replace(hash, key, value);
|
|
|
|
|
#else
|
|
|
|
|
gboolean contained = g_hash_table_contains(hash, key);
|
|
|
|
|
|
|
|
|
|
g_hash_table_replace(hash, key, value);
|
|
|
|
|
return !contained;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
nm_g_hash_table_insert(GHashTable *hash, gpointer key, gpointer value)
|
|
|
|
|
{
|
|
|
|
|
/* glib 2.40 added a return value indicating whether the key already existed
|
|
|
|
|
* (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */
|
|
|
|
|
#if GLIB_CHECK_VERSION(2, 40, 0)
|
|
|
|
|
return g_hash_table_insert(hash, key, value);
|
|
|
|
|
#else
|
|
|
|
|
gboolean contained = g_hash_table_contains(hash, key);
|
|
|
|
|
|
|
|
|
|
g_hash_table_insert(hash, key, value);
|
|
|
|
|
return !contained;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline gboolean
|
|
|
|
|
nm_g_hash_table_add(GHashTable *hash, gpointer key)
|
|
|
|
|
{
|
|
|
|
|
/* glib 2.40 added a return value indicating whether the key already existed
|
|
|
|
|
* (910191597a6c2e5d5d460e9ce9efb4f47d9cc63c). */
|
|
|
|
|
#if GLIB_CHECK_VERSION(2, 40, 0)
|
|
|
|
|
return g_hash_table_add(hash, key);
|
|
|
|
|
#else
|
|
|
|
|
gboolean contained = g_hash_table_contains(hash, key);
|
|
|
|
|
|
|
|
|
|
g_hash_table_add(hash, key);
|
|
|
|
|
return !contained;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 40, 0) || defined(NM_GLIB_COMPAT_H_TEST)
|
|
|
|
|
static inline void
|
|
|
|
|
_nm_g_ptr_array_insert(GPtrArray *array, int index_, gpointer data)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail(array);
|
|
|
|
|
g_return_if_fail(index_ >= -1);
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
g_return_if_fail(index_ <= (int) array->len);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
g_ptr_array_add(array, data);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
if (index_ != -1 && index_ != (int) (array->len - 1)) {
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
memmove(&(array->pdata[index_ + 1]),
|
|
|
|
|
&(array->pdata[index_]),
|
|
|
|
|
(array->len - index_ - 1) * sizeof(gpointer));
|
|
|
|
|
array->pdata[index_] = data;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2018-07-09 13:40:53 +02:00
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 40, 0)
|
|
|
|
|
#define g_ptr_array_insert(array, index, data) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
_nm_g_ptr_array_insert(array, index, data); \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
#else
|
|
|
|
|
#define g_ptr_array_insert(array, index, data) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
|
|
|
|
|
g_ptr_array_insert(array, index, data); \
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 40, 0)
|
|
|
|
|
static inline gboolean
|
|
|
|
|
_g_key_file_save_to_file(GKeyFile *key_file, const char *filename, GError **error)
|
|
|
|
|
{
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
char * contents;
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
gboolean success;
|
|
|
|
|
gsize length;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(key_file != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail(filename != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail(error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
contents = g_key_file_to_data(key_file, &length, NULL);
|
|
|
|
|
g_assert(contents != NULL);
|
|
|
|
|
|
|
|
|
|
success = g_file_set_contents(filename, contents, length, error);
|
|
|
|
|
g_free(contents);
|
|
|
|
|
|
|
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
#define g_key_file_save_to_file(key_file, filename, error) \
|
|
|
|
|
_g_key_file_save_to_file(key_file, filename, error)
|
|
|
|
|
#else
|
|
|
|
|
#define g_key_file_save_to_file(key_file, filename, error) \
|
|
|
|
|
({ \
|
|
|
|
|
gboolean _success; \
|
|
|
|
|
\
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
|
|
|
|
|
_success = g_key_file_save_to_file(key_file, filename, error); \
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS \
|
|
|
|
|
_success; \
|
|
|
|
|
})
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
|
|
|
|
|
#if GLIB_CHECK_VERSION(2, 36, 0)
|
|
|
|
|
#define g_credentials_get_unix_pid(creds, error) \
|
|
|
|
|
({ \
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS(g_credentials_get_unix_pid)((creds), (error)); \
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS \
|
|
|
|
|
})
|
|
|
|
|
#else
|
|
|
|
|
#define g_credentials_get_unix_pid(creds, error) \
|
|
|
|
|
({ \
|
|
|
|
|
struct ucred *native_creds; \
|
|
|
|
|
\
|
|
|
|
|
native_creds = g_credentials_get_native((creds), G_CREDENTIALS_TYPE_LINUX_UCRED); \
|
|
|
|
|
g_assert(native_creds); \
|
|
|
|
|
native_creds->pid; \
|
|
|
|
|
})
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 40, 0) || defined(NM_GLIB_COMPAT_H_TEST)
|
|
|
|
|
static inline gpointer *
|
|
|
|
|
_nm_g_hash_table_get_keys_as_array(GHashTable *hash_table, guint *length)
|
|
|
|
|
{
|
|
|
|
|
GHashTableIter iter;
|
|
|
|
|
gpointer key, *ret;
|
|
|
|
|
guint i = 0;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(hash_table, NULL);
|
|
|
|
|
|
|
|
|
|
ret = g_new0(gpointer, g_hash_table_size(hash_table) + 1);
|
|
|
|
|
g_hash_table_iter_init(&iter, hash_table);
|
|
|
|
|
|
|
|
|
|
while (g_hash_table_iter_next(&iter, &key, NULL))
|
|
|
|
|
ret[i++] = key;
|
|
|
|
|
|
|
|
|
|
ret[i] = NULL;
|
|
|
|
|
|
|
|
|
|
if (length)
|
|
|
|
|
*length = i;
|
|
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 40, 0)
|
|
|
|
|
#define g_hash_table_get_keys_as_array(hash_table, length) \
|
|
|
|
|
({ _nm_g_hash_table_get_keys_as_array(hash_table, length); })
|
|
|
|
|
#else
|
|
|
|
|
#define g_hash_table_get_keys_as_array(hash_table, length) \
|
|
|
|
|
({ \
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS(g_hash_table_get_keys_as_array) \
|
|
|
|
|
((hash_table), (length)); \
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS \
|
|
|
|
|
})
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
#ifndef g_info
|
|
|
|
|
/* g_info was only added with 2.39.2 */
|
|
|
|
|
#define g_info(...) g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, __VA_ARGS__)
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-05-12 14:25:36 +02:00
|
|
|
static inline gpointer
|
2020-06-15 15:56:30 +02:00
|
|
|
_nm_g_steal_pointer(gpointer pp)
|
2016-05-12 14:25:36 +02:00
|
|
|
{
|
|
|
|
|
gpointer *ptr = (gpointer *) pp;
|
|
|
|
|
gpointer ref;
|
|
|
|
|
|
|
|
|
|
ref = *ptr;
|
|
|
|
|
*ptr = NULL;
|
|
|
|
|
|
|
|
|
|
return ref;
|
|
|
|
|
}
|
2020-06-15 15:56:30 +02:00
|
|
|
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 44, 0)
|
|
|
|
|
static inline gpointer
|
|
|
|
|
g_steal_pointer(gpointer pp)
|
|
|
|
|
{
|
|
|
|
|
return _nm_g_steal_pointer(pp);
|
|
|
|
|
}
|
2019-02-20 14:35:47 +01:00
|
|
|
#endif
|
2016-05-12 14:25:36 +02:00
|
|
|
|
2019-02-20 14:35:47 +01:00
|
|
|
#ifdef g_steal_pointer
|
|
|
|
|
#undef g_steal_pointer
|
2016-05-12 14:25:36 +02:00
|
|
|
#endif
|
2020-06-15 15:56:30 +02:00
|
|
|
#define g_steal_pointer(pp) ((typeof(*(pp))) _nm_g_steal_pointer(pp))
|
2016-05-12 14:25:36 +02:00
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-05-20 20:44:05 +02:00
|
|
|
static inline gboolean
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
_nm_g_strv_contains(const char *const *strv, const char *str)
|
2016-05-20 20:44:05 +02:00
|
|
|
{
|
2016-06-17 12:02:22 +02:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 44, 0)
|
2016-05-20 20:44:05 +02:00
|
|
|
g_return_val_if_fail(strv != NULL, FALSE);
|
|
|
|
|
g_return_val_if_fail(str != NULL, FALSE);
|
|
|
|
|
|
|
|
|
|
for (; *strv != NULL; strv++) {
|
|
|
|
|
if (g_str_equal(str, *strv))
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
|
#else
|
2016-06-17 12:02:22 +02:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
return g_strv_contains(strv, str);
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
2016-05-20 20:44:05 +02:00
|
|
|
#endif
|
2016-06-17 12:02:22 +02:00
|
|
|
}
|
|
|
|
|
#define g_strv_contains _nm_g_strv_contains
|
2016-05-20 20:44:05 +02:00
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
static inline GVariant *
|
all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.
$ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
587
$ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
21114
One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during
g_object_set (obj, PROPERTY, (gint) value, NULL);
However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.
Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).
A simple style guide is instead: don't use these typedefs.
No manual actions, I only ran the bash script:
FILES=($(git ls-files '*.[hc]'))
sed -i \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\> /\1 /g' \
-e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
"${FILES[@]}"
2018-07-11 07:40:19 +02:00
|
|
|
_nm_g_variant_new_take_string(char *string)
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
{
|
|
|
|
|
#if !GLIB_CHECK_VERSION(2, 36, 0)
|
|
|
|
|
GVariant *value;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(string != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail(g_utf8_validate(string, -1, NULL), NULL);
|
|
|
|
|
|
|
|
|
|
value = g_variant_new_string(string);
|
|
|
|
|
g_free(string);
|
|
|
|
|
return value;
|
|
|
|
|
#elif !GLIB_CHECK_VERSION(2, 38, 0)
|
|
|
|
|
GVariant *value;
|
|
|
|
|
GBytes * bytes;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(string != NULL, NULL);
|
|
|
|
|
g_return_val_if_fail(g_utf8_validate(string, -1, NULL), NULL);
|
|
|
|
|
|
|
|
|
|
bytes = g_bytes_new_take(string, strlen(string) + 1);
|
|
|
|
|
value = g_variant_new_from_bytes(G_VARIANT_TYPE_STRING, bytes, TRUE);
|
|
|
|
|
g_bytes_unref(bytes);
|
|
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
#else
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
|
|
|
|
return g_variant_new_take_string(string);
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
#define g_variant_new_take_string _nm_g_variant_new_take_string
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
shared: restore compat code in nm-glib.h for 2.32 compatibility
In commit 8a46b25cfa8c33daa8af37bb8103ca02286001b1, NetworkManager
bumped its glib dependency to 2.40 or newer.
"nm-glib.h" header is precisely the compatiblity implementation that we
use to cope with older glib versions. Note, that the same implementation
is also used by applet and VPN plugins.
However, applet and VPN plugins don't yet require 2.40 glib. Also,
they don't yet require NetworkManager 1.12.0 API (which was the one
that bumped the glib requirement to 2.40). Hence, when "nm-glib.h"
is used in applet or VPN, it must still cope with older versions,
although, the code is not used by NetworkManager itself.
Partly revert 8a46b25cfa8c33daa8af37bb8103ca02286001b1 so that nm-glib.h
again works for 2.32 or newer.
The same is true, also for "nm-test-utils.h", which is also used by
applet and VPN plugins.
2018-07-09 13:20:17 +02:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 38, 0)
|
|
|
|
|
_nm_printf(1, 2) static inline GVariant *_nm_g_variant_new_printf(const char *format_string, ...)
|
|
|
|
|
{
|
|
|
|
|
char * string;
|
|
|
|
|
va_list ap;
|
|
|
|
|
|
|
|
|
|
g_return_val_if_fail(format_string, NULL);
|
|
|
|
|
|
|
|
|
|
va_start(ap, format_string);
|
|
|
|
|
string = g_strdup_vprintf(format_string, ap);
|
|
|
|
|
va_end(ap);
|
|
|
|
|
|
|
|
|
|
return g_variant_new_take_string(string);
|
|
|
|
|
}
|
|
|
|
|
#define g_variant_new_printf(...) _nm_g_variant_new_printf(__VA_ARGS__)
|
|
|
|
|
#else
|
|
|
|
|
#define g_variant_new_printf(...) \
|
|
|
|
|
({ \
|
|
|
|
|
GVariant *_v; \
|
|
|
|
|
\
|
|
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
|
|
|
|
|
_v = g_variant_new_printf(__VA_ARGS__); \
|
|
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS \
|
|
|
|
|
_v; \
|
|
|
|
|
})
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-06-25 08:25:26 +02:00
|
|
|
/* Recent glib also casts the results to typeof(Obj), but only if
|
|
|
|
|
*
|
|
|
|
|
* ( defined(g_has_typeof) && GLIB_VERSION_MAX_ALLOWED >= GLIB_VERSION_2_56 )
|
|
|
|
|
*
|
|
|
|
|
* Since we build NetworkManager with older GLIB_VERSION_MAX_ALLOWED, it's
|
|
|
|
|
* not taking effect.
|
|
|
|
|
*
|
|
|
|
|
* Override this. */
|
|
|
|
|
#undef g_object_ref
|
|
|
|
|
#undef g_object_ref_sink
|
2017-12-06 10:04:50 +01:00
|
|
|
#define g_object_ref(Obj) ((typeof(Obj)) g_object_ref(Obj))
|
|
|
|
|
#define g_object_ref_sink(Obj) ((typeof(Obj)) g_object_ref_sink(Obj))
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-03-19 11:21:59 +01:00
|
|
|
#ifndef g_autofree
|
|
|
|
|
/* we still don't rely on recent glib to provide g_autofree. Hence, we continue
|
|
|
|
|
* to use our gs_* free macros that we took from libgsystem.
|
|
|
|
|
*
|
|
|
|
|
* To ease migration towards g_auto*, add a compat define for g_autofree. */
|
|
|
|
|
#define g_autofree gs_free
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-07-09 13:40:53 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-01-04 18:27:42 +01:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 47, 1)
|
|
|
|
|
/* Older versions of g_value_unset() only allowed to unset a GValue which
|
|
|
|
|
* was initialized previously. This was relaxed ([1], [2], [3]).
|
|
|
|
|
*
|
|
|
|
|
* Our nm_auto_unset_gvalue macro requires to be able to call g_value_unset().
|
|
|
|
|
* Also, it is our general practice to allow for that. Add a compat implementation.
|
|
|
|
|
*
|
|
|
|
|
* [1] https://gitlab.gnome.org/GNOME/glib/commit/4b2d92a864f1505f1b08eb639d74293fa32681da
|
|
|
|
|
* [2] commit "Allow passing unset GValues to g_value_unset()"
|
|
|
|
|
* [3] https://bugzilla.gnome.org/show_bug.cgi?id=755766
|
|
|
|
|
*/
|
|
|
|
|
static inline void
|
|
|
|
|
_nm_g_value_unset(GValue *value)
|
|
|
|
|
{
|
|
|
|
|
g_return_if_fail(value);
|
|
|
|
|
|
|
|
|
|
if (value->g_type != 0)
|
|
|
|
|
g_value_unset(value);
|
|
|
|
|
}
|
|
|
|
|
#define g_value_unset _nm_g_value_unset
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-09-03 16:41:59 +02:00
|
|
|
/* 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"
|
|
|
|
|
|
2019-01-04 18:27:42 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-02-05 11:59:49 +01:00
|
|
|
/* G_SOURCE_FUNC was added in 2.57.2. */
|
|
|
|
|
#undef G_SOURCE_FUNC
|
2019-11-09 08:47:10 +01:00
|
|
|
#define G_SOURCE_FUNC(f) ((GSourceFunc)(void (*)(void))(f))
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
shared: add a compat implementation for g_atomic_pointer_get()
With glib2-2.67.0-1.fc34.x86_64.rpm, clang-11.0.0-2.fc34.x86_64.rpm, we
get a failure for g_atomic_pointer_get():
../shared/nm-glib-aux/nm-hash-utils.c:38:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = g_atomic_pointer_get(&global_seed);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:109:32: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
return ((*((const guint *) _get_hash_key())) ^ static_seed) ?: 3679500967u;
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:123:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = _get_hash_key();
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
2020-11-02 10:08:09 +01:00
|
|
|
/* g_atomic_pointer_get() is implemented as a macro, and it is also used for
|
|
|
|
|
* (gsize *) arguments. However, that leads to compiler warnings in certain
|
|
|
|
|
* configurations. Work around it, by redefining the macro. */
|
|
|
|
|
static inline gpointer
|
|
|
|
|
_g_atomic_pointer_get(void **atomic)
|
|
|
|
|
{
|
|
|
|
|
return g_atomic_pointer_get(atomic);
|
|
|
|
|
}
|
|
|
|
|
#undef g_atomic_pointer_get
|
|
|
|
|
#define g_atomic_pointer_get(atomic) \
|
|
|
|
|
({ \
|
|
|
|
|
typeof(*atomic) *const _atomic = (atomic); \
|
|
|
|
|
\
|
|
|
|
|
/* g_atomic_pointer_get() is used by glib also for (gsize *) pointers,
|
|
|
|
|
* not only pointers to pointers. We thus don't enforce that (*atomic)
|
|
|
|
|
* is a pointer, but of suitable size/alignment. */ \
|
|
|
|
|
\
|
|
|
|
|
G_STATIC_ASSERT(sizeof(*_atomic) == sizeof(gpointer)); \
|
|
|
|
|
G_STATIC_ASSERT(_nm_alignof(*_atomic) == _nm_alignof(gpointer)); \
|
|
|
|
|
(void) (0 ? (gpointer) * (_atomic) : NULL); \
|
|
|
|
|
\
|
|
|
|
|
(typeof(*_atomic)) _g_atomic_pointer_get((void **) _atomic); \
|
|
|
|
|
})
|
|
|
|
|
|
2020-11-02 10:35:25 +01:00
|
|
|
/* Reimplement g_atomic_pointer_set() macro too. Our variant does more type
|
|
|
|
|
* checks. */
|
|
|
|
|
static inline void
|
|
|
|
|
_g_atomic_pointer_set(void **atomic, void *newval)
|
|
|
|
|
{
|
|
|
|
|
return g_atomic_pointer_set(atomic, newval);
|
|
|
|
|
}
|
|
|
|
|
#undef g_atomic_pointer_set
|
|
|
|
|
#define g_atomic_pointer_set(atomic, newval) \
|
|
|
|
|
({ \
|
|
|
|
|
typeof(*atomic) *const _atomic = (atomic); \
|
|
|
|
|
typeof(*_atomic) const _newval = (newval); \
|
|
|
|
|
_nm_unused gconstpointer const _val_type_check = _newval; \
|
|
|
|
|
\
|
|
|
|
|
(void) (0 ? (gpointer) * (_atomic) : NULL); \
|
|
|
|
|
\
|
|
|
|
|
_g_atomic_pointer_set((void **) _atomic, (void *) _newval); \
|
|
|
|
|
})
|
|
|
|
|
|
shared/glib: reimplement g_atomic_pointer_compare_and_exchange() macro
With glib 2.63.2 and clang 9.0.0 (Fedora 32) we get compile errors:
../clients/cloud-setup/nmcs-provider-ec2.c:51:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const char **' [-Werror,-Wincompatible-pointer-types]
if (!g_atomic_pointer_compare_and_exchange (&base_cached, NULL, base))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/bluetooth/nm-bluez-manager.c:2836:2: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') [-Werror,-Wincompatible-pointer-types]
g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, NULL, &priv->vtable_network_server);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/bluetooth/nm-bluez-manager.c:2853:2: error: passing 'typeof ((&priv->vtable_network_server)) *' (aka 'struct _NMBtVTableNetworkServer **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, &priv->vtable_network_server, NULL);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/nm-device.c:8857:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'GBytes **' (aka 'struct _GBytes **') [-Werror,-Wincompatible-pointer-types]
if (!g_atomic_pointer_compare_and_exchange (&global_duid, NULL, p)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
The issue happens because glib passes the "atomic" argument to
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
without cast, and clang 9 seems to be picky about const pointers.
Add our own version of the macro that does better casts while also having
better compile time checks for valid arguments.
(cherry picked from commit f5b0713651f8603f93be82a47b22ed578762f5eb)
2019-12-13 12:06:20 +01:00
|
|
|
/* Glib implements g_atomic_pointer_compare_and_exchange() as a macro.
|
|
|
|
|
* For one, to inline the atomic operation and also to perform some type checks
|
|
|
|
|
* on the arguments.
|
|
|
|
|
* Depending on compiler and glib version, glib passes the arguments as they
|
|
|
|
|
* are to __atomic_compare_exchange_n(). Some clang version don't accept const
|
|
|
|
|
* pointers there. Reimplement the macro to get that right, but with stronger
|
|
|
|
|
* type checks (as we use typeof()). Had one job. */
|
|
|
|
|
static inline gboolean
|
shared: add a compat implementation for g_atomic_pointer_get()
With glib2-2.67.0-1.fc34.x86_64.rpm, clang-11.0.0-2.fc34.x86_64.rpm, we
get a failure for g_atomic_pointer_get():
../shared/nm-glib-aux/nm-hash-utils.c:38:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = g_atomic_pointer_get(&global_seed);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:109:32: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
return ((*((const guint *) _get_hash_key())) ^ static_seed) ?: 3679500967u;
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:123:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = _get_hash_key();
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
2020-11-02 10:08:09 +01:00
|
|
|
_g_atomic_pointer_compare_and_exchange(void **atomic, void *oldval, void *newval)
|
shared/glib: reimplement g_atomic_pointer_compare_and_exchange() macro
With glib 2.63.2 and clang 9.0.0 (Fedora 32) we get compile errors:
../clients/cloud-setup/nmcs-provider-ec2.c:51:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const char **' [-Werror,-Wincompatible-pointer-types]
if (!g_atomic_pointer_compare_and_exchange (&base_cached, NULL, base))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/bluetooth/nm-bluez-manager.c:2836:2: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') [-Werror,-Wincompatible-pointer-types]
g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, NULL, &priv->vtable_network_server);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/bluetooth/nm-bluez-manager.c:2853:2: error: passing 'typeof ((&priv->vtable_network_server)) *' (aka 'struct _NMBtVTableNetworkServer **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, &priv->vtable_network_server, NULL);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/nm-device.c:8857:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'GBytes **' (aka 'struct _GBytes **') [-Werror,-Wincompatible-pointer-types]
if (!g_atomic_pointer_compare_and_exchange (&global_duid, NULL, p)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
The issue happens because glib passes the "atomic" argument to
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
without cast, and clang 9 seems to be picky about const pointers.
Add our own version of the macro that does better casts while also having
better compile time checks for valid arguments.
(cherry picked from commit f5b0713651f8603f93be82a47b22ed578762f5eb)
2019-12-13 12:06:20 +01:00
|
|
|
{
|
shared: add a compat implementation for g_atomic_pointer_get()
With glib2-2.67.0-1.fc34.x86_64.rpm, clang-11.0.0-2.fc34.x86_64.rpm, we
get a failure for g_atomic_pointer_get():
../shared/nm-glib-aux/nm-hash-utils.c:38:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = g_atomic_pointer_get(&global_seed);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:109:32: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
return ((*((const guint *) _get_hash_key())) ^ static_seed) ?: 3679500967u;
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:123:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = _get_hash_key();
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
2020-11-02 10:08:09 +01:00
|
|
|
return g_atomic_pointer_compare_and_exchange(atomic, oldval, newval);
|
shared/glib: reimplement g_atomic_pointer_compare_and_exchange() macro
With glib 2.63.2 and clang 9.0.0 (Fedora 32) we get compile errors:
../clients/cloud-setup/nmcs-provider-ec2.c:51:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const char **' [-Werror,-Wincompatible-pointer-types]
if (!g_atomic_pointer_compare_and_exchange (&base_cached, NULL, base))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/bluetooth/nm-bluez-manager.c:2836:2: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') [-Werror,-Wincompatible-pointer-types]
g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, NULL, &priv->vtable_network_server);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/bluetooth/nm-bluez-manager.c:2853:2: error: passing 'typeof ((&priv->vtable_network_server)) *' (aka 'struct _NMBtVTableNetworkServer **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, &priv->vtable_network_server, NULL);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/nm-device.c:8857:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'GBytes **' (aka 'struct _GBytes **') [-Werror,-Wincompatible-pointer-types]
if (!g_atomic_pointer_compare_and_exchange (&global_duid, NULL, p)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
The issue happens because glib passes the "atomic" argument to
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
without cast, and clang 9 seems to be picky about const pointers.
Add our own version of the macro that does better casts while also having
better compile time checks for valid arguments.
(cherry picked from commit f5b0713651f8603f93be82a47b22ed578762f5eb)
2019-12-13 12:06:20 +01:00
|
|
|
}
|
|
|
|
|
#undef g_atomic_pointer_compare_and_exchange
|
shared: add a compat implementation for g_atomic_pointer_get()
With glib2-2.67.0-1.fc34.x86_64.rpm, clang-11.0.0-2.fc34.x86_64.rpm, we
get a failure for g_atomic_pointer_get():
../shared/nm-glib-aux/nm-hash-utils.c:38:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = g_atomic_pointer_get(&global_seed);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:109:32: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
return ((*((const guint *) _get_hash_key())) ^ static_seed) ?: 3679500967u;
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:123:9: error: passing 'typeof (*(&global_seed)) *' (aka 'const unsigned char *volatile *') to parameter of type 'const guint8 **' (aka 'const unsigned char **') discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g = _get_hash_key();
^~~~~~~~~~~~~~~
../shared/nm-glib-aux/nm-hash-utils.c:84:14: note: expanded from macro '_get_hash_key'
_g = g_atomic_pointer_get(&global_seed); \
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:112:38: note: expanded from macro 'g_atomic_pointer_get'
__atomic_load (gapg_temp_atomic, &gapg_temp_newval, __ATOMIC_SEQ_CST); \
^~~~~~~~~~~~~~~~~
2020-11-02 10:08:09 +01:00
|
|
|
#define g_atomic_pointer_compare_and_exchange(atomic, oldval, newval) \
|
|
|
|
|
({ \
|
|
|
|
|
typeof(*atomic) *const _atomic = (atomic); \
|
|
|
|
|
typeof(*_atomic) const _oldval = (oldval); \
|
|
|
|
|
typeof(*_atomic) const _newval = (newval); \
|
|
|
|
|
_nm_unused gconstpointer const _val_type_check = _oldval; \
|
|
|
|
|
\
|
|
|
|
|
(void) (0 ? (gpointer) * (_atomic) : NULL); \
|
|
|
|
|
\
|
|
|
|
|
_g_atomic_pointer_compare_and_exchange((void **) _atomic, \
|
|
|
|
|
(void *) _oldval, \
|
|
|
|
|
(void *) _newval); \
|
shared/glib: reimplement g_atomic_pointer_compare_and_exchange() macro
With glib 2.63.2 and clang 9.0.0 (Fedora 32) we get compile errors:
../clients/cloud-setup/nmcs-provider-ec2.c:51:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const char **' [-Werror,-Wincompatible-pointer-types]
if (!g_atomic_pointer_compare_and_exchange (&base_cached, NULL, base))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/bluetooth/nm-bluez-manager.c:2836:2: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') [-Werror,-Wincompatible-pointer-types]
g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, NULL, &priv->vtable_network_server);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/bluetooth/nm-bluez-manager.c:2853:2: error: passing 'typeof ((&priv->vtable_network_server)) *' (aka 'struct _NMBtVTableNetworkServer **') to parameter of type 'const NMBtVTableNetworkServer **' (aka 'const struct _NMBtVTableNetworkServer **') discards qualifiers in nested pointer types [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
g_atomic_pointer_compare_and_exchange (&nm_bt_vtable_network_server, &priv->vtable_network_server, NULL);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
../src/devices/nm-device.c:8857:8: error: incompatible pointer types passing 'typeof ((((void *)0))) *' (aka 'void **') to parameter of type 'GBytes **' (aka 'struct _GBytes **') [-Werror,-Wincompatible-pointer-types]
if (!g_atomic_pointer_compare_and_exchange (&global_duid, NULL, p)) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/glib-2.0/glib/gatomic.h:192:44: note: expanded from macro 'g_atomic_pointer_compare_and_exchange'
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) ? TRUE : FALSE; \
^~~~~~~~~~~~~~
The issue happens because glib passes the "atomic" argument to
__atomic_compare_exchange_n ((atomic), &gapcae_oldval, (newval), FALSE, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST)
without cast, and clang 9 seems to be picky about const pointers.
Add our own version of the macro that does better casts while also having
better compile time checks for valid arguments.
(cherry picked from commit f5b0713651f8603f93be82a47b22ed578762f5eb)
2019-12-13 12:06:20 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2019-12-20 12:40:45 +01:00
|
|
|
#if !GLIB_CHECK_VERSION(2, 58, 0)
|
|
|
|
|
static inline gboolean
|
|
|
|
|
g_hash_table_steal_extended(GHashTable * hash_table,
|
|
|
|
|
gconstpointer lookup_key,
|
|
|
|
|
gpointer * stolen_key,
|
|
|
|
|
gpointer * stolen_value)
|
|
|
|
|
{
|
2019-12-23 08:01:23 +01:00
|
|
|
g_assert(stolen_key);
|
|
|
|
|
g_assert(stolen_value);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2019-12-20 12:40:45 +01:00
|
|
|
if (g_hash_table_lookup_extended(hash_table, lookup_key, stolen_key, stolen_value)) {
|
|
|
|
|
g_hash_table_steal(hash_table, lookup_key);
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
2019-12-23 08:01:23 +01:00
|
|
|
*stolen_key = NULL;
|
|
|
|
|
*stolen_value = NULL;
|
2019-12-20 12:40:45 +01:00
|
|
|
return FALSE;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
#define g_hash_table_steal_extended(hash_table, lookup_key, stolen_key, stolen_value) \
|
|
|
|
|
({ \
|
2019-12-23 08:01:23 +01:00
|
|
|
gpointer *_stolen_key = (stolen_key); \
|
|
|
|
|
gpointer *_stolen_value = (stolen_value); \
|
|
|
|
|
\
|
|
|
|
|
/* we cannot allow NULL arguments, because then we would leak the values in
|
2020-10-22 13:29:27 +02:00
|
|
|
* the compat implementation. */ \
|
2019-12-23 08:01:23 +01:00
|
|
|
g_assert(_stolen_key); \
|
|
|
|
|
g_assert(_stolen_value); \
|
|
|
|
|
\
|
2019-12-20 12:40:45 +01:00
|
|
|
G_GNUC_BEGIN_IGNORE_DEPRECATIONS \
|
2019-12-23 08:01:23 +01:00
|
|
|
g_hash_table_steal_extended(hash_table, lookup_key, _stolen_key, _stolen_value); \
|
2019-12-20 12:40:45 +01:00
|
|
|
G_GNUC_END_IGNORE_DEPRECATIONS \
|
|
|
|
|
})
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-04-26 15:46:53 +02:00
|
|
|
__attribute__((
|
|
|
|
|
__deprecated__("Don't use g_cancellable_reset(). Create a new cancellable instead."))) void
|
|
|
|
|
_nm_g_cancellable_reset(GCancellable *cancellable);
|
|
|
|
|
|
|
|
|
|
#undef g_cancellable_reset
|
|
|
|
|
#define g_cancellable_reset(cancellable) _nm_g_cancellable_reset(cancellable)
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2015-04-06 16:42:31 -04:00
|
|
|
#endif /* __NM_GLIB_H__ */
|