From 8837ad6ff1b64c3d4deeb108ed8ddd29fba9cabb Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Thu, 14 Oct 2021 09:15:19 +0200 Subject: [PATCH] Berry stability fix --- lib/libesp32/Berry/src/be_vm.c | 24 +++++++++++++++++------- tasmota/xdrv_52_9_berry.ino | 1 + 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/lib/libesp32/Berry/src/be_vm.c b/lib/libesp32/Berry/src/be_vm.c index 27cd4f685..915977cda 100644 --- a/lib/libesp32/Berry/src/be_vm.c +++ b/lib/libesp32/Berry/src/be_vm.c @@ -786,27 +786,34 @@ newframe: /* a new call frame */ dispatch(); } opcase(GETMBR): { - bvalue *a = RA(), *b = RKB(), *c = RKC(); + bvalue a_temp; /* copy result to a temp variable because the stack may be relocated in virtual member calls */ + // bvalue *a = RA(), *b = RKB(), *c = RKC(); + bvalue *b = RKB(), *c = RKC(); if (var_isinstance(b) && var_isstr(c)) { - obj_attribute(vm, b, var_tostr(c), a); + obj_attribute(vm, b, var_tostr(c), &a_temp); reg = vm->reg; } else if (var_isclass(b) && var_isstr(c)) { - class_attribute(vm, b, c, a); + class_attribute(vm, b, c, &a_temp); reg = vm->reg; } else if (var_ismodule(b) && var_isstr(c)) { - module_attribute(vm, b, c, a); + module_attribute(vm, b, c, &a_temp); reg = vm->reg; } else { attribute_error(vm, "attribute", b, c); } + bvalue *a = RA(); + *a = a_temp; /* assign the resul to the specified register on the updated stack */ dispatch(); } opcase(GETMET): { - bvalue *a = RA(), *b = RKB(), *c = RKC(); + bvalue a_temp; /* copy result to a temp variable because the stack may be relocated in virtual member calls */ + bvalue *b = RKB(), *c = RKC(); if (var_isinstance(b) && var_isstr(c)) { binstance *obj = var_toobj(b); - int type = obj_attribute(vm, b, var_tostr(c), a); + int type = obj_attribute(vm, b, var_tostr(c), &a_temp); reg = vm->reg; + bvalue *a = RA(); + *a = a_temp; if (basetype(type) == BE_FUNCTION) { /* check if the object is a superinstance, if so get the lowest possible subclass */ while (obj->sub) { @@ -819,7 +826,10 @@ newframe: /* a new call frame */ str(be_instance_name(obj)), str(var_tostr(c))); } } else if (var_ismodule(b) && var_isstr(c)) { - module_attribute(vm, b, c, &a[1]); + module_attribute(vm, b, c, &a_temp); + reg = vm->reg; + bvalue *a = RA(); + a[1] = a_temp; var_settype(a, NOT_METHOD); } else { attribute_error(vm, "method", b, c); diff --git a/tasmota/xdrv_52_9_berry.ino b/tasmota/xdrv_52_9_berry.ino index 8940b807e..091a1d608 100644 --- a/tasmota/xdrv_52_9_berry.ino +++ b/tasmota/xdrv_52_9_berry.ino @@ -120,6 +120,7 @@ void BerryDumpErrorAndClear(bvm *vm, bool berry_console) { top = be_top(vm); // update top after dump } else { AddLog(LOG_LEVEL_ERROR, PSTR(D_LOG_BERRY "Exception> '%s' - %s"), be_tostring(berry.vm, -2), be_tostring(berry.vm, -1)); + be_tracestack(vm); } } else { be_dumpstack(vm);