From d2cd52b97168df5a9a55e49f2a5794b08df23d79 Mon Sep 17 00:00:00 2001 From: r4 Date: Sun, 29 May 2022 21:04:42 +0200 Subject: [PATCH] slap restrict (almost) everywhere --- include/ds/error.h | 6 +++--- include/ds/generic/map.h | 4 ++-- include/ds/generic/smap.h | 4 ++-- src/ds/error.c | 4 ++-- src/ds/fmt.c | 10 +++++----- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/include/ds/error.h b/include/ds/error.h index 94e61db..fb91136 100644 --- a/include/ds/error.h +++ b/include/ds/error.h @@ -80,7 +80,7 @@ typedef struct Error { /* Returns true if the given error structure actually contains a real error. */ static inline bool error_is(Error e) { return e.kind != ErrorNone; } /* Same as error_is but takes a pointer and does NULL checking. */ -static inline bool error_ptr_is(Error *e) { return e != NULL && e->kind != ErrorNone; } +static inline bool error_ptr_is(Error *restrict e) { return e != NULL && e->kind != ErrorNone; } /* Call this at the beginning of any program that makes use of any of the more * advanced error features (those which involve heap allocation). */ @@ -92,9 +92,9 @@ void error_term(); #include ; fmt("%{Error:destroy}", err); */ -size_t error_to_string(char *buf, size_t size, Error e, bool destroy); +size_t error_to_string(char *restrict buf, size_t size, Error e, bool destroy); Error *_error_heapify(Error e); -Error _error_hereify(const char *file, size_t line, Error e); +Error _error_hereify(const char *restrict file, size_t line, Error e); #endif diff --git a/include/ds/generic/map.h b/include/ds/generic/map.h index e6761dc..db53196 100644 --- a/include/ds/generic/map.h +++ b/include/ds/generic/map.h @@ -52,7 +52,7 @@ FUNCDECL(VTYPE *, _get)(NAME m, KTYPE key); FUNCDECL(Error, _set)(NAME *m, KTYPE key, VTYPE val); FUNCDECL(bool, _del)(NAME m, KTYPE key); FUNCDECL(Error, _rehash)(NAME *m, size_t new_minimum_cap); -FUNCDECL(bool, _it_next)(NAME m, ITEM_TYPE **it); +FUNCDECL(bool, _it_next)(NAME m, ITEM_TYPE **restrict it); #ifdef GENERIC_IMPL VARDEF(const char *, __val_fmt) = NULL; @@ -199,7 +199,7 @@ FUNCDEF(Error, _rehash)(NAME *m, size_t new_minimum_cap) { return OK(); } -FUNCDEF(bool, _it_next)(NAME m, ITEM_TYPE **it) { +FUNCDEF(bool, _it_next)(NAME m, ITEM_TYPE **restrict it) { *it == NULL ? *it = m.data : (*it)++; while (*it < m.data + m.cap && (*it)->state != OCCUPIED) { (*it)++; } return *it < m.data + m.cap; diff --git a/include/ds/generic/smap.h b/include/ds/generic/smap.h index 227704f..cc07ca7 100644 --- a/include/ds/generic/smap.h +++ b/include/ds/generic/smap.h @@ -46,7 +46,7 @@ FUNCDECL(TYPE *, _get)(NAME m, const char *key); FUNCDECL(Error, _set)(NAME *m, const char *key, TYPE val); FUNCDECL(bool, _del)(NAME m, const char *key); FUNCDECL(Error, _rehash)(NAME *m, size_t new_minimum_cap); -FUNCDECL(bool, _it_next)(NAME m, ITEM_TYPE **it); +FUNCDECL(bool, _it_next)(NAME m, ITEM_TYPE **restrict it); #ifdef GENERIC_IMPL VARDEF(const char *, __val_fmt) = NULL; @@ -198,7 +198,7 @@ FUNCDEF(Error, _rehash)(NAME *m, size_t new_minimum_cap) { return OK(); } -FUNCDEF(bool, _it_next)(NAME m, ITEM_TYPE **it) { +FUNCDEF(bool, _it_next)(NAME m, ITEM_TYPE **restrict it) { *it == NULL ? *it = m.data : (*it)++; while (*it < m.data + m.cap && (!(*it)->key || (*it)->key == TOMBSTONE)) { (*it)++; } return *it < m.data + m.cap; diff --git a/src/ds/error.c b/src/ds/error.c index a6112ec..f2307ee 100644 --- a/src/ds/error.c +++ b/src/ds/error.c @@ -18,7 +18,7 @@ void error_term() { free(error_reserved_for_error); } -size_t error_to_string(char *buf, size_t size, Error e, bool destroy) { +size_t error_to_string(char *restrict buf, size_t size, Error e, bool destroy) { size_t written = 0; if (e.has_location) { written += snprintf(buf + written, sub_clamped(size, written), "%s:%zu: ", e.file, e.line); @@ -66,7 +66,7 @@ Error *_error_heapify(Error e) { return res; } -Error _error_hereify(const char *file, size_t line, Error e) { +Error _error_hereify(const char *restrict file, size_t line, Error e) { e.has_location = true; e.file = file; e.line = line; diff --git a/src/ds/fmt.c b/src/ds/fmt.c index f63ae4e..2d3ca4d 100644 --- a/src/ds/fmt.c +++ b/src/ds/fmt.c @@ -272,7 +272,7 @@ static void _fmts_putc_func(FmtContext *restrict ctx, char c) { /********************************\ |* The guts of any fmt function *| \********************************/ -static Error _fmt_main(bool use_err_location, const char *file, size_t line, FmtContext *ctx, const char *restrict format, va_list args) { +static Error _fmt_main(bool use_err_location, const char *restrict file, size_t line, FmtContext *restrict ctx, const char *restrict format, va_list args) { if (!initialized) { const char *err_str = "fmt: fmt_init() must be called at the beginning of the program before using any other fmt functions, and fmt_term() must be called when done\n"; return use_err_location ? ERROR_STRING_LOCATION(file, line, err_str) : ERROR_STRING(err_str); @@ -506,7 +506,7 @@ void fmt_register(const char *restrict keyword, FmtPrintFunc print_func) { _print_func_map_set(&_print_funcs, keyword, print_func); } -void _fmtv(const char *file, size_t line, const char *restrict format, va_list args) { +void _fmtv(const char *restrict file, size_t line, const char *restrict format, va_list args) { FmtContext ctx = { .ctx_data = stdout, .putc_func = _fmtf_putc_func, @@ -514,7 +514,7 @@ void _fmtv(const char *file, size_t line, const char *restrict format, va_list a _fmtcv(file, line, &ctx, format, args); } -void _fmt(const char *file, size_t line, const char *restrict format, ...) { +void _fmt(const char *restrict file, size_t line, const char *restrict format, ...) { va_list args; va_start(args, format); _fmtv(file, line, format, args); @@ -544,11 +544,11 @@ size_t _fmts(const char *restrict file, size_t line, char *restrict buf, size_t return res; } -void _fmtcv(const char *restrict file, size_t line, FmtContext *ctx, const char *restrict format, va_list args) { +void _fmtcv(const char *restrict file, size_t line, FmtContext *restrict ctx, const char *restrict format, va_list args) { ERROR_ASSERT(_fmt_main(true, file, line, ctx, format, args)); } -void _fmtc(const char *restrict file, size_t line, FmtContext *ctx, const char *restrict format, ...) { +void _fmtc(const char *restrict file, size_t line, FmtContext *restrict ctx, const char *restrict format, ...) { va_list args; va_start(args, format); _fmtcv(file, line, ctx, format, args);