From 73a613119b08f334c4cfc30bb6bbfd8e304c9673 Mon Sep 17 00:00:00 2001 From: Stephan Hadinger Date: Sun, 6 Jun 2021 17:41:09 +0200 Subject: [PATCH 1/3] Fix berry compiler bug #101 --- lib/libesp32/Berry/src/be_code.c | 2 +- lib/libesp32/Berry/tests/suffix.be | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/libesp32/Berry/src/be_code.c b/lib/libesp32/Berry/src/be_code.c index 68865190c..8d4a62b05 100644 --- a/lib/libesp32/Berry/src/be_code.c +++ b/lib/libesp32/Berry/src/be_code.c @@ -317,7 +317,7 @@ static void free_suffix(bfuncinfo *finfo, bexpdesc *e) be_code_freeregs(finfo, 1); } /* release object register */ - if (e->v.ss.tt == ETREG && (int)e->v.ss.obj >= nlocal) { + if (e->v.ss.tt == ETREG && (int)e->v.ss.obj >= nlocal && (e->v.ss.obj + 1 >= finfo->freereg)) { be_code_freeregs(finfo, 1); } } diff --git a/lib/libesp32/Berry/tests/suffix.be b/lib/libesp32/Berry/tests/suffix.be index 222b092d8..11f429aa7 100644 --- a/lib/libesp32/Berry/tests/suffix.be +++ b/lib/libesp32/Berry/tests/suffix.be @@ -9,3 +9,20 @@ var pairs = { for i : 0 .. keys.size() - 1 assert(pairs[keys[i]] == 'value' .. i + 1) end + +#- test cases related to #101 -# +class C var l end +c=C() +c.l=[0,1,2] + +def t_101_nok_1() return c.l[0..1] end +def t_101_ok_1() var l2 = c.l return l2[0..1] end + +t_i = 0 +def t_101_nok_2() return c.l[t_i] end +def t_101_ok_2() return c.l[0] end + +assert(t_101_nok_1() == [0, 1]) +assert(t_101_ok_1() == [0, 1]) +assert(t_101_nok_2() == 0) +assert(t_101_ok_2() == 0) From 5175653922c46e68274ec49a1aab92a04a149acb Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 6 Jun 2021 18:05:28 +0200 Subject: [PATCH 2/3] Fix compilation error --- tasmota/xdrv_12_home_assistant.ino | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 36fa9bd22..7378be79c 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -888,7 +888,11 @@ void HAssAnnounceSensors(void) TasmotaGlobal.tele_period = tele_period_save; size_t sensordata_len = ResponseLength(); char sensordata[sensordata_len+2]; // dynamically adjust the size +#ifdef MQTT_DATA_STRING + strcpy(sensordata, TasmotaGlobal.mqtt_data.c_str()); // we can use strcpy since the buffer has the right size +#else strcpy(sensordata, TasmotaGlobal.mqtt_data); // we can use strcpy since the buffer has the right size +#eindif // ******************* JSON TEST ******************* // char sensordata[512]; From d76868e136e4fc63e0c7b504c8c781a9cd9533d6 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 6 Jun 2021 18:08:31 +0200 Subject: [PATCH 3/3] Fix compilation error --- tasmota/xdrv_12_home_assistant.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xdrv_12_home_assistant.ino b/tasmota/xdrv_12_home_assistant.ino index 7378be79c..870efa30a 100644 --- a/tasmota/xdrv_12_home_assistant.ino +++ b/tasmota/xdrv_12_home_assistant.ino @@ -892,7 +892,7 @@ void HAssAnnounceSensors(void) strcpy(sensordata, TasmotaGlobal.mqtt_data.c_str()); // we can use strcpy since the buffer has the right size #else strcpy(sensordata, TasmotaGlobal.mqtt_data); // we can use strcpy since the buffer has the right size -#eindif +#endif // ******************* JSON TEST ******************* // char sensordata[512];