Maintenance (#98)

* Fix copyright
* Remove thanks
* Update CONTRIBUTING.md
* Remove bitfields from struct KernAux_Arch_I386_TSS
* Change description of package "mbr"
* Make generic file stable
* Rename printf examples
This commit is contained in:
Alex Kotov 2022-06-25 23:28:28 +03:00 committed by GitHub
parent 74d14aff8f
commit 0922a18e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 168 additions and 95 deletions

8
.gitignore vendored
View File

@ -108,8 +108,6 @@
/examples/assert /examples/assert
/examples/cmdline /examples/cmdline
/examples/fprintf
/examples/fprintf_va
/examples/generic_file /examples/generic_file
/examples/generic_malloc /examples/generic_malloc
/examples/generic_mutex /examples/generic_mutex
@ -117,9 +115,11 @@
/examples/ntoa /examples/ntoa
/examples/panic /examples/panic
/examples/pfa /examples/pfa
/examples/printf_file
/examples/printf_file_va
/examples/printf_fmt /examples/printf_fmt
/examples/snprintf /examples/printf_str
/examples/snprintf_va /examples/printf_str_va
/examples/units_human /examples/units_human
/tests/multiboot2_header_print1 /tests/multiboot2_header_print1

View File

@ -2,16 +2,73 @@ Common
------ ------
* Add your name to [COPYING](/COPYING). * Add your name to [COPYING](/COPYING).
* **Don't** add your name to `AUTHORS` - it's for maintainers. * Don't add your name to `AUTHORS` - it's for maintainers.
* Add copyright notice in the beginning of changed files except the headers. * Add copyright notice in the beginning of changed files except the headers.
* If you change the behavior (even just fix a bug) of **libkernaux** (stable) or * If you change the behavior (even just fix a bug) of **libkernaux** (stable) or
[libc](/libc), add a record to [ChangeLog](/ChangeLog). [libc](/libc), add a record to [ChangeLog](/ChangeLog).
Prohibitions:
* Don't commit binary files
* Don't commit configuration files of your editor or IDE
* Don't use encodings other than ASCII and UTF-8
* Don't use alphabets other than Latin
* Don't use languages other than English
* Don't use tabulations (I don't hate tabs, but people can not use them
properly)
* Don't leave trailing whitespaces
* Don't forget the newline character in the end of files
The following statements are recommendations, but highly encouraged:
* Write documentation
* Write tests
* Keep lines less than 80 characters long for better experience on split screen
### Programming mistakes
* Always check documentation, manuals and specifications
Avoid stupid errors with:
* Manual memory management
* `malloc` may return `NULL`
* Memory leak (forget to `free`)
* Use after `free`/`realloc`
* Double `free`/`realloc`
* `free`ing/`realloc`ating unallocated memory
* Changing the original pointer to the allocated memory (use `const`!)
* `NULL` pointers and `nil`/`None`/whatever objects
* Division by zero
* Pointer arithmetic - consider type size
* Type sizes (like `long` on 32-bit and 64-bit)
* Integer arithmetic overflow
* Bit shift
* Endianness (byte order)
* Data packing
* Data alignment
* Thread safety
* Undefined behavior
* Logical expressions (tautology, whatever)
* Checking for an error (return value, pointer argument, whatever)
* Use of not fully initialized data
* Not reading beyond a buffer, array or string
* The index of the last item, which is less than the buffer size
* Negative indices
* The terminating null character in a string
* Allowed values of arguments
* Possible values of parameters
* Operator precedence
* Default case in switch statements
* Braces (curly brackets) around code blocks
C language C language
---------- ----------
Use **cppcheck**.
* Name regular functions (*not methods*) and variables in lower snake case * Name regular functions (*not methods*) and variables in lower snake case
(example: `foo_bar`). (example: `foo_bar`).
* Name macros in upper snake case (example: `FOO_BAR`). * Name macros in upper snake case (example: `FOO_BAR`).
@ -78,6 +135,22 @@ FooBar_init(foobar);
FooBar_do_something(foobar); FooBar_do_something(foobar);
``` ```
* Mark variables and parameters with `const` if you don't plan to modify them
* Only omit braces (curly brackets) of a block if it's statement is placed on
the same line as conditional statement:
```c
// Good:
if (foo) return bar;
if (foo) {
return bar;
}
// Bad:
if (foo)
return bar;
```
Python Python
@ -90,6 +163,8 @@ Nothing here yet.
Ruby Ruby
---- ----
* Freeze objects if you don't plan to modify them
### Matz's Ruby interpreter ### Matz's Ruby interpreter
Use **RuboCop**. See [bindings/ruby/.rubocop.yml](/bindings/ruby/.rubocop.yml) Use **RuboCop**. See [bindings/ruby/.rubocop.yml](/bindings/ruby/.rubocop.yml)

