Add __attribute__((const, pure, format)) in various places

I'm assuming that it's fine if a _const_ or _pure_ function
calls assert. It is assumed that the assert won't trigger,
and even if it does, it can only trigger on the first call
with a given set of parameters, and we don't care if the
compiler moves the order of calls.
parent 2f79c10e
......@@ -64,8 +64,8 @@ int automount_send_ready(Automount *a, int status);
int automount_add_one_mount_link(Automount *a, Mount *m);
const char* automount_state_to_string(AutomountState i);
AutomountState automount_state_from_string(const char *s);
const char* automount_state_to_string(AutomountState i) _const_;
AutomountState automount_state_from_string(const char *s) _pure_;
const char* automount_result_to_string(AutomountResult i);
AutomountResult automount_result_from_string(const char *s);
const char* automount_result_to_string(AutomountResult i) _const_;
AutomountResult automount_result_from_string(const char *s) _pure_;
......@@ -42,8 +42,8 @@ struct CGroupAttribute {
int cgroup_attribute_apply(CGroupAttribute *a, CGroupBonding *b);
int cgroup_attribute_apply_list(CGroupAttribute *first, CGroupBonding *b);
bool cgroup_attribute_matches(CGroupAttribute *a, const char *controller, const char *name);
CGroupAttribute *cgroup_attribute_find_list(CGroupAttribute *first, const char *controller, const char *name);
bool cgroup_attribute_matches(CGroupAttribute *a, const char *controller, const char *name) _pure_;
CGroupAttribute *cgroup_attribute_find_list(CGroupAttribute *first, const char *controller, const char *name) _pure_;
void cgroup_attribute_free(CGroupAttribute *a);
void cgroup_attribute_free_list(CGroupAttribute *first);
......
......@@ -76,7 +76,7 @@ void cgroup_bonding_trim_list(CGroupBonding *first, bool delete_root);
int cgroup_bonding_is_empty(CGroupBonding *b);
int cgroup_bonding_is_empty_list(CGroupBonding *first);
CGroupBonding *cgroup_bonding_find_list(CGroupBonding *first, const char *controller);
CGroupBonding *cgroup_bonding_find_list(CGroupBonding *first, const char *controller) _pure_;
char *cgroup_bonding_to_string(CGroupBonding *b);
......
......@@ -66,5 +66,5 @@ bool condition_test_list(Condition *c);
void condition_dump(Condition *c, FILE *f, const char *prefix);
void condition_dump_list(Condition *c, FILE *f, const char *prefix);
const char* condition_type_to_string(ConditionType t);
int condition_type_from_string(const char *s);
const char* condition_type_to_string(ConditionType t) _const_;
int condition_type_from_string(const char *s) _pure_;
......@@ -124,13 +124,13 @@ static void device_dump(Unit *u, FILE *f, const char *prefix) {
prefix, strna(d->sysfs));
}
static UnitActiveState device_active_state(Unit *u) {
_pure_ static UnitActiveState device_active_state(Unit *u) {
assert(u);
return state_translation_table[DEVICE(u)->state];
}
static const char *device_sub_state_to_string(Unit *u) {
_pure_ static const char *device_sub_state_to_string(Unit *u) {
assert(u);
return device_state_to_string(DEVICE(u)->state);
......
......@@ -52,5 +52,5 @@ extern const UnitVTable device_vtable;
void device_fd_event(Manager *m, int events);
const char* device_state_to_string(DeviceState i);
DeviceState device_state_from_string(const char *s);
const char* device_state_to_string(DeviceState i) _const_;
DeviceState device_state_from_string(const char *s) _pure_;
......@@ -144,7 +144,7 @@ static int flags_fds(const int fds[], unsigned n_fds, bool nonblock) {
return 0;
}
static const char *tty_path(const ExecContext *context) {
_pure_ static const char *tty_path(const ExecContext *context) {
assert(context);
if (context->tty_path)
......@@ -509,7 +509,7 @@ fail:
return r;
}
static int write_confirm_message(const char *format, ...) {
_printf_attr_(1, 2) static int write_confirm_message(const char *format, ...) {
int fd;
va_list ap;
......
......@@ -210,8 +210,8 @@ void exec_status_start(ExecStatus *s, pid_t pid);
void exec_status_exit(ExecStatus *s, ExecContext *context, pid_t pid, int code, int status);
void exec_status_dump(ExecStatus *s, FILE *f, const char *prefix);
const char* exec_output_to_string(ExecOutput i);
ExecOutput exec_output_from_string(const char *s);
const char* exec_output_to_string(ExecOutput i) _const_;
ExecOutput exec_output_from_string(const char *s) _pure_;
const char* exec_input_to_string(ExecInput i);
ExecInput exec_input_from_string(const char *s);
const char* exec_input_to_string(ExecInput i) _const_;
ExecInput exec_input_from_string(const char *s) _pure_;
......@@ -569,7 +569,7 @@ int job_run_and_invalidate(Job *j) {
return r;
}
static const char *job_get_status_message_format(Unit *u, JobType t, JobResult result) {
_pure_ static const char *job_get_status_message_format(Unit *u, JobType t, JobResult result) {
const UnitStatusMessageFormats *format_table;
assert(u);
......@@ -588,7 +588,7 @@ static const char *job_get_status_message_format(Unit *u, JobType t, JobResult r
return NULL;
}
static const char *job_get_status_message_format_try_harder(Unit *u, JobType t, JobResult result) {
_pure_ static const char *job_get_status_message_format_try_harder(Unit *u, JobType t, JobResult result) {
const char *format;
assert(u);
......
......@@ -183,22 +183,22 @@ void job_dependency_free(JobDependency *l);
int job_merge(Job *j, Job *other);
JobType job_type_lookup_merge(JobType a, JobType b);
JobType job_type_lookup_merge(JobType a, JobType b) _pure_;
static inline bool job_type_is_mergeable(JobType a, JobType b) {
_pure_ static inline bool job_type_is_mergeable(JobType a, JobType b) {
return job_type_lookup_merge(a, b) >= 0;
}
static inline bool job_type_is_conflicting(JobType a, JobType b) {
_pure_ static inline bool job_type_is_conflicting(JobType a, JobType b) {
return !job_type_is_mergeable(a, b);
}
static inline bool job_type_is_superset(JobType a, JobType b) {
_pure_ static inline bool job_type_is_superset(JobType a, JobType b) {
/* Checks whether operation a is a "superset" of b in its actions */
return a == job_type_lookup_merge(a, b);
}
bool job_type_is_redundant(JobType a, UnitActiveState b);
bool job_type_is_redundant(JobType a, UnitActiveState b) _pure_;
/* Collapses a state-dependent job type into a simpler type by observing
* the state of the unit which it is going to be applied to. */
......@@ -221,14 +221,14 @@ char *job_dbus_path(Job *j);
void job_shutdown_magic(Job *j);
const char* job_type_to_string(JobType t);
JobType job_type_from_string(const char *s);
const char* job_type_to_string(JobType t) _const_;
JobType job_type_from_string(const char *s) _pure_;
const char* job_state_to_string(JobState t);
JobState job_state_from_string(const char *s);
const char* job_state_to_string(JobState t) _const_;
JobState job_state_from_string(const char *s) _pure_;
const char* job_mode_to_string(JobMode t);
JobMode job_mode_from_string(const char *s);
const char* job_mode_to_string(JobMode t) _const_;
JobMode job_mode_from_string(const char *s) _pure_;
const char* job_result_to_string(JobResult t);
JobResult job_result_from_string(const char *s);
const char* job_result_to_string(JobResult t) _const_;
JobResult job_result_from_string(const char *s) _pure_;
......@@ -26,6 +26,8 @@ typedef struct KillContext KillContext;
#include <stdbool.h>
#include <stdio.h>
#include "macro.h"
typedef enum KillMode {
/* The kill mode is a property of a unit. */
KILL_CONTROL_GROUP = 0,
......@@ -53,8 +55,8 @@ typedef enum KillWho {
void kill_context_init(KillContext *c);
void kill_context_dump(KillContext *c, FILE *f, const char *prefix);
const char *kill_mode_to_string(KillMode k);
KillMode kill_mode_from_string(const char *s);
const char *kill_mode_to_string(KillMode k) _const_;
KillMode kill_mode_from_string(const char *s) _pure_;
const char *kill_who_to_string(KillWho k);
KillWho kill_who_from_string(const char *s);
const char *kill_who_to_string(KillWho k) _const_;
KillWho kill_who_from_string(const char *s) _pure_;
......@@ -284,7 +284,7 @@ int manager_distribute_fds(Manager *m, FDSet *fds);
int manager_reload(Manager *m);
bool manager_is_reloading_or_reexecuting(Manager *m);
bool manager_is_reloading_or_reexecuting(Manager *m) _pure_;
void manager_reset_failed(Manager *m);
......
......@@ -136,7 +136,7 @@ static void mount_done(Unit *u) {
unit_unwatch_timer(u, &m->timer_watch);
}
static MountParameters* get_mount_parameters_fragment(Mount *m) {
_pure_ static MountParameters* get_mount_parameters_fragment(Mount *m) {
assert(m);
if (m->from_fragment)
......@@ -145,7 +145,7 @@ static MountParameters* get_mount_parameters_fragment(Mount *m) {
return NULL;
}
static MountParameters* get_mount_parameters(Mount *m) {
_pure_ static MountParameters* get_mount_parameters(Mount *m) {
assert(m);
if (m->from_proc_self_mountinfo)
......@@ -1260,19 +1260,19 @@ static int mount_deserialize_item(Unit *u, const char *key, const char *value, F
return 0;
}
static UnitActiveState mount_active_state(Unit *u) {
_pure_ static UnitActiveState mount_active_state(Unit *u) {
assert(u);
return state_translation_table[MOUNT(u)->state];
}
static const char *mount_sub_state_to_string(Unit *u) {
_pure_ static const char *mount_sub_state_to_string(Unit *u) {
assert(u);
return mount_state_to_string(MOUNT(u)->state);
}
static bool mount_check_gc(Unit *u) {
_pure_ static bool mount_check_gc(Unit *u) {
Mount *m = MOUNT(u);
assert(m);
......
......@@ -111,13 +111,13 @@ extern const UnitVTable mount_vtable;
void mount_fd_event(Manager *m, int events);
const char* mount_state_to_string(MountState i);
MountState mount_state_from_string(const char *s);
const char* mount_state_to_string(MountState i) _const_;
MountState mount_state_from_string(const char *s) _pure_;
const char* mount_exec_command_to_string(MountExecCommand i);
MountExecCommand mount_exec_command_from_string(const char *s);
const char* mount_exec_command_to_string(MountExecCommand i) _const_;
MountExecCommand mount_exec_command_from_string(const char *s) _pure_;
const char* mount_result_to_string(MountResult i);
MountResult mount_result_from_string(const char *s);
const char* mount_result_to_string(MountResult i) _const_;
MountResult mount_result_from_string(const char *s) _pure_;
void warn_if_dir_nonempty(const char *unit, const char* where);
......@@ -680,13 +680,13 @@ static int path_deserialize_item(Unit *u, const char *key, const char *value, FD
return 0;
}
static UnitActiveState path_active_state(Unit *u) {
_pure_ static UnitActiveState path_active_state(Unit *u) {
assert(u);
return state_translation_table[PATH(u)->state];
}
static const char *path_sub_state_to_string(Unit *u) {
_pure_ static const char *path_sub_state_to_string(Unit *u) {
assert(u);
return path_state_to_string(PATH(u)->state);
......
......@@ -98,11 +98,11 @@ void path_free_specs(Path *p);
extern const UnitVTable path_vtable;
const char* path_state_to_string(PathState i);
PathState path_state_from_string(const char *s);
const char* path_state_to_string(PathState i) _const_;
PathState path_state_from_string(const char *s) _pure_;
const char* path_type_to_string(PathType i);
PathType path_type_from_string(const char *s);
const char* path_type_to_string(PathType i) _const_;
PathType path_type_from_string(const char *s) _pure_;
const char* path_result_to_string(PathResult i);
PathResult path_result_from_string(const char *s);
const char* path_result_to_string(PathResult i) _const_;
PathResult path_result_from_string(const char *s) _pure_;
......@@ -174,7 +174,7 @@ static int audit_callback(
user_avc's into the /var/log/audit/audit.log, otherwise they will be
sent to syslog.
*/
static int log_callback(int type, const char *fmt, ...) {
_printf_attr_(2, 3) static int log_callback(int type, const char *fmt, ...) {
va_list ap;
va_start(ap, fmt);
......
......@@ -1878,7 +1878,7 @@ static int main_pid_good(Service *s) {
return -EAGAIN;
}
static int control_pid_good(Service *s) {
_pure_ static int control_pid_good(Service *s) {
assert(s);
return s->control_pid > 0;
......@@ -2570,7 +2570,7 @@ static int service_reload(Unit *u) {
return 0;
}
static bool service_can_reload(Unit *u) {
_pure_ static bool service_can_reload(Unit *u) {
Service *s = SERVICE(u);
assert(s);
......@@ -2782,7 +2782,7 @@ static int service_deserialize_item(Unit *u, const char *key, const char *value,
return 0;
}
static UnitActiveState service_active_state(Unit *u) {
_pure_ static UnitActiveState service_active_state(Unit *u) {
const UnitActiveState *table;
assert(u);
......@@ -2818,7 +2818,7 @@ static bool service_check_gc(Unit *u) {
return false;
}
static bool service_check_snapshot(Unit *u) {
_pure_ static bool service_check_snapshot(Unit *u) {
Service *s = SERVICE(u);
assert(s);
......
......@@ -203,23 +203,23 @@ struct Socket;
int service_set_socket_fd(Service *s, int fd, struct Socket *socket);
const char* service_state_to_string(ServiceState i);
ServiceState service_state_from_string(const char *s);
const char* service_state_to_string(ServiceState i) _const_;
ServiceState service_state_from_string(const char *s) _pure_;
const char* service_restart_to_string(ServiceRestart i);
ServiceRestart service_restart_from_string(const char *s);
const char* service_restart_to_string(ServiceRestart i) _const_;
ServiceRestart service_restart_from_string(const char *s) _pure_;
const char* service_type_to_string(ServiceType i);
ServiceType service_type_from_string(const char *s);
const char* service_type_to_string(ServiceType i) _const_;
ServiceType service_type_from_string(const char *s) _pure_;
const char* service_exec_command_to_string(ServiceExecCommand i);
ServiceExecCommand service_exec_command_from_string(const char *s);
const char* service_exec_command_to_string(ServiceExecCommand i) _const_;
ServiceExecCommand service_exec_command_from_string(const char *s) _pure_;
const char* notify_access_to_string(NotifyAccess i);
NotifyAccess notify_access_from_string(const char *s);
const char* notify_access_to_string(NotifyAccess i) _const_;
NotifyAccess notify_access_from_string(const char *s) _pure_;
const char* service_result_to_string(ServiceResult i);
ServiceResult service_result_from_string(const char *s);
const char* service_result_to_string(ServiceResult i) _const_;
ServiceResult service_result_from_string(const char *s) _pure_;
const char* start_limit_action_to_string(StartLimitAction i);
StartLimitAction start_limit_action_from_string(const char *s);
const char* start_limit_action_to_string(StartLimitAction i) _const_;
StartLimitAction start_limit_action_from_string(const char *s) _pure_;
......@@ -173,13 +173,13 @@ static int snapshot_deserialize_item(Unit *u, const char *key, const char *value
return 0;
}
static UnitActiveState snapshot_active_state(Unit *u) {
_pure_ static UnitActiveState snapshot_active_state(Unit *u) {
assert(u);
return state_translation_table[SNAPSHOT(u)->state];
}
static const char *snapshot_sub_state_to_string(Unit *u) {
_pure_ static const char *snapshot_sub_state_to_string(Unit *u) {
assert(u);
return snapshot_state_to_string(SNAPSHOT(u)->state);
......
......@@ -46,5 +46,5 @@ extern const UnitVTable snapshot_vtable;
int snapshot_create(Manager *m, const char *name, bool cleanup, DBusError *e, Snapshot **s);
void snapshot_remove(Snapshot *s);
const char* snapshot_state_to_string(SnapshotState i);
SnapshotState snapshot_state_from_string(const char *s);
const char* snapshot_state_to_string(SnapshotState i) _const_;
SnapshotState snapshot_state_from_string(const char *s) _pure_;
......@@ -344,7 +344,7 @@ static int socket_add_default_dependencies(Socket *s) {
return unit_add_two_dependencies_by_name(UNIT(s), UNIT_BEFORE, UNIT_CONFLICTS, SPECIAL_SHUTDOWN_TARGET, NULL, true);
}
static bool socket_has_exec(Socket *s) {
_pure_ static bool socket_has_exec(Socket *s) {
unsigned i;
assert(s);
......@@ -410,7 +410,7 @@ static int socket_load(Unit *u) {
return socket_verify(s);
}
static const char* listen_lookup(int family, int type) {
_const_ static const char* listen_lookup(int family, int type) {
if (family == AF_NETLINK)
return "ListenNetlink";
......@@ -1957,13 +1957,13 @@ static int socket_distribute_fds(Unit *u, FDSet *fds) {
return 0;
}
static UnitActiveState socket_active_state(Unit *u) {
_pure_ static UnitActiveState socket_active_state(Unit *u) {
assert(u);
return state_translation_table[SOCKET(u)->state];
}
static const char *socket_sub_state_to_string(Unit *u) {
_pure_ static const char *socket_sub_state_to_string(Unit *u) {
assert(u);
return socket_state_to_string(SOCKET(u)->state);
......@@ -1991,7 +1991,7 @@ const char* socket_port_type_to_string(SocketPort *p) {
}
}
static bool socket_check_gc(Unit *u) {
_pure_ static bool socket_check_gc(Unit *u) {
Socket *s = SOCKET(u);
assert(u);
......
......@@ -167,13 +167,13 @@ void socket_free_ports(Socket *s);
extern const UnitVTable socket_vtable;
const char* socket_state_to_string(SocketState i);
SocketState socket_state_from_string(const char *s);
const char* socket_state_to_string(SocketState i) _const_;
SocketState socket_state_from_string(const char *s) _pure_;
const char* socket_exec_command_to_string(SocketExecCommand i);
SocketExecCommand socket_exec_command_from_string(const char *s);
const char* socket_exec_command_to_string(SocketExecCommand i) _const_;
SocketExecCommand socket_exec_command_from_string(const char *s) _pure_;
const char* socket_result_to_string(SocketResult i);
SocketResult socket_result_from_string(const char *s);
const char* socket_result_to_string(SocketResult i) _const_;
SocketResult socket_result_from_string(const char *s) _pure_;
const char* socket_port_type_to_string(SocketPort *p);
const char* socket_port_type_to_string(SocketPort *p) _pure_;
......@@ -899,19 +899,19 @@ static int swap_deserialize_item(Unit *u, const char *key, const char *value, FD
return 0;
}
static UnitActiveState swap_active_state(Unit *u) {
_pure_ static UnitActiveState swap_active_state(Unit *u) {
assert(u);
return state_translation_table[SWAP(u)->state];
}
static const char *swap_sub_state_to_string(Unit *u) {
_pure_ static const char *swap_sub_state_to_string(Unit *u) {
assert(u);
return swap_state_to_string(SWAP(u)->state);
}
static bool swap_check_gc(Unit *u) {
_pure_ static bool swap_check_gc(Unit *u) {
Swap *s = SWAP(u);
assert(s);
......
......@@ -111,11 +111,11 @@ int swap_add_one_mount_link(Swap *s, Mount *m);
int swap_dispatch_reload(Manager *m);
int swap_fd_event(Manager *m, int events);
const char* swap_state_to_string(SwapState i);
SwapState swap_state_from_string(const char *s);
const char* swap_state_to_string(SwapState i) _const_;
SwapState swap_state_from_string(const char *s) _pure_;
const char* swap_exec_command_to_string(SwapExecCommand i);
SwapExecCommand swap_exec_command_from_string(const char *s);
const char* swap_exec_command_to_string(SwapExecCommand i) _const_;
SwapExecCommand swap_exec_command_from_string(const char *s) _pure_;
const char* swap_result_to_string(SwapResult i);
SwapResult swap_result_from_string(const char *s);
const char* swap_result_to_string(SwapResult i) _const_;
SwapResult swap_result_from_string(const char *s) _pure_;
......@@ -184,13 +184,13 @@ static int target_deserialize_item(Unit *u, const char *key, const char *value,
return 0;
}
static UnitActiveState target_active_state(Unit *u) {
_pure_ static UnitActiveState target_active_state(Unit *u) {
assert(u);
return state_translation_table[TARGET(u)->state];
}
static const char *target_sub_state_to_string(Unit *u) {
_pure_ static const char *target_sub_state_to_string(Unit *u) {
assert(u);
return target_state_to_string(TARGET(u)->state);
......
......@@ -40,5 +40,5 @@ struct Target {
extern const UnitVTable target_vtable;
const char* target_state_to_string(TargetState i);
TargetState target_state_from_string(const char *s);
const char* target_state_to_string(TargetState i) _const_;
TargetState target_state_from_string(const char *s) _pure_;
......@@ -464,13 +464,13 @@ static int timer_deserialize_item(Unit *u, const char *key, const char *value, F
return 0;
}
static UnitActiveState timer_active_state(Unit *u) {
_pure_ static UnitActiveState timer_active_state(Unit *u) {
assert(u);
return state_translation_table[TIMER(u)->state];
}
static const char *timer_sub_state_to_string(Unit *u) {
_pure_ static const char *timer_sub_state_to_string(Unit *u) {
assert(u);
return timer_state_to_string(TIMER(u)->state);
......
......@@ -87,11 +87,11 @@ void timer_free_values(Timer *t);
extern const UnitVTable timer_vtable;
const char *timer_state_to_string(TimerState i);
TimerState timer_state_from_string(const char *s);
const char *timer_state_to_string(TimerState i) _const_;
TimerState timer_state_from_string(const char *s) _pure_;
const char *timer_base_to_string(TimerBase i);
TimerBase timer_base_from_string(const char *s);
const char *timer_base_to_string(TimerBase i) _const_;
TimerBase timer_base_from_string(const char *s) _pure_;
const char* timer_result_to_string(TimerResult i);
TimerResult timer_result_from_string(const char *s);
const char* timer_result_to_string(TimerResult i) _const_;
TimerResult timer_result_from_string(const char *s) _pure_;
......@@ -140,7 +140,7 @@ static void transaction_merge_and_delete_job(Transaction *tr, Job *j, Job *other
transaction_delete_job(tr, other, true);
}
static bool job_is_conflicted_by(Job *j) {
_pure_ static bool job_is_conflicted_by(Job *j) {
JobDependency *l;
assert(j);
......@@ -320,7 +320,7 @@ rescan:
}
}
static bool unit_matters_to_anchor(Unit *u, Job *j) {
_pure_ static bool unit_matters_to_anchor(Unit *u, Job *j) {
assert(u);
assert(!j->transaction_prev);
......
......@@ -949,7 +949,7 @@ bool unit_condition_test(Unit *u) {
return u->condition_result;
}
static const char* unit_get_status_message_format(Unit *u, JobType t) {
_pure_ static const char* unit_get_status_message_format(Unit *u, JobType t) {
const UnitStatusMessageFormats *format_table;
assert(u);
......@@ -966,7 +966,7 @@ static const char* unit_get_status_message_format(Unit *u, JobType t) {
return format_table->starting_stopping[t == JOB_STOP];
}
static const char *unit_get_status_message_format_try_harder(Unit *u, JobType t) {
_pure_ static const char *unit_get_status_message_format_try_harder(Unit *u, JobType t) {
const char *format;
assert(u);
......
......@@ -468,13 +468,13 @@ void unit_add_to_gc_queue(Unit *u);
int unit_merge(Unit *u, Unit *other);
int unit_merge_by_name(Unit *u, const char *other);
Unit *unit_follow_merge(Unit *u);
Unit *unit_follow_merge(Unit *u) _pure_;