Berry fixed 'be_top is non zero' warning when calling C mapped functions (#23989)

* Berry fixed 'be_top is non zero' warning when calling C mapped functions

* Better implementation
This commit is contained in:
s-hadinger 2025-10-08 22:39:34 +02:00 committed by GitHub
parent bd0d7d0ac3
commit cdc9af224b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 0 deletions

View File

@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file.
- ESP32 Platform from 2025.09.30 to 2025.10.30, Framework (Arduino Core) from v3.1.3.250808 to v3.1.4 and IDF from v5.3.3.250801 to v5.3.4.250826 (#23971) - ESP32 Platform from 2025.09.30 to 2025.10.30, Framework (Arduino Core) from v3.1.3.250808 to v3.1.4 and IDF from v5.3.3.250801 to v5.3.4.250826 (#23971)
### Fixed ### Fixed
- Berry fixed 'be_top is non zero' warning when calling C mapped functions
### Removed ### Removed

View File

@ -11,6 +11,7 @@
#include "be_mapping.h" #include "be_mapping.h"
#include "be_exec.h" #include "be_exec.h"
#include "be_vm.h"
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
@ -580,8 +581,17 @@ int be_call_c_func(bvm *vm, const void * func, const char * return_type, const c
if (return_type != NULL && return_type[0] == '&') { if (return_type != NULL && return_type[0] == '&') {
if (c_args < 8) { p[c_args] = (intptr_t) &return_len; } if (c_args < 8) { p[c_args] = (intptr_t) &return_len; }
} }
// We do some special trickery here, we need to set be_top to zero
// but in the same time we need to keep argument '1' to set the instance
// later. So we increment first vm->reg and we set vm->top to the same value
uint32_t reg_save = (argc > 0) ? 1 : 0;
vm->reg += reg_save;
vm->top = vm->reg;
intptr_t ret = 0; intptr_t ret = 0;
if (f) ret = (*f)(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]); if (f) ret = (*f)(p[0], p[1], p[2], p[3], p[4], p[5], p[6], p[7]);
// now we restore vm->reg
vm->reg -= reg_save;
vm->top = vm->reg + reg_save;
// berry_log_C("be_call_c_func '%s' -> '%s': (%i,%i,%i,%i,%i,%i) -> %i", return_type, arg_type, p[0], p[1], p[2], p[3], p[4], p[5], ret); // berry_log_C("be_call_c_func '%s' -> '%s': (%i,%i,%i,%i,%i,%i) -> %i", return_type, arg_type, p[0], p[1], p[2], p[3], p[4], p[5], ret);
if ((return_type == NULL) || (strlen(return_type) == 0)) { be_return_nil(vm); } // does not return if ((return_type == NULL) || (strlen(return_type) == 0)) { be_return_nil(vm); } // does not return