View File

@ -48,7 +48,7 @@ zero). Work-in-progress APIs can change at any time.
* [Declarations](/include/kernaux/arch/) * [Declarations](/include/kernaux/arch/)
* [Functions](/include/kernaux/asm/) * [Functions](/include/kernaux/asm/)
* Generic types * Generic types
* [File](/include/kernaux/generic/file.h) (*work in progress*) * [File](/include/kernaux/generic/file.h) (*non-breaking since* **?.?.?**)
* [Example](/examples/generic_file.c) * [Example](/examples/generic_file.c)
* [Memory allocator](/include/kernaux/generic/malloc.h) (*non-breaking since* **?.?.?**) * [Memory allocator](/include/kernaux/generic/malloc.h) (*non-breaking since* **?.?.?**)
* [Example](/examples/generic_malloc.c) * [Example](/examples/generic_malloc.c)
@ -62,7 +62,7 @@ zero). Work-in-progress APIs can change at any time.
* [Example](/examples/pfa.c) * [Example](/examples/pfa.c)
* Data formats * Data formats
* [ELF](/include/kernaux/elf.h) (*work in progress*) * [ELF](/include/kernaux/elf.h) (*work in progress*)
* [Master Boot Record](/include/kernaux/mbr.h) (*work in progress*) * [MBR](/include/kernaux/mbr.h) (*work in progress*)
* [Multiboot 2 (GRUB 2)](/include/kernaux/multiboot2.h) (*work in progress*) * [Multiboot 2 (GRUB 2)](/include/kernaux/multiboot2.h) (*work in progress*)
* Utilities * Utilities
* [Measurement units utils](/include/kernaux/units.h) (*work in progress*) * [Measurement units utils](/include/kernaux/units.h) (*work in progress*)
@ -70,17 +70,15 @@ zero). Work-in-progress APIs can change at any time.
* [Memory map](/include/kernaux/memmap.h.in) (*non-breaking since* **0.4.0**) * [Memory map](/include/kernaux/memmap.h.in) (*non-breaking since* **0.4.0**)
* [Example](/examples/memmap.c) * [Example](/examples/memmap.c)
* [printf format parser](/include/kernaux/printf_fmt.h) (*work in progress*) * [printf format parser](/include/kernaux/printf_fmt.h) (*work in progress*)
* Code from [https://github.com/mpaland/printf](https://github.com/mpaland/printf). Thank you!
* [Example](/examples/printf_fmt.c) * [Example](/examples/printf_fmt.c)
* Usual functions * Usual functions
* [itoa/ftoa replacement](/include/kernaux/ntoa.h) (*non-breaking since* **0.4.0**) * [itoa/ftoa replacement](/include/kernaux/ntoa.h) (*non-breaking since* **0.4.0**)
* [Example](/examples/ntoa.c) * [Example](/examples/ntoa.c)
* [printf replacement](/include/kernaux/printf.h.in) (*non-breaking since* **?.?.?**) * [printf replacement](/include/kernaux/printf.h.in) (*non-breaking since* **?.?.?**)
* Code from [https://github.com/mpaland/printf](https://github.com/mpaland/printf). Thank you! * [Example: fprintf](/examples/printf_file.c)
* [Example: fprintf](/examples/fprintf.c) * [Example: vfprintf](/examples/printf_file_va.c)
* [Example: vfprintf](/examples/fprintf_va.c) * [Example: snprintf](/examples/printf_str.c)
* [Example: snprintf](/examples/snprintf.c) * [Example: vsnprintf](/examples/printf_str_va.c)
* [Example: vsnprintf](/examples/snprintf_va.c)
* libc replacement (*work in progress*) * libc replacement (*work in progress*)
* [ctype.h](/libc/include/ctype.h) * [ctype.h](/libc/include/ctype.h)
* [inttypes.h](/libc/include/inttypes.h) * [inttypes.h](/libc/include/inttypes.h)

View File

@ -1,7 +1,7 @@
# The code was taken from Marco Paland's printf. # The code was taken from Marco Paland's printf.
# Copyright (c) 2014-2019 Marco Paland <info@paland.com> # Copyright (c) 2014-2019 Marco Paland <info@paland.com>
# Copyright (c) 2020-2022 Alex Kotov # Copyright (c) 2021-2022 Alex Kotov
# TODO: add remaining tests from # TODO: add remaining tests from
# https://github.com/mpaland/printf/blob/master/test/test_suite.cpp # https://github.com/mpaland/printf/blob/master/test/test_suite.cpp

View File

@ -65,7 +65,7 @@ AC_ARG_WITH( [asm], AS_HELP_STRING([--without-asm], [without
AC_ARG_WITH( [cmdline], AS_HELP_STRING([--without-cmdline], [without command line parser])) AC_ARG_WITH( [cmdline], AS_HELP_STRING([--without-cmdline], [without command line parser]))
AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils])) AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils]))
AC_ARG_WITH( [free-list], AS_HELP_STRING([--without-free-list], [without free list memory allocator])) AC_ARG_WITH( [free-list], AS_HELP_STRING([--without-free-list], [without free list memory allocator]))
AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record])) AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without MBR utils]))
AC_ARG_WITH( [memmap], AS_HELP_STRING([--without-memmap], [without memory map])) AC_ARG_WITH( [memmap], AS_HELP_STRING([--without-memmap], [without memory map]))
AC_ARG_WITH( [multiboot2], AS_HELP_STRING([--without-multiboot2], [without Multiboot 2 information parser])) AC_ARG_WITH( [multiboot2], AS_HELP_STRING([--without-multiboot2], [without Multiboot 2 information parser]))
AC_ARG_WITH( [ntoa], AS_HELP_STRING([--without-ntoa], [without itoa/ftoa])) AC_ARG_WITH( [ntoa], AS_HELP_STRING([--without-ntoa], [without itoa/ftoa]))
@ -248,7 +248,7 @@ AS_IF([test "$with_asm" = yes], [AC_DEFINE([WITH_ASM], [1]
AS_IF([test "$with_cmdline" = yes], [AC_DEFINE([WITH_CMDLINE], [1], [with command line parser])]) AS_IF([test "$with_cmdline" = yes], [AC_DEFINE([WITH_CMDLINE], [1], [with command line parser])])
AS_IF([test "$with_elf" = yes], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])]) AS_IF([test "$with_elf" = yes], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])])
AS_IF([test "$with_free_list" = yes], [AC_DEFINE([WITH_FREE_LIST], [1], [with free list memory allocator])]) AS_IF([test "$with_free_list" = yes], [AC_DEFINE([WITH_FREE_LIST], [1], [with free list memory allocator])])
AS_IF([test "$with_mbr" = yes], [AC_DEFINE([WITH_MBR], [1], [with Master Boot Record])]) AS_IF([test "$with_mbr" = yes], [AC_DEFINE([WITH_MBR], [1], [with MBR utils])])
AS_IF([test "$with_memmap" = yes], [AC_DEFINE([WITH_MEMMAP], [1], [with memory map])]) AS_IF([test "$with_memmap" = yes], [AC_DEFINE([WITH_MEMMAP], [1], [with memory map])])
AS_IF([test "$with_multiboot2" = yes], [AC_DEFINE([WITH_MULTIBOOT2], [1], [with Multiboot 2 information parser])]) AS_IF([test "$with_multiboot2" = yes], [AC_DEFINE([WITH_MULTIBOOT2], [1], [with Multiboot 2 information parser])])
AS_IF([test "$with_ntoa" = yes], [AC_DEFINE([WITH_NTOA], [1], [with ntoa])]) AS_IF([test "$with_ntoa" = yes], [AC_DEFINE([WITH_NTOA], [1], [with ntoa])])

