libnm: merge branch 'th/libnm-connection-get-private'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1400
This commit is contained in:
Thomas Haller 2022-10-03 17:56:40 +02:00
commit e7582e7dd3
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 58 additions and 47 deletions

View file

@ -54,33 +54,6 @@ static gboolean _nm_connection_clear_settings(NMConnection *connection, NMConnec
/*****************************************************************************/
#undef NM_IS_SIMPLE_CONNECTION
#define NM_IS_SIMPLE_CONNECTION(self) \
({ \
gconstpointer _self1 = (self); \
gboolean _result; \
\
_result = \
(_self1 \
&& (((GTypeInstance *) _self1)->g_class == _nm_simple_connection_class_instance)); \
\
nm_assert(_result == G_TYPE_CHECK_INSTANCE_TYPE(_self1, NM_TYPE_SIMPLE_CONNECTION)); \
\
_result; \
})
#undef NM_IS_CONNECTION
#define NM_IS_CONNECTION(self) \
({ \
gconstpointer _self0 = (self); \
\
(_self0 \
&& (NM_IS_SIMPLE_CONNECTION(_self0) \
|| G_TYPE_CHECK_INSTANCE_TYPE(_self0, NM_TYPE_CONNECTION))); \
})
/*****************************************************************************/
void
_nm_connection_private_clear(NMConnectionPrivate *priv)
{
@ -124,19 +97,19 @@ _nm_connection_get_private_from_qdata(NMConnection *connection)
return priv;
}
#define NM_CONNECTION_GET_PRIVATE(connection) \
({ \
NMConnection *_connection = (connection); \
NMConnectionPrivate *_priv; \
\
if (G_LIKELY(NM_IS_SIMPLE_CONNECTION(_connection))) \
_priv = (gpointer) (&(((char *) _connection)[_nm_simple_connection_private_offset])); \
else \
_priv = _nm_connection_get_private_from_qdata(_connection); \
\
nm_assert(_priv && _priv->self == _connection); \
\
_priv; \
#define NM_CONNECTION_GET_PRIVATE(connection) \
({ \
NMConnection *_connection = (connection); \
NMConnectionPrivate *_priv; \
\
if (G_LIKELY(NM_IS_SIMPLE_CONNECTION(_connection))) \
_priv = _NM_SIMPLE_CONNECTION_GET_CONNECTION_PRIVATE(_connection); \
else \
_priv = _nm_connection_get_private_from_qdata(_connection); \
\
nm_assert(_priv && _priv->self == _connection); \
\
_priv; \
})
/*****************************************************************************/

View file

@ -13,6 +13,7 @@
#include "nm-setting.h"
#include "nm-setting-bridge.h"
#include "nm-connection.h"
#include "nm-simple-connection.h"
#include "nm-core-enum-types.h"
#include "libnm-core-intern/nm-core-internal.h"
@ -31,6 +32,48 @@ typedef struct {
extern GTypeClass *_nm_simple_connection_class_instance;
extern int _nm_simple_connection_private_offset;
#undef NM_IS_SIMPLE_CONNECTION
#define NM_IS_SIMPLE_CONNECTION(self) \
({ \
gconstpointer _self1 = (self); \
gboolean _result; \
\
_result = \
(_self1 \
&& (((GTypeInstance *) _self1)->g_class == _nm_simple_connection_class_instance)); \
\
nm_assert(_result == G_TYPE_CHECK_INSTANCE_TYPE(_self1, NM_TYPE_SIMPLE_CONNECTION)); \
\
_result; \
})
#undef NM_IS_CONNECTION
#define NM_IS_CONNECTION(self) \
({ \
gconstpointer _self0 = (self); \
\
(_self0 \
&& (NM_IS_SIMPLE_CONNECTION(_self0) \
|| G_TYPE_CHECK_INSTANCE_TYPE(_self0, NM_TYPE_CONNECTION))); \
})
#define _NM_SIMPLE_CONNECTION_GET_CONNECTION_PRIVATE(connection) \
({ \
gpointer _connection_1 = (connection); \
NMConnectionPrivate *_priv_1; \
\
nm_assert(NM_IS_SIMPLE_CONNECTION(_connection_1)); \
\
_priv_1 = (void *) (&(((char *) _connection_1)[_nm_simple_connection_private_offset])); \
\
nm_assert(_priv_1 \
== G_TYPE_INSTANCE_GET_PRIVATE(_connection_1, \
NM_TYPE_SIMPLE_CONNECTION, \
NMConnectionPrivate)); \
\
_priv_1; \
})
void _nm_connection_private_clear(NMConnectionPrivate *priv);
/*****************************************************************************/

View file

@ -47,9 +47,6 @@ G_DEFINE_TYPE_WITH_CODE(NMSimpleConnection,
G_IMPLEMENT_INTERFACE(NM_TYPE_CONNECTION,
nm_simple_connection_interface_init);)
#define _GET_PRIVATE(self) \
G_TYPE_INSTANCE_GET_PRIVATE(self, NM_TYPE_SIMPLE_CONNECTION, NMConnectionPrivate)
/*****************************************************************************/
static void
@ -57,7 +54,7 @@ nm_simple_connection_init(NMSimpleConnection *self)
{
NMConnectionPrivate *priv;
priv = _GET_PRIVATE(self);
priv = _NM_SIMPLE_CONNECTION_GET_CONNECTION_PRIVATE(self);
priv->self = (NMConnection *) self;
}
@ -157,14 +154,12 @@ nm_simple_connection_new_clone(NMConnection *connection)
static void
dispose(GObject *object)
{
NMConnection *connection = NM_CONNECTION(object);
#if NM_MORE_ASSERTS
g_signal_handlers_disconnect_by_data(object,
(gpointer) &_nm_assert_connection_unchanging_user_data);
#endif
_nm_connection_private_clear(_GET_PRIVATE(connection));
_nm_connection_private_clear(_NM_SIMPLE_CONNECTION_GET_CONNECTION_PRIVATE(object));
G_OBJECT_CLASS(nm_simple_connection_parent_class)->dispose(object);
}