Commit Graph

27 Commits

Author SHA1 Message Date
Beniamino Galvani
bc9d034775 macros: avoid signed overflow in nm_utils_is_power_of_two()
If __x is signed and its value is the minimum allowed for the type,
(__x - 1) causes a signed overflow, which has an undefined
behavior. Compiling with -fsanitize=undefined produces the warnings:

test-general.c:4499:619: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
test-general.c:4506:681: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'TEST_IS_POWER_OF_TWP_ENUM_SIGNED'
test-general.c:4501:619: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'long int'
test-general.c:4509:691: runtime error: signed integer overflow: -9223372036854775808 - 1 cannot be represented in type 'TEST_IS_POWER_OF_TWP_ENUM_UNSIGNED_64'

Change the order of expressions to avoid this.

Fixes: 0a3c1f5774
2015-11-15 11:13:29 +01:00
Glenn Washburn
6263703286 build: disable Pragmas for pre 4.6 gcc
Gcc 4.6 introduced Pragma "GCC diagnostic" (https://gcc.gnu.org/gcc-4.6/changes.html)
Don't use them for older gcc.

[thaller@redhat.com: modified original patch]

https://bugzilla.gnome.org/show_bug.cgi?id=757910
2015-11-13 17:19:40 +01:00
Thomas Haller
abd607257b macros: add nm_sprintf_buf() helper macro 2015-11-01 17:28:07 +01:00
Thomas Haller
204fcd33d8 macros: add nm_clear_g_cancellable() utility 2015-11-01 17:28:07 +01:00
Thomas Haller
2041e140bf macros: add nm_clear_g_variant() util 2015-10-12 14:44:31 +02:00
Thomas Haller
76958f94d4 macros: remove early return from nm_clear_g_signal_handler()
It is valid to call nm_clear_g_signal_handler() with missing
@self argument if (and only if) the @id is unspecified as well.

Remove the check for @self to get an assertion in case @id
is missing *and* @self is invalid. In this case,
g_signal_handler_disconnect() will raise a g_critical() for us.

Fixes: c33416178f
2015-10-12 11:10:48 +02:00
Jiří Klimeš
c33416178f macros: allow NULL pointer in nm_clear_g_signal_handler()
It does not make sense to issue an error. This should be a helper function.
"NetworkManager[18341]: nm_clear_g_signal_handler: assertion 'G_IS_OBJECT (self)' failed"
error started since commit e6d7fee5a6 due to that.
2015-10-12 09:07:54 +02:00
Thomas Haller
d4d2e65eb7 macros: add NM_SET_OUT() macro 2015-10-07 16:35:19 +02:00
Thomas Haller
7182304684 config: allow to enable/disable configuration snippets
Support a new configuration option

  [.config]
  enable=<ENABLED>

for configuration snippets.

This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.

Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.

<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"

There are several motivations for this:

- the user can disable an entire configuration snippet by toggeling
  one entry.
  This generalizes  the functionality of the global-dns.enable
  setting, but in a way that applies to configuration on a per-file
  basis.

- for developing, we often switch between different versions of
  NetworkManager. Thus, we might want to use different configuration.
  E.g. before global-dns options, I want to use "dns=none" and manage
  resolv.conf myself. Now, I can use global-dns setting to do that.
  That can be achieved with something like the following (not exactly,
  it's an example only):

      [.config]
      enable=nm-version-min:1.1
      [main]
      dns=default
      [global-dns-domain-*]
      nameserver=127.0.0.1

  Arguably, this would be more awesome, if we would bump our micro devel
  version (1.1.0) more often while developing 1.2.0 (*hint*).

- in principle, packages could drop configuration snippets and enable
  them based on the NetworkManager version.

- with the "env:" spec, you can enable/disable snippets by configuring
  an environment variable. Again, useful for testing and developing.
2015-10-05 17:12:50 +02:00
Thomas Haller
6395c829bb build: make NM_MORE_ASSERTS define numeric for different levels of more-asserts
Allows to enable more-asserts more granularly.

Unfortunately, the old check was "${enable_more_asserts} == "yes", thus
we cannot extend "--enable-more-assert=level" because that would mean
that the same build script cannot set the option on both old and new
NetworkManager.
Thus, add a new option --with-more-asserts=level. If you put the
following in your build script, it will work as expected whether
you build a new or an old version of NetworkManager.
  ./configure --enable-more-asserts --with-more-asserts=5
2015-10-05 15:25:54 +02:00
Thomas Haller
c98c7a486c macros: add nm_clear_g_signal_handler() helper 2015-10-02 16:42:44 +02:00
Thomas Haller
6bcc1eda0b macros: add NM_PRINT_FMT_QUOTE_STRING() macro 2015-08-25 16:37:43 +02:00
Thomas Haller
96cacc07e8 macros: use short-circuit evaluation in NM_IN_SET()
All current users of NM_IN_SET() would rather use short-circuit evalation
(or don't care). It seems that doing it by default seems favorable.

The only downside is, that this might have somewhat unexpected behavior
to a user who expects a regular function (which would evaluate always
all arguments).

Fixes: 7860ef959a
2015-08-12 16:04:17 +02:00
Thomas Haller
7860ef959a macros: rework NM_IN_SET() macro to expand to a plain logical expression
Let the preprocessor do more work, but generate a simple expression that
the compiler can optimize (presumably) better.
2015-08-12 14:30:18 +02:00
Thomas Haller
19c3ea948a all: make use of new header file "nm-default.h" 2015-08-05 15:32:40 +02:00
Dan Winship
3452ee2a0e all: rename nm-glib-compat.h to nm-glib.h, use everywhere
Rather than randomly including one or more of <glib.h>,
<glib-object.h>, and <gio/gio.h> everywhere (and forgetting to include
"nm-glib-compat.h" most of the time), rename nm-glib-compat.h to
nm-glib.h, include <gio/gio.h> from there, and then change all .c
files in NM to include "nm-glib.h" rather than including the glib
headers directly.

(Public headers files still have to include the real glib headers,
since nm-glib.h isn't installed...)

Also, remove glib includes from header files that are already
including a base object header file (which must itself already include
the glib headers).
2015-07-24 13:25:47 -04:00
Thomas Haller
8bca864111 core: move NM_DEFINE_SINGLETON macros to src/NetworkManagerUtils.h
NM_DEFINE_SINGLETON is used only by core and makes use of nm-logging.
It does not belong to "include/nm-macros-internal.h". Move it to "src/".
2015-07-24 18:07:16 +02:00
Thomas Haller
981817e998 Revert "core: move NM_DEFINE_SINGLETON macros to src/NetworkManagerUtils.h"
This reverts commit 1bca459865.

I accidentely pushed that commit. Revert.
2015-07-24 16:24:22 +02:00
Thomas Haller
1bca459865 core: move NM_DEFINE_SINGLETON macros to src/NetworkManagerUtils.h
NM_DEFINE_SINGLETON is used only by core and makes use of nm-logging.
It does not belong to "include/nm-macros-internal.h". Move it to "src/".
2015-07-24 15:45:46 +02:00
Thomas Haller
d6a331bd8c macros: add nm_strstrip() util 2015-07-02 15:50:03 +02:00
Dan Winship
64ff214bb8 macros: add NM_BACKPORT_SYMBOL()
Add a macro to insert the necessary compiler/linker magic to add a
copy of an existing symbol to an older version. Also, update
check-exports.sh to be able to check for such symbols by listed them
commented-out in the appropriate section.

[thaller@redhat.com: patch modified]

Related: https://bugzilla.gnome.org/show_bug.cgi?id=742993
2015-06-26 16:28:33 +02:00
Thomas Haller
083327b830 trivial: fix spelling error in code comment 2015-06-21 15:29:30 +02:00
Thomas Haller
972f61fcd7 macros: add NM_PRINT_FMT_QUOTED() macro 2015-06-17 17:46:54 +02:00
Thomas Haller
0a3c1f5774 utils: add nm_utils_is_power_of_two() macro 2015-06-17 11:41:43 +02:00
Thomas Haller
57958b93b6 utils: add NM_FLAGS_SET(), NM_FLAGS_UNSET() and NM_FLAGS_ASSIGN() macros 2015-06-05 16:52:49 +02:00
Thomas Haller
fe3e1849b7 core: make nm_assert() always compile condition
Even if asserts are not enabled, still let the compiler see what we would
assert. Otherwise, we get warnings about unused variables or we migth miss
compile errors inside nm_assert().
2015-06-05 16:52:49 +02:00
Thomas Haller
b8b1a01d96 build: rename file "include/nm-utils-internal.h" to "nm-macros-internal.h"
We already have "nm-utils*.h" and "NetworkManagerUtils.h" headers. Rename
"include/nm-utils-internal.h" to "nm-macros-internal.h". I think that
name is better, because this file is header-only, internal, and
repository-wide.

Also, it will never contain non-header-only declarations because
there is no backing object file under "include/".
It will only contain macros and inline functions.
2015-06-01 14:47:08 +02:00