diff options
author | Alejandro Colomar <alx@kernel.org> | 2024-04-18 14:38:54 +0200 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2024-04-18 14:39:09 +0200 |
commit | bb04fc7810829264bf866a9271a6d9ae3266997f (patch) | |
tree | 37069384a05274315cebf4c8e170e2855c18f326 | |
parent | 2d0ad23a6e952bc9df578d7329287b37facaa777 (diff) |
include/a2i/str2i.h, lib/src/a2i/str2i.c: Don't inline these functions
We've learnt from the xz backdoor that dependencies can be very
dangerous. By not inlining, we isolate the damage that our library
could cause. If a bug is ever found here, fixing the library should be
enough. If one wants to optimize, they still can use LTO.
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | include/a2i/str2i.h | 101 | ||||
-rw-r--r-- | lib/src/a2i/str2i.c | 85 |
2 files changed, 83 insertions, 103 deletions
diff --git a/include/a2i/str2i.h b/include/a2i/str2i.h index e315337..4118d9e 100644 --- a/include/a2i/str2i.h +++ b/include/a2i/str2i.h @@ -6,12 +6,7 @@ #define INCLUDE_A2I_STR2I_H_ -#include <limits.h> -#include <stddef.h> - -#include <a2i/a2i.h> #include <a2i/attr.h> -#include <a2i/inline.h> #define str2i(TYPE, ...) \ @@ -43,7 +38,6 @@ )(__VA_ARGS__) \ ) - #define str2u(TYPE, ...) \ ( \ _Generic((TYPE) 0, \ @@ -56,97 +50,26 @@ ) -#define A2I_STR2I_PROTOTYPE(name, TYPE) \ +#define A2I_STR2I_ATTR \ A2I_ATTR_ACCESS(write_only, 1) \ A2I_ATTR_ACCESS(read_only, 2) \ A2I_ATTR_STRING(2) \ - a2i_inline int name(TYPE *restrict n, const char *s) #if defined(__clang__) # pragma clang assume_nonnull begin #endif -A2I_STR2I_PROTOTYPE(str2shh, signed char); -A2I_STR2I_PROTOTYPE(str2sh, short); -A2I_STR2I_PROTOTYPE(str2si, int); -A2I_STR2I_PROTOTYPE(str2sl, long); -A2I_STR2I_PROTOTYPE(str2sll, long long); - -A2I_STR2I_PROTOTYPE(str2uhh, unsigned char); -A2I_STR2I_PROTOTYPE(str2uh, unsigned short); -A2I_STR2I_PROTOTYPE(str2ui, unsigned int); -A2I_STR2I_PROTOTYPE(str2ul, unsigned long); -A2I_STR2I_PROTOTYPE(str2ull, unsigned long long); - - -a2i_inline int -str2shh(signed char *restrict n, const char *restrict s) -{ - return a2i(signed char, n, s, NULL, 0, SCHAR_MIN, SCHAR_MAX); -} - - -a2i_inline int -str2sh(short *restrict n, const char *restrict s) -{ - return a2i(short, n, s, NULL, 0, SHRT_MIN, SHRT_MAX); -} - - -a2i_inline int -str2si(int *restrict n, const char *restrict s) -{ - return a2i(int, n, s, NULL, 0, INT_MIN, INT_MAX); -} - - -a2i_inline int -str2sl(long *restrict n, const char *restrict s) -{ - return a2i(long, n, s, NULL, 0, LONG_MIN, LONG_MAX); -} - - -a2i_inline int -str2sll(long long *restrict n, const char *restrict s) -{ - return a2i(long long, n, s, NULL, 0, LLONG_MIN, LLONG_MAX); -} - - -a2i_inline int -str2uhh(unsigned char *restrict n, const char *restrict s) -{ - return a2i(unsigned char, n, s, NULL, 0, 0, UCHAR_MAX); -} - - -a2i_inline int -str2uh(unsigned short *restrict n, const char *restrict s) -{ - return a2i(unsigned short, n, s, NULL, 0, 0, USHRT_MAX); -} - - -a2i_inline int -str2ui(unsigned int *restrict n, const char *restrict s) -{ - return a2i(unsigned int, n, s, NULL, 0, 0, UINT_MAX); -} - - -a2i_inline int -str2ul(unsigned long *restrict n, const char *restrict s) -{ - return a2i(unsigned long, n, s, NULL, 0, 0, ULONG_MAX); -} - - -a2i_inline int -str2ull(unsigned long long *restrict n, const char *restrict s) -{ - return a2i(unsigned long long, n, s, NULL, 0, 0, ULLONG_MAX); -} +A2I_STR2I_ATTR int str2shh(signed char *restrict n, const char *restrict s); +A2I_STR2I_ATTR int str2sh(short *restrict n, const char *restrict s); +A2I_STR2I_ATTR int str2si(int *restrict n, const char *restrict s); +A2I_STR2I_ATTR int str2sl(long *restrict n, const char *restrict s); +A2I_STR2I_ATTR int str2sll(long long *restrict n, const char *restrict s); + +A2I_STR2I_ATTR int str2uhh(unsigned char *restrict n, const char *restrict s); +A2I_STR2I_ATTR int str2uh(unsigned short *restrict n, const char *restrict s); +A2I_STR2I_ATTR int str2ui(unsigned int *restrict n, const char *restrict s); +A2I_STR2I_ATTR int str2ul(unsigned long *restrict n, const char *restrict s); +A2I_STR2I_ATTR int str2ull(unsigned long long *restrict n, const char *restrict s); #if defined(__clang__) # pragma clang assume_nonnull end #endif diff --git a/lib/src/a2i/str2i.c b/lib/src/a2i/str2i.c index ba69ac2..218abce 100644 --- a/lib/src/a2i/str2i.c +++ b/lib/src/a2i/str2i.c @@ -4,18 +4,75 @@ #include <a2i/str2i.h> +#include <limits.h> +#include <stddef.h> -#pragma clang assume_nonnull begin -extern inline int str2shh(signed char *restrict n, const char *restrict s); -extern inline int str2sh(short *restrict n, const char *restrict s); -extern inline int str2si(int *restrict n, const char *restrict s); -extern inline int str2sl(long *restrict n, const char *restrict s); -extern inline int str2sll(long long *restrict n, const char *restrict s); - -extern inline int str2uhh(unsigned char *restrict n, const char *restrict s); -extern inline int str2uh(unsigned short *restrict n, const char *restrict s); -extern inline int str2ui(unsigned int *restrict n, const char *restrict s); -extern inline int str2ul(unsigned long *restrict n, const char *restrict s); -extern inline int str2ull(unsigned long long *restrict n, - const char *restrict s); -#pragma clang assume_nonnull end +#include <a2i/a2i.h> + + +#if defined(__clang__) +# pragma clang assume_nonnull begin +#endif +int +str2shh(signed char *restrict n, const char *restrict s) +{ + return a2i(signed char, n, s, NULL, 0, SCHAR_MIN, SCHAR_MAX); +} + +int +str2sh(short *restrict n, const char *restrict s) +{ + return a2i(short, n, s, NULL, 0, SHRT_MIN, SHRT_MAX); +} + +int +str2si(int *restrict n, const char *restrict s) +{ + return a2i(int, n, s, NULL, 0, INT_MIN, INT_MAX); +} + +int +str2sl(long *restrict n, const char *restrict s) +{ + return a2i(long, n, s, NULL, 0, LONG_MIN, LONG_MAX); +} + +int +str2sll(long long *restrict n, const char *restrict s) +{ + return a2i(long long, n, s, NULL, 0, LLONG_MIN, LLONG_MAX); +} + + +int +str2uhh(unsigned char *restrict n, const char *restrict s) +{ + return a2i(unsigned char, n, s, NULL, 0, 0, UCHAR_MAX); +} + +int +str2uh(unsigned short *restrict n, const char *restrict s) +{ + return a2i(unsigned short, n, s, NULL, 0, 0, USHRT_MAX); +} + +int +str2ui(unsigned int *restrict n, const char *restrict s) +{ + return a2i(unsigned int, n, s, NULL, 0, 0, UINT_MAX); +} + +int +str2ul(unsigned long *restrict n, const char *restrict s) +{ + return a2i(unsigned long, n, s, NULL, 0, 0, ULONG_MAX); +} + +int +str2ull(unsigned long long *restrict n, const char *restrict s) +{ + return a2i(unsigned long long, n, s, NULL, 0, 0, ULLONG_MAX); +} +#if defined(__clang__) +# pragma clang assume_nonnull end +#endif |