Commit Graph

21 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek 349cc4a507 build-sys: use #if Y instead of #ifdef Y everywhere
The advantage is that is the name is mispellt, cpp will warn us.

$ git grep -Ee "conf.set\('(HAVE|ENABLE)_" -l|xargs sed -r -i "s/conf.set\('(HAVE|ENABLE)_/conf.set10('\1_/"
$ git grep -Ee '#ifn?def (HAVE|ENABLE)' -l|xargs sed -r -i 's/#ifdef (HAVE|ENABLE)/#if \1/; s/#ifndef (HAVE|ENABLE)/#if ! \1/;'
$ git grep -Ee 'if.*defined\(HAVE' -l|xargs sed -i -r 's/defined\((HAVE_[A-Z0-9_]*)\)/\1/g'
$ git grep -Ee 'if.*defined\(ENABLE' -l|xargs sed -i -r 's/defined\((ENABLE_[A-Z0-9_]*)\)/\1/g'
+ manual changes to meson.build

squash! build-sys: use #if Y instead of #ifdef Y everywhere

v2:
- fix incorrect setting of HAVE_LIBIDN2
2017-10-04 12:09:29 +02:00
Andreas Rammhold 3742095b27
tree-wide: use IN_SET where possible
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.
2017-10-02 13:09:54 +02:00
Lennart Poettering d97c5aeab8 set: add new set_put_strsplit() call
It's like set_put_strdup(), but splits up a string via an extract_first_word()
loop.
2016-06-21 13:20:48 +02:00
Lennart Poettering 454f0f8680 hashmap: optimize set_put_strdup() a bit
Hashing should be quicker than allocating, hence let's first check if the
string already exists and only then allocate a new copy for it.
2016-04-29 17:35:32 +02:00
Lennart Poettering 1a39bc8c65 hashmap: use void* and uint8_t* for generic pointers
As suggested by CODING_STYLE we should use "void*" as type for generic memory,
and uint8_t* for generic bytes. Hence use that instead of "char*", which should
really be used only for strings these days.
2016-02-22 23:24:47 +01:00
Daniel Mack b26fa1a2fb tree-wide: remove Emacs lines from all files
This should be handled fine now by .dir-locals.el, so need to carry that
stuff in every file.
2016-02-10 13:41:57 +01:00
Lennart Poettering 758dd67e8d basic: split hash functions into their own header files
The hash operations are not really that specific to hashmaps, hence split them into a .c module of their own.
2016-01-11 19:39:59 +01:00
Henrik Kaare Poulsen 3d4db144b0 basic: ENABLE_DEBUG_HASHMAP needs <pthread.h>
this is a follow-up for commit 11c3a36649
2015-12-15 07:10:50 +00:00
Thomas Hindoe Paaboel Andersen 11c3a36649 basic: include only what we use
This is a cleaned up result of running iwyu but without forward
declarations on src/basic.
2015-11-30 21:51:03 +01:00
Daniel Mack 933f9caeeb siphash24: let siphash24_finalize() and siphash24() return the result directly
Rather than passing a pointer to return the result, return it directly
from the function calls.

Also, return the result in native endianess, and let the callers care
about the conversion. For hash tables and bloom filters, we don't care,
but in order to keep MAC addresses and DHCP client IDs stable, we
explicitly convert to LE.
2015-11-16 23:17:52 +01:00
Martin Pitt dbe81cbd2a siphash24: change result argument to uint64_t
Change the "out" parameter from uint8_t[8] to uint64_t. On architectures which
enforce pointer alignment this fixes crashes when we previously cast an
unaligned array to uint64_t*, and on others this should at least improve
performance as the compiler now aligns these properly.

This also simplifies the code in most cases by getting rid of typecasts. The
only place which we can't change is struct duid's en.id, as that is _packed_
and public API, so we can't enforce alignment of the "id" field and have to
use memcpy instead.
2015-11-16 15:20:29 +01:00
Lennart Poettering b5efdb8af4 util-lib: split out allocation calls into alloc-util.[ch] 2015-10-27 13:45:53 +01:00
Lennart Poettering d4510856a0 util-lib: move is_main_thread() to process-util.[ch] 2015-10-27 13:25:57 +01:00
Tom Gundersen 0cb3c28688 siphash24: unify API
Make the API of the new helpers more similar to the old wrapper.

In particular we now return the hash as a byte string to avoid
any endianness problems.
2015-10-06 17:47:00 +02:00
Tom Gundersen 1e2527a6fe hashmap: hash_funcs - make inputs unambiguous
Make sure all variable-length inputs are properly terminated or that
their length is encoded in some way. This avoids ambiguity of
adjacent inputs.

E.g., in case of a hash function taking two strings, compressing "ab"
followed by "c" is now distinct from "a" followed by "bc".
2015-10-05 19:21:02 +02:00
Tom Gundersen b826ab586c hashmap: refactor hash_func
All our hash functions are based on siphash24(), factor out
siphash_init() and siphash24_finalize() and pass the siphash
state to the hash functions rather than the hash key.

This simplifies the hash functions, and in particular makes
composition simpler as calling siphash24_compress() repeatedly
on separate chunks of input has the same effect as first
concatenating the input and then calling siphash23_compress()
on the result.
2015-10-05 18:22:10 +02:00
David Herrmann 38489ef8b2 Merge pull request #294 from teg/hashmap-debug-locking-2
hashmap: debug - lock access to the global hashmap list
2015-06-18 22:05:09 +02:00
Tom Gundersen 4f1b306169 hashmap: debug - lock access to the global hashmap list
This may be used from multi-threaded programs (say through nss-resolve),
so we must protect the global list.

This is still only relevant for debug builds, so we do not try to handle
cases where the locking fail, but simply assert.
2015-06-18 21:35:18 +02:00
Michal Schmidt 8f8a5213a9 hashmap: allow NULL key in ordered_hashmap_next()
There is no reason to require key to be non-NULL.
Change test_ordered_hashmap_next() to use trivial_hash_ops in order to
test NULL key too.
2015-06-17 17:28:44 +02:00
David Herrmann 8927b1dad2 hashmap: fix iterators to not skip entries
Currently, the HASHMAP iterators stop at the first NULL entry in a
hashmap. This is non-obvious and breaks users like sd-device, which
legitimately store NULL values in a hashmap.

Fix all the iterators by taking a pointer to the value storage, instead of
returning it. The iterators now return a boolean that tells whether the
end of the list was reached.

Current users of HASHMAP_FOREACH() are *NOT* changed to explicitly check
for NULL. If it turns out, there were users that inserted NULL into
hashmaps, but didn't properly check for it during iteration, then we
really want to find those and fix them.
2015-06-14 16:56:02 +02:00
Kay Sievers a095315b3c build-sys: split internal basic/ library from shared/
basic/      can be used by everything
            cannot use anything outside of basic/

libsystemd/ can use basic/
            cannot use shared/

shared/     can use libsystemd/
2015-06-11 10:52:46 +02:00
Renamed from src/shared/hashmap.c (Browse further)