From 55be1866ad87098263c6076aa06d8bf0f13b8483 Mon Sep 17 00:00:00 2001 From: s-hadinger <49731213+s-hadinger@users.noreply.github.com> Date: Sun, 25 Feb 2024 21:17:08 +0100 Subject: [PATCH] Berry add explicit error log when memory allocation fails (#20807) --- CHANGELOG.md | 1 + lib/libesp32/berry/src/be_exec.c | 4 ++++ lib/libesp32/berry/src/berry.h | 1 + tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino | 6 ++++++ 4 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 32f9686ff..6f526a72e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file. - QMC5883l check for overflow and scale reading (#20643) - TasMesh support for LWT messages (#20392) - Show calculated heat index if temperature and humidity is available with ``#define USE_HEAT_INDEX`` (#4771) +- Berry add explicit error log when memory allocation fails ### Breaking Changed diff --git a/lib/libesp32/berry/src/be_exec.c b/lib/libesp32/berry/src/be_exec.c index 43791c66a..794987933 100644 --- a/lib/libesp32/berry/src/be_exec.c +++ b/lib/libesp32/berry/src/be_exec.c @@ -79,6 +79,10 @@ void be_throw(bvm *vm, int errorcode) #if BE_USE_PERF_COUNTERS vm->counter_exc++; #endif + /* if BE_MALLOC_FAIL then call */ + if (errorcode == BE_MALLOC_FAIL) { + if (vm->obshook != NULL) (*vm->obshook)(vm, BE_OBS_MALLOC_FAIL, vm->gc.usage); + } if (vm->errjmp) { vm->errjmp->status = errorcode; exec_throw(vm->errjmp); diff --git a/lib/libesp32/berry/src/berry.h b/lib/libesp32/berry/src/berry.h index 962a01ebb..e8ee792de 100644 --- a/lib/libesp32/berry/src/berry.h +++ b/lib/libesp32/berry/src/berry.h @@ -676,6 +676,7 @@ enum beobshookevents { BE_OBS_GC_END, /**< end of GC, arg = allocated size */ BE_OBS_VM_HEARTBEAT, /**< VM heartbeat called every million instructions */ BE_OBS_STACK_RESIZE_START, /**< Berry stack resized */ + BE_OBS_MALLOC_FAIL, /**< Memory allocation failed */ }; typedef int (*bctypefunc)(bvm*, const void*); /**< bctypefunc */ diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino index a9db89010..c31ee9f04 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_9_berry.ino @@ -298,6 +298,12 @@ void BerryObservability(bvm *vm, int event...) { } } break; + case BE_OBS_MALLOC_FAIL: + { + int32_t vm_usage2 = va_arg(param, int32_t); + AddLog(LOG_LEVEL_ERROR, D_LOG_BERRY "*** MEMORY ALLOCATION FAILED *** usage %i bytes", vm_usage2); + } + break; default: break; }