View File

@ -21,26 +21,6 @@ cmdline_LDADD = $(top_builddir)/libkernaux.la
cmdline_SOURCES = main.c cmdline.c cmdline_SOURCES = main.c cmdline.c
endif endif
###########
# fprintf #
###########
if WITH_PRINTF
TESTS += fprintf
fprintf_LDADD = $(top_builddir)/libkernaux.la
fprintf_SOURCES = main.c fprintf.c
endif
##############
# fprintf_va #
##############
if WITH_PRINTF
TESTS += fprintf_va
fprintf_va_LDADD = $(top_builddir)/libkernaux.la
fprintf_va_SOURCES = main.c fprintf_va.c
endif
################ ################
# generic_file # # generic_file #
################ ################
@ -103,6 +83,26 @@ pfa_LDADD = $(top_builddir)/libkernaux.la
pfa_SOURCES = main.c pfa.c pfa_SOURCES = main.c pfa.c
endif endif
###############
# printf_file #
###############
if WITH_PRINTF
TESTS += printf_file
printf_file_LDADD = $(top_builddir)/libkernaux.la
printf_file_SOURCES = main.c printf_file.c
endif
##################
# printf_file_va #
##################
if WITH_PRINTF
TESTS += printf_file_va
printf_file_va_LDADD = $(top_builddir)/libkernaux.la
printf_file_va_SOURCES = main.c printf_file_va.c
endif
############## ##############
# printf_fmt # # printf_fmt #
############## ##############
@ -113,24 +113,24 @@ printf_fmt_LDADD = $(top_builddir)/libkernaux.la
printf_fmt_SOURCES = main.c printf_fmt.c printf_fmt_SOURCES = main.c printf_fmt.c
endif endif
############ ##############
# snprintf # # printf_str #
############ ##############
if WITH_PRINTF if WITH_PRINTF
TESTS += snprintf TESTS += printf_str
snprintf_LDADD = $(top_builddir)/libkernaux.la printf_str_LDADD = $(top_builddir)/libkernaux.la
snprintf_SOURCES = main.c snprintf.c printf_str_SOURCES = main.c printf_str.c
endif endif
############### #################
# snprintf_va # # printf_str_va #
############### #################
if WITH_PRINTF if WITH_PRINTF
TESTS += snprintf_va TESTS += printf_str_va
snprintf_va_LDADD = $(top_builddir)/libkernaux.la printf_str_va_LDADD = $(top_builddir)/libkernaux.la
snprintf_va_SOURCES = main.c snprintf_va.c printf_str_va_SOURCES = main.c printf_str_va.c
endif endif
############### ###############

