string-table: Introduce DECLARE_STRING_TABLE_LOOKUP() and friends

Let's introduce these for the following two reasons:
- Using them makes sure the parameter names match between declaration
  and definition (if both use the corresponding macros).
- They make sure developers can't forget the _const_ and _pure_
  attributes for the declarations.

This commit also includes some include sorting fixes
This commit is contained in:
Daan De Meyer
2026-01-02 04:05:45 +09:00
committed by Yu Watanabe
parent daff8ea8bb
commit aec52c1e6e
139 changed files with 351 additions and 589 deletions
+1 -2
View File
@@ -10,8 +10,7 @@ typedef enum ImageCleanPoolMode {
_IMAGE_CLEAN_POOL_INVALID = -EINVAL,
} ImageCleanPoolMode;
ImageCleanPoolMode image_clean_pool_mode_from_string(const char *s) _pure_;
const char* image_clean_pool_mode_to_string(ImageCleanPoolMode mode) _const_;
DECLARE_STRING_TABLE_LOOKUP(image_clean_pool_mode, ImageCleanPoolMode);
int image_clean_pool_operation(Manager *manager, ImageCleanPoolMode mode, Operation **ret_operation);
int clean_pool_read_first_entry(FILE *file, int child_error, sd_bus_error *error);
+4 -8
View File
@@ -107,14 +107,11 @@ void machine_release_unit(Machine *m);
MachineState machine_get_state(Machine *m);
const char* machine_class_to_string(MachineClass t) _const_;
MachineClass machine_class_from_string(const char *s) _pure_;
DECLARE_STRING_TABLE_LOOKUP(machine_class, MachineClass);
const char* machine_state_to_string(MachineState t) _const_;
MachineState machine_state_from_string(const char *s) _pure_;
DECLARE_STRING_TABLE_LOOKUP(machine_state, MachineState);
const char* kill_whom_to_string(KillWhom k) _const_;
KillWhom kill_whom_from_string(const char *s) _pure_;
DECLARE_STRING_TABLE_LOOKUP(kill_whom, KillWhom);
int machine_openpt(Machine *m, int flags, char **ret_peer);
int machine_start_getty(Machine *m, const char *ptmx_name, sd_bus_error *error);
@@ -149,8 +146,7 @@ typedef enum AcquireMetadata {
_ACQUIRE_METADATA_INVALID = -EINVAL,
} AcquireMetadata;
AcquireMetadata acquire_metadata_from_string(const char *s) _pure_;
const char* acquire_metadata_to_string(AcquireMetadata am) _const_;
DECLARE_STRING_TABLE_LOOKUP(acquire_metadata, AcquireMetadata);
inline static bool should_acquire_metadata(AcquireMetadata am) {
return am == ACQUIRE_METADATA_YES || am == ACQUIRE_METADATA_GRACEFUL;
}