Merge pull request #20981 from poettering/glibc-less-internal
various clean-ups: use less glibc internal symbols, modernize some other stuff
This commit is contained in:
+1
-1
@@ -25,7 +25,7 @@
|
||||
#define _public_ __attribute__((__visibility__("default")))
|
||||
#define _hidden_ __attribute__((__visibility__("hidden")))
|
||||
#define _weakref_(x) __attribute__((__weakref__(#x)))
|
||||
#define _alignas_(x) __attribute__((__aligned__(__alignof(x))))
|
||||
#define _alignas_(x) __attribute__((__aligned__(__alignof__(x))))
|
||||
#define _alignptr_ __attribute__((__aligned__(sizeof(void*))))
|
||||
#define _warn_unused_result_ __attribute__((__warn_unused_result__))
|
||||
|
||||
|
||||
@@ -119,7 +119,7 @@ int sigprocmask_many(int how, sigset_t *old, ...) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *const __signal_table[] = {
|
||||
static const char *const static_signal_table[] = {
|
||||
[SIGHUP] = "HUP",
|
||||
[SIGINT] = "INT",
|
||||
[SIGQUIT] = "QUIT",
|
||||
@@ -155,13 +155,13 @@ static const char *const __signal_table[] = {
|
||||
[SIGSYS] = "SYS"
|
||||
};
|
||||
|
||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
|
||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(static_signal, int);
|
||||
|
||||
const char *signal_to_string(int signo) {
|
||||
static thread_local char buf[STRLEN("RTMIN+") + DECIMAL_STR_MAX(int)];
|
||||
const char *name;
|
||||
|
||||
name = __signal_to_string(signo);
|
||||
name = static_signal_to_string(signo);
|
||||
if (name)
|
||||
return name;
|
||||
|
||||
@@ -190,7 +190,7 @@ int signal_from_string(const char *s) {
|
||||
s += 3;
|
||||
|
||||
/* Check that the input is a signal name. */
|
||||
signo = __signal_from_string(s);
|
||||
signo = static_signal_from_string(s);
|
||||
if (signo > 0)
|
||||
return signo;
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
/* hey glibc, APIs with callbacks without a user pointer are so useless */
|
||||
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
|
||||
__compar_d_fn_t compar, void *arg) {
|
||||
comparison_userdata_fn_t compar, void *arg) {
|
||||
size_t l, u, idx;
|
||||
const void *p;
|
||||
int comparison;
|
||||
|
||||
+14
-8
@@ -5,14 +5,20 @@
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
/* This is the same as glibc's internal __compar_d_fn_t type. glibc exports a public comparison_fn_t, for the
|
||||
* external type __compar_fn_t, but doesn't do anything similar for __compar_d_fn_t. Let's hence do that
|
||||
* ourselves, picking a name that is obvious, but likely enough to not clash with glibc's choice of naming if
|
||||
* they should ever add one. */
|
||||
typedef int (*comparison_userdata_fn_t)(const void *, const void *, void *);
|
||||
|
||||
void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
|
||||
__compar_d_fn_t compar, void *arg);
|
||||
comparison_userdata_fn_t compar, void *arg);
|
||||
|
||||
#define typesafe_bsearch_r(k, b, n, func, userdata) \
|
||||
({ \
|
||||
const typeof(b[0]) *_k = k; \
|
||||
int (*_func_)(const typeof(b[0])*, const typeof(b[0])*, typeof(userdata)) = func; \
|
||||
xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_d_fn_t) _func_, userdata); \
|
||||
xbsearch_r((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_userdata_fn_t) _func_, userdata); \
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -20,7 +26,7 @@ void *xbsearch_r(const void *key, const void *base, size_t nmemb, size_t size,
|
||||
* that only if nmemb > 0.
|
||||
*/
|
||||
static inline void* bsearch_safe(const void *key, const void *base,
|
||||
size_t nmemb, size_t size, __compar_fn_t compar) {
|
||||
size_t nmemb, size_t size, comparison_fn_t compar) {
|
||||
if (nmemb <= 0)
|
||||
return NULL;
|
||||
|
||||
@@ -32,14 +38,14 @@ static inline void* bsearch_safe(const void *key, const void *base,
|
||||
({ \
|
||||
const typeof(b[0]) *_k = k; \
|
||||
int (*_func_)(const typeof(b[0])*, const typeof(b[0])*) = func; \
|
||||
bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (__compar_fn_t) _func_); \
|
||||
bsearch_safe((const void*) _k, (b), (n), sizeof((b)[0]), (comparison_fn_t) _func_); \
|
||||
})
|
||||
|
||||
/**
|
||||
* Normal qsort requires base to be nonnull. Here were require
|
||||
* that only if nmemb > 0.
|
||||
*/
|
||||
static inline void _qsort_safe(void *base, size_t nmemb, size_t size, __compar_fn_t compar) {
|
||||
static inline void _qsort_safe(void *base, size_t nmemb, size_t size, comparison_fn_t compar) {
|
||||
if (nmemb <= 1)
|
||||
return;
|
||||
|
||||
@@ -52,10 +58,10 @@ static inline void _qsort_safe(void *base, size_t nmemb, size_t size, __compar_f
|
||||
#define typesafe_qsort(p, n, func) \
|
||||
({ \
|
||||
int (*_func_)(const typeof(p[0])*, const typeof(p[0])*) = func; \
|
||||
_qsort_safe((p), (n), sizeof((p)[0]), (__compar_fn_t) _func_); \
|
||||
_qsort_safe((p), (n), sizeof((p)[0]), (comparison_fn_t) _func_); \
|
||||
})
|
||||
|
||||
static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_d_fn_t compar, void *userdata) {
|
||||
static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, comparison_userdata_fn_t compar, void *userdata) {
|
||||
if (nmemb <= 1)
|
||||
return;
|
||||
|
||||
@@ -66,7 +72,7 @@ static inline void qsort_r_safe(void *base, size_t nmemb, size_t size, __compar_
|
||||
#define typesafe_qsort_r(p, n, func, userdata) \
|
||||
({ \
|
||||
int (*_func_)(const typeof(p[0])*, const typeof(p[0])*, typeof(userdata)) = func; \
|
||||
qsort_r_safe((p), (n), sizeof((p)[0]), (__compar_d_fn_t) _func_, userdata); \
|
||||
qsort_r_safe((p), (n), sizeof((p)[0]), (comparison_userdata_fn_t) _func_, userdata); \
|
||||
})
|
||||
|
||||
int cmp_int(const int *a, const int *b);
|
||||
|
||||
@@ -55,9 +55,9 @@ typedef uint64_t __sd_bitwise be64_t;
|
||||
#undef le64toh
|
||||
|
||||
#if __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define bswap_16_on_le(x) __bswap_16(x)
|
||||
#define bswap_32_on_le(x) __bswap_32(x)
|
||||
#define bswap_64_on_le(x) __bswap_64(x)
|
||||
#define bswap_16_on_le(x) bswap_16(x)
|
||||
#define bswap_32_on_le(x) bswap_32(x)
|
||||
#define bswap_64_on_le(x) bswap_64(x)
|
||||
#define bswap_16_on_be(x) (x)
|
||||
#define bswap_32_on_be(x) (x)
|
||||
#define bswap_64_on_be(x) (x)
|
||||
@@ -65,9 +65,9 @@ typedef uint64_t __sd_bitwise be64_t;
|
||||
#define bswap_16_on_le(x) (x)
|
||||
#define bswap_32_on_le(x) (x)
|
||||
#define bswap_64_on_le(x) (x)
|
||||
#define bswap_16_on_be(x) __bswap_16(x)
|
||||
#define bswap_32_on_be(x) __bswap_32(x)
|
||||
#define bswap_64_on_be(x) __bswap_64(x)
|
||||
#define bswap_16_on_be(x) bswap_16(x)
|
||||
#define bswap_32_on_be(x) bswap_32(x)
|
||||
#define bswap_64_on_be(x) bswap_64(x)
|
||||
#endif
|
||||
|
||||
static inline le16_t htole16(uint16_t value) { return (le16_t __sd_force) bswap_16_on_be(value); }
|
||||
|
||||
Reference in New Issue
Block a user