View File

@ -82,48 +82,48 @@ KERNAUX_STATIC_TEST_STRUCT_SIZE(KernAux_Arch_I386_DTE, 8);
*/ */
struct KernAux_Arch_I386_TSS { struct KernAux_Arch_I386_TSS {
// 0x00 // 0x00
unsigned prev_tss : 16; uint16_t prev_tss;
unsigned _zero0 : 16; uint16_t _zero0;
// 0x04 // 0x04
unsigned esp0 : 32; uint32_t esp0;
unsigned ss0 : 16; uint16_t ss0;
unsigned _zero1 : 16; uint16_t _zero1;
unsigned esp1 : 32; uint32_t esp1;
unsigned ss1 : 16; uint16_t ss1;
unsigned _zero2 : 16; uint16_t _zero2;
unsigned esp2 : 32; uint32_t esp2;
unsigned ss2 : 16; uint16_t ss2;
unsigned _zero3 : 16; uint16_t _zero3;
// 0x1c // 0x1c
unsigned cr3 : 32; uint32_t cr3;
unsigned eip : 32; uint32_t eip;
unsigned eflags : 32; uint32_t eflags;
unsigned eax : 32; uint32_t eax;
unsigned ecx : 32; uint32_t ecx;
unsigned edx : 32; uint32_t edx;
unsigned ebx : 32; uint32_t ebx;
unsigned esp : 32; uint32_t esp;
unsigned ebp : 32; uint32_t ebp;
unsigned esi : 32; uint32_t esi;
unsigned edi : 32; uint32_t edi;
// 0x48 // 0x48
unsigned es : 16; uint16_t es;
unsigned _zero4 : 16; uint16_t _zero4;
unsigned cs : 16; uint16_t cs;
unsigned _zero5 : 16; uint16_t _zero5;
unsigned ss : 16; uint16_t ss;
unsigned _zero6 : 16; uint16_t _zero6;
unsigned ds : 16; uint16_t ds;
unsigned _zero7 : 16; uint16_t _zero7;
unsigned fs : 16; uint16_t fs;
unsigned _zero8 : 16; uint16_t _zero8;
unsigned gs : 16; uint16_t gs;
unsigned _zero9 : 16; uint16_t _zero9;
unsigned ldt : 16; uint16_t ldt;
unsigned _zero10 : 16; uint16_t _zero10;
// 0x64 // 0x64
unsigned _zero11 : 16; uint16_t _zero11;
unsigned io_map_base : 16; uint16_t io_map_base;
} }
KERNAUX_PACKING_ATTR; KERNAUX_PACKING_ATTR;

