diff --git a/include/akstdlib.h b/include/akstdlib.h index dca62df..6dd2d6e 100644 --- a/include/akstdlib.h +++ b/include/akstdlib.h @@ -92,10 +92,10 @@ extern "C" { */ #if defined(__GNUC__) || defined(__clang__) /** @brief Mark a printf-style format argument for compile-time checking. */ -#define AKSL_PRINTF_FORMAT(__fmt_index, __first_arg) \ +#define AKSL_PRINTF_FORMAT(__fmt_index, __first_arg) \ __attribute__((format(printf, __fmt_index, __first_arg))) /** @brief Mark a scanf-style format argument for compile-time checking. */ -#define AKSL_SCANF_FORMAT(__fmt_index, __first_arg) \ +#define AKSL_SCANF_FORMAT(__fmt_index, __first_arg) \ __attribute__((format(scanf, __fmt_index, __first_arg))) #else /** @brief No-op where the compiler has no format attribute. */ diff --git a/scripts/reindent.el b/scripts/reindent.el new file mode 100644 index 0000000..d4557f7 --- /dev/null +++ b/scripts/reindent.el @@ -0,0 +1,25 @@ +;; Canonical reindent: Emacs cc-mode "stroustrup", c-basic-offset 4, +;; indent-tabs-mode on, tab-width 8. A correct file is a fixed point of this. +;; +;; inextern-lang is set to 0 because akstdlib.h wraps its whole body in +;; extern "C" { }, and cc-mode otherwise indents every declaration in the file +;; one level for it. That is a real cc-mode behaviour rather than a bug, but it +;; is not the house style and not what the file looked like before. +;; +;; AGENTS.md forbids introducing clang-format, and this is why the tool that +;; decides what "correct" means has to be the same engine the author's editor +;; runs: this offset is not something clang-format could be made to agree with. +(require 'cc-mode) +(setq-default indent-tabs-mode t) +(setq-default tab-width 8) +(setq c-default-style "stroustrup") +(dolist (file command-line-args-left) + (find-file file) + (c-mode) + (setq indent-tabs-mode t + tab-width 8 + c-basic-offset 4) + (c-set-offset 'inextern-lang 0) + (indent-region (point-min) (point-max)) + (when (buffer-modified-p) (save-buffer)) + (kill-buffer)) diff --git a/src/collections.c b/src/collections.c index 2e2ac52..3ffe4c4 100644 --- a/src/collections.c +++ b/src/collections.c @@ -106,8 +106,8 @@ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_insert_after(aksl_ListNode *node, a * the case a caller is most likely to get wrong by hand. */ akerr_ErrorContext AKERR_NOIGNORE *aksl_list_insert_before(aksl_ListNode **head, - aksl_ListNode *node, - aksl_ListNode *obj) + aksl_ListNode *node, + aksl_ListNode *obj) { PREPARE_ERROR(e); FAIL_ZERO_RETURN(e, head, AKERR_NULLPOINTER, "head=%p, node=%p, obj=%p", diff --git a/tests/aksl_capture.h b/tests/aksl_capture.h index 507a041..68e3187 100644 --- a/tests/aksl_capture.h +++ b/tests/aksl_capture.h @@ -231,50 +231,50 @@ static int __attribute__((unused)) aksl_take(akerr_ErrorContext *e) * The context is always released, including on the failure path, so a failing * assertion does not also corrupt the pool-leak checks that follow it. */ -#define AKSL_CHECK_STATUS(__expr, __expected) \ - do { \ - int __st = aksl_take(__expr); \ - if ( __st != (__expected) ) { \ - fprintf(stderr, \ - " CHECK FAILED: %s\n" \ - " got %d (%s) \"%s\"\n" \ - " expected %d (%s)\n" \ - " at %s:%d\n", \ - #__expr, \ - __st, akerr_name_for_status(__st, NULL), \ - aksl_last_message, \ - (__expected), \ - akerr_name_for_status((__expected), NULL), \ - __FILE__, __LINE__); \ - return 1; \ - } \ +#define AKSL_CHECK_STATUS(__expr, __expected) \ + do { \ + int __st = aksl_take(__expr); \ + if ( __st != (__expected) ) { \ + fprintf(stderr, \ + " CHECK FAILED: %s\n" \ + " got %d (%s) \"%s\"\n" \ + " expected %d (%s)\n" \ + " at %s:%d\n", \ + #__expr, \ + __st, akerr_name_for_status(__st, NULL), \ + aksl_last_message, \ + (__expected), \ + akerr_name_for_status((__expected), NULL), \ + __FILE__, __LINE__); \ + return 1; \ + } \ } while ( 0 ) /* * Success is represented by a NULL error context, not just status 0. This catches * wrappers that incorrectly raise an error using a stale errno value of 0. */ -#define AKSL_CHECK_OK(__expr) \ - do { \ - akerr_ErrorContext *__e = (__expr); \ - if ( __e != NULL ) { \ - int __st = aksl_take(__e); \ - fprintf(stderr, \ - " CHECK FAILED: %s\n" \ +#define AKSL_CHECK_OK(__expr) \ + do { \ + akerr_ErrorContext *__e = (__expr); \ + if ( __e != NULL ) { \ + int __st = aksl_take(__e); \ + fprintf(stderr, \ + " CHECK FAILED: %s\n" \ " returned error context with status %d (%s) \"%s\"\n" \ - " expected no error context\n" \ - " at %s:%d\n", \ - #__expr, \ - __st, akerr_name_for_status(__st, NULL), \ - aksl_last_message, \ - __FILE__, __LINE__); \ - return 1; \ - } \ - aksl_last_status = 0; \ - aksl_last_message[0] = '\0'; \ - aksl_last_function[0] = '\0'; \ - aksl_last_file[0] = '\0'; \ - aksl_last_line = 0; \ + " expected no error context\n" \ + " at %s:%d\n", \ + #__expr, \ + __st, akerr_name_for_status(__st, NULL), \ + aksl_last_message, \ + __FILE__, __LINE__); \ + return 1; \ + } \ + aksl_last_status = 0; \ + aksl_last_message[0] = '\0'; \ + aksl_last_function[0] = '\0'; \ + aksl_last_file[0] = '\0'; \ + aksl_last_line = 0; \ } while ( 0 ) #define AKSL_CHECK_CONTAINS(needle) \ @@ -287,37 +287,37 @@ static int __attribute__((unused)) aksl_take(akerr_ErrorContext *e) * Message checks are secondary: the returned akerr status is the contract. Keep * the status and message assertions coupled so tests cannot pass on text alone. */ -#define AKSL_CHECK_STATUS_MSG_CONTAINS(__expr, __expected, __needle) \ - do { \ - int __st = aksl_take(__expr); \ - if ( __st != (__expected) ) { \ - fprintf(stderr, \ - " CHECK FAILED: %s\n" \ - " got %d (%s) \"%s\"\n" \ - " expected %d (%s)\n" \ - " at %s:%d\n", \ - #__expr, \ - __st, akerr_name_for_status(__st, NULL), \ - aksl_last_message, \ - (__expected), \ - akerr_name_for_status((__expected), NULL), \ - __FILE__, __LINE__); \ - return 1; \ - } \ - if ( strstr(aksl_last_message, (__needle)) == NULL ) { \ - fprintf(stderr, \ - " CHECK FAILED: message from %s\n" \ - " got \"%s\"\n" \ - " expected substring \"%s\"\n" \ - " status %d (%s)\n" \ - " at %s:%d\n", \ - #__expr, \ - aksl_last_message, \ - (__needle), \ - __st, akerr_name_for_status(__st, NULL), \ - __FILE__, __LINE__); \ - return 1; \ - } \ +#define AKSL_CHECK_STATUS_MSG_CONTAINS(__expr, __expected, __needle) \ + do { \ + int __st = aksl_take(__expr); \ + if ( __st != (__expected) ) { \ + fprintf(stderr, \ + " CHECK FAILED: %s\n" \ + " got %d (%s) \"%s\"\n" \ + " expected %d (%s)\n" \ + " at %s:%d\n", \ + #__expr, \ + __st, akerr_name_for_status(__st, NULL), \ + aksl_last_message, \ + (__expected), \ + akerr_name_for_status((__expected), NULL), \ + __FILE__, __LINE__); \ + return 1; \ + } \ + if ( strstr(aksl_last_message, (__needle)) == NULL ) { \ + fprintf(stderr, \ + " CHECK FAILED: message from %s\n" \ + " got \"%s\"\n" \ + " expected substring \"%s\"\n" \ + " status %d (%s)\n" \ + " at %s:%d\n", \ + #__expr, \ + aksl_last_message, \ + (__needle), \ + __st, akerr_name_for_status(__st, NULL), \ + __FILE__, __LINE__); \ + return 1; \ + } \ } while ( 0 ) /* ---------------------------------------------------------------------- */ @@ -329,22 +329,22 @@ static int __attribute__((unused)) aksl_take(akerr_ErrorContext *e) * test left the error pool as it found it -- a wrapper that fails to release a * context is a bug in the library, not just in the test. */ -#define AKSL_RUN(__failures, __fn) \ - do { \ - int __before = aksl_slots_in_use(); \ - int __r = __fn(); \ - int __after = aksl_slots_in_use(); \ - if ( __r != 0 ) { \ - fprintf(stderr, "FAIL %s\n", #__fn); \ - (__failures)++; \ - } else if ( __after != __before ) { \ - fprintf(stderr, \ - "FAIL %s (leaked %d error pool slot(s))\n", \ - #__fn, __after - __before); \ - (__failures)++; \ - } else { \ - fprintf(stderr, "ok %s\n", #__fn); \ - } \ +#define AKSL_RUN(__failures, __fn) \ + do { \ + int __before = aksl_slots_in_use(); \ + int __r = __fn(); \ + int __after = aksl_slots_in_use(); \ + if ( __r != 0 ) { \ + fprintf(stderr, "FAIL %s\n", #__fn); \ + (__failures)++; \ + } else if ( __after != __before ) { \ + fprintf(stderr, \ + "FAIL %s (leaked %d error pool slot(s))\n", \ + #__fn, __after - __before); \ + (__failures)++; \ + } else { \ + fprintf(stderr, "ok %s\n", #__fn); \ + } \ } while ( 0 ) #define AKSL_REPORT(__failures) \