diff --git a/.cirrus.yml b/.cirrus.yml index 62fd6488..55447c1d 100644 --- a/.cirrus.yml +++ b/.cirrus.yml @@ -12,7 +12,7 @@ main_freebsd_task: - pip install --user Jinja2 PyYAML main_build_script: - ./autogen.sh - - ./configure --enable-debug --enable-fixtures --enable-checks-all CFLAGS='-O3' + - ./configure --enable-fixtures --enable-checks-all CFLAGS='-O3' - make - sudo make install main_test_script: @@ -32,7 +32,7 @@ mruby_freebsd_task: - unzip mruby-3.1.0.zip main_build_script: - ./autogen.sh - - ./configure --enable-debug CFLAGS='-O3' + - ./configure CFLAGS='-O3' - make - sudo make install mruby_test_script: @@ -56,7 +56,7 @@ ruby_freebsd_task: - sudo make install main_build_script: - ./autogen.sh - - ./configure --enable-debug CFLAGS='-O3' + - ./configure CFLAGS='-O3' - make - sudo make install ruby_build_script: @@ -78,7 +78,7 @@ rust_freebsd_task: - curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y main_build_script: - ./autogen.sh - - ./configure --enable-debug CFLAGS='-O3' + - ./configure CFLAGS='-O3' - make - sudo make install rust_test_script: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9e4175b2..7c301771 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,7 +24,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - debug: ['--disable-debug', '--enable-debug'] + assert: ['--disable-assert', '--enable-assert'] cc: ['gcc', 'clang', 'tcc'] opt: ['', '-O0', '-O3'] steps: @@ -34,7 +34,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure ${{matrix.debug}} --enable-fixtures --enable-checks --enable-checks-pthreads --enable-checks-python CC='${{matrix.cc}}' CFLAGS='${{matrix.opt}}' + run: ./configure ${{matrix.assert}} --enable-fixtures --enable-checks --enable-checks-pthreads --enable-checks-python CC='${{matrix.cc}}' CFLAGS='${{matrix.opt}}' - name: make run: make - name: check @@ -99,7 +99,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure --enable-debug --enable-checks --enable-checks-pthreads --enable-checks-python --without-${{matrix.packages.without}} ${{matrix.packages.dependencies}} + run: ./configure --enable-checks --enable-checks-pthreads --enable-checks-python --without-${{matrix.packages.without}} ${{matrix.packages.dependencies}} - name: make run: make - name: check @@ -111,7 +111,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - debug: ['--disable-debug', '--enable-debug'] + assert: ['--disable-assert', '--enable-assert'] steps: - uses: actions/checkout@v2 - name: apt update @@ -121,7 +121,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure --host='i386-elf' ${{matrix.debug}} --enable-freestanding --with-libc CC="$(which i686-linux-gnu-gcc)" + run: ./configure --host='i386-elf' ${{matrix.assert}} --enable-freestanding --with-libc CC="$(which i686-linux-gnu-gcc)" - name: make run: make @@ -138,7 +138,7 @@ jobs: - name: extract run: tar -xzf "libkernaux-$(cat VERSION).tar.gz" - name: configure - run: cd "libkernaux-$(cat VERSION)" && ./configure --enable-debug --enable-checks --enable-checks-pthreads --enable-checks-python + run: cd "libkernaux-$(cat VERSION)" && ./configure --enable-checks --enable-checks-pthreads --enable-checks-python - name: make run: cd "libkernaux-$(cat VERSION)" && make - name: check diff --git a/.github/workflows/mruby.yml b/.github/workflows/mruby.yml index afd12f76..5519483e 100644 --- a/.github/workflows/mruby.yml +++ b/.github/workflows/mruby.yml @@ -13,7 +13,7 @@ jobs: MRUBY_YAML_USE_SYSTEM_LIBRARY: x strategy: matrix: - debug: ['--disable-debug', '--enable-debug'] + assert: ['--disable-assert', '--enable-assert'] packages: - configure: '' - configure: '--without-all' @@ -30,7 +30,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure ${{matrix.debug}} ${{matrix.packages.configure}} CFLAGS='-O3' + run: ./configure ${{matrix.assert}} ${{matrix.packages.configure}} CFLAGS='-O3' - name: make run: make - name: install diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index d5a2ca6d..d6336254 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - debug: ['--disable-debug', '--enable-debug'] + assert: ['--disable-assert', '--enable-assert'] packages: - configure: '' - configure: '--without-all' @@ -28,7 +28,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure ${{matrix.debug}} ${{matrix.packages.configure}} CFLAGS='-O3' + run: ./configure ${{matrix.assert}} ${{matrix.packages.configure}} CFLAGS='-O3' - name: make run: make - name: install diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 875ba189..63dd9e16 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - debug: ['--disable-debug', '--enable-debug'] + assert: ['--disable-assert', '--enable-assert'] packages: - configure: '' - configure: '--without-all' @@ -27,7 +27,7 @@ jobs: - name: autogen run: ./autogen.sh - name: configure - run: ./configure ${{matrix.debug}} ${{matrix.packages.configure}} CFLAGS='-O3' + run: ./configure ${{matrix.assert}} ${{matrix.packages.configure}} CFLAGS='-O3' - name: make run: make - name: install diff --git a/.openbsd.yml b/.openbsd.yml index e5838687..593ce5fc 100644 --- a/.openbsd.yml +++ b/.openbsd.yml @@ -31,7 +31,7 @@ tasks: - build: | cd libkernaux ./autogen.sh - ./configure --enable-debug --enable-fixtures --enable-checks-all CFLAGS='-O3' + ./configure --enable-fixtures --enable-checks-all CFLAGS='-O3' make doas make install - test: | diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 5b038900..9a26086e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,6 +25,13 @@ The following statements are recommendations, but highly encouraged: * Write tests * Keep lines less than 80 characters long for better experience on split screen +### Things to review periodically + +* `git grep -i fixme` +* `git grep -i todo` +* `git grep -i cppcheck-suppress` +* `git grep -i rubocop:disable` + ### Programming mistakes * Always check documentation, manuals and specifications @@ -62,13 +69,6 @@ Avoid stupid errors with: * Default case in switch statements * Braces (curly brackets) around code blocks -### Things to review periodically - -* `git grep -i fixme` -* `git grep -i todo` -* `git grep -i cppcheck-suppress` -* `git grep -i rubocop:disable` - C language diff --git a/ChangeLog b/ChangeLog index 84faee21..debee2ba 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2022-12-21 Alex Kotov + + * configure.ac: Rename feature "--(enable|disable)-debug" to + "--(enable|disable)-assert" + * include/: Definition "KERNAUX_DEBUG" has been removed + * include/kernaux/runtime.h: New header + * include/kernaux/assert.h: Removed header + 2022-12-19 Alex Kotov * src/multiboot2/*_print.c: Print Multiboot 2 ELF section headers diff --git a/Makefile.am b/Makefile.am index de9909f1..6cea67f1 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2,7 +2,7 @@ include $(top_srcdir)/make/shared.am include $(top_srcdir)/make/checks.am ACLOCAL_AMFLAGS = -I m4 -EXTRA_DIST = autogen.sh CONTRIBUTING.md sha256sums.txt +EXTRA_DIST = autogen.sh CONTRIBUTING.md sha256sums.txt src/assert.h SUBDIRS = include @@ -35,10 +35,10 @@ lib_LTLIBRARIES = libkernaux.la libkernaux_la_LDFLAGS = -version-info @PACKAGE_VERSION_SO@ libkernaux_la_LIBADD = libkernaux_la_SOURCES = \ - src/assert.c \ src/generic/display.c \ src/generic/malloc.c \ - src/generic/mutex.c + src/generic/mutex.c \ + src/runtime.c ######## # libc # diff --git a/README.md b/README.md index 833b7618..2eceab87 100644 --- a/README.md +++ b/README.md @@ -40,15 +40,13 @@ zero). Work-in-progress APIs can change at any time. * Basic features * [Feature macros](/include/kernaux/version.h.in) (*work in progress*) + * [Runtime environment](/include/kernaux/runtime.h) (*non-breaking since* **?.?.?**) * [Macros](/include/kernaux/macro.h) (*non-breaking since* **0.6.0**) * [Example: packing](/examples/macro_packing.c) * [Example: CAST\_\*](/examples/macro_cast.c); * [Example: CONTAINER\_OF](/examples/macro_container_of.c) * [Example: BITS](/examples/macro_bits.c) * [Example: STATIC\_TEST\*](/examples/macro_static_test.c) - * [Assertions](/include/kernaux/assert.h) (*non-breaking since* **0.4.0**) - * [Example: Assert](/examples/assert.c) - * [Example: Panic](/examples/panic.c) * Stack trace *(planned)* * Generic types * [Display](/include/kernaux/generic/display.h) (*non-breaking since* **?.?.?**) @@ -100,7 +98,6 @@ zero). Work-in-progress APIs can change at any time. `#define` the following C preprocessor macros before including `` and `` files. They have effect on your code, not the library code. -* `KERNAUX_DEBUG` - enable assertions. * `KERNAUX_ACCESS_PRIVATE` - disable access modifier "private". Don't do this! * `KERNAUX_ACCESS_PROTECTED` - disable access modifier "protected". Only do this in a file where you implement an inherited type. @@ -110,12 +107,12 @@ zero). Work-in-progress APIs can change at any time. ### Global variables ```c -// in +// in void (*kernaux_assert_cb)(const char *file, int line, const char *msg) ``` Assertion callback. It's better to always set it to some function which always -interrupts the execution, even when debugging is disabled. It may for example +interrupts the execution, even when assertions are disabled. It may for example call `abort()` in hosted environment, raise an exception in Ruby, panic in Rust or power off the machine in freestanding environment. It may also log the error location and message. @@ -153,7 +150,7 @@ stable options. #### Features -* `--(enable|disable)-debug` - debugging +* `--(enable|disable)-assert` - assertions * `--(enable|disable)-float` - floating-point arithmetic * `--(enable|disable)-werror` - fail on warning (`CFLAGS+='-Werror'`) diff --git a/configure.ac b/configure.ac index 6b632b05..79e230a2 100644 --- a/configure.ac +++ b/configure.ac @@ -22,7 +22,7 @@ AC_CANONICAL_HOST AC_CONFIG_MACRO_DIRS([m4]) AC_CONFIG_HEADERS([config.h]) -AC_CONFIG_SRCDIR([src/assert.c]) +AC_CONFIG_SRCDIR([src/runtime.c]) AC_CONFIG_FILES([ Makefile examples/Makefile @@ -48,7 +48,7 @@ AC_SUBST([PACKAGE_VERSION_SO], m4_normalize(m4_include([VERSION_SO]))) ############### dnl Features (enabled by default) -AC_ARG_ENABLE([debug], AS_HELP_STRING([--disable-debug], [disable debugging])) +AC_ARG_ENABLE([assert], AS_HELP_STRING([--disable-assert], [disable assertions])) AC_ARG_ENABLE([float], AS_HELP_STRING([--disable-float], [disable floating-point arithmetic])) AC_ARG_ENABLE([werror], AS_HELP_STRING([--disable-werror], [disable -Werror])) @@ -134,7 +134,7 @@ AS_IF([test "$with_all" = no], do_without_all) ################## dnl Features (enabled by default) -AS_IF([test "$enable_debug" = no ], [enable_debug=no], [enable_debug=yes]) +AS_IF([test "$enable_assert" = no ], [enable_assert=no], [enable_assert=yes]) AS_IF([test "$enable_float" = no ], [enable_float=no], [enable_float=yes]) AS_IF([test "$enable_werror" = no ], [enable_werror=no], [enable_werror=yes]) @@ -200,7 +200,7 @@ dnl Architecture (additional) AM_CONDITIONAL([ASM_X86], [test "$host_cpu" = i386 -o "$host_cpu" = x86_64]) dnl Features (enabled by default) -AM_CONDITIONAL([ENABLE_DEBUG], [test "$enable_debug" = yes]) +AM_CONDITIONAL([ENABLE_ASSERT], [test "$enable_assert" = yes]) AM_CONDITIONAL([ENABLE_FLOAT], [test "$enable_float" = yes]) AM_CONDITIONAL([ENABLE_WERROR], [test "$enable_werror" = yes]) @@ -252,7 +252,7 @@ AS_IF([test "$host_cpu" = i386], [AC_DEFINE([ASM_X86], AS_IF([test "$host_cpu" = x86_64], [AC_DEFINE([ASM_X86], [1], [architecture is x86])]) dnl Features (enabled by default) -AS_IF([test "$enable_debug" = yes], [AC_DEFINE([ENABLE_DEBUG], [1], [enabled debugging])]) +AS_IF([test "$enable_assert" = yes], [AC_DEFINE([ENABLE_ASSERT], [1], [enabled assertions])]) AS_IF([test "$enable_float" = yes], [AC_DEFINE([ENABLE_FLOAT], [1], [enabled floating-point arithmetic])]) AS_IF([test "$enable_werror" = yes], [AC_DEFINE([ENABLE_WERROR], [1], [enabled -Werror])]) @@ -289,9 +289,6 @@ dnl Packages (virtual) AS_IF([test "$with_arch_i386" = yes], [AC_DEFINE([WITH_ARCH_X86], [1], [with architecture x86])]) AS_IF([test "$with_arch_x86_64" = yes], [AC_DEFINE([WITH_ARCH_X86], [1], [with architecture x86])]) -dnl Additional -AS_IF([test "$enable_debug" = yes], [AC_DEFINE([KERNAUX_DEBUG], [1], [enabled debugging])]) - ########################## diff --git a/examples/.gitignore b/examples/.gitignore index 61817aee..fea0c55c 100644 --- a/examples/.gitignore +++ b/examples/.gitignore @@ -1,4 +1,3 @@ -/assert /cmdline /generic_display /generic_malloc @@ -11,7 +10,6 @@ /memmap /multiboot2_header_macro /ntoa -/panic /pfa /printf_file /printf_file_va diff --git a/examples/Makefile.am b/examples/Makefile.am index 29e32d4c..76411d5c 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -3,14 +3,6 @@ include $(top_srcdir)/make/shared.am TESTS = noinst_PROGRAMS = $(TESTS) -########## -# assert # -########## - -TESTS += assert -assert_LDADD = $(top_builddir)/libkernaux.la -assert_SOURCES = assert.c - ########### # cmdline # ########### @@ -117,14 +109,6 @@ ntoa_LDADD = $(top_builddir)/libkernaux.la ntoa_SOURCES = main.c ntoa.c endif -######### -# panic # -######### - -TESTS += panic -panic_LDADD = $(top_builddir)/libkernaux.la -panic_SOURCES = panic.c - ####### # pfa # ####### diff --git a/examples/assert.c b/examples/assert.c deleted file mode 100644 index d9cdaf39..00000000 --- a/examples/assert.c +++ /dev/null @@ -1,53 +0,0 @@ -#define KERNAUX_DEBUG -#include - -#include -#include -#include - -static unsigned int count = 0; -static const char *last_file = NULL; -static int last_line = 0; -static const char *last_str = NULL; - -static void assert_cb( - const char *const file, - const int line, - const char *const str -) { - ++count; - last_file = file; - last_line = line; - last_str = str; -} - -int main() -{ - kernaux_assert_cb = assert_cb; - - // cppcheck-suppress duplicateExpression - KERNAUX_ASSERT(1 == 1); - - assert(count == 0); - assert(last_file == NULL); - assert(last_line == 0); - assert(last_str == NULL); - - // cppcheck-suppress duplicateExpression - KERNAUX_ASSERT(1 != 1); - - assert(count == 1); - assert(strcmp(last_file, __FILE__) == 0); - assert(last_line == __LINE__ - 4); - assert(strcmp(last_str, "1 != 1") == 0); - - // cppcheck-suppress staticStringCompare - KERNAUX_ASSERT(strcmp("qwe", "rty") == 0); - - assert(count == 2); - assert(strcmp(last_file, __FILE__) == 0); - assert(last_line == __LINE__ - 4); - assert(strcmp(last_str, "strcmp(\"qwe\", \"rty\") == 0") == 0); - - return 0; -} diff --git a/examples/main.c b/examples/main.c index f89d4a14..50eed31f 100644 --- a/examples/main.c +++ b/examples/main.c @@ -2,7 +2,7 @@ #include "config.h" #endif -#include +#include #include #include diff --git a/examples/panic.c b/examples/panic.c deleted file mode 100644 index 375e7992..00000000 --- a/examples/panic.c +++ /dev/null @@ -1,48 +0,0 @@ -#define KERNAUX_DEBUG -#include - -#include -#include -#include - -static unsigned int count = 0; -static const char *last_file = NULL; -static int last_line = 0; -static const char *last_str = NULL; - -static void assert_cb( - const char *const file, - const int line, - const char *const str -) { - ++count; - last_file = file; - last_line = line; - last_str = str; -} - -int main() -{ - KERNAUX_PANIC("foo"); - - assert(count == 0); - assert(last_file == NULL); - assert(last_line == 0); - assert(last_str == NULL); - - kernaux_assert_cb = assert_cb; - - KERNAUX_PANIC("bar"); - - assert(count == 1); - assert(strcmp(last_file, __FILE__) == 0); - assert(last_line == __LINE__ - 4); - assert(strcmp(last_str, "bar") == 0); - - KERNAUX_PANIC("car"); - - assert(count == 2); - assert(strcmp(last_file, __FILE__) == 0); - assert(last_line == __LINE__ - 4); - assert(strcmp(last_str, "car") == 0); -} diff --git a/fixtures/multiboot2_bin_examples_gen.c.in b/fixtures/multiboot2_bin_examples_gen.c.in index 668906a8..5f7feabb 100644 --- a/fixtures/multiboot2_bin_examples_gen.c.in +++ b/fixtures/multiboot2_bin_examples_gen.c.in @@ -2,7 +2,7 @@ #include "config.h" #endif -#include +#include #include #include diff --git a/include/Makefile.am b/include/Makefile.am index f58d01df..9a4f2dae 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -9,7 +9,6 @@ nobase_include_HEADERS = \ kernaux/asm/riscv64.h \ kernaux/asm/x86_64.h \ kernaux/asm/x86.h \ - kernaux/assert.h \ kernaux/cmdline.h \ kernaux/elf.h \ kernaux/free_list.h \ @@ -35,5 +34,6 @@ nobase_include_HEADERS = \ kernaux/pfa.h \ kernaux/printf.h \ kernaux/printf_fmt.h \ + kernaux/runtime.h \ kernaux/units.h \ kernaux/version.h diff --git a/include/kernaux.h b/include/kernaux.h index 38ae77a0..7d3888d5 100644 --- a/include/kernaux.h +++ b/include/kernaux.h @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -21,5 +20,6 @@ #include #include #include +#include #include #include diff --git a/include/kernaux/runtime.h b/include/kernaux/runtime.h new file mode 100644 index 00000000..20ac4cf2 --- /dev/null +++ b/include/kernaux/runtime.h @@ -0,0 +1,18 @@ +#ifndef KERNAUX_INCLUDED_RUNTIME +#define KERNAUX_INCLUDED_RUNTIME + +#ifdef __cplusplus +extern "C" { +#endif + +typedef void (*KernAux_Assert_Cb)(const char *file, int line, const char *msg); + +extern KernAux_Assert_Cb kernaux_assert_cb; + +void kernaux_assert_do(const char *file, int line, const char *msg); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/arch/i386/idt.c b/src/arch/i386/idt.c index 1a7d848b..d604c154 100644 --- a/src/arch/i386/idt.c +++ b/src/arch/i386/idt.c @@ -2,8 +2,9 @@ #include "config.h" #endif +#include "../../assert.h" + #include -#include #include @@ -15,7 +16,7 @@ void KernAux_Arch_I386_IDTE_init_intr( const uint16_t cs_selector, const uint8_t dpl ) { - KERNAUX_ASSERT(idte); + KERNAUX_NOTNULL(idte); memset(idte, 0, sizeof(*idte)); KernAux_Arch_I386_IDTE_set_offset(idte, offset); @@ -28,7 +29,7 @@ void KernAux_Arch_I386_IDTE_init_task( const uint16_t tss_selector, const uint8_t dpl ) { - KERNAUX_ASSERT(idte); + KERNAUX_NOTNULL(idte); memset(idte, 0, sizeof(*idte)); idte->selector = tss_selector; @@ -41,7 +42,7 @@ void KernAux_Arch_I386_IDTE_init_trap( const uint16_t cs_selector, const uint8_t dpl ) { - KERNAUX_ASSERT(idte); + KERNAUX_NOTNULL(idte); memset(idte, 0, sizeof(*idte)); KernAux_Arch_I386_IDTE_set_offset(idte, offset); @@ -51,14 +52,14 @@ void KernAux_Arch_I386_IDTE_init_trap( uint32_t KernAux_Arch_I386_IDTE_offset(const KernAux_Arch_I386_IDTE idte) { - KERNAUX_ASSERT(idte); + KERNAUX_NOTNULL(idte); return (idte->offset_high << 16) | idte->offset_low; } uint8_t KernAux_Arch_I386_IDTE_dpl(const KernAux_Arch_I386_IDTE idte) { - KERNAUX_ASSERT(idte); + KERNAUX_NOTNULL(idte); return 3 & (idte->flags >> 5); } @@ -67,7 +68,7 @@ void KernAux_Arch_I386_IDTE_set_offset( const KernAux_Arch_I386_IDTE idte, const uint32_t offset ) { - KERNAUX_ASSERT(idte); + KERNAUX_NOTNULL(idte); idte->offset_low = 0xffffu & offset; idte->offset_high = 0xffffu & (offset >> 16); diff --git a/include/kernaux/assert.h b/src/assert.h similarity index 56% rename from include/kernaux/assert.h rename to src/assert.h index 09e01720..b9816b45 100644 --- a/include/kernaux/assert.h +++ b/src/assert.h @@ -1,11 +1,9 @@ #ifndef KERNAUX_INCLUDED_ASSERT #define KERNAUX_INCLUDED_ASSERT -#ifdef __cplusplus -extern "C" { -#endif +#include -#ifdef KERNAUX_DEBUG +#ifdef ENABLE_ASSERT #define KERNAUX_PANIC(msg) (kernaux_assert_do(__FILE__, __LINE__, msg)) #define KERNAUX_ASSERT(cond) ((cond) ? (void)0 : KERNAUX_PANIC(#cond)) #else @@ -13,12 +11,6 @@ extern "C" { #define KERNAUX_ASSERT(cond) ((void)0) #endif -void kernaux_assert_do(const char *file, int line, const char *msg); - -extern void (*kernaux_assert_cb)(const char *file, int line, const char *msg); - -#ifdef __cplusplus -} -#endif +#define KERNAUX_NOTNULL(cond) KERNAUX_ASSERT(cond) #endif diff --git a/src/cmdline.c b/src/cmdline.c index b76af7d8..1552aa51 100644 --- a/src/cmdline.c +++ b/src/cmdline.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include @@ -58,10 +59,10 @@ bool kernaux_cmdline( const size_t arg_count_max, const size_t buffer_size ) { - KERNAUX_ASSERT(cmdline); - KERNAUX_ASSERT(error_msg); + KERNAUX_NOTNULL(cmdline); + KERNAUX_NOTNULL(error_msg); KERNAUX_ASSERT(argc); - KERNAUX_ASSERT(argv); + KERNAUX_NOTNULL(argv); KERNAUX_ASSERT(arg_count_max > 0); KERNAUX_ASSERT(buffer_size > 0); @@ -100,8 +101,8 @@ bool kernaux_cmdline_common( const size_t arg_count_max, const size_t buffer_size ) { - KERNAUX_ASSERT(cmdline); - KERNAUX_ASSERT(error_msg); + KERNAUX_NOTNULL(cmdline); + KERNAUX_NOTNULL(error_msg); KERNAUX_ASSERT(argc); (void)arg_idxs; diff --git a/src/free_list.c b/src/free_list.c index 988901c5..378b522c 100644 --- a/src/free_list.c +++ b/src/free_list.c @@ -9,7 +9,8 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include #include @@ -69,7 +70,7 @@ void KernAux_FreeList_init( const KernAux_FreeList free_list, const KernAux_Mutex mutex ) { - KERNAUX_ASSERT(free_list); + KERNAUX_NOTNULL(free_list); free_list->malloc.calloc = NULL; free_list->malloc.free = KernAux_FreeList_free; @@ -84,8 +85,8 @@ void KernAux_FreeList_add_zone( void *const ptr, const size_t size ) { - KERNAUX_ASSERT(free_list); - KERNAUX_ASSERT(ptr); + KERNAUX_NOTNULL(free_list); + KERNAUX_NOTNULL(ptr); KERNAUX_ASSERT(size >= MIN_ZONE_SIZE); LOCK(free_list); @@ -126,8 +127,8 @@ block_found: void KernAux_FreeList_free(void *const malloc, void *const ptr) { const KernAux_FreeList free_list = malloc; - KERNAUX_ASSERT(free_list); - KERNAUX_ASSERT(ptr); + KERNAUX_NOTNULL(free_list); + KERNAUX_NOTNULL(ptr); LOCK(free_list); @@ -164,7 +165,7 @@ block_added: void *KernAux_FreeList_malloc(void *const malloc, size_t size) { const KernAux_FreeList free_list = malloc; - KERNAUX_ASSERT(free_list); + KERNAUX_NOTNULL(free_list); KERNAUX_ASSERT(size); LOCK(free_list); @@ -220,8 +221,8 @@ void *KernAux_FreeList_realloc( const size_t new_size ) { const KernAux_FreeList free_list = malloc; - KERNAUX_ASSERT(free_list); - KERNAUX_ASSERT(old_ptr); + KERNAUX_NOTNULL(free_list); + KERNAUX_NOTNULL(old_ptr); KERNAUX_ASSERT(new_size); LOCK(free_list); @@ -243,7 +244,7 @@ void *KernAux_FreeList_realloc( void KernAux_FreeList_defrag(const KernAux_FreeList free_list) { - KERNAUX_ASSERT(free_list); + KERNAUX_NOTNULL(free_list); for ( KernAux_FreeList_Node item_node = free_list->head; @@ -267,8 +268,8 @@ void KernAux_FreeList_insert( const KernAux_FreeList_Node prev, const KernAux_FreeList_Node next ) { - KERNAUX_ASSERT(free_list); - KERNAUX_ASSERT(node); + KERNAUX_NOTNULL(free_list); + KERNAUX_NOTNULL(node); KERNAUX_ASSERT(node != prev); KERNAUX_ASSERT(node != next); KERNAUX_ASSERT(!prev || prev->next == next); @@ -285,8 +286,8 @@ void KernAux_FreeList_remove( const KernAux_FreeList free_list, const KernAux_FreeList_Node node ) { - KERNAUX_ASSERT(free_list); - KERNAUX_ASSERT(node); + KERNAUX_NOTNULL(free_list); + KERNAUX_NOTNULL(node); KERNAUX_ASSERT(!node->next || node->next->prev == node); KERNAUX_ASSERT(!node->prev || node->prev->next == node); diff --git a/src/generic/display.c b/src/generic/display.c index 36a40919..0fe5d3fb 100644 --- a/src/generic/display.c +++ b/src/generic/display.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include #include @@ -10,7 +11,7 @@ void KernAux_Display_putc(const KernAux_Display display, const char c) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); KERNAUX_ASSERT(display->putc); // Inherited implementation @@ -19,7 +20,7 @@ void KernAux_Display_putc(const KernAux_Display display, const char c) void KernAux_Display_print(const KernAux_Display display, const char *const s) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); KERNAUX_ASSERT(display->putc); // Default implementation @@ -28,7 +29,7 @@ void KernAux_Display_print(const KernAux_Display display, const char *const s) void KernAux_Display_println(const KernAux_Display display, const char *const s) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); KERNAUX_ASSERT(display->putc); // Default implementation @@ -41,7 +42,7 @@ void KernAux_Display_write( const char *const data, const size_t size ) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); KERNAUX_ASSERT(display->putc); // Default implementation @@ -53,7 +54,7 @@ void KernAux_Display_writeln( const char *const data, const size_t size ) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); KERNAUX_ASSERT(display->putc); // Default implementation @@ -66,7 +67,7 @@ void KernAux_Display_printf( const char *const format, ... ) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); // Default implementation va_list va; @@ -80,7 +81,7 @@ void KernAux_Display_printlnf( const char *const format, ... ) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); // Default implementation va_list va; @@ -94,7 +95,7 @@ void KernAux_Display_vprintf( const char *const format, va_list va ) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); KERNAUX_ASSERT(display->vprintf); // Inherited implementation @@ -106,7 +107,7 @@ void KernAux_Display_vprintlnf( const char *const format, va_list va ) { - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(display); KERNAUX_ASSERT(display->putc); // Default implementation diff --git a/src/generic/malloc.c b/src/generic/malloc.c index 7de56bff..f85b5f4d 100644 --- a/src/generic/malloc.c +++ b/src/generic/malloc.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include #include @@ -10,7 +11,7 @@ void *KernAux_Malloc_calloc(KernAux_Malloc malloc, size_t nmemb, size_t size) { - KERNAUX_ASSERT(malloc); + KERNAUX_NOTNULL(malloc); // Common implementation const size_t total_size = nmemb * size; @@ -28,7 +29,7 @@ void *KernAux_Malloc_calloc(KernAux_Malloc malloc, size_t nmemb, size_t size) void KernAux_Malloc_free(KernAux_Malloc malloc, void *ptr) { - KERNAUX_ASSERT(malloc); + KERNAUX_NOTNULL(malloc); KERNAUX_ASSERT(malloc->free); // Common implementation @@ -40,7 +41,7 @@ void KernAux_Malloc_free(KernAux_Malloc malloc, void *ptr) void *KernAux_Malloc_malloc(KernAux_Malloc malloc, size_t size) { - KERNAUX_ASSERT(malloc); + KERNAUX_NOTNULL(malloc); KERNAUX_ASSERT(malloc->malloc); // Common implementation @@ -52,7 +53,7 @@ void *KernAux_Malloc_malloc(KernAux_Malloc malloc, size_t size) void *KernAux_Malloc_realloc(KernAux_Malloc malloc, void *ptr, size_t size) { - KERNAUX_ASSERT(malloc); + KERNAUX_NOTNULL(malloc); KERNAUX_ASSERT(malloc->realloc); // Common implementation diff --git a/src/generic/mutex.c b/src/generic/mutex.c index 9b5eed6e..37296342 100644 --- a/src/generic/mutex.c +++ b/src/generic/mutex.c @@ -2,12 +2,13 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include void KernAux_Mutex_lock(const KernAux_Mutex mutex) { - KERNAUX_ASSERT(mutex); + KERNAUX_NOTNULL(mutex); KERNAUX_ASSERT(mutex->lock); mutex->lock((void*)mutex); @@ -15,7 +16,7 @@ void KernAux_Mutex_lock(const KernAux_Mutex mutex) void KernAux_Mutex_unlock(const KernAux_Mutex mutex) { - KERNAUX_ASSERT(mutex); + KERNAUX_NOTNULL(mutex); KERNAUX_ASSERT(mutex->unlock); mutex->unlock((void*)mutex); diff --git a/src/mbr.c b/src/mbr.c index f9f3418a..c505117b 100644 --- a/src/mbr.c +++ b/src/mbr.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include @@ -10,14 +11,14 @@ bool KernAux_Mbr_is_valid(const struct KernAux_Mbr *const mbr) { - KERNAUX_ASSERT(mbr); + KERNAUX_NOTNULL(mbr); return KernAux_Mbr_Info_is_valid(&mbr->info); } bool KernAux_Mbr_Info_is_valid(const struct KernAux_Mbr_Info *const mbr_info) { - KERNAUX_ASSERT(mbr_info); + KERNAUX_NOTNULL(mbr_info); if (mbr_info->magic != KERNAUX_MBR_MAGIC) return false; @@ -32,7 +33,7 @@ bool KernAux_Mbr_Info_is_valid(const struct KernAux_Mbr_Info *const mbr_info) bool KernAux_Mbr_Entry_is_valid(const struct KernAux_Mbr_Entry *const mbr_entry) { - KERNAUX_ASSERT(mbr_entry); + KERNAUX_NOTNULL(mbr_entry); // TODO: implement this (void)mbr_entry; diff --git a/src/memmap.c b/src/memmap.c index 04534a90..cb76d25c 100644 --- a/src/memmap.c +++ b/src/memmap.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include diff --git a/src/multiboot2/header_helpers.c b/src/multiboot2/header_helpers.c index 1eff9801..20d3f641 100644 --- a/src/multiboot2/header_helpers.c +++ b/src/multiboot2/header_helpers.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include #include @@ -13,7 +14,7 @@ const struct KernAux_Multiboot2_HTagBase const struct KernAux_Multiboot2_Header *const multiboot2_header, const uint16_t tag_type ) { - KERNAUX_ASSERT(multiboot2_header); + KERNAUX_NOTNULL(multiboot2_header); const struct KernAux_Multiboot2_HTagBase *tag_base = (struct KernAux_Multiboot2_HTagBase*) @@ -38,8 +39,8 @@ const struct KernAux_Multiboot2_HTagBase const uint16_t tag_type, const struct KernAux_Multiboot2_HTagBase *const after_tag ) { - KERNAUX_ASSERT(multiboot2_header); - KERNAUX_ASSERT(after_tag); + KERNAUX_NOTNULL(multiboot2_header); + KERNAUX_NOTNULL(after_tag); const struct KernAux_Multiboot2_HTagBase *tag_base = (struct KernAux_Multiboot2_HTagBase*) diff --git a/src/multiboot2/header_is_valid.c b/src/multiboot2/header_is_valid.c index 1409bd13..bb0fff14 100644 --- a/src/multiboot2/header_is_valid.c +++ b/src/multiboot2/header_is_valid.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include #include @@ -12,7 +13,7 @@ bool KernAux_Multiboot2_Header_is_valid( const struct KernAux_Multiboot2_Header *const multiboot2_header ) { - KERNAUX_ASSERT(multiboot2_header); + KERNAUX_NOTNULL(multiboot2_header); if (multiboot2_header->magic != KERNAUX_MULTIBOOT2_HEADER_MAGIC) { return false; @@ -86,7 +87,7 @@ bool KernAux_Multiboot2_Header_is_valid( bool KernAux_Multiboot2_HTagBase_is_valid( const struct KernAux_Multiboot2_HTagBase *tag_base ) { - KERNAUX_ASSERT(tag_base); + KERNAUX_NOTNULL(tag_base); switch (tag_base->type) { case KERNAUX_MULTIBOOT2_HTAG_NONE: @@ -141,7 +142,7 @@ bool KernAux_Multiboot2_HTagBase_is_valid( bool KernAux_Multiboot2_HTag_None_is_valid( const struct KernAux_Multiboot2_HTag_None *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_NONE && tag->base.size == 8 @@ -151,7 +152,7 @@ bool KernAux_Multiboot2_HTag_None_is_valid( bool KernAux_Multiboot2_HTag_InfoReq_is_valid( const struct KernAux_Multiboot2_HTag_InfoReq *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_INFO_REQ && tag->base.size > 8 && @@ -162,7 +163,7 @@ bool KernAux_Multiboot2_HTag_InfoReq_is_valid( bool KernAux_Multiboot2_HTag_Addr_is_valid( const struct KernAux_Multiboot2_HTag_Addr *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_ADDR && tag->base.size == 24 @@ -172,7 +173,7 @@ bool KernAux_Multiboot2_HTag_Addr_is_valid( bool KernAux_Multiboot2_HTag_EntryAddr_is_valid( const struct KernAux_Multiboot2_HTag_EntryAddr *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_ENTRY_ADDR && tag->base.size == 12 @@ -182,7 +183,7 @@ bool KernAux_Multiboot2_HTag_EntryAddr_is_valid( bool KernAux_Multiboot2_HTag_Flags_is_valid( const struct KernAux_Multiboot2_HTag_Flags *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_FLAGS && tag->base.size == 12 @@ -192,7 +193,7 @@ bool KernAux_Multiboot2_HTag_Flags_is_valid( bool KernAux_Multiboot2_HTag_Framebuffer_is_valid( const struct KernAux_Multiboot2_HTag_Framebuffer *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_FRAMEBUFFER && tag->base.size == 20 @@ -202,7 +203,7 @@ bool KernAux_Multiboot2_HTag_Framebuffer_is_valid( bool KernAux_Multiboot2_HTag_ModuleAlign_is_valid( const struct KernAux_Multiboot2_HTag_ModuleAlign *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_MODULE_ALIGN && tag->base.size == 8 @@ -212,7 +213,7 @@ bool KernAux_Multiboot2_HTag_ModuleAlign_is_valid( bool KernAux_Multiboot2_HTag_EFIBootServices_is_valid( const struct KernAux_Multiboot2_HTag_EFIBootServices *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_EFI_BOOT_SERVICES && tag->base.size == 8 @@ -222,7 +223,7 @@ bool KernAux_Multiboot2_HTag_EFIBootServices_is_valid( bool KernAux_Multiboot2_HTag_EFII386EntryAddr_is_valid( const struct KernAux_Multiboot2_HTag_EFII386EntryAddr *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_EFI_I386_ENTRY_ADDR && tag->base.size == 12 @@ -232,7 +233,7 @@ bool KernAux_Multiboot2_HTag_EFII386EntryAddr_is_valid( bool KernAux_Multiboot2_HTag_EFIAmd64EntryAddr_is_valid( const struct KernAux_Multiboot2_HTag_EFIAmd64EntryAddr *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_EFI_AMD64_ENTRY_ADDR && tag->base.size == 12 @@ -242,7 +243,7 @@ bool KernAux_Multiboot2_HTag_EFIAmd64EntryAddr_is_valid( bool KernAux_Multiboot2_HTag_RelocatableHeader_is_valid( const struct KernAux_Multiboot2_HTag_RelocatableHeader *tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); if (!( tag->base.type == KERNAUX_MULTIBOOT2_HTAG_RELOCATABLE_HEADER && diff --git a/src/multiboot2/header_print.c b/src/multiboot2/header_print.c index f0e95065..af9b231f 100644 --- a/src/multiboot2/header_print.c +++ b/src/multiboot2/header_print.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include #include #include @@ -20,8 +21,8 @@ do { KernAux_Display_printlnf(display, format, __VA_ARGS__); } while (0) #define HEADER(Type) do { \ - KERNAUX_ASSERT(tag); \ - KERNAUX_ASSERT(display); \ + KERNAUX_NOTNULL(tag); \ + KERNAUX_NOTNULL(display); \ \ if (!KernAux_Multiboot2_HTag_##Type##_is_valid(tag)) { \ PRINTLN("Multiboot 2 header tag // invalid!"); \ @@ -100,8 +101,8 @@ void KernAux_Multiboot2_Header_print( const struct KernAux_Multiboot2_Header *const multiboot2_header, const KernAux_Display display ) { - KERNAUX_ASSERT(multiboot2_header); - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(multiboot2_header); + KERNAUX_NOTNULL(display); KERNAUX_CAST_CONST(unsigned long, magic, multiboot2_header->magic); KERNAUX_CAST_CONST(unsigned long, arch, multiboot2_header->arch); @@ -136,8 +137,8 @@ void KernAux_Multiboot2_HTagBase_print( const struct KernAux_Multiboot2_HTagBase *const tag_base, const KernAux_Display display ) { - KERNAUX_ASSERT(tag_base); - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(tag_base); + KERNAUX_NOTNULL(display); switch (tag_base->type) { case KERNAUX_MULTIBOOT2_HTAG_NONE: diff --git a/src/multiboot2/info_helpers.c b/src/multiboot2/info_helpers.c index 3eeba2d4..6e940fa9 100644 --- a/src/multiboot2/info_helpers.c +++ b/src/multiboot2/info_helpers.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include #include @@ -13,7 +14,7 @@ const struct KernAux_Multiboot2_ITagBase const struct KernAux_Multiboot2_Info *const multiboot2_info, const uint32_t tag_type ) { - KERNAUX_ASSERT(multiboot2_info); + KERNAUX_NOTNULL(multiboot2_info); const struct KernAux_Multiboot2_ITagBase *tag_base = (struct KernAux_Multiboot2_ITagBase*) @@ -38,8 +39,8 @@ const struct KernAux_Multiboot2_ITagBase const uint32_t tag_type, const struct KernAux_Multiboot2_ITagBase *const after_tag ) { - KERNAUX_ASSERT(multiboot2_info); - KERNAUX_ASSERT(after_tag); + KERNAUX_NOTNULL(multiboot2_info); + KERNAUX_NOTNULL(after_tag); const struct KernAux_Multiboot2_ITagBase *tag_base = (struct KernAux_Multiboot2_ITagBase*) @@ -63,7 +64,7 @@ const struct KernAux_Multiboot2_ITagBase const char *KernAux_Multiboot2_Info_boot_cmd_line( const struct KernAux_Multiboot2_Info *const multiboot2_info ) { - KERNAUX_ASSERT(multiboot2_info); + KERNAUX_NOTNULL(multiboot2_info); const struct KernAux_Multiboot2_ITag_BootCmdLine *const tag = (struct KernAux_Multiboot2_ITag_BootCmdLine*) diff --git a/src/multiboot2/info_is_valid.c b/src/multiboot2/info_is_valid.c index aed43223..75755f93 100644 --- a/src/multiboot2/info_is_valid.c +++ b/src/multiboot2/info_is_valid.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include #include @@ -12,7 +13,7 @@ bool KernAux_Multiboot2_Info_is_valid( const struct KernAux_Multiboot2_Info *const multiboot2_info ) { - KERNAUX_ASSERT(multiboot2_info); + KERNAUX_NOTNULL(multiboot2_info); if (multiboot2_info->total_size < sizeof(struct KernAux_Multiboot2_Info) + @@ -67,7 +68,7 @@ bool KernAux_Multiboot2_Info_is_valid( bool KernAux_Multiboot2_ITagBase_is_valid( const struct KernAux_Multiboot2_ITagBase *const tag_base ) { - KERNAUX_ASSERT(tag_base); + KERNAUX_NOTNULL(tag_base); switch (tag_base->type) { case KERNAUX_MULTIBOOT2_ITAG_NONE: @@ -167,7 +168,7 @@ bool KernAux_Multiboot2_ITagBase_is_valid( bool KernAux_Multiboot2_ITag_None_is_valid( const struct KernAux_Multiboot2_ITag_None *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_NONE && tag->base.size == 8 @@ -177,7 +178,7 @@ bool KernAux_Multiboot2_ITag_None_is_valid( bool KernAux_Multiboot2_ITag_BootCmdLine_is_valid( const struct KernAux_Multiboot2_ITag_BootCmdLine *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); size_t index = 1; @@ -198,7 +199,7 @@ bool KernAux_Multiboot2_ITag_BootCmdLine_is_valid( bool KernAux_Multiboot2_ITag_BootLoaderName_is_valid( const struct KernAux_Multiboot2_ITag_BootLoaderName *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); size_t index = 1; @@ -219,7 +220,7 @@ bool KernAux_Multiboot2_ITag_BootLoaderName_is_valid( bool KernAux_Multiboot2_ITag_Module_is_valid( const struct KernAux_Multiboot2_ITag_Module *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); size_t index = 1; @@ -241,7 +242,7 @@ bool KernAux_Multiboot2_ITag_Module_is_valid( bool KernAux_Multiboot2_ITag_BasicMemoryInfo_is_valid( const struct KernAux_Multiboot2_ITag_BasicMemoryInfo *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_BASIC_MEMORY_INFO && tag->base.size == 16 @@ -251,7 +252,7 @@ bool KernAux_Multiboot2_ITag_BasicMemoryInfo_is_valid( bool KernAux_Multiboot2_ITag_BIOSBootDevice_is_valid( const struct KernAux_Multiboot2_ITag_BIOSBootDevice *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_BIOS_BOOT_DEVICE && tag->base.size == 20 @@ -261,7 +262,7 @@ bool KernAux_Multiboot2_ITag_BIOSBootDevice_is_valid( bool KernAux_Multiboot2_ITag_MemoryMap_is_valid( const struct KernAux_Multiboot2_ITag_MemoryMap *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_MEMORY_MAP && tag->base.size >= 16 && @@ -274,7 +275,7 @@ bool KernAux_Multiboot2_ITag_MemoryMap_is_valid( bool KernAux_Multiboot2_ITag_VBEInfo_is_valid( const struct KernAux_Multiboot2_ITag_VBEInfo *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_VBE_INFO && tag->base.size == 784 @@ -284,7 +285,7 @@ bool KernAux_Multiboot2_ITag_VBEInfo_is_valid( bool KernAux_Multiboot2_ITag_FramebufferInfo_is_valid( const struct KernAux_Multiboot2_ITag_FramebufferInfo *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_FRAMEBUFFER_INFO && tag->base.size >= 32 @@ -294,7 +295,7 @@ bool KernAux_Multiboot2_ITag_FramebufferInfo_is_valid( bool KernAux_Multiboot2_ITag_ELFSymbols_is_valid( const struct KernAux_Multiboot2_ITag_ELFSymbols *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_ELF_SYMBOLS && tag->base.size >= 20 && @@ -308,7 +309,7 @@ bool KernAux_Multiboot2_ITag_ELFSymbols_is_valid( bool KernAux_Multiboot2_ITag_APMTable_is_valid( const struct KernAux_Multiboot2_ITag_APMTable *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_APM_TABLE && tag->base.size == 28 @@ -318,7 +319,7 @@ bool KernAux_Multiboot2_ITag_APMTable_is_valid( bool KernAux_Multiboot2_ITag_EFI32bitSystemTablePtr_is_valid( const struct KernAux_Multiboot2_ITag_EFI32bitSystemTablePtr *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_SYSTEM_TABLE_PTR && tag->base.size == 12 @@ -328,7 +329,7 @@ bool KernAux_Multiboot2_ITag_EFI32bitSystemTablePtr_is_valid( bool KernAux_Multiboot2_ITag_EFI64bitSystemTablePtr_is_valid( const struct KernAux_Multiboot2_ITag_EFI64bitSystemTablePtr *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_SYSTEM_TABLE_PTR && tag->base.size == 16 @@ -338,7 +339,7 @@ bool KernAux_Multiboot2_ITag_EFI64bitSystemTablePtr_is_valid( bool KernAux_Multiboot2_ITag_SMBIOSTables_is_valid( const struct KernAux_Multiboot2_ITag_SMBIOSTables *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_SMBIOS_TABLES && tag->base.size >= 16 @@ -348,7 +349,7 @@ bool KernAux_Multiboot2_ITag_SMBIOSTables_is_valid( bool KernAux_Multiboot2_ITag_ACPIOldRSDP_is_valid( const struct KernAux_Multiboot2_ITag_ACPIOldRSDP *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_ACPI_OLD_RSDP && tag->base.size >= 8 @@ -358,7 +359,7 @@ bool KernAux_Multiboot2_ITag_ACPIOldRSDP_is_valid( bool KernAux_Multiboot2_ITag_ACPINewRSDP_is_valid( const struct KernAux_Multiboot2_ITag_ACPINewRSDP *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_ACPI_NEW_RSDP && tag->base.size >= 8 @@ -368,7 +369,7 @@ bool KernAux_Multiboot2_ITag_ACPINewRSDP_is_valid( bool KernAux_Multiboot2_ITag_NetworkingInfo_is_valid( const struct KernAux_Multiboot2_ITag_NetworkingInfo *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_NETWORKING_INFO && tag->base.size >= 8 @@ -378,7 +379,7 @@ bool KernAux_Multiboot2_ITag_NetworkingInfo_is_valid( bool KernAux_Multiboot2_ITag_EFIMemoryMap_is_valid( const struct KernAux_Multiboot2_ITag_EFIMemoryMap *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_MEMORY_MAP && tag->base.size >= 16 @@ -388,7 +389,7 @@ bool KernAux_Multiboot2_ITag_EFIMemoryMap_is_valid( bool KernAux_Multiboot2_ITag_EFIBootServicesNotTerminated_is_valid( const struct KernAux_Multiboot2_ITag_EFIBootServicesNotTerminated *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_BOOT_SERVICES_NOT_TERMINATED && @@ -399,7 +400,7 @@ bool KernAux_Multiboot2_ITag_EFIBootServicesNotTerminated_is_valid( bool KernAux_Multiboot2_ITag_EFI32bitImageHandlePtr_is_valid( const struct KernAux_Multiboot2_ITag_EFI32bitImageHandlePtr *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_32BIT_IMAGE_HANDLE_PTR && tag->base.size == 12 @@ -409,7 +410,7 @@ bool KernAux_Multiboot2_ITag_EFI32bitImageHandlePtr_is_valid( bool KernAux_Multiboot2_ITag_EFI64bitImageHandlePtr_is_valid( const struct KernAux_Multiboot2_ITag_EFI64bitImageHandlePtr *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_EFI_64BIT_IMAGE_HANDLE_PTR && tag->base.size == 16 @@ -419,7 +420,7 @@ bool KernAux_Multiboot2_ITag_EFI64bitImageHandlePtr_is_valid( bool KernAux_Multiboot2_ITag_ImageLoadBasePhysAddr_is_valid( const struct KernAux_Multiboot2_ITag_ImageLoadBasePhysAddr *const tag ) { - KERNAUX_ASSERT(tag); + KERNAUX_NOTNULL(tag); return ( tag->base.type == KERNAUX_MULTIBOOT2_ITAG_IMAGE_LOAD_BASE_PHYS_ADDR && tag->base.size == 12 diff --git a/src/multiboot2/info_print.c b/src/multiboot2/info_print.c index 95992757..ecdb10cd 100644 --- a/src/multiboot2/info_print.c +++ b/src/multiboot2/info_print.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "../assert.h" + #include #include #include @@ -21,8 +22,8 @@ do { KernAux_Display_printlnf(display, format, __VA_ARGS__); } while (0) #define HEADER(Type) do { \ - KERNAUX_ASSERT(tag); \ - KERNAUX_ASSERT(display); \ + KERNAUX_NOTNULL(tag); \ + KERNAUX_NOTNULL(display); \ \ if (!KernAux_Multiboot2_ITag_##Type##_is_valid(tag)) { \ PRINTLN("Multiboot 2 info tag // invalid!"); \ @@ -83,8 +84,8 @@ void KernAux_Multiboot2_Info_print( const struct KernAux_Multiboot2_Info *const multiboot2_info, const KernAux_Display display ) { - KERNAUX_ASSERT(multiboot2_info); - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(multiboot2_info); + KERNAUX_NOTNULL(display); KERNAUX_CAST_CONST(unsigned long, total_size, multiboot2_info->total_size); KERNAUX_CAST_CONST(unsigned long, reserved, multiboot2_info->reserved); @@ -112,8 +113,8 @@ void KernAux_Multiboot2_ITagBase_print( const struct KernAux_Multiboot2_ITagBase *const tag_base, const KernAux_Display display ) { - KERNAUX_ASSERT(tag_base); - KERNAUX_ASSERT(display); + KERNAUX_NOTNULL(tag_base); + KERNAUX_NOTNULL(display); switch (tag_base->type) { case KERNAUX_MULTIBOOT2_ITAG_NONE: diff --git a/src/ntoa.c b/src/ntoa.c index 561e0087..70d9611c 100644 --- a/src/ntoa.c +++ b/src/ntoa.c @@ -2,14 +2,15 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include char *kernaux_utoa(uint64_t value, char *buffer, int base, const char *prefix) { - KERNAUX_ASSERT(buffer); + KERNAUX_NOTNULL(buffer); // Protect caller from invalid state in case of future assertions // cppcheck-suppress ctunullpointer diff --git a/src/pfa.c b/src/pfa.c index 76aec898..f4535a6f 100644 --- a/src/pfa.c +++ b/src/pfa.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include @@ -41,14 +42,14 @@ static void KernAux_PFA_mark( void KernAux_PFA_initialize(const KernAux_PFA pfa) { - KERNAUX_ASSERT(pfa); + KERNAUX_NOTNULL(pfa); // cppcheck-suppress ctunullpointer memset(pfa->flags, 0, sizeof(pfa->flags)); } bool KernAux_PFA_is_available(const KernAux_PFA pfa, const size_t page_addr) { - KERNAUX_ASSERT(pfa); + KERNAUX_NOTNULL(pfa); KERNAUX_ASSERT(page_addr % KERNAUX_PFA_PAGE_SIZE == 0); // cppcheck-suppress ctunullpointer @@ -77,7 +78,7 @@ void KernAux_PFA_mark( size_t start, size_t end ) { - KERNAUX_ASSERT(pfa); + KERNAUX_NOTNULL(pfa); KERNAUX_ASSERT(start < end); const size_t start_rem = start % KERNAUX_PFA_PAGE_SIZE; @@ -105,7 +106,7 @@ void KernAux_PFA_mark( size_t KernAux_PFA_alloc_pages(const KernAux_PFA pfa, size_t mem_size) { - KERNAUX_ASSERT(pfa); + KERNAUX_NOTNULL(pfa); const size_t mem_rem = mem_size % KERNAUX_PFA_PAGE_SIZE; @@ -144,7 +145,7 @@ void KernAux_PFA_free_pages( const size_t page_addr, size_t mem_size ) { - KERNAUX_ASSERT(pfa); + KERNAUX_NOTNULL(pfa); KERNAUX_ASSERT(page_addr % KERNAUX_PFA_PAGE_SIZE == 0); const size_t mem_rem = mem_size % KERNAUX_PFA_PAGE_SIZE; diff --git a/src/printf.c b/src/printf.c index 2f05c33b..d567c0f7 100644 --- a/src/printf.c +++ b/src/printf.c @@ -13,7 +13,8 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include @@ -70,8 +71,8 @@ static size_t _etoa(out_fct_type out, char* buffer, size_t idx, size_t maxlen, d int kernaux_fprintf(void (*out)(char, void*), void *data, const char* format, ...) { - KERNAUX_ASSERT(out); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(out); + KERNAUX_NOTNULL(format); va_list va; va_start(va, format); @@ -83,8 +84,8 @@ int kernaux_fprintf(void (*out)(char, void*), void *data, const char* format, .. int kernaux_vfprintf(void (*out)(char, void*), void *data, const char* format, va_list va) { - KERNAUX_ASSERT(out); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(out); + KERNAUX_NOTNULL(format); const out_fct_wrap_type out_fct_wrap = { out, data }; return _vsnprintf(_out_fct, (char*)(uintptr_t)&out_fct_wrap, (size_t)-1, format, va); @@ -92,8 +93,8 @@ int kernaux_vfprintf(void (*out)(char, void*), void *data, const char* format, v int kernaux_snprintf(char* buffer, size_t count, const char* format, ...) { - KERNAUX_ASSERT(buffer); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(buffer); + KERNAUX_NOTNULL(format); va_list va; va_start(va, format); @@ -104,16 +105,16 @@ int kernaux_snprintf(char* buffer, size_t count, const char* format, ...) int kernaux_vsnprintf(char* buffer, size_t count, const char* format, va_list va) { - KERNAUX_ASSERT(buffer); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(buffer); + KERNAUX_NOTNULL(format); return _vsnprintf(_out_buffer, buffer, count, format, va); } int kernaux_sprintf(char* buffer, const char* format, ...) { - KERNAUX_ASSERT(buffer); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(buffer); + KERNAUX_NOTNULL(format); va_list va; va_start(va, format); @@ -128,7 +129,7 @@ int kernaux_sprintf(char* buffer, const char* format, ...) int _vsnprintf(out_fct_type out, char* buffer, const size_t maxlen, const char* format, va_list va) { - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(format); size_t idx = 0u; diff --git a/src/printf_fmt.c b/src/printf_fmt.c index ea1886ea..191ee36f 100644 --- a/src/printf_fmt.c +++ b/src/printf_fmt.c @@ -9,7 +9,8 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include @@ -35,7 +36,7 @@ static unsigned int _atoi(const char** str); struct KernAux_PrintfFmt_Spec KernAux_PrintfFmt_Spec_create_out( const char **const format ) { - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(format); const struct KernAux_PrintfFmt_Spec spec = KernAux_PrintfFmt_Spec_create(*format); @@ -47,8 +48,8 @@ struct KernAux_PrintfFmt_Spec KernAux_PrintfFmt_Spec_create_out_new( const char *const format, const char **const new_format ) { - KERNAUX_ASSERT(format); - KERNAUX_ASSERT(new_format); + KERNAUX_NOTNULL(format); + KERNAUX_NOTNULL(new_format); *new_format = NULL; const struct KernAux_PrintfFmt_Spec spec = @@ -59,7 +60,7 @@ struct KernAux_PrintfFmt_Spec KernAux_PrintfFmt_Spec_create_out_new( struct KernAux_PrintfFmt_Spec KernAux_PrintfFmt_Spec_create(const char *format) { - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(format); struct KernAux_PrintfFmt_Spec spec; @@ -87,7 +88,7 @@ struct KernAux_PrintfFmt_Spec KernAux_PrintfFmt_Spec_create(const char *format) void KernAux_PrintfFmt_Spec_set_width(const Spec spec, const int width) { - KERNAUX_ASSERT(spec); + KERNAUX_NOTNULL(spec); if (width < 0) { spec->flags |= KERNAUX_PRINTF_FMT_FLAGS_LEFT; // reverse padding @@ -99,7 +100,7 @@ void KernAux_PrintfFmt_Spec_set_width(const Spec spec, const int width) void KernAux_PrintfFmt_Spec_set_precision(const Spec spec, const int precision) { - KERNAUX_ASSERT(spec); + KERNAUX_NOTNULL(spec); spec->precision = precision > 0 ? (unsigned int)precision : 0u; } @@ -110,8 +111,8 @@ void KernAux_PrintfFmt_Spec_set_precision(const Spec spec, const int precision) void parse_flags(const Spec spec, const char **const format) { - KERNAUX_ASSERT(spec); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(spec); + KERNAUX_NOTNULL(format); KERNAUX_ASSERT(*format); bool running = true; @@ -144,8 +145,8 @@ void parse_flags(const Spec spec, const char **const format) void parse_width(const Spec spec, const char **const format) { - KERNAUX_ASSERT(spec); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(spec); + KERNAUX_NOTNULL(format); KERNAUX_ASSERT(*format); if (isdigit(**format)) { @@ -161,8 +162,8 @@ void parse_width(const Spec spec, const char **const format) void parse_precision(const Spec spec, const char **const format) { - KERNAUX_ASSERT(spec); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(spec); + KERNAUX_NOTNULL(format); KERNAUX_ASSERT(*format); if (**format == '.') { @@ -184,8 +185,8 @@ void parse_precision(const Spec spec, const char **const format) void parse_length(const Spec spec, const char **const format) { - KERNAUX_ASSERT(spec); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(spec); + KERNAUX_NOTNULL(format); KERNAUX_ASSERT(*format); switch (**format) { @@ -236,8 +237,8 @@ void parse_length(const Spec spec, const char **const format) void parse_type(const Spec spec, const char **const format) { - KERNAUX_ASSERT(spec); - KERNAUX_ASSERT(format); + KERNAUX_NOTNULL(spec); + KERNAUX_NOTNULL(format); KERNAUX_ASSERT(*format); switch (**format) { diff --git a/src/assert.c b/src/runtime.c similarity index 69% rename from src/assert.c rename to src/runtime.c index 301e24a9..e7e78880 100644 --- a/src/assert.c +++ b/src/runtime.c @@ -2,11 +2,11 @@ #include "config.h" #endif -#include +#include #include -void (*kernaux_assert_cb)(const char *file, int line, const char *msg) = NULL; +KernAux_Assert_Cb kernaux_assert_cb = NULL; void kernaux_assert_do( const char *const file, diff --git a/src/units.c b/src/units.c index 67cb8d2b..911f186a 100644 --- a/src/units.c +++ b/src/units.c @@ -2,7 +2,8 @@ #include "config.h" #endif -#include +#include "assert.h" + #include #include @@ -16,7 +17,7 @@ bool kernaux_units_human_raw( char *const buffer, const size_t buffer_size ) { - KERNAUX_ASSERT(buffer); + KERNAUX_NOTNULL(buffer); KERNAUX_ASSERT(buffer_size > 0); char tmp_buffer[TMP_BUFFER_SIZE]; @@ -56,7 +57,7 @@ bool kernaux_units_human_dec( char *const buffer, const size_t buffer_size ) { - KERNAUX_ASSERT(buffer); + KERNAUX_NOTNULL(buffer); KERNAUX_ASSERT(buffer_size > 0); char tmp_buffer[TMP_BUFFER_SIZE]; diff --git a/tests/Makefile.am b/tests/Makefile.am index 04419860..b3a3ab20 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -304,7 +304,7 @@ endif # test_ntoa_assert # #################### -if ENABLE_DEBUG +if ENABLE_ASSERT if WITH_NTOA TESTS += test_ntoa_assert test_ntoa_assert_LDADD = $(top_builddir)/libkernaux.la @@ -330,7 +330,7 @@ endif # test_pfa_assert # ################### -if ENABLE_DEBUG +if ENABLE_ASSERT if WITH_PFA TESTS += test_pfa_assert test_pfa_assert_LDADD = $(top_builddir)/libkernaux.la diff --git a/tests/main.c b/tests/main.c index 453b5054..f2a2c77c 100644 --- a/tests/main.c +++ b/tests/main.c @@ -2,7 +2,7 @@ #include "config.h" #endif -#include +#include #include #include diff --git a/tests/test_memmap.c b/tests/test_memmap.c index ff35279d..ee33769e 100644 --- a/tests/test_memmap.c +++ b/tests/test_memmap.c @@ -4,20 +4,21 @@ #define KERNAUX_ACCESS_PRIVATE -#include #include #include +#include #include +#include #include #include #include static KernAux_MemMap memmap; +static jmp_buf jmpbuf; static unsigned int assert_count_exp = 0; static unsigned int assert_count_ctr = 0; - static const char *assert_last_file = NULL; static void assert_cb( @@ -27,6 +28,8 @@ static void assert_cb( ) { ++assert_count_ctr; assert_last_file = file; + + longjmp(jmpbuf, 1); } static void before_assert() @@ -36,7 +39,7 @@ static void before_assert() static void expect_assert() { -#ifdef ENABLE_DEBUG +#ifdef ENABLE_ASSERT // cppcheck-suppress assignmentInAssert assert(assert_count_ctr == ++assert_count_exp); assert(strstr(assert_last_file, "src/memmap.c") != NULL); @@ -52,6 +55,8 @@ static void expect_assert() void test_main() { + assert(setjmp(jmpbuf) == 0); + kernaux_assert_cb = assert_cb; { @@ -71,7 +76,9 @@ void test_main() assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL); before_assert(); - assert(!KernAux_MemMap_finish(memmap)); + if (setjmp(jmpbuf) == 0) { + assert(!KernAux_MemMap_finish(memmap)); + } expect_assert(); } @@ -183,7 +190,9 @@ void test_main() assert(MEMMAP.entries[0].limit == 2); before_assert(); - assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL); + if (setjmp(jmpbuf) == 0) { + assert(KernAux_MemMap_entry_by_index(memmap, 0) == NULL); + } expect_assert(); } diff --git a/tests/test_ntoa_assert.c b/tests/test_ntoa_assert.c index 108467b9..433e5bba 100644 --- a/tests/test_ntoa_assert.c +++ b/tests/test_ntoa_assert.c @@ -2,8 +2,8 @@ #include "config.h" #endif -#include #include +#include #include #include diff --git a/tests/test_pfa_assert.c b/tests/test_pfa_assert.c index 885217f7..78ce5acb 100644 --- a/tests/test_pfa_assert.c +++ b/tests/test_pfa_assert.c @@ -2,9 +2,9 @@ #include "config.h" #endif -#include #include #include +#include #include #include