Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about defining lfs_malloc/lfs_free as macros #894

Open
rahmanih opened this issue Nov 18, 2023 · 2 comments
Open

about defining lfs_malloc/lfs_free as macros #894

rahmanih opened this issue Nov 18, 2023 · 2 comments

Comments

@rahmanih
Copy link

rahmanih commented Nov 18, 2023

Hi,

lfs_malloc() and lfs_free() are currently provided as functions using the system malloc & free
this prevents the LittleFS from using RTOS memory allocation like the FreeRTOS pvPortMalloc() & pvPortFree()
it is possible to consider using macros instead of example

#ifndef LFS_NO_MALLOC

#ifndef lfs_malloc
#define lfs_malloc                malloc
#endif

#ifndef lfs_free
#define lfs_free                  free
#endif

#endif

regards
Haithem.

@geky
Copy link
Member

geky commented Nov 27, 2023

Hi @rahmanih, it is currently possible to override lfs_malloc/lfs_free by providing your own lfs_utils.h:

littlefs/lfs_util.h

Lines 11 to 21 in c733d9e

// Users can override lfs_util.h with their own configuration by defining
// LFS_CONFIG as a header file to include (-DLFS_CONFIG=lfs_config.h).
//
// If LFS_CONFIG is used, none of the default utils will be emitted and must be
// provided by the config file. To start, I would suggest copying lfs_util.h
// and modifying as needed.
#ifdef LFS_CONFIG
#define LFS_STRINGIZE(x) LFS_STRINGIZE2(x)
#define LFS_STRINGIZE2(x) #x
#include LFS_STRINGIZE(LFS_CONFIG)
#else

Though I've come to realize this is unnecessarily cumbersome for many util overrides, and having simple ifdefs as you mentioned would be better. It's something on my TODO list. There is some other config-related work I was batching it up with which is why I haven't gotten to it yet.

@geky
Copy link
Member

geky commented Dec 19, 2023

Improving things over here: #909

Let me know if anything looks wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants