Skip to content

Commit 0f79742

Browse files
committed
Merge branch 'develop'
2 parents c1463a4 + c36034a commit 0f79742

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1074
-622
lines changed

.clang-format

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ AlignConsecutiveBitFields:
1616
AlignConsecutiveDeclarations: None
1717
AlignEscapedNewlines: Right
1818
AlignOperands: Align
19-
SortIncludes: false
19+
SortIncludes: true
2020
InsertBraces: true # Control statements must have curly brackets
2121
AlignTrailingComments: true
2222
AllowAllArgumentsOnNextLine: true
2323
AllowAllParametersOfDeclarationOnNextLine: true
2424
AllowShortEnumsOnASingleLine: true
2525
AllowShortBlocksOnASingleLine: Empty
26-
AllowShortCaseLabelsOnASingleLine: false
26+
AllowShortCaseLabelsOnASingleLine: true
2727
AllowShortFunctionsOnASingleLine: All
2828
AllowShortLambdasOnASingleLine: All
2929
AllowShortIfStatementsOnASingleLine: Never

.clang-tidy

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
Checks: "*,
3+
-abseil-*,
4+
-altera-*,
5+
-android-*,
6+
-fuchsia-*,
7+
-google-*,
8+
-llvm*,
9+
-modernize-use-trailing-return-type,
10+
-zircon-*,
11+
-readability-else-after-return,
12+
-readability-static-accessed-through-instance,
13+
-readability-avoid-const-params-in-decls,
14+
-cppcoreguidelines-non-private-member-variables-in-classes,
15+
-misc-non-private-member-variables-in-classes,
16+
"
17+
WarningsAsErrors: ''
18+
HeaderFilterRegex: ''
19+
FormatStyle: none

.readthedocs.yaml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
version: 2
2+
build:
3+
os: ubuntu-22.04
4+
tools:
5+
python: "3.11"
6+
7+
# Build documentation in the docs/ directory with Sphinx
8+
sphinx:
9+
configuration: docs/conf.py
10+
11+
# Python configuration
12+
python:
13+
install:
14+
- requirements: docs/requirements.txt
15+
16+
formats:
17+
- pdf
18+
- epub

.vscode/settings.json

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,14 @@
44
"lwevt_type.h": "c",
55
"lwevt.h": "c",
66
"string.h": "c",
7-
"lwevt_opt.h": "c"
7+
"lwevt_opt.h": "c",
8+
"streambuf": "c",
9+
"lwmem.h": "c",
10+
"lwmem_opt.h": "c",
11+
"array": "c",
12+
"string_view": "c",
13+
"initializer_list": "c",
14+
"limits.h": "c"
815
},
916
"esbonio.sphinx.confDir": ""
1017
}

