-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Improvements to heap-memory and PSRAM handling #4791
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
Changes from all commits
b96a950
516aa62
48fbb1d
9bd9d32
ec29161
32743ab
f9d0c19
39870f8
0328f5c
2c7ac77
b8bd2a7
477b13a
190262f
c665d59
1560ce4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,35 +39,29 @@ uint32_t colorBalanceFromKelvin(uint16_t kelvin, uint32_t rgb); | |
uint8_t realtimeBroadcast(uint8_t type, IPAddress client, uint16_t length, const byte *buffer, uint8_t bri=255, bool isRGBW=false); | ||
|
||
//util.cpp | ||
// PSRAM allocation wrappers | ||
#if !defined(ESP8266) && !defined(CONFIG_IDF_TARGET_ESP32C3) | ||
// memory allocation wrappers | ||
extern "C" { | ||
void *p_malloc(size_t); // prefer PSRAM over DRAM | ||
void *p_calloc(size_t, size_t); // prefer PSRAM over DRAM | ||
void *p_realloc(void *, size_t); // prefer PSRAM over DRAM | ||
void *p_realloc_malloc(void *ptr, size_t size); // realloc with malloc fallback, prefer PSRAM over DRAM | ||
inline void p_free(void *ptr) { heap_caps_free(ptr); } | ||
void *d_malloc(size_t); // prefer DRAM over PSRAM | ||
void *d_calloc(size_t, size_t); // prefer DRAM over PSRAM | ||
void *d_realloc(void *, size_t); // prefer DRAM over PSRAM | ||
void *d_realloc_malloc(void *ptr, size_t size); // realloc with malloc fallback, prefer DRAM over PSRAM | ||
// prefer DRAM over PSRAM (if available) in d_ alloc functions | ||
void *d_malloc(size_t); | ||
void *d_calloc(size_t, size_t); | ||
void *d_realloc_malloc(void *ptr, size_t size); | ||
#ifndef ESP8266 | ||
inline void d_free(void *ptr) { heap_caps_free(ptr); } | ||
#else | ||
inline void d_free(void *ptr) { free(ptr); } | ||
#endif | ||
#if defined(BOARD_HAS_PSRAM) | ||
// prefer PSRAM over DRAM in p_ alloc functions | ||
void *p_malloc(size_t); | ||
void *p_calloc(size_t, size_t); | ||
void *p_realloc_malloc(void *ptr, size_t size); | ||
inline void p_free(void *ptr) { heap_caps_free(ptr); } | ||
#else | ||
#define p_malloc d_malloc | ||
#define p_calloc d_calloc | ||
#define p_free d_free | ||
#endif | ||
} | ||
Comment on lines
+42
to
64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainRemove duplicated alloc wrappers and C-linkage; include the canonical header instead.
Replace the block with the single canonical include: -//util.cpp
-// memory allocation wrappers
-extern "C" {
- // prefer DRAM over PSRAM (if available) in d_ alloc functions
- void *d_malloc(size_t);
- void *d_calloc(size_t, size_t);
- void *d_realloc_malloc(void *ptr, size_t size);
- #ifndef ESP8266
- inline void d_free(void *ptr) { heap_caps_free(ptr); }
- #else
- inline void d_free(void *ptr) { free(ptr); }
- #endif
- #if defined(BOARD_HAS_PSRAM)
- // prefer PSRAM over DRAM in p_ alloc functions
- void *p_malloc(size_t);
- void *p_calloc(size_t, size_t);
- void *p_realloc_malloc(void *ptr, size_t size);
- inline void p_free(void *ptr) { heap_caps_free(ptr); }
- #else
- #define p_malloc d_malloc
- #define p_calloc d_calloc
- #define p_free d_free
- #endif
-}
+#include "fcn_declare.h" // allocator declarations and mappings (incl. p_realloc_malloc alias) 🏁 Script executed: #!/bin/bash
# Show any remaining extern "C" allocator decls and ensure p_realloc_malloc has a no-PSRAM alias.
rg -nP 'extern\\s*"C"\\s*{[^}]*\\bd_.*malloc' wled00 | sed -n '1,200p'
rg -n '\\bp_realloc_malloc\\b' wled00 Length of output: 110 🏁 Script executed: #!/bin/bash
# Locate fcn_declare.h
echo "Finding fcn_declare.h..."
find . -type f -name 'fcn_declare.h'
# Inspect its allocator declarations if found
FCN=$(find . -type f -name 'fcn_declare.h' | head -n1)
if [ -n "$FCN" ]; then
echo "Contents of $FCN around allocator declarations:"
rg -n 'malloc' -C3 "$FCN"
else
echo "fcn_declare.h not found"
fi
# Show the extern "C" block in bus_manager.cpp
echo 'Showing extern "C" block in wled00/bus_manager.cpp:'
rg -n 'extern "C"' -C5 wled00/bus_manager.cpp
# Check for p_realloc_malloc alias in fcn_declare.h
if [ -f "$FCN" ]; then
echo "Checking p_realloc_malloc in $FCN:"
rg -n 'p_realloc_malloc' -C2 "$FCN"
fi Length of output: 2141 🏁 Script executed: #!/bin/bash
# Inspect util.cpp for allocator definitions and linkage
echo "Searching for extern \"C\" in util.cpp:"
rg -n 'extern "C"' -C3 wled00/util.cpp
echo "--- Definitions of d_malloc, d_realloc_malloc in util.cpp ---"
rg -nP 'void\s*\*\s*d_malloc' -C3 wled00/util.cpp
rg -nP 'void\s*\*\s*d_realloc_malloc' -C3 wled00/util.cpp
echo "--- Definitions of p_realloc_malloc and p_malloc in util.cpp ---"
rg -nP 'void\s*\*\s*p_realloc_malloc' -C3 wled00/util.cpp
rg -nP 'void\s*\*\s*p_malloc' -C3 wled00/util.cpp Length of output: 2252 🏁 Script executed: #!/bin/bash
# Show first 50 lines of util.cpp to inspect includes
sed -n '1,50p' wled00/util.cpp
# Check if fcn_declare.h is included in util.cpp
rg -n '#include.*fcn_declare.h' -C2 wled00/util.cpp Length of output: 1719 Replace manual alloc wrappers in bus_manager.cpp with the canonical header and add the missing p_realloc_malloc fallback
🤖 Prompt for AI Agents
|
||
#else | ||
extern "C" { | ||
void *realloc_malloc(void *ptr, size_t size); | ||
} | ||
#define p_malloc malloc | ||
#define p_calloc calloc | ||
#define p_realloc realloc | ||
#define p_realloc_malloc realloc_malloc | ||
#define p_free free | ||
#define d_malloc malloc | ||
#define d_calloc calloc | ||
#define d_realloc realloc | ||
#define d_realloc_malloc realloc_malloc | ||
#define d_free free | ||
#endif | ||
|
||
//color mangling macros | ||
#define RGBW32(r,g,b,w) (uint32_t((byte(w) << 24) | (byte(r) << 16) | (byte(g) << 8) | (byte(b)))) | ||
|
@@ -902,7 +896,7 @@ void BusManager::esp32RMTInvertIdle() { | |
else if (lvl == RMT_IDLE_LEVEL_LOW) lvl = RMT_IDLE_LEVEL_HIGH; | ||
else continue; | ||
rmt_set_idle_level(ch, idle_out, lvl); | ||
u++ | ||
u++; | ||
} | ||
} | ||
#endif | ||
|
Uh oh!
There was an error while loading. Please reload this page.