diff options
author | Thomas Haller <thaller@redhat.com> | 2021-02-08 18:02:57 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2021-02-09 12:38:19 +0100 |
commit | 7abac1b89a4583f76696baf0a3fbc8735a9e7bb8 (patch) | |
tree | 8ed2a30f43714c1f519090da46af7ba5036abfd8 | |
parent | 318824cb413b4ffb5756984cac80a813ba4e7da6 (diff) | |
download | NetworkManager-th/nm-default-cleanup.tar.gz |
shared: move redefining G_VARIANT_TYPE() to "nm-glib-aux/nm-default-glib.h"th/nm-default-cleanup
We redefine G_VARIANT_TYPE() because we don't want to pay a run time
check for what should be a simple cast.
But this is strictly tied to glib, and it must only be done after glib.h
was included. Move it to the right place.
-rw-r--r-- | shared/nm-glib-aux/nm-default-glib.h | 31 | ||||
-rw-r--r-- | shared/nm-std-aux/nm-default-std.h | 29 |
2 files changed, 31 insertions, 29 deletions
diff --git a/shared/nm-glib-aux/nm-default-glib.h b/shared/nm-glib-aux/nm-default-glib.h index 59da3ad7fe..34b23f7761 100644 --- a/shared/nm-glib-aux/nm-default-glib.h +++ b/shared/nm-glib-aux/nm-default-glib.h @@ -30,6 +30,37 @@ /*****************************************************************************/ +#if NM_MORE_ASSERTS == 0 + #ifndef G_DISABLE_CAST_CHECKS + /* Unless compiling with G_DISABLE_CAST_CHECKS, glib performs type checking + * during G_VARIANT_TYPE() via g_variant_type_checked_(). This is not necessary + * because commonly this cast is needed during something like + * + * g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}")); + * + * Note that in if the variant type would be invalid, the check still + * wouldn't make the buggy code magically work. Instead of passing a + * bogus type string (bad), it would pass %NULL to g_variant_builder_init() + * (also bad). + * + * Also, a function like g_variant_builder_init() already validates + * the input type via something like + * + * g_return_if_fail (g_variant_type_is_container (type)); + * + * So, by having G_VARIANT_TYPE() also validate the type, we validate + * twice, whereas the first validation is rather pointless because it + * doesn't prevent the function to be called with invalid arguments. + * + * Just patch G_VARIANT_TYPE() to perform no check. + */ + #undef G_VARIANT_TYPE + #define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string)) + #endif +#endif + +/*****************************************************************************/ + #include "nm-gassert-patch.h" #include "nm-std-aux/nm-std-aux.h" diff --git a/shared/nm-std-aux/nm-default-std.h b/shared/nm-std-aux/nm-default-std.h index 5ba39a0b60..fe16d35fe2 100644 --- a/shared/nm-std-aux/nm-default-std.h +++ b/shared/nm-std-aux/nm-default-std.h @@ -93,35 +93,6 @@ #endif #endif -#if NM_MORE_ASSERTS == 0 - #ifndef G_DISABLE_CAST_CHECKS - /* Unless compiling with G_DISABLE_CAST_CHECKS, glib performs type checking - * during G_VARIANT_TYPE() via g_variant_type_checked_(). This is not necessary - * because commonly this cast is needed during something like - * - * g_variant_builder_init (&props, G_VARIANT_TYPE ("a{sv}")); - * - * Note that in if the variant type would be invalid, the check still - * wouldn't make the buggy code magically work. Instead of passing a - * bogus type string (bad), it would pass %NULL to g_variant_builder_init() - * (also bad). - * - * Also, a function like g_variant_builder_init() already validates - * the input type via something like - * - * g_return_if_fail (g_variant_type_is_container (type)); - * - * So, by having G_VARIANT_TYPE() also validate the type, we validate - * twice, whereas the first validation is rather pointless because it - * doesn't prevent the function to be called with invalid arguments. - * - * Just patch G_VARIANT_TYPE() to perform no check. - */ - #undef G_VARIANT_TYPE - #define G_VARIANT_TYPE(type_string) ((const GVariantType *) (type_string)) - #endif -#endif - /*****************************************************************************/ #include <stdlib.h> |