Merge branch 'develop'

This commit is contained in:
Tilen Majerle 2021-04-11 10:58:58 +02:00
commit 53e784a79d
26 changed files with 148 additions and 37 deletions

3
.github/FUNDING.yml vendored Normal file
View File

@ -0,0 +1,3 @@
# These are supported funding model platforms
custom: ['paypal.me/tilz0R']

35
CHANGELOG.md Normal file
View File

@ -0,0 +1,35 @@
# Changelog
## Develop
## v1.5.0
- Add option to cleanup memory on free and realloc operations
## v1.4.0
- New artistic code style
- Replace configuration
- Several bug fixes
## v1.3.0
- Added option for custom LwMEM instance for complete isolation
- Added `_ex` functions for extended features for custom instances
- Added macros for backward-compatible, default instance, allocation functions
- Added option to force LwMEM to allocate memory at specific region
- Added win32 examples
## v1.2.0
- Fix comments to easily undestand architecture
- Migrate examples to CMSIS-OS v2
- Use pre-increment instead of post-increment
- Other C code style fixes
## v1.1.0
- Added support for thread-safety application
- Added boundary check of all internal pointers
- Added tests code directly in library
- Bug fixes

View File

@ -29,7 +29,7 @@
* This file is part of Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H
@ -42,7 +42,9 @@
* Open "include/lwmem/lwmem_opt.h" and
* copy & replace here settings you want to change values
*/
#define LWMEM_CFG_OS 1
#define LWMEM_CFG_OS_MUTEX_HANDLE HANDLE
#define LWMEM_CFG_OS 1
#define LWMEM_CFG_OS_MUTEX_HANDLE HANDLE
#define LWMEM_CFG_ENABLE_STATS 0
#define LWMEM_CFG_CLEAN_MEMORY 1
#endif /* OW_HDR_OPTS_H */
#endif /* LWMEM_HDR_OPTS_H */

View File

@ -26,27 +26,32 @@ project = 'LwMEM'
copyright = '2020, Tilen MAJERLE'
author = 'Tilen MAJERLE'
# The full version, including alpha/beta/rc tags
version = '1.4.0'
# Try to get branch at which this is running
# and try to determine which version to display in sphinx
# Version is using git tag if on master or "latest-develop" if on develop branch
version = ''
git_branch = ''
# Get current branch
res = os.popen('git branch').read().strip()
for line in res.split("\n"):
if line[0] == '*':
git_branch = line[1:].strip()
# Decision for display version
try:
if git_branch.index('develop') >= 0:
version = "latest-develop"
except Exception:
print("Exception for index check")
git_branch = git_branch.replace('(HEAD detached at ', '').replace(')', '')
if git_branch.find('master') >= 0 or git_branch.find('main') >= 0:
version = os.popen('git describe --tags --abbrev=0').read().strip()
if version == '':
version = 'v0.0.0'
elif git_branch.find('develop') != -1 and not (git_branch.find('develop-') >= 0 or git_branch.find('develop/') >= 0):
version = 'latest-develop'
else:
version = 'branch-' + git_branch
# For debugging purpose
# For debugging purpose only
print("GIT BRANCH: " + git_branch)
print("VERSION: " + version)
print("GIT VERSION: " + version)
# -- General configuration ---------------------------------------------------
@ -123,7 +128,7 @@ master_doc = 'index'
#
#
breathe_projects = {
"lwmem": "_build/xml/"
"lwmem": "_build/xml/"
}
breathe_default_project = "lwmem"
breathe_default_members = ('members', 'undoc-members')

View File

@ -5,10 +5,13 @@ Welcome to the documentation for version |version|.
LwMEM is lightweight dynamic memory manager optimized for embedded systems.
.. image:: static/images/logo.svg
:align: center
.. rst-class:: center
.. rst-class:: index_links
:ref:`download_library` :ref:`getting_started` `Open Github <https://github.com/MaJerle/lwmem>`_
:ref:`download_library` :ref:`getting_started` `Open Github <https://github.com/MaJerle/lwmem>`_ `Donate <https://paypal.me/tilz0R>`_
Features
^^^^^^^^

View File

@ -1,7 +1,7 @@
breathe>=4.9.1
colorama
docutils>=0.14
sphinx>=2.0.1
docutils==0.16
sphinx>=3.5.1
sphinx_rtd_theme
sphinx-tabs
sphinxcontrib-svg2pdfconverter

1
docs/static/images/logo.drawio vendored Normal file
View File