.vscode/tasks.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"version": "2.1.0",
2+
"version": "2.0.0",
33
"tasks": [
44
{
55
"type": "cppbuild",

AUTHORS

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Tilen Majerle <[email protected]>
2+
3+
Tilen Majerle <[email protected]>
4+

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
## Develop
44

5+
## v2.2.0
6+
7+
- Rework library CMake with removed INTERFACE type
8+
- Add `LWMEM_CFG_FULL` to allow control build configuration of the library
9+
- Implement support for simple (no realloc, no free, grow-only malloc) allocation mechanism
10+
511
## v2.1.0
612

713
- Split CMakeLists.txt files between library and executable

CMakeLists.txt

+7-22
Original file line numberDiff line numberDiff line change
@@ -6,41 +6,26 @@ project(LwLibPROJECT)
66
if(NOT PROJECT_IS_TOP_LEVEL)
77
add_subdirectory(lwmem)
88
else()
9-
# Set as executable
109
add_executable(${PROJECT_NAME})
11-
12-
# Add key executable block
1310
target_sources(${PROJECT_NAME} PUBLIC
1411
${CMAKE_CURRENT_LIST_DIR}/dev/main.cpp
1512
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c
13+
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test_simple.c
1614

1715
# win32 port
1816
${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c
1917
)
20-
21-
# Add key include paths
2218
target_include_directories(${PROJECT_NAME} PUBLIC
2319
${CMAKE_CURRENT_LIST_DIR}
2420
${CMAKE_CURRENT_LIST_DIR}/dev
2521
)
2622

27-
# Compilation definition information
28-
target_compile_definitions(${PROJECT_NAME} PUBLIC
29-
WIN32
30-
_DEBUG
31-
CONSOLE
32-
LWMEM_DEV
33-
)
34-
35-
# Compiler options
36-
target_compile_options(${PROJECT_NAME} PRIVATE
37-
-Wall
38-
-Wextra
39-
-Wpedantic
40-
)
41-
4223
# Add subdir with lwmem and link to the project
24+
set(LWMEM_OPTS_FILE ${CMAKE_CURRENT_LIST_DIR}/dev/lwmem_opts.h)
4325
add_subdirectory(lwmem)
44-
target_link_libraries(${PROJECT_NAME} lwmem)
45-
target_link_libraries(${PROJECT_NAME} lwmem_cpp)
26+
target_link_libraries(${PROJECT_NAME} PUBLIC lwmem_cpp)
27+
28+
# Add compile options to the library, which will propagate options to executable through public link
29+
target_compile_definitions(lwmem PUBLIC WIN32 _DEBUG CONSOLE LWMEM_DEV)
30+
target_compile_options(lwmem PUBLIC -Wall -Wextra -Wpedantic)
4631
endif()

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Tilen MAJERLE
3+
Copyright (c) 2024 Tilen MAJERLE
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Features
66

7-
* Written in ANSI C99, compatible with ``size_t`` for size data types
7+
* Written in C (C11), compatible with ``size_t`` for size data types
88
* Implements standard C library functions for memory allocation, malloc, calloc, realloc and free
99
* Uses *first-fit* algorithm to search for free block
1010
* Supports multiple allocation instances to split between memories and/or CPU cores
@@ -13,16 +13,17 @@
1313
* Supports embedded applications with fragmented memories
1414
* Supports automotive applications
1515
* Supports advanced free/realloc algorithms to optimize memory usage
16+
* **Since v2.2.0** Supports light implementation with allocation only
1617
* Operating system ready, thread-safe API
1718
* C++ wrapper functions
1819
* User friendly MIT license
1920

2021
## Contribute
2122

22-
Fresh contributions are always welcome. Simple instructions to proceed::
23+
Fresh contributions are always welcome. Simple instructions to proceed:
2324

2425
1. Fork Github repository
25-
2. Respect [C style & coding rules](https://github.com/MaJerle/c-code-style) used by the library
26+
2. Follow [C style & coding rules](https://github.com/MaJerle/c-code-style) already used in the project
2627
3. Create a pull request to develop branch with new features or bug fixes
2728

2829
Alternatively you may:

dev/lwmem_opts.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

66
/*
7-
* Copyright (c) 2023 Tilen MAJERLE
7+
* Copyright (c) 2024 Tilen MAJERLE
88
*
99
* Permission is hereby granted, free of charge, to any person
1010
* obtaining a copy of this software and associated documentation
@@ -41,9 +41,10 @@
4141
* Open "include/lwmem/lwmem_opt.h" and
4242
* copy & replace here settings you want to change values
4343
*/
44-
#define LWMEM_CFG_OS 1
45-
#define LWMEM_CFG_OS_MUTEX_HANDLE HANDLE
46-
#define LWMEM_CFG_ENABLE_STATS 0
47-
#define LWMEM_CFG_CLEAN_MEMORY 1
44+
#define LWMEM_CFG_OS 1
45+
#define LWMEM_CFG_OS_MUTEX_HANDLE HANDLE
46+
#define LWMEM_CFG_ENABLE_STATS 0
47+
#define LWMEM_CFG_CLEAN_MEMORY 1
48+
#define LWMEM_CFG_FULL 0
4849

4950
#endif /* LWMEM_HDR_OPTS_H */

dev/main.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1-
#include "lwmem/lwmem.h"
2-
#include "lwmem/lwmem.hpp"
31
#include <iostream>
42
#include <stdint.h>
53
#include <string.h>
4+
#include "lwmem/lwmem.h"
5+
#include "lwmem/lwmem.hpp"
66

77
extern "C" void lwmem_test_run(void);
8+
extern "C" void lwmem_test_simple_run(void);
89
extern "C" void lwmem_test_memory_structure(void);
910

1011
/* Setup manager */
11-
Lwmem::LwmemLight<1024> manager;
12+
static Lwmem::LwmemLight<1024> manager;
1213

1314
int
1415
main(void) {
16+
#if LWMEM_CFG_FULL
1517
lwmem_test_memory_structure();
1618
//lwmem_test_run();
19+
#else
20+
lwmem_test_simple_run();
21+
#endif
1722

23+
#if 1
1824
/* Test C++ code */
1925
void* ret = manager.malloc(123);
2026
std::cout << ret << std::endl;
27+
#if LWMEM_CFG_FULL
2128
manager.free(ret);
29+
#endif /* LWMEM_CFG_FULL */
30+
#endif
2231

2332
return 0;
2433
}

docs/authors/index.rst

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.. _authors:
2+
3+
Authors
4+
=======
5+
6+
List of authors and contributors to the library
7+
8+
.. literalinclude:: ../../AUTHORS

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# -- Project information -----------------------------------------------------
2424

2525
project = 'LwMEM'
26-
copyright = '2022, Tilen MAJERLE'
26+
copyright = '2023, Tilen MAJERLE'
2727
author = 'Tilen MAJERLE'
2828

2929
# Try to get branch at which this is running

docs/examples_src/example_realloc_enlarge_full.c

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1-
#define ASSERT(x) do { \
2-
if (!(x)) { \
3-
printf("Assert failed with condition (" # x ")\r\n"); \
4-
} else {\
5-
printf("Assert passed with condition (" # x ")\r\n"); \
6-
}\
7-
} while (0)
1+
#define ASSERT(x) \
2+
do { \
3+
if (!(x)) { \
4+
printf("Assert failed with condition (" #x ")\r\n"); \
5+
} else { \
6+
printf("Assert passed with condition (" #x ")\r\n"); \
7+
} \
8+
} while (0)
89

910
/* For debug purposes */
1011
lwmem_region_t* regions_used;
11-
size_t regions_count = 1; /* Use only 1 region for debug purposes of non-free areas */
12+
size_t regions_count = 1; /* Use only 1 region for debug purposes of non-free areas */
1213

1314
int
1415
main(void) {
15-
uint8_t* ptr1, *ptr2, *ptr3, *ptr4;
16-
uint8_t* rptr1, *rptr2, *rptr3, *rptr4;
16+
uint8_t *ptr1, *ptr2, *ptr3, *ptr4;
17+
uint8_t *rptr1, *rptr2, *rptr3, *rptr4;
1718

1819
/* Create regions for debug purpose */
1920
if (!lwmem_debug_create_regions(&regions_used, regions_count, 128)) {
@@ -31,11 +32,11 @@ main(void) {
3132
ptr2 = lwmem_malloc(4);
3233
ptr3 = lwmem_malloc(4);
3334
ptr4 = lwmem_malloc(16);
34-
lwmem_free(ptr1); /* Free but keep value for future comparison */
35-
lwmem_free(ptr3); /* Free but keep value for future comparison */
35+
lwmem_free(ptr1); /* Free but keep value for future comparison */
36+
lwmem_free(ptr3); /* Free but keep value for future comparison */
3637
lwmem_debug_print(1, 1);
3738
printf("Debug above is effectively state 3\r\n");
38-
lwmem_debug_save_state(); /* Every restore operations rewinds here */
39+
lwmem_debug_save_state(); /* Every restore operations rewinds here */
3940

4041
/* We always try to reallocate pointer ptr2 */
4142

@@ -53,7 +54,7 @@ main(void) {
5354
printf("State 3b\r\n");
5455
rptr2 = lwmem_realloc(ptr2, 20);
5556
lwmem_debug_print(1, 1);
56-
ASSERT(rptr2 == ptr2);
57+
ASSERT(rptr2 == ptr1);
5758

5859
/* Create 3c case */
5960
printf("\r\n------------------------------------------------------------------------\r\n");

docs/examples_src/example_realloc_enlarge_full_log.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ State 3b
5252
| 4 | 0034A548 | 1 | 56 | 48 |Free block |
5353
| 5 | 0034A580 | 0 | 0 | 0 |End of region |
5454
|-------|----------|--------|------|------------------|----------------|
55-
Assert failed with condition (rptr2 == ptr2)
55+
Assert passed with condition (rptr2 == ptr1)
5656

5757
------------------------------------------------------------------------
5858
-- > State restored to last saved!

docs/get-started/index.rst

+18-4
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,18 @@ Update cloned to latest version
5757
Add library to project
5858
^^^^^^^^^^^^^^^^^^^^^^
5959

60-
At this point it is assumed that you have successfully download library, either cloned it or from releases page.
61-
Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path
60+
At this point it is assumed that you have successfully download library, either with ``git clone`` command or with manual download from the library releases page.
61+
Next step is to add the library to the project, by means of source files to compiler inputs and header files in search path.
62+
63+
*CMake* is the main supported build system. Package comes with the ``CMakeLists.txt`` and ``library.cmake`` files, both located in the ``lwmem`` directory:
64+
65+
* ``library.cmake``: It is a fully configured set of variables and with library definition. User can include this file to the project file with ``include(path/to/library.cmake)`` and then manually use the variables provided by the file, such as list of source files, include paths or necessary compiler definitions. It is up to the user to properly use the this file on its own.
66+
* ``CMakeLists.txt``: It is a wrapper-only file and includes ``library.cmake`` file. It is used for when user wants to include the library to the main project by simply calling *CMake* ``add_subdirectory`` command, followed by ``target_link_libraries`` to link external library to the final project.
67+
68+
.. tip::
69+
Open ``library.cmake`` and analyze the provided information. Among variables, you can also find list of all possible exposed libraries for the user.
70+
71+
If you do not use the *CMake*, you can do the following:
6272

6373
* Copy ``lwmem`` folder to your project, it contains library files
6474
* Add ``lwmem/src/include`` folder to `include path` of your toolchain. This is where `C/C++` compiler can find the files during compilation process. Usually using ``-I`` flag
@@ -70,15 +80,19 @@ Configuration file
7080
^^^^^^^^^^^^^^^^^^
7181

7282
Configuration file is used to overwrite default settings defined for the essential use case.
73-
Library comes with template config file, which can be modified according to needs.
83+
Library comes with template config file, which can be modified according to the application needs.
7484
and it should be copied (or simply renamed in-place) and named ``lwmem_opts.h``
7585

7686
.. note::
7787
Default configuration template file location: ``lwmem/src/include/lwmem/lwmem_opts_template.h``.
7888
File must be renamed to ``lwmem_opts.h`` first and then copied to the project directory where compiler
7989
include paths have access to it by using ``#include "lwmem_opts.h"``.
8090

81-
List of configuration options are available in the :ref:`api_lwmem_opt` section.
91+
.. tip::
92+
If you are using *CMake* build system, define the variable ``LWMEM_OPTS_FILE`` before adding library's directory to the *CMake* project.
93+
Variable must contain the path to the user options file. If not provided and to avoid build error, one will be generated in the build directory.
94+
95+
Configuration options list is available available in the :ref:`api_lwmem_opt` section.
8296
If any option is about to be modified, it should be done in configuration file
8397

8498
.. literalinclude:: ../../lwmem/src/include/lwmem/lwmem_opts_template.h

0 commit comments

Comments
 (0)