From bf593304ef24e04102955f2f535cf0703a8c5989 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 9 Jul 2018 13:46:47 +0200 Subject: [PATCH] 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. --- shared/nm-utils/nm-glib.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/shared/nm-utils/nm-glib.h b/shared/nm-utils/nm-glib.h index 08ede9e59..fd7865195 100644 --- a/shared/nm-utils/nm-glib.h +++ b/shared/nm-utils/nm-glib.h @@ -20,6 +20,14 @@ #ifndef __NM_GLIB_H__ #define __NM_GLIB_H__ +/*****************************************************************************/ + +#ifndef __NM_MACROS_INTERNAL_H__ +#error "nm-glib.h requires nm-macros-internal.h. Do not include this directly" +#endif + +/*****************************************************************************/ + #include #include