]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fundamental: Remove types-fundamental.h
authorJan Janssen <medhefgo@web.de>
Fri, 24 Jun 2022 08:45:52 +0000 (10:45 +0200)
committerJan Janssen <medhefgo@web.de>
Mon, 27 Jun 2022 10:16:27 +0000 (12:16 +0200)
This removes the fundamental typedefs in favor of just using standard C
types. These are all used internally anyway and also do not do anything
special to warrant any redefinition to EFI types.

Even for BOOLEAN we can safely use stdbool. The defition from the EFI
specification is fully compatible, including making any other values
than 0/1 as undefined.

The exception is sd_char as those need to be char16_t. The typedef is
moved to string-util-fundamental.h instead.

src/fundamental/bootspec-fundamental.c
src/fundamental/bootspec-fundamental.h
src/fundamental/efivars-fundamental.c
src/fundamental/efivars-fundamental.h
src/fundamental/macro-fundamental.h
src/fundamental/meson.build
src/fundamental/string-util-fundamental.c
src/fundamental/string-util-fundamental.h
src/fundamental/types-fundamental.h [deleted file]

index c0138926a5881a88ae9eccef292a7e22778d73e9..4ba7c4c28d32bd79d34c971321ff53487b07e1e6 100644 (file)
@@ -2,7 +2,7 @@
 
 #include "bootspec-fundamental.h"
 
