Merge pull request #11416 from s-hadinger/berry_mar_21

Minor fixes
This commit is contained in:
s-hadinger 2021-03-21 17:48:27 +01:00 committed by GitHub
commit d59cdf6cd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 4 deletions

View File

@ -163,8 +163,14 @@
* The default is to use the functions in the standard library.
**/
#ifdef USE_BERRY_PSRAM
extern void *special_malloc(uint32_t size);
extern void *special_realloc(void *ptr, size_t size);
#ifdef __cplusplus
extern "C" {
#endif
extern void *berry_malloc(uint32_t size);
extern void *berry_realloc(void *ptr, size_t size);
#ifdef __cplusplus
}
#endif
#define BE_EXPLICIT_MALLOC special_malloc
#define BE_EXPLICIT_REALLOC special_realloc
#else

View File

@ -317,7 +317,7 @@ extern "C" {
int32_t top = be_top(vm); // Get the number of arguments
if (top == 1 || (top == 2 && be_isint(vm, 2))) {
int32_t light_num = 0;
if (top > 0) {
if (top > 1) {
light_num = be_toint(vm, 2);
}
push_getlight(vm, light_num);

View File

@ -47,6 +47,32 @@ void checkBeTop(void) {
}
}
/*********************************************************************************************\
* Memory handler
* Use PSRAM if available
\*********************************************************************************************/
extern "C" {
void *berry_malloc(uint32_t size);
void *berry_realloc(void *ptr, size_t size);
#ifdef USE_BERRY_PSRAM
void *berry_malloc(uint32_t size) {
return special_malloc(size);
}
void *berry_realloc(void *ptr, size_t size) {
return special_realloc(ptr, size);
}
#else
void *berry_malloc(uint32_t size) {
return malloc(size);
}
void *berry_realloc(void *ptr, size_t size) {
return realloc(ptr, size);
}
#endif // USE_BERRY_PSRAM
}
/*********************************************************************************************\
* Handlers for Berry calls and async
*
@ -564,7 +590,7 @@ void HandleBerryConsoleRefresh(void)
if (svalue.length()) {
berry.log.reset(); // clear all previous logs
berry.repl_active = true; // start recording
AddLog_P(LOG_LEVEL_INFO, PSTR("BRY: received command %s"), svalue.c_str());
// AddLog_P(LOG_LEVEL_INFO, PSTR("BRY: received command %s"), svalue.c_str());
berry.log.addString(svalue.c_str(), nullptr, BERRY_CONSOLE_CMD_DELIMITER);
// Call berry