mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-12 04:41:26 +04:00
[FL-3925] JS views finished (#4155)
* js: value destructuring and tests * js: temporary fix to see size impact * js_val: reduce code size 1 * i may be stupid. * test: js_value args * Revert "js: temporary fix to see size impact" This reverts commitf51d726dba. * pvs: silence warnings * style: formatting * pvs: silence warnings? * pvs: silence warnings?? * js_value: redesign declaration types for less code * js: temporary fix to see size impact * style: formatting * pvs: fix helpful warnings * js_value: reduce .rodata size * pvs: fix helpful warning * js_value: reduce code size 1 * fix build error * style: format * Revert "js: temporary fix to see size impact" This reverts commitd6a46f0179. * style: format * js: move to new arg parser * style: format * feat: all js views done * js, toolbox: generalize string owning * toolbox: silence pvs warning --------- Co-authored-by: hedger <hedger@nanode.su> Co-authored-by: hedger <hedger@users.noreply.github.com>
This commit is contained in:
@@ -29,6 +29,7 @@ env.Append(
|
||||
File("float_tools.h"),
|
||||
File("value_index.h"),
|
||||
File("tar/tar_archive.h"),
|
||||
File("str_buffer.h"),
|
||||
File("stream/stream.h"),
|
||||
File("stream/file_stream.h"),
|
||||
File("stream/string_stream.h"),
|
||||
|
||||
18
lib/toolbox/str_buffer.c
Normal file
18
lib/toolbox/str_buffer.c
Normal file
@@ -0,0 +1,18 @@
|
||||
#include "str_buffer.h"
|
||||
|
||||
const char* str_buffer_make_owned_clone(StrBuffer* buffer, const char* str) {
|
||||
char* owned = strdup(str);
|
||||
buffer->n_owned_strings++;
|
||||
buffer->owned_strings =
|
||||
realloc(buffer->owned_strings, buffer->n_owned_strings * sizeof(const char*)); // -V701
|
||||
buffer->owned_strings[buffer->n_owned_strings - 1] = owned;
|
||||
return owned;
|
||||
}
|
||||
|
||||
void str_buffer_clear_all_clones(StrBuffer* buffer) {
|
||||
for(size_t i = 0; i < buffer->n_owned_strings; i++) {
|
||||
free(buffer->owned_strings[i]);
|
||||
}
|
||||
free(buffer->owned_strings);
|
||||
buffer->owned_strings = NULL;
|
||||
}
|
||||
47
lib/toolbox/str_buffer.h
Normal file
47
lib/toolbox/str_buffer.h
Normal file
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* @file str_buffer.h
|
||||
*
|
||||
* Allows you to create an owned clone of however many strings that you need,
|
||||
* then free all of them at once. Essentially the simplest possible append-only
|
||||
* unindexable array of owned C-style strings.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <furi.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief StrBuffer instance
|
||||
*
|
||||
* Place this struct directly wherever you want, it doesn't have to be `alloc`ed
|
||||
* and `free`d.
|
||||
*/
|
||||
typedef struct {
|
||||
char** owned_strings;
|
||||
size_t n_owned_strings;
|
||||
} StrBuffer;
|
||||
|
||||
/**
|
||||
* @brief Makes a owned duplicate of the provided string
|
||||
*
|
||||
* @param[in] buffer StrBuffer instance
|
||||
* @param[in] str Input C-style string
|
||||
*
|
||||
* @returns C-style string that contains to be valid event after `str` becomes
|
||||
* invalid
|
||||
*/
|
||||
const char* str_buffer_make_owned_clone(StrBuffer* buffer, const char* str);
|
||||
|
||||
/**
|
||||
* @brief Clears all owned duplicates
|
||||
*
|
||||
* @param[in] buffer StrBuffer instance
|
||||
*/
|
||||
void str_buffer_clear_all_clones(StrBuffer* buffer);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user