View File

@ -1,9 +1,9 @@
/** /**
* The code was taken from musl libc. * The code was taken from musl libc.
* *
* Copyright (c) 2011 Rich Felker * Copyright (c) 2011 Rich Felker
* Copyright (c) 2020-2022 Alex Kotov * Copyright (c) 2022 Alexander Monakov
* Copyright (c) 2022 Alexander Monakov * Copyright (c) 2022 Alex Kotov
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H

View File

@ -2,7 +2,7 @@
* The code was taken from musl libc. * The code was taken from musl libc.
* *
* Copyright (c) 2011-2015 Rich Felker * Copyright (c) 2011-2015 Rich Felker
* Copyright (c) 2020-2022 Alex Kotov * Copyright (c) 2022 Alex Kotov
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H

View File

@ -3,8 +3,8 @@
* *
* Copyright (c) 2011 Nicholas J. Kain * Copyright (c) 2011 Nicholas J. Kain
* Copyright (c) 2011-2012 Rich Felker * Copyright (c) 2011-2012 Rich Felker
* Copyright (c) 2020-2022 Alex Kotov
* Copyright (c) 2022 Alexander Monakov * Copyright (c) 2022 Alexander Monakov
* Copyright (c) 2022 Alex Kotov
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H

View File

@ -3,8 +3,8 @@
* *
* Copyright (c) 2011 Nicholas J. Kain * Copyright (c) 2011 Nicholas J. Kain
* Copyright (c) 2011-2012 Rich Felker * Copyright (c) 2011-2012 Rich Felker
* Copyright (c) 2020-2022 Alex Kotov
* Copyright (c) 2022 Alexander Monakov * Copyright (c) 2022 Alexander Monakov
* Copyright (c) 2022 Alex Kotov
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H

View File

@ -2,7 +2,7 @@
* The code was inspired by the Embedded Artistry's libmemory. * The code was inspired by the Embedded Artistry's libmemory.
* *
* Copyright (c) 2017-2022 Embedded Artistry LLC * Copyright (c) 2017-2022 Embedded Artistry LLC
* Copyright (c) 2020-2022 Alex Kotov * Copyright (c) 2022 Alex Kotov
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H

View File

@ -2,7 +2,7 @@
* The code was taken from Marco Paland's printf. * The code was taken from Marco Paland's printf.
* *
* Copyright (c) 2014-2019 Marco Paland <info@paland.com> * Copyright (c) 2014-2019 Marco Paland <info@paland.com>
* Copyright (c) 2020-2022 Alex Kotov * Copyright (c) 2021-2022 Alex Kotov
* *
* Tiny [v]fprintf, sfprintf and [v]snprintf implementation, optimized for speed * Tiny [v]fprintf, sfprintf and [v]snprintf implementation, optimized for speed
* on embedded systems with a very limited resources. These routines are thread * on embedded systems with a very limited resources. These routines are thread

View File

@ -2,7 +2,7 @@
* The code was taken from Marco Paland's printf. * The code was taken from Marco Paland's printf.
* *
* Copyright (c) 2014-2019 Marco Paland <info@paland.com> * Copyright (c) 2014-2019 Marco Paland <info@paland.com>
* Copyright (c) 2020-2022 Alex Kotov * Copyright (c) 2021-2022 Alex Kotov
*/ */
#ifdef HAVE_CONFIG_H #ifdef HAVE_CONFIG_H