@ -0,0 +1 @@
<mxfile host="Electron" modified="2020-12-05T00:19:20.329Z" agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/12.3.2 Chrome/78.0.3904.113 Electron/7.1.2 Safari/537.36" etag="V0MvXZe_QYE6MFCmOuaH" version="12.3.2" type="device" pages="1"><diagram id="Wsjaadh77UIxB9X1bxos" name="Page-1">jZLLbsMgEEW/xstItkmiZNs0TaUm2WSRNTITgwoei+Di9OuL68EPRZW6gjnzAO4lYTvTHiyv5QkF6CRPRZuw1yTPs3SzCUtHHj3ZrgmUVgkqGsFFfUPsJNooAfdZoUPUTtVzWGBVQeFmjFuLfl52Qz0/teYlPIFLwfUzvSrhZE83q3Tk76BKGU/OUsoYHosJ3CUX6CeI7RO2s4iu35l2B7oTL+rS9739kR0uZqFy/2k4L8QStsYfz6Z5WW4/bvqaLWjKF9cNPfjoT/sT3dg9ogwWm0pANylL2IuXysGl5kWX9cH4wKQzmtJ3Z/FzkGsdyA0rR96yLh60SEPw/JB4K7AO2gmihx0ADTj7CCWUZctV30K/LI+xHz3L1mSEnPgVfeT0Tcph9Khk2JCYMRxN+81Nvj7b/wA=</diagram></mxfile>

3
docs/static/images/logo.svg vendored Normal file
View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="166px" height="56px" viewBox="-0.5 -0.5 166 56" content="&lt;mxfile host=&quot;Electron&quot; modified=&quot;2020-12-05T00:19:26.005Z&quot; agent=&quot;Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/12.3.2 Chrome/78.0.3904.113 Electron/7.1.2 Safari/537.36&quot; etag=&quot;trUYxRFioqzHlO3q13mI&quot; version=&quot;12.3.2&quot; type=&quot;device&quot; pages=&quot;1&quot;&gt;&lt;diagram id=&quot;Wsjaadh77UIxB9X1bxos&quot; name=&quot;Page-1&quot;&gt;jZLLbsMgEEW/xstItkmiZNs0TaUm2WSRNTITgwoei+Di9OuL68EPRZW6gjnzAO4lYTvTHiyv5QkF6CRPRZuw1yTPs3SzCUtHHj3ZrgmUVgkqGsFFfUPsJNooAfdZoUPUTtVzWGBVQeFmjFuLfl52Qz0/teYlPIFLwfUzvSrhZE83q3Tk76BKGU/OUsoYHosJ3CUX6CeI7RO2s4iu35l2B7oTL+rS9739kR0uZqFy/2k4L8QStsYfz6Z5WW4/bvqaLWjKF9cNPfjoT/sT3dg9ogwWm0pANylL2IuXysGl5kWX9cH4wKQzmtJ3Z/FzkGsdyA0rR96yLh60SEPw/JB4K7AO2gmihx0ADTj7CCWUZctV30K/LI+xHz3L1mSEnPgVfeT0Tcph9Khk2JCYMRxN+81Nvj7b/wA=&lt;/diagram&gt;&lt;/mxfile&gt;"><defs/><g><rect x="3" y="3" width="160" height="50" rx="7.5" ry="7.5" fill="#ffffff" stroke="#000000" stroke-width="6" pointer-events="all"/><g transform="translate(17.5,6.5)"><switch><foreignObject style="overflow:visible;" pointer-events="all" width="130" height="41" requiredFeatures="http://www.w3.org/TR/SVG11/feature#Extensibility"><div xmlns="http://www.w3.org/1999/xhtml" style="display: inline-block; font-size: 36px; font-family: Helvetica; color: rgb(0, 0, 0); line-height: 1.2; vertical-align: top; width: 131px; white-space: nowrap; overflow-wrap: normal; text-align: center;"><div xmlns="http://www.w3.org/1999/xhtml" style="display:inline-block;text-align:inherit;text-decoration:inherit;white-space:normal;">LwMEM</div></div></foreignObject><text x="65" y="39" fill="#000000" text-anchor="middle" font-size="36px" font-family="Helvetica">LwMEM</text></switch></g></g></svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H

View File

@ -27,7 +27,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef __MAIN_H
#define __MAIN_H

View File

@ -27,7 +27,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#include "main.h"
#include "cmsis_os.h"

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H

View File

@ -27,7 +27,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef __MAIN_H
#define __MAIN_H

View File

@ -27,7 +27,7 @@
* OTHER DEALINGS IN THE SOFTWARE.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#include "main.h"
#include "lwmem/lwmem.h"

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H

View File

