Commit graph

33 commits

Author SHA1 Message Date
Thomas Haller
f5b89e8060
shared: add nm_mult_clamped_u() helper 2020-10-27 17:04:20 +01:00
Thomas Haller
931573dfda
shared: rename nm_add_u32_clamped() to nm_add_clamped_u32() 2020-10-27 17:04:19 +01:00
Thomas Haller
c947c51651
shared: add nm_ptr_to_uintptr() helper 2020-10-23 17:11:53 +02:00
Thomas Haller
b38075b751
shared: add nm_add_u32_clamped() helper 2020-10-23 17:11:53 +02:00
Thomas Haller
f74b7718b3
shared: add typedefs for integers for different endianness
Kernel uses such typedefs (__le32) and systemd too (le32_t).
As we don't want to rely on systemd headers in our code
base, let's also define them.

They have of course very little effect beside making it clearer to
the reviewer that a certain variable is not supposed to be in native
endianness.
2020-09-30 09:49:20 +02:00
Thomas Haller
b019950eaf
shared: include "stdint.h" in our base headers
While we often use and prefer the glib typedefs (like guint32), there
are places where we want to use the fixed width integer types from C99.

In particular, next we will introduce typedefs like nm_le64_t for
integers in different endianness.

Also, here we are about "nm-std-aux", so the glib typedefs are not
available.

I feel a header like <stdint.h> is such a basic C requirement, that
is should just be available to us everywhere.
2020-09-30 09:49:20 +02:00
Thomas Haller
f37dd5d394
shared: move NM_CMP*() macros to "nm-std-aux.h"
I would need these macros earlier in "nm-glib-aux/nm-shared-utils.h",
so it would be sufficient to just move them.

