[FL-2274] Inventing streams and moving FFF to them (#981)

* Streams: string stream
* String stream: updated insert/delete api
* Streams: generic stream interface and string stream implementation
* Streams: helpers for insert and delete_and_insert
* FFF: now compatible with streams
* MinUnit: introduced tests with arguments
* FFF: stream access violation
* Streams: copy data between streams
* Streams: file stream
* FFF: documentation
* FFStream: documentation
* FFF: alloc as file
* MinUnit: support for nested tests
* Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout.
* FFF: simplified file open function
* Streams: unit tests
* FFF: tests
* Streams: declare cache_size constant as define, to allow variable modified arrays
* FFF: lib moved to a separate folder
* iButton: new FFF
* RFID: new FFF
* Animations: new FFF
* IR: new FFF
* NFC: new FFF
* Flipper file format: delete lib
* U2F: new FFF
* Subghz: new FFF and streams
* Streams: read line
* Streams: split
* FuriCore: implement memset with extra asserts
* FuriCore: implement extra heap asserts without inventing memset
* Scene manager: protected access to the scene id stack with a size check
* NFC worker: dirty fix for issue where hal_nfc was busy on app start
* Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc.
* FuriCore: cleanup memmgr code.
* Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console.
* Memmgr: added ability to track allocations and deallocations through console.
* FFStream: some speedup
* Streams, FF: minor fixes
* Tests: restore
* File stream: a slightly more thread-safe version of file_stream_delete_and_insert

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
SG
2022-02-19 05:53:46 +10:00
committed by GitHub
parent 242241987e
commit 274c12fc56
257 changed files with 4480 additions and 2657 deletions

View File

@@ -290,7 +290,7 @@ ButtonMenuItem* button_menu_add_item(
}
ButtonMenu* button_menu_alloc(void) {
ButtonMenu* button_menu = furi_alloc(sizeof(ButtonMenu));
ButtonMenu* button_menu = malloc(sizeof(ButtonMenu));
button_menu->view = view_alloc();
view_set_orientation(button_menu->view, ViewOrientationVertical);
view_set_context(button_menu->view, button_menu);

View File

@@ -65,7 +65,7 @@ static void button_panel_view_draw_callback(Canvas* canvas, void* _model);
static bool button_panel_view_input_callback(InputEvent* event, void* context);
ButtonPanel* button_panel_alloc() {
ButtonPanel* button_panel = furi_alloc(sizeof(ButtonPanel));
ButtonPanel* button_panel = malloc(sizeof(ButtonPanel));
button_panel->view = view_alloc();
view_set_orientation(button_panel->view, ViewOrientationVertical);
view_set_context(button_panel->view, button_panel);
@@ -173,7 +173,7 @@ void button_panel_add_item(
ButtonItem** button_item_ptr =
button_panel_get_item(model, matrix_place_x, matrix_place_y);
furi_check(*button_item_ptr == NULL);
*button_item_ptr = furi_alloc(sizeof(ButtonItem));
*button_item_ptr = malloc(sizeof(ButtonItem));
ButtonItem* button_item = *button_item_ptr;
button_item->callback = callback;
button_item->callback_context = callback_context;

View File

@@ -695,7 +695,7 @@ static void byte_input_reset_model_input_data(ByteInputModel* model) {
* @return ByteInput instance pointer
*/
ByteInput* byte_input_alloc() {
ByteInput* byte_input = furi_alloc(sizeof(ByteInput));
ByteInput* byte_input = malloc(sizeof(ByteInput));
byte_input->view = view_alloc();
view_set_context(byte_input->view, byte_input);
view_allocate_model(byte_input->view, ViewModelTypeLocking, sizeof(ByteInputModel));

View File

@@ -60,7 +60,7 @@ static bool dialog_view_input_callback(InputEvent* event, void* context) {
}
Dialog* dialog_alloc() {
Dialog* dialog = furi_alloc(sizeof(Dialog));
Dialog* dialog = malloc(sizeof(Dialog));
dialog->view = view_alloc();
view_set_context(dialog->view, dialog);
view_allocate_model(dialog->view, ViewModelTypeLockFree, sizeof(DialogModel));

View File

@@ -114,7 +114,7 @@ static bool dialog_ex_view_input_callback(InputEvent* event, void* context) {
}
DialogEx* dialog_ex_alloc() {
DialogEx* dialog_ex = furi_alloc(sizeof(DialogEx));
DialogEx* dialog_ex = malloc(sizeof(DialogEx));
dialog_ex->view = view_alloc();
view_set_context(dialog_ex->view, dialog_ex);
view_allocate_model(dialog_ex->view, ViewModelTypeLockFree, sizeof(DialogExModel));

View File

@@ -14,7 +14,7 @@ static bool empty_screen_view_input_callback(InputEvent* event, void* context) {
}
EmptyScreen* empty_screen_alloc() {
EmptyScreen* empty_screen = furi_alloc(sizeof(EmptyScreen));
EmptyScreen* empty_screen = malloc(sizeof(EmptyScreen));
empty_screen->view = view_alloc();
view_set_context(empty_screen->view, empty_screen);
view_set_draw_callback(empty_screen->view, empty_screen_view_draw_callback);
@@ -31,4 +31,4 @@ void empty_screen_free(EmptyScreen* empty_screen) {
View* empty_screen_get_view(EmptyScreen* empty_screen) {
furi_assert(empty_screen);
return empty_screen->view;
}
}

View File

@@ -181,7 +181,7 @@ static bool file_select_init_inner(FileSelect* file_select) {
}
FileSelect* file_select_alloc() {
FileSelect* file_select = furi_alloc(sizeof(FileSelect));
FileSelect* file_select = malloc(sizeof(FileSelect));
file_select->view = view_alloc();
file_select->fs_api = furi_record_open("storage");
@@ -278,7 +278,7 @@ bool file_select_fill_strings(FileSelect* file_select) {
uint8_t string_counter = 0;
uint16_t file_counter = 0;
const uint8_t name_length = 100;
char* name = furi_alloc(name_length);
char* name = malloc(name_length);
uint16_t first_file_index = 0;
with_view_model(
@@ -346,7 +346,7 @@ bool file_select_fill_count(FileSelect* file_select) {
uint16_t file_counter = 0;
const uint8_t name_length = 100;
char* name = furi_alloc(name_length);
char* name = malloc(name_length);
if(!storage_dir_open(directory, file_select->path)) {
storage_dir_close(directory);
@@ -397,7 +397,7 @@ void file_select_set_selected_file_internal(FileSelect* file_select, const char*
File* directory = storage_file_alloc(file_select->fs_api);
const uint8_t name_length = 100;
char* name = furi_alloc(name_length);
char* name = malloc(name_length);
uint16_t file_position = 0;
bool file_found = false;
@@ -472,4 +472,4 @@ void file_select_set_selected_file(FileSelect* file_select, const char* filename
if(!file_select_fill_strings(file_select)) {
file_select->callback(false, file_select->context);
}
}
}

View File

@@ -125,7 +125,7 @@ static void menu_exit(void* context) {
}
Menu* menu_alloc() {
Menu* menu = furi_alloc(sizeof(Menu));
Menu* menu = malloc(sizeof(Menu));
menu->view = view_alloc(menu->view);
view_set_context(menu->view, menu);
view_allocate_model(menu->view, ViewModelTypeLocking, sizeof(MenuModel));

View File

@@ -108,7 +108,7 @@ void popup_stop_timer(void* context) {
}
Popup* popup_alloc() {
Popup* popup = furi_alloc(sizeof(Popup));
Popup* popup = malloc(sizeof(Popup));
popup->view = view_alloc();
popup->timer = osTimerNew(popup_timer_callback, osTimerOnce, popup, NULL);
furi_assert(popup->timer);

View File

@@ -120,7 +120,7 @@ static bool submenu_view_input_callback(InputEvent* event, void* context) {
}
Submenu* submenu_alloc() {
Submenu* submenu = furi_alloc(sizeof(Submenu));
Submenu* submenu = malloc(sizeof(Submenu));
submenu->view = view_alloc();
view_set_context(submenu->view, submenu);
view_allocate_model(submenu->view, ViewModelTypeLocking, sizeof(SubmenuModel));

View File

@@ -128,7 +128,7 @@ static bool text_box_view_input_callback(InputEvent* event, void* context) {
}
TextBox* text_box_alloc() {
TextBox* text_box = furi_alloc(sizeof(TextBox));
TextBox* text_box = malloc(sizeof(TextBox));
text_box->view = view_alloc();
view_set_context(text_box->view, text_box);
view_allocate_model(text_box->view, ViewModelTypeLocking, sizeof(TextBoxModel));

View File

@@ -410,7 +410,7 @@ void text_input_timer_callback(void* context) {
}
TextInput* text_input_alloc() {
TextInput* text_input = furi_alloc(sizeof(TextInput));
TextInput* text_input = malloc(sizeof(TextInput));
text_input->view = view_alloc();
view_set_context(text_input->view, text_input);
view_allocate_model(text_input->view, ViewModelTypeLocking, sizeof(TextInputModel));

View File

@@ -28,7 +28,7 @@ bool validator_is_file_callback(const char* text, string_t error, void* context)
ValidatorIsFile*
validator_is_file_alloc_init(const char* app_path_folder, const char* app_extension) {
ValidatorIsFile* instance = furi_alloc(sizeof(ValidatorIsFile));
ValidatorIsFile* instance = malloc(sizeof(ValidatorIsFile));
instance->app_path_folder = app_path_folder;
instance->app_extension = app_extension;

View File

@@ -276,7 +276,7 @@ void variable_item_list_process_ok(VariableItemList* variable_item_list) {
}
VariableItemList* variable_item_list_alloc() {
VariableItemList* variable_item_list = furi_alloc(sizeof(VariableItemList));
VariableItemList* variable_item_list = malloc(sizeof(VariableItemList));
variable_item_list->view = view_alloc();
view_set_context(variable_item_list->view, variable_item_list);
view_allocate_model(

View File

@@ -52,7 +52,7 @@ static bool gui_widget_view_input_callback(InputEvent* event, void* context) {
}
Widget* widget_alloc() {
Widget* widget = furi_alloc(sizeof(Widget));
Widget* widget = malloc(sizeof(Widget));
widget->view = view_alloc();
view_set_context(widget->view, widget);
view_allocate_model(widget->view, ViewModelTypeLocking, sizeof(GuiWidgetModel));

View File

@@ -61,14 +61,14 @@ WidgetElement* widget_element_button_create(
ButtonCallback callback,
void* context) {
// Allocate and init model
GuiButtonModel* model = furi_alloc(sizeof(GuiButtonModel));
GuiButtonModel* model = malloc(sizeof(GuiButtonModel));
model->button_type = button_type;
model->callback = callback;
model->context = context;
string_init_set_str(model->text, text);
// Allocate and init Element
WidgetElement* gui_button = furi_alloc(sizeof(WidgetElement));
WidgetElement* gui_button = malloc(sizeof(WidgetElement));
gui_button->parent = NULL;
gui_button->input = gui_button_input;
gui_button->draw = gui_button_draw;

View File

@@ -29,7 +29,7 @@ WidgetElement* widget_element_frame_create(
uint8_t height,
uint8_t radius) {
// Allocate and init model
GuiFrameModel* model = furi_alloc(sizeof(GuiFrameModel));
GuiFrameModel* model = malloc(sizeof(GuiFrameModel));
model->x = x;
model->y = y;
model->width = width;
@@ -37,7 +37,7 @@ WidgetElement* widget_element_frame_create(
model->radius = radius;
// Allocate and init Element
WidgetElement* gui_frame = furi_alloc(sizeof(WidgetElement));
WidgetElement* gui_frame = malloc(sizeof(WidgetElement));
gui_frame->parent = NULL;
gui_frame->input = NULL;
gui_frame->draw = gui_frame_draw;

View File

@@ -27,13 +27,13 @@ WidgetElement* widget_element_icon_create(uint8_t x, uint8_t y, const Icon* icon
furi_assert(icon);
// Allocate and init model
GuiIconModel* model = furi_alloc(sizeof(GuiIconModel));
GuiIconModel* model = malloc(sizeof(GuiIconModel));
model->x = x;
model->y = y;
model->icon = icon;
// Allocate and init Element
WidgetElement* gui_icon = furi_alloc(sizeof(WidgetElement));
WidgetElement* gui_icon = malloc(sizeof(WidgetElement));
gui_icon->parent = NULL;
gui_icon->input = NULL;
gui_icon->draw = gui_icon_draw;

View File

@@ -46,7 +46,7 @@ WidgetElement* widget_element_string_create(
furi_assert(text);
// Allocate and init model
GuiStringModel* model = furi_alloc(sizeof(GuiStringModel));
GuiStringModel* model = malloc(sizeof(GuiStringModel));
model->x = x;
model->y = y;
model->horizontal = horizontal;
@@ -55,7 +55,7 @@ WidgetElement* widget_element_string_create(
string_init_set_str(model->text, text);
// Allocate and init Element
WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
gui_string->parent = NULL;
gui_string->input = NULL;
gui_string->draw = gui_string_draw;

View File

@@ -47,7 +47,7 @@ WidgetElement* widget_element_string_multiline_create(
furi_assert(text);
// Allocate and init model
GuiStringMultiLineModel* model = furi_alloc(sizeof(GuiStringMultiLineModel));
GuiStringMultiLineModel* model = malloc(sizeof(GuiStringMultiLineModel));
model->x = x;
model->y = y;
model->horizontal = horizontal;
@@ -56,7 +56,7 @@ WidgetElement* widget_element_string_multiline_create(
string_init_set_str(model->text, text);
// Allocate and init Element
WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
gui_string->parent = NULL;
gui_string->input = NULL;
gui_string->draw = gui_string_multiline_draw;

View File

@@ -50,7 +50,7 @@ WidgetElement* widget_element_text_box_create(
furi_assert(text);
// Allocate and init model
GuiTextBoxModel* model = furi_alloc(sizeof(GuiTextBoxModel));
GuiTextBoxModel* model = malloc(sizeof(GuiTextBoxModel));
model->x = x;
model->y = y;
model->width = width;
@@ -60,7 +60,7 @@ WidgetElement* widget_element_text_box_create(
string_init_set_str(model->text, text);
// Allocate and init Element
WidgetElement* gui_string = furi_alloc(sizeof(WidgetElement));
WidgetElement* gui_string = malloc(sizeof(WidgetElement));
gui_string->parent = NULL;
gui_string->input = NULL;
gui_string->draw = gui_text_box_draw;