slap restrict (almost) everywhere
This commit is contained in:
parent
4da0422c5a
commit
d2cd52b971
@ -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 <ds/fmt.h>;
|
||||
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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
10
src/ds/fmt.c
10
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);
|
||||
|
Loading…
Reference in New Issue
Block a user