@ -29,12 +29,11 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_H
#define LWMEM_HDR_H
#include <string.h>
#include <stdint.h>
#include <limits.h>
#include "lwmem/lwmem_opt.h"
@ -67,6 +66,14 @@ typedef struct lwmem_block {
or `0` when block is considered free */
} lwmem_block_t;
/**
* \brief Statistics structure
*/
typedef struct {
uint32_t nr_alloc; /*!< Number of all allocated blocks in single instance */
uint32_t nr_free; /*!< Number of frees in the LwMEM instance */
} lwmem_stats_t;
/**
* \brief LwMEM main structure
*/
@ -78,6 +85,9 @@ typedef struct lwmem {
#if LWMEM_CFG_OS || __DOXYGEN__
LWMEM_CFG_OS_MUTEX_HANDLE mutex; /*!< System mutex for OS */
#endif /* LWMEM_CFG_OS || __DOXYGEN__ */
#if LWMEM_CFG_ENABLE_STATS || __DOXYGEN__
lwmem_stats_t stats; /*!< Statistics */
#endif /* LWMEM_CFG_ENABLE_STATS || __DOXYGEN__ */
#if defined(LWMEM_DEV) && !__DOXYGEN__
lwmem_block_t start_block_first_use; /*!< Value of start block for very first time.
This is used only during validation process and is removed in final use */

View File

@ -29,11 +29,14 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPT_H
#define LWMEM_HDR_OPT_H
/* Uncomment to ignore user options (or set macro in compiler flags) */
/* #define LWMEM_IGNORE_USER_OPTS */
/* Include application options */
#ifndef LWMEM_IGNORE_USER_OPTS
#include "lwmem_opts.h"
@ -82,6 +85,24 @@ extern "C" {
#define LWMEM_CFG_ALIGN_NUM ((size_t)4)
#endif
/**
* \brief Enables `1` or disables `0` memory cleanup on free operation (or realloc).
*
* It resets unused memory to `0x00` and prevents other applications seeing old data.
* It is disabled by default since it has performance penalties.
* /
#ifndef LWMEM_CFG_CLEAN_MEMORY
#define LWMEM_CFG_CLEAN_MEMORY 0
#endif
/**
* \brief Enables `1` or disables `0` statistics in the library
*
*/
#ifndef LWMEM_CFG_ENABLE_STATS
#define LWMEM_CFG_ENABLE_STATS 0
#endif
/**
* \}
*/

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_OPTS_H
#define LWMEM_HDR_OPTS_H

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#ifndef LWMEM_HDR_SYS_H
#define LWMEM_HDR_SYS_H

View File

@ -29,9 +29,10 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#include <limits.h>
#include <string.h>
#include "lwmem/lwmem.h"
#if LWMEM_CFG_OS
@ -144,6 +145,13 @@
#define LWMEM_UNPROTECT(lw)
#endif /* !LWMEM_CFG_OS */
/* Statistics part */
#if LWMEM_CFG_ENABLE_STATS
#define LWMEM_INC_STATS(field) (++(field))
#else
#define LWMEM_INC_STATS(field)
#endif /* LWMEM_CFG_ENABLE_STATS */
/**
* \brief LwMEM default structure used by application
*/
@ -202,6 +210,11 @@ static void
prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) {
lwmem_block_t* prev;
/* Check valid inputs */
if (nb == NULL) {
return;
}
/*
* Try to find position to put new block in-between
* Search until all free block addresses are lower than entry block
@ -218,6 +231,17 @@ prv_insert_free_block(lwmem_t* const lw, lwmem_block_t* nb) {
* Previous block is last free block before input block
*/
#if LWMEM_CFG_CLEAN_MEMORY
/*
* Reset user memory. This is to reset memory
* after it has been freed by the application.
*
* By doing this, we protect data left by app
* and we make sure new allocations cannot see old information
*/
LWMEM_MEMSET(LWMEM_GET_PTR_FROM_BLOCK(nb), 0x00, nb->size - LWMEM_BLOCK_META_SIZE);
#endif /* LWMEM_CFG_RESET_MEMORY */
/*
* Check if previous block and input block together create one big contiguous block
* If this is the case, merge blocks together and increase previous block by input block size
@ -387,6 +411,8 @@ prv_alloc(lwmem_t* const lw, const lwmem_region_t* region, const size_t size) {
prv_split_too_big_block(lw, curr, final_size); /* Split block if it is too big */
LWMEM_BLOCK_SET_ALLOC(curr); /* Set block as allocated */
LWMEM_INC_STATS(LWMEM_GET_LW(lw)->stats.nr_alloc);
return retval;
}
@ -403,6 +429,8 @@ prv_free(lwmem_t* const lw, void* const ptr) {
LWMEM_GET_LW(lw)->mem_available_bytes += block->size; /* Increase available bytes */
prv_insert_free_block(lw, block); /* Put block back to list of free block */
LWMEM_INC_STATS(LWMEM_GET_LW(lw)->stats.nr_free);
}
}

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#include "system/lwmem_sys.h"

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#include "system/lwmem_sys.h"

View File

@ -29,7 +29,7 @@
* This file is part of LwMEM - Lightweight dynamic memory manager library.
*
* Author: Tilen MAJERLE <tilen@majerle.eu>
* Version: v1.4.0
* Version: v1.5.0
*/
#include "system/lwmem_sys.h"