Berry callback now passes 5 arguments instead of 4 (in line with documentation) (#22908)

This commit is contained in:
s-hadinger 2025-01-31 12:20:52 +01:00 committed by GitHub
parent 7dd6b999ca
commit 0288157fdb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 8 deletions

View File

@ -30,6 +30,7 @@ All notable changes to this project will be documented in this file.
- ESP32 Platform from 2025.01.30 to 2025.01.31 (#22832) - ESP32 Platform from 2025.01.30 to 2025.01.31 (#22832)
- Berry `gpio.pin_mode` frees PWM on pin - Berry `gpio.pin_mode` frees PWM on pin
- GPIOViewer from v1.6.0 to v1.6.1 (No functional change) - GPIOViewer from v1.6.0 to v1.6.1 (No functional change)
- Berry callback now passes 5 arguments instead of 4 (in line with documentation)
### Fixed ### Fixed
- Sonoff SPM `PowerOnState` overrules `SSPMPowerOnState` in mixed 4Relay setup with 4Relay version 1.0.0 - Sonoff SPM `PowerOnState` overrules `SSPMPowerOnState` in mixed 4Relay setup with 4Relay version 1.0.0

View File

@ -19,13 +19,13 @@ enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_D
/*********************************************************************************************\ /*********************************************************************************************\
* Callback structures * Callback structures
* *
* We allow 4 parameters, or 3 if method (first arg is `self`) * We allow 5 parameters, or 4 if method (first arg is `self`)
* This could be extended if needed * This could be extended if needed
\*********************************************************************************************/ \*********************************************************************************************/
typedef int (*berry_callback_t)(int v0, int v1, int v2, int v3); typedef int (*berry_callback_t)(int v0, int v1, int v2, int v3, int v4);
static int call_berry_cb(int num, int v0, int v1, int v2, int v3); static int call_berry_cb(int num, int v0, int v1, int v2, int v3, int v4);
#define BERRY_CB(n) int berry_cb_##n(int v0, int v1, int v2, int v3) { return call_berry_cb(n, v0, v1, v2, v3); } #define BERRY_CB(n) int berry_cb_##n(int v0, int v1, int v2, int v3, int v4) { return call_berry_cb(n, v0, v1, v2, v3, v4); }
// list the callbacks // list the callbacks
BERRY_CB(0); BERRY_CB(0);
BERRY_CB(1); BERRY_CB(1);
@ -242,7 +242,7 @@ static int be_cb_get_cb_list(bvm *vm) {
* We allow 4 parameters, or 3 if method (first arg is `self`) * We allow 4 parameters, or 3 if method (first arg is `self`)
* This could be extended if needed * This could be extended if needed
\*********************************************************************************************/ \*********************************************************************************************/
static int call_berry_cb(int num, int v0, int v1, int v2, int v3) { static int call_berry_cb(int num, int v0, int v1, int v2, int v3, int v4) {
// call berry cb dispatcher // call berry cb dispatcher
int32_t ret = 0; int32_t ret = 0;
// retrieve vm and function // retrieve vm and function
@ -259,15 +259,16 @@ static int call_berry_cb(int num, int v0, int v1, int v2, int v3) {
be_pushint(vm, v1); be_pushint(vm, v1);
be_pushint(vm, v2); be_pushint(vm, v2);
be_pushint(vm, v3); be_pushint(vm, v3);
be_pushint(vm, v4);
ret = be_pcall(vm, 4); // 4 arguments ret = be_pcall(vm, 5); // 4 arguments
if (ret != 0) { if (ret != 0) {
if (vm->obshook != NULL) (*vm->obshook)(vm, BE_OBS_PCALL_ERROR); if (vm->obshook != NULL) (*vm->obshook)(vm, BE_OBS_PCALL_ERROR);
be_pop(vm, be_top(vm)); // clear Berry stack be_pop(vm, be_top(vm)); // clear Berry stack
return 0; return 0;
} }
ret = be_toint(vm, -5); ret = be_toint(vm, -6);
be_pop(vm, 5); // remove result be_pop(vm, 6); // remove result
return ret; return ret;
} }