Berry add explicit error log when memory allocation fails (#20807)

This commit is contained in:
s-hadinger 2024-02-25 21:17:08 +01:00 committed by GitHub
parent 3dcd8d7f13
commit 55be1866ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 12 additions and 0 deletions

View File

@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- QMC5883l check for overflow and scale reading (#20643) - QMC5883l check for overflow and scale reading (#20643)
- TasMesh support for LWT messages (#20392) - TasMesh support for LWT messages (#20392)
- Show calculated heat index if temperature and humidity is available with ``#define USE_HEAT_INDEX`` (#4771) - 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 ### Breaking Changed

View File

@ -79,6 +79,10 @@ void be_throw(bvm *vm, int errorcode)
#if BE_USE_PERF_COUNTERS #if BE_USE_PERF_COUNTERS
vm->counter_exc++; vm->counter_exc++;
#endif #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) { if (vm->errjmp) {
vm->errjmp->status = errorcode; vm->errjmp->status = errorcode;
exec_throw(vm->errjmp); exec_throw(vm->errjmp);

View File

@ -676,6 +676,7 @@ enum beobshookevents {
BE_OBS_GC_END, /**< end of GC, arg = allocated size */ BE_OBS_GC_END, /**< end of GC, arg = allocated size */
BE_OBS_VM_HEARTBEAT, /**< VM heartbeat called every million instructions */ BE_OBS_VM_HEARTBEAT, /**< VM heartbeat called every million instructions */
BE_OBS_STACK_RESIZE_START, /**< Berry stack resized */ BE_OBS_STACK_RESIZE_START, /**< Berry stack resized */
BE_OBS_MALLOC_FAIL, /**< Memory allocation failed */
}; };
typedef int (*bctypefunc)(bvm*, const void*); /**< bctypefunc */ typedef int (*bctypefunc)(bvm*, const void*); /**< bctypefunc */

View File

@ -298,6 +298,12 @@ void BerryObservability(bvm *vm, int event...) {
} }
} }
break; 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: default:
break; break;
} }