However, when I already move them, move them to "nm-std-aux/nm-std-aux.h"
because they don't need a glib dependency.
2020-09-30 09:48:26 +02:00
Thomas Haller
88071abb43
all: unify comment style for SPDX-License-Identifier tag
Our coding style recommends C style comments (/* */) instead of C++
(//). Also, systemd (which we partly fork) uses C style comments for
the SPDX-License-Identifier.

Unify the style.

  $ sed -i '1 s#// SPDX-License-Identifier: \([^ ]\+\)$#/* SPDX-License-Identifier: \1 */#' -- $(git ls-files -- '*.[hc]' '*.[hc]pp')
2020-09-29 16:50:53 +02:00
Thomas Haller
740b092fda
format: replace tabs for indentation in code comments
sed -i \
     -e 's/^'$'\t'' \*/     */g' \
     -e 's/^'$'\t\t'' \*/         */g' \
     -e 's/^'$'\t\t\t'' \*/             */g' \
     -e 's/^'$'\t\t\t\t'' \*/                 */g' \
     -e 's/^'$'\t\t\t\t\t'' \*/                     */g' \
     -e 's/^'$'\t\t\t\t\t\t'' \*/                         */g' \
     -e 's/^'$'\t\t\t\t\t\t\t'' \*/                             */g' \
     $(git ls-files -- '*.[hc]')
2020-09-28 16:07:52 +02:00
Antonio Cardace
328fb90f3e
all: reformat all with new clang-format style
Run:

    ./contrib/scripts/nm-code-format.sh -i
    ./contrib/scripts/nm-code-format.sh -i

Yes, it needs to run twice because the first run doesn't yet produce the
final result.

Signed-off-by: Antonio Cardace <acardace@redhat.com>
2020-09-28 16:07:51 +02:00
Thomas Haller
0f4221da42
shared: extend NM_IN_SET()/NM_IN_STRSET() macros to support up to 30 arguments 2020-09-10 22:09:50 +02:00
Thomas Haller
cc8da77637
shared: add NM_STR_HAS_SUFFIX_WITH_MORE()/NM_STR_HAS_SUFFIX_ASCII_CASE_WITH_MORE() macros
They are like NM_STR_HAS_SUFFIX()/NM_STR_HAS_SUFFIX_ASCII_CASE(), but require that
the checked string is not identical to the suffix. They require some non-empty word
preceding the suffix.
2020-08-07 11:43:32 +02:00
Thomas Haller
6bf5f014c8
shared: change NM_SWAP() macro to take pointer arguments
This makes the macro more function like. Also, taking a pointer
makes it a bit clearer that this possibly changes the value.

Of course, it's not a big difference to before, but this
form seems slightly preferable to me.
2020-08-06 18:12:01 +02:00
Antonio Cardace
2e70391033
shared: extend NM_IN_STRSET and NM_IN_SET to support up to 20 args
https://bugzilla.redhat.com/show_bug.cgi?id=1847814
2020-08-06 11:21:45 +02:00
Thomas Haller
b16b42266d
shared: make implementation for NM_IN_STRSET() more reusable 2020-08-05 10:22:10 +02:00
Thomas Haller
62c1a1b5b2
shared: move nm_utils_is_power_of_two() to nm-stdaux and add nm_utils_is_power_of_two_or_zero() 2020-07-31 08:53:04 +02:00
Thomas Haller
8346870aa6
shared: add nm_assert_unreachable_val() macro 2020-07-24 16:03:15 +02:00
Thomas Haller
7ae8100d7a
shared: add NM_IS_IPv4() macro
This is of course trivial. However, we use this macro at several places
as and index into an array of length 2, to lookup either the IPv4 or
IPv6 element. As such, this MUST return 0 or 1. This promise is what the
macro should convey.
2020-07-23 15:29:23 +02:00
Thomas Haller
56a0aa06ac
shared: move addr-family helpers to "nm-std-aux.h"
Handling address families is something we do all over the place.
Move some simple helper code to "nm-std-aux.h".
2020-07-23 15:29:23 +02:00
Thomas Haller
b17e3cf707
all: add trailing semicolon to NM_AUTO_DEFINE_FCN_*() uses 2020-07-19 12:01:56 +02:00
Thomas Haller
8bd2673484
shared: add _NM_DUMMY_STRUCT_FOR_TRAILING_SEMICOLON define
Will be used next.
2020-07-19 11:37:23 +02:00
Thomas Haller
4168c19e04
shared: move nm_close(), nm_auto_close, nm_steal_fd(), nm_steal_int() to nm-std-aux 2020-07-12 13:05:13 +02:00
Thomas Haller
6feab75447
shared: add nm_steal_pointer()/nm_clear_free() to "nm-std-aux.h"
There is the team of nm_auto*, nm_clear_pointer() and nm_steal_pointer().
These goes nicely together so that an autovariable owns a resource,
to free it (clear) and to transfer ownership (steal).

We have these also in glib, but we certainly also need it if we don't
have glib because that very much goes together with nm_auto*. Add it.
2020-07-07 22:32:35 +02:00
Thomas Haller
1d6e208c12
shared: move NM_AUTO_DEFINE_FCN*(), nm_auto_free and nm_clear_pointer() to "nm-std-aux.h" 2020-07-07 22:25:42 +02:00
Thomas Haller
1b9001f867
shared: include <stdbool.h> in "nm-std-aux.h" and fix glib-ism
For a long time already we build with gnu11/C11. We thus rely on having
<stdbool.h> around, which is C99. Use it.

Also fix "nm-std-aux.h" to not use TRUE/FALSE glib defines.
2020-07-07 22:25:19 +02:00
Thomas Haller
3b80c6c28f
shared: make NM_BOOLEAN_EXPR() macro composable and use it for _G_BOOLEAN_EXPR()
We redefine _G_BOOLEAN_EXPR(), so let it use NM_BOOLEAN_EXPR().

Also, we use G_LIKELY() (and thus NM_BOOLEAN_EXPR()) inside nm_assert(),
and we use nm_assert() in some macros. To be able to nest nm_assert()
calls, we need to create unique variable names for NM_BOOLEAN_EXPR().
2020-07-07 21:52:22 +02:00
Thomas Haller
f0deb24249
shared: move various basic helpers from "nm-macros-internal.h" to "nm-std-aux.h"
These are generally useful and independent of glib. Move them to
nm-std-aux, which has no glib dependency.
2020-07-07 21:33:25 +02:00
Thomas Haller
b9e458b184
shared: add NM_N_ELEMENTS() macro 2020-07-06 14:11:23 +02:00
Thomas Haller
d407c1271c
shared: move NM_SET_OUT() to "nm-std-aux.h" 2020-07-06 14:11:22 +02:00
Thomas Haller
b109d63376
shared: add min/max macros to "nm-std-aux.h" 2020-07-06 11:45:37 +02:00
Thomas Haller
5361317f68
shared: add macros for declaration attribute to "nm-std-aux.h" 2020-07-06 11:45:37 +02:00
Thomas Haller
030d68aef7
shared: add nm_assert() to "nm-std-aux.h"
Having assertion macros that are disabled by default, is not
only useful for our glib code, but should also be available
for nm-std-aux. Move the macros.
2020-07-06 11:45:37 +02:00
Thomas Haller
5dd923cd86
shared: add "nm-std-aux/nm-std-aux.h" header
"nm-std-aux" is an utility library that has no glib depdencency. That
is the difference to "nm-glib-aux".
2020-07-06 11:10:43 +02:00