-sd_bool bootspec_pick_name_version_sort_key(
+bool bootspec_pick_name_version_sort_key(
                 const sd_char *os_pretty_name,
                 const sd_char *os_image_id,
                 const sd_char *os_name,
@@ -47,7 +47,7 @@ sd_bool bootspec_pick_name_version_sort_key(
         good_sort_key = os_image_id ?: os_id;
 
         if (!good_name)
-                return sd_false;
+                return false;
 
         if (ret_name)
                 *ret_name = good_name;
@@ -58,5 +58,5 @@ sd_bool bootspec_pick_name_version_sort_key(
         if (ret_sort_key)
                 *ret_sort_key = good_sort_key;
 
-        return sd_true;
+        return true;
 }
index ff88f8bc3f4c537d6653c874fbf30e282d1f9e88..19b489ccf55ad32bb34d17f2905c3be6e181d369 100644 (file)
@@ -1,9 +1,9 @@
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 #pragma once
 
-#include "types-fundamental.h"
+#include "string-util-fundamental.h"
 
-sd_bool bootspec_pick_name_version_sort_key(
+bool bootspec_pick_name_version_sort_key(
                 const sd_char *os_pretty_name,
                 const sd_char *os_image_id,
                 const sd_char *os_name,
index 1eaa45526646ef58afdfe1f34604339daf96e6d7..2ec3bfb2f0ee7309ae38999f0a46f656dcda9051 100644 (file)
@@ -16,12 +16,7 @@ const sd_char *secure_boot_mode_to_string(SecureBootMode m) {
         return (m >= 0 && m < _SECURE_BOOT_MAX) ? table[m] : NULL;
 }
 
-SecureBootMode decode_secure_boot_mode(
-                sd_bool secure,
-                sd_bool audit,
-                sd_bool deployed,
-                sd_bool setup) {
-
+SecureBootMode decode_secure_boot_mode(bool secure, bool audit, bool deployed, bool setup) {
         /* See figure 32-4 Secure Boot Modes from UEFI Specification 2.9 */
         if (secure && deployed && !audit && !setup)
                 return SECURE_BOOT_DEPLOYED;
index 94254554652573bac9f4cf8fced2703c1d26d392..d1b70eafdce3a814c449de44af2fc6a3e30c1e92 100644 (file)
@@ -4,10 +4,6 @@
 #include <errno.h>
 #include "string-util-fundamental.h"
 
-#ifndef UINT64_C
-#  define UINT64_C(c) (c ## ULL)
-#endif
-
 #define EFI_LOADER_FEATURE_CONFIG_TIMEOUT          (UINT64_C(1) << 0)
 #define EFI_LOADER_FEATURE_CONFIG_TIMEOUT_ONE_SHOT (UINT64_C(1) << 1)
 #define EFI_LOADER_FEATURE_ENTRY_DEFAULT           (UINT64_C(1) << 2)
@@ -30,8 +26,4 @@ typedef enum SecureBootMode {
 } SecureBootMode;
 
 const sd_char *secure_boot_mode_to_string(SecureBootMode m);
-SecureBootMode decode_secure_boot_mode(
-                sd_bool secure,
-                sd_bool audit,
-                sd_bool deployed,
-                sd_bool setup);
+SecureBootMode decode_secure_boot_mode(bool secure, bool audit, bool deployed, bool setup);
index 18370ac46a7cc926818f25c6af1823370bfcbfeb..3c38afcab8293645b76d63ebd0b632d9a0cf67bd 100644 (file)
@@ -3,11 +3,12 @@
 
 #ifndef SD_BOOT
 #  include <assert.h>
-#  include <stddef.h>
 #endif
 
 #include <limits.h>
-#include "types-fundamental.h"
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
 
 #define _align_(x) __attribute__((__aligned__(x)))
 #define _alignas_(x) __attribute__((__aligned__(__alignof__(x))))
  * on this macro will run concurrently to all other code conditionalized
  * the same way, there's no ordering or completion enforced. */
 #define ONCE __ONCE(UNIQ_T(_once_, UNIQ))
-#define __ONCE(o)                                                       \
-        ({                                                              \
-                static sd_bool (o) = sd_false;                          \
-                __sync_bool_compare_and_swap(&(o), sd_false, sd_true);  \
+#define __ONCE(o)                                                \
+        ({                                                       \
+                static bool (o) = false;                         \
+                __sync_bool_compare_and_swap(&(o), false, true); \
         })
 
 #undef MAX
 
 #define IN_SET(x, ...)                                                  \
         ({                                                              \
-                sd_bool _found = sd_false;                              \
+                bool _found = false;                                    \
                 /* If the build breaks in the line below, you need to extend the case macros. (We use "long double" as  \
                  * type for the array, in the hope that checkers such as ubsan don't complain that the initializers for \
                  * the array are not representable by the base type. Ideally we'd use typeof(x) as base type, but that  \
                 assert_cc(ELEMENTSOF(__assert_in_set) <= 20);           \
                 switch (x) {                                            \
                 FOR_EACH_MAKE_CASE(__VA_ARGS__)                         \
-                        _found = sd_true;                               \
+                        _found = true;                                  \
                        break;                                           \
                 default:                                                \
                         break;                                          \
         })
 
 static inline size_t ALIGN_TO(size_t l, size_t ali) {
-        /* sd-boot uses UINTN for size_t, let's make sure SIZE_MAX is correct. */
-        assert_cc(SIZE_MAX == ~(size_t)0);
-
         /* Check that alignment is exponent of 2 */
 #if SIZE_MAX == UINT_MAX
         assert(__builtin_popcount(ali) == 1);
index f927788c3adb67f606e7dcaddfaab53645c9c161..2ec4a28433d477d65854f2242c9cfc59f24c08f8 100644 (file)
@@ -8,7 +8,6 @@ fundamental_headers = files(
         'macro-fundamental.h',
         'sha256.h',
         'string-util-fundamental.h',
-        'types-fundamental.h',
 )
 
 # for sd-boot
index 169568e2446dc23a19e04ab7068c1e1750b7f248..6f690b9c906af4079d71a123b44f48eb36b7206c 100644 (file)
@@ -77,21 +77,21 @@ sd_char* endswith_no_case(const sd_char *s, const sd_char *postfix) {
         return (sd_char*) s + sl - pl;
 }
 
-static sd_bool is_digit(sd_char a) {
+static bool is_digit(sd_char a) {
         /* Locale-independent version of isdigit(). */
         return a >= '0' && a <= '9';
 }
 
-static sd_bool is_alpha(sd_char a) {
+static bool is_alpha(sd_char a) {
         /* Locale-independent version of isalpha(). */
         return (a >= 'a' && a <= 'z') || (a >= 'A' && a <= 'Z');
 }
 
-static sd_bool is_valid_version_char(sd_char a) {
+static bool is_valid_version_char(sd_char a) {
         return is_digit(a) || is_alpha(a) || IN_SET(a, '~', '-', '^', '.');
 }
 
-sd_int strverscmp_improved(const sd_char *a, const sd_char *b) {
+int strverscmp_improved(const sd_char *a, const sd_char *b) {
         /* This function is similar to strverscmp(3), but it treats '-' and '.' as separators.
          *
          * The logic is based on rpm's rpmvercmp(), but unlike rpmvercmp(), it distiguishes e.g.
@@ -129,7 +129,7 @@ sd_int strverscmp_improved(const sd_char *a, const sd_char *b) {
 
         for (;;) {
                 const sd_char *aa, *bb;
-                sd_int r;
+                int r;
 
                 /* Drop leading invalid characters. */
                 while (*a != '\0' && !is_valid_version_char(*a))
index 8048a07f737019425e43d0ca83c2c15ae752e60d..72fa0d7c908bd9150ed026fed8c60e19b713b2da 100644 (file)
 #  define strcasecmp strcasecmp16
 #  define strncasecmp strncasecmp16
 #  define STR_C(str)       (L ## str)
+typedef char16_t sd_char;
 #else
 #  define STR_C(str)       (str)
+typedef char sd_char;
 #endif
 
 #define streq(a,b) (strcmp((a),(b)) == 0)
 #define strcaseeq(a,b) (strcasecmp((a),(b)) == 0)
 #define strncaseeq(a, b, n) (strncasecmp((a), (b), (n)) == 0)
 
-static inline sd_int strcmp_ptr(const sd_char *a, const sd_char *b) {
+static inline int strcmp_ptr(const sd_char *a, const sd_char *b) {
         if (a && b)
                 return strcmp(a, b);
 
         return CMP(a, b);
 }
 
-static inline sd_int strcasecmp_ptr(const sd_char *a, const sd_char *b) {
+static inline int strcasecmp_ptr(const sd_char *a, const sd_char *b) {
         if (a && b)
                 return strcasecmp(a, b);
 
         return CMP(a, b);
 }
 
-static inline sd_bool streq_ptr(const sd_char *a, const sd_char *b) {
+static inline bool streq_ptr(const sd_char *a, const sd_char *b) {
         return strcmp_ptr(a, b) == 0;
 }
 
-static inline sd_bool strcaseeq_ptr(const sd_char *a, const sd_char *b) {
+static inline bool strcaseeq_ptr(const sd_char *a, const sd_char *b) {
         return strcasecmp_ptr(a, b) == 0;
 }
 
@@ -63,7 +65,7 @@ sd_char *startswith_no_case(const sd_char *s, const sd_char *prefix) _pure_;
 sd_char *endswith(const sd_char *s, const sd_char *postfix) _pure_;
 sd_char *endswith_no_case(const sd_char *s, const sd_char *postfix) _pure_;
 
-static inline sd_bool isempty(const sd_char *a) {
+static inline bool isempty(const sd_char *a) {
         return !a || a[0] == '\0';
 }
 
@@ -71,7 +73,7 @@ static inline const sd_char *strempty(const sd_char *s) {
         return s ?: STR_C("");
 }
 
-static inline const sd_char *yes_no(sd_bool b) {
+static inline const sd_char *yes_no(bool b) {
         return b ? STR_C("yes") : STR_C("no");
 }
 
@@ -79,7 +81,7 @@ static inline const sd_char* comparison_operator(int result) {
         return result < 0 ? STR_C("<") : result > 0 ? STR_C(">") : STR_C("==");
 }
 
-sd_int strverscmp_improved(const sd_char *a, const sd_char *b);
+int strverscmp_improved(const sd_char *a, const sd_char *b);
 
 /* Like startswith(), but operates on arbitrary memory blocks */
 static inline void *memory_startswith(const void *p, size_t sz, const sd_char *token) {
diff --git a/src/fundamental/types-fundamental.h b/src/fundamental/types-fundamental.h
deleted file mode 100644 (file)
index 5977e40..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#pragma once
-
-/* This defines a number of basic types that are one thing in userspace and another in the UEFI environment,
- * but mostly the same in concept and behaviour.
- *
- * Note: if the definition of these types/values has slightly different semantics in userspace and in the
- * UEFI environment then please prefix its name with "sd_" to make clear these types have special semantics,
- * and *we* defined them. Otherwise, if the types are effectively 100% identical in behaviour in userspace
- * and UEFI environment you can omit the prefix. (Examples: sd_char is 8 bit in userspace and 16 bit in UEFI
- * space hence it should have the sd_ prefix; but size_t in userspace and UINTN in UEFI environment are 100%
- * defined the same way ultimately, hence it's OK to just define size_t as alias to UINTN in UEFI
- * environment, so that size_t can be used everywhere, without any "sd_" prefix.)
- *
- * Note: we generally prefer the userspace names of types and concepts. i.e. if in doubt please name types
- * after the userspace vocabulary, and let's keep UEFI vocabulary specific to the UEFI build environment. */
-
-#ifdef SD_BOOT
-#include <efi.h>
-
-typedef BOOLEAN sd_bool;
-typedef CHAR16  sd_char;
-typedef INTN    sd_int;
-typedef UINTN   size_t;
-
-#define sd_true  TRUE
-#define sd_false FALSE
-#else
-#include <stdbool.h>
-#include <stdint.h>
-
-typedef bool    sd_bool;
-typedef char    sd_char;
-typedef int     sd_int;
-
-#define sd_true  true
-#define sd_false false
-
-#endif