]>
Commit | Line | Data |
---|---|---|
4a6708fd JP |
1 | From 5159c34ea8923bf0c17fd31e183c5803b72b97f3 Mon Sep 17 00:00:00 2001 |
2 | From: Thomas Haller <thaller@redhat.com> | |
3 | Date: Mon, 5 Feb 2018 13:10:24 +0100 | |
4 | Subject: ovs: fix compiler error for passing NMDevice pointer to | |
5 | NM_DEVICE_OVS_INTERFACE_GET_PRIVATE() | |
6 | MIME-Version: 1.0 | |
7 | Content-Type: text/plain; charset=UTF-8 | |
8 | Content-Transfer-Encoding: 8bit | |
9 | ||
10 | NM_DEVICE_OVS_INTERFACE_GET_PRIVATE() is implemented via the _NM_GET_PRIVATE() | |
11 | macro. This macro uses C11's _Generic() to provide additional compiler checks | |
12 | when casting from an incompatible pointer type. | |
13 | ||
14 | As such, | |
15 | ||
16 | NMDevice *device = ...; | |
17 | NMDeviceOvsInterfacePrivate *priv; | |
18 | ||
19 | priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE (device); | |
20 | ||
21 | causes a compilation error: | |
22 | ||
23 | error: ‘_Generic’ selector of type ‘NMDevice * {aka struct _NMDevice *}’ is not compatible with any association | |
24 | ||
25 | One workaround would be to cast the pointer first: | |
26 | ||
27 | priv = NM_DEVICE_OVS_INTERFACE_GET_PRIVATE ((NMDeviceOvsInterface *) device); | |
28 | ||
29 | A better fix is to mark NMDevice as a compatible pointer in _NM_GET_PRIVATE(), | |
30 | which this patch does. | |
31 | ||
32 | Previously, this went unnoticed, because due to bug "a43bf3388 build: fix configure | |
33 | check for CC support of _Generic() and __auto_type", we failed to detect support | |
34 | for _Generic() when compiling with -Werror. That essentially disables this check, | |
35 | and NM_DEVICE_OVS_INTERFACE_GET_PRIVATE() would do a direct cast. | |
36 | ||
37 | A workaround for this build failure might be to build with -Werror, which accidentally | |
38 | results in not using _Generic(). | |
39 | ||
40 | https://bugzilla.gnome.org/show_bug.cgi?id=793183 | |
41 | ||
42 | Fixes: 8ad310f8e3cb0157cfa5fa8ff10f313555cf8e3c | |
43 | (cherry picked from commit 782578122c6cb23bdbee0b01eddceee1b967a673) | |
44 | --- | |
45 | src/devices/ovs/nm-device-ovs-interface.c | 2 +- | |
46 | 1 file changed, 1 insertion(+), 1 deletion(-) | |
47 | ||
48 | diff --git a/src/devices/ovs/nm-device-ovs-interface.c b/src/devices/ovs/nm-device-ovs-interface.c | |
49 | index e746a3f..ce32c2d 100644 | |
50 | --- a/src/devices/ovs/nm-device-ovs-interface.c | |
51 | +++ b/src/devices/ovs/nm-device-ovs-interface.c | |
52 | @@ -50,7 +50,7 @@ struct _NMDeviceOvsInterfaceClass { | |
53 | ||
54 | G_DEFINE_TYPE (NMDeviceOvsInterface, nm_device_ovs_interface, NM_TYPE_DEVICE) | |
55 | ||
56 | -#define NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceOvsInterface, NM_IS_DEVICE_OVS_INTERFACE) | |
57 | +#define NM_DEVICE_OVS_INTERFACE_GET_PRIVATE(self) _NM_GET_PRIVATE (self, NMDeviceOvsInterface, NM_IS_DEVICE_OVS_INTERFACE, NMDevice) | |
58 | ||
59 | /*****************************************************************************/ | |
60 | ||
61 | -- | |
62 | cgit v1.1 | |
63 |