NetworkManager/src/devices/nm-device-logging.h
Thomas Haller 31940037fa
device: fix _Generic() types for _NM_DEVICE_CAST() macro (2)
clang (x86_64, 3.4.2-9.el7) fails:

    ../src/devices/nm-device.c:957:9: error: controlling expression type 'typeof (*self) *const' (aka 'struct _NMDevice *const') not compatible with any generic association type
            _LOGT(LOGD_DEVICE,
            ^~~~~~~~~~~~~~~~~~
    ../shared/nm-glib-aux/nm-logging-fwd.h:162:20: note: expanded from macro '_LOGT'
    #define _LOGT(...) _NMLOG(_LOGL_TRACE, __VA_ARGS__)
                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    ../src/devices/nm-device-logging.h:34:81: note: expanded from macro '_NMLOG'
                const char *const    _ifname = _nm_device_get_iface(_NM_DEVICE_CAST(_self)); \
                                                                                    ^~~~~
    ../src/devices/nm-device-logging.h:14:63: note: expanded from macro '_NM_DEVICE_CAST'
        #define _NM_DEVICE_CAST(self) _NM_ENSURE_TYPE(NMDevice *, self)
                                                                  ^
    ../shared/nm-glib-aux/nm-macros-internal.h:664:53: note: expanded from macro '_NM_ENSURE_TYPE'
        #define _NM_ENSURE_TYPE(type, value) (_Generic((value), type : (value)))
                                                        ^

Fixes: cc35dc3bdf ('device: improve "nm-device-logging.h" to support a self pointer of NMDevice type')
2020-11-10 22:54:32 +01:00

52 lines
2.9 KiB
C

/* SPDX-License-Identifier: GPL-2.0+ */
/*
* Copyright (C) 2014 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_DEVICE_LOGGING_H__
#define __NETWORKMANAGER_DEVICE_LOGGING_H__
#include "nm-device.h"
#if !_NM_CC_SUPPORT_GENERIC
#define _NM_DEVICE_CAST(self) ((NMDevice *) (self))
#elif !defined(_NMLOG_DEVICE_TYPE)
#define _NM_DEVICE_CAST(self) \
_Generic((self), NMDevice * \
: ((NMDevice *) (self)), NMDevice *const \
: ((NMDevice *) (self)))
#else
#define _NM_DEVICE_CAST(self) \
_Generic((self), \
_NMLOG_DEVICE_TYPE * : ((NMDevice *) (self)), \
_NMLOG_DEVICE_TYPE * const: ((NMDevice *) (self)), \
NMDevice * : ((NMDevice *) (self)), \
NMDevice * const: ((NMDevice *) (self)))
#endif
#undef _NMLOG_ENABLED
#define _NMLOG_ENABLED(level, domain) (nm_logging_enabled((level), (domain)))
#define _NMLOG(level, domain, ...) \
G_STMT_START \
{ \
const NMLogLevel _level = (level); \
const NMLogDomain _domain = (domain); \
\
if (nm_logging_enabled(_level, _domain)) { \
typeof(*self) *const _self = (self); \
const char *const _ifname = _nm_device_get_iface(_NM_DEVICE_CAST(_self)); \
\
nm_log_obj(_level, \
_domain, \
_ifname, \
NULL, \
_self, \
"device", \
"%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
NM_PRINT_FMT_QUOTED(_ifname, "(", _ifname, ")", "[null]") \
_NM_UTILS_MACRO_REST(__VA_ARGS__)); \
} \
} \
G_STMT_END
#endif /* __NETWORKMANAGER_DEVICE_LOGGING_H__ */