From 4c0d4d192c34094f29a7cb1c69bebb3a11b5771e Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Fri, 17 Jun 2022 19:06:19 +0300 Subject: [PATCH] Main: include/kernaux/malloc.h: Added --- ChangeLog | 5 +++++ Makefile.am | 3 +++ README.md | 2 ++ configure.ac | 6 ++++++ include/Makefile.am | 3 +++ include/kernaux.h.in | 1 + include/kernaux/malloc.h | 12 ++++++++++++ src/malloc.c | 8 ++++++++ 8 files changed, 40 insertions(+) create mode 100644 include/kernaux/malloc.h create mode 100644 src/malloc.c diff --git a/ChangeLog b/ChangeLog index d512818..c031157 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2022-06-17 Alex Kotov + + * configure.ac: Added package "malloc" + * include/kernaux/malloc.h: Added + 2022-06-16 Alex Kotov libkernaux 0.4.0 released diff --git a/Makefile.am b/Makefile.am index 1df1659..0d0edba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,6 +51,9 @@ endif if WITH_LIBC libkernaux_la_LIBADD += libc/libc.la endif +if WITH_MALLOC +libkernaux_la_SOURCES += src/malloc.c +endif if WITH_MBR libkernaux_la_SOURCES += src/mbr.c endif diff --git a/README.md b/README.md index 6ed3220..2818f61 100644 --- a/README.md +++ b/README.md @@ -65,6 +65,7 @@ zero). Work-in-progress APIs can change at any time. * Utilities * [Measurement units utils](/include/kernaux/units.h) (*work in progress*) * [Example: To human](/examples/units_human.c) + * [Memory allocator](/include/kernaux/malloc.h) (*work in progress*) * [Memory map](/include/kernaux/memmap.h.in) (*non-breaking since* **0.4.0**) * [Example](/examples/memmap.c) * [printf format parser](/include/kernaux/printf_fmt.h) (*work in progress*) @@ -148,6 +149,7 @@ explicitly included, use `--without-all`. * `--with[out]-cmdline` - command line parser * `--with[out]-io` - input/output +* `--with[out]-malloc` - memory allocator * `--with[out]-memmap` - memory map * `--with[out]-ntoa` - itoa/ftoa * `--with[out]-printf` - printf diff --git a/configure.ac b/configure.ac index 1786793..be7bef6 100644 --- a/configure.ac +++ b/configure.ac @@ -62,6 +62,7 @@ AC_ARG_WITH( [console], AS_HELP_STRING([--without-console], [without s AC_ARG_WITH( [elf], AS_HELP_STRING([--without-elf], [without ELF utils])) AC_ARG_WITH( [framebuffer], AS_HELP_STRING([--without-framebuffer], [without framebuffer])) AC_ARG_WITH( [io], AS_HELP_STRING([--without-io], [without input/output])) +AC_ARG_WITH( [malloc], AS_HELP_STRING([--without-malloc], [without memory allocator])) AC_ARG_WITH( [mbr], AS_HELP_STRING([--without-mbr], [without Master Boot Record])) 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])) @@ -94,6 +95,7 @@ if test -z "$with_console"; then with_console=no; fi if test -z "$with_elf"; then with_elf=no; fi if test -z "$with_framebuffer"; then with_framebuffer=no; fi if test -z "$with_io"; then with_io=no; fi +if test -z "$with_malloc"; then with_malloc=no; fi if test -z "$with_mbr"; then with_mbr=no; fi if test -z "$with_memmap"; then with_memmap=no; fi if test -z "$with_multiboot2"; then with_multiboot2=no; fi @@ -130,6 +132,7 @@ AS_IF([test "$with_console" = no ], [with_console=no], [with_cons AS_IF([test "$with_elf" = no ], [with_elf=no], [with_elf=yes]) AS_IF([test "$with_framebuffer" = no ], [with_framebuffer=no], [with_framebuffer=yes]) AS_IF([test "$with_io" = no ], [with_io=no], [with_io=yes]) +AS_IF([test "$with_malloc" = no ], [with_malloc=no], [with_malloc=yes]) AS_IF([test "$with_mbr" = no ], [with_mbr=no], [with_mbr=yes]) AS_IF([test "$with_memmap" = no ], [with_memmap=no], [with_memmap=yes]) AS_IF([test "$with_multiboot2" = no ], [with_multiboot2=no], [with_multiboot2=yes]) @@ -187,6 +190,7 @@ AM_CONDITIONAL([WITH_CONSOLE], [test "$with_console" = yes]) AM_CONDITIONAL([WITH_ELF], [test "$with_elf" = yes]) AM_CONDITIONAL([WITH_FRAMEBUFFER], [test "$with_framebuffer" = yes]) AM_CONDITIONAL([WITH_IO], [test "$with_io" = yes]) +AM_CONDITIONAL([WITH_MALLOC], [test "$with_malloc" = yes]) AM_CONDITIONAL([WITH_MBR], [test "$with_mbr" = yes]) AM_CONDITIONAL([WITH_MEMMAP], [test "$with_memmap" = yes]) AM_CONDITIONAL([WITH_MULTIBOOT2], [test "$with_multiboot2" = yes]) @@ -227,6 +231,7 @@ AS_IF([test "$with_console" = yes], [AC_DEFINE([WITH_CONSOLE], [1] AS_IF([test "$with_elf" = yes], [AC_DEFINE([WITH_ELF], [1], [with ELF utils])]) AS_IF([test "$with_framebuffer" = yes], [AC_DEFINE([WITH_FRAMEBUFFER], [1], [with framebuffer])]) AS_IF([test "$with_io" = yes], [AC_DEFINE([WITH_IO], [1], [with input/output])]) +AS_IF([test "$with_malloc" = yes], [AC_DEFINE([WITH_MALLOC], [1], [with memory allocator])]) AS_IF([test "$with_mbr" = yes], [AC_DEFINE([WITH_MBR], [1], [with Master Boot Record])]) 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])]) @@ -254,6 +259,7 @@ AS_IF([test "$with_console" = no], [AC_SUBST([comment_line_console], [// AS_IF([test "$with_elf" = no], [AC_SUBST([comment_line_elf], [//])]) AS_IF([test "$with_framebuffer" = no], [AC_SUBST([comment_line_framebuffer], [//])]) AS_IF([test "$with_io" = no], [AC_SUBST([comment_line_io], [//])]) +AS_IF([test "$with_malloc" = no], [AC_SUBST([comment_line_malloc], [//])]) AS_IF([test "$with_mbr" = no], [AC_SUBST([comment_line_mbr], [//])]) AS_IF([test "$with_memmap" = no], [AC_SUBST([comment_line_memmap], [//])]) AS_IF([test "$with_multiboot2" = no], [AC_SUBST([comment_line_multiboot2], [//])]) diff --git a/include/Makefile.am b/include/Makefile.am index ca79577..ad4b8eb 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -31,6 +31,9 @@ endif if WITH_IO nobase_include_HEADERS += kernaux/io.h endif +if WITH_MALLOC +nobase_include_HEADERS += kernaux/malloc.h +endif if WITH_MBR nobase_include_HEADERS += kernaux/mbr.h endif diff --git a/include/kernaux.h.in b/include/kernaux.h.in index 0bcbc40..6485e9b 100644 --- a/include/kernaux.h.in +++ b/include/kernaux.h.in @@ -11,6 +11,7 @@ @comment_line_elf@#include @comment_line_framebuffer@#include @comment_line_io@#include +@comment_line_malloc@#include @comment_line_mbr@#include @comment_line_memmap@#include @comment_line_multiboot2@#include diff --git a/include/kernaux/malloc.h b/include/kernaux/malloc.h new file mode 100644 index 0000000..0c00627 --- /dev/null +++ b/include/kernaux/malloc.h @@ -0,0 +1,12 @@ +#ifndef KERNAUX_INCLUDED_MALLOC +#define KERNAUX_INCLUDED_MALLOC + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/malloc.c b/src/malloc.c new file mode 100644 index 0000000..aa4f37d --- /dev/null +++ b/src/malloc.c @@ -0,0 +1,8 @@ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +__attribute__((unused)) +static const int foobar = 1;