From 104ed789a759a344146431ded54cde9fefb063ec Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 18 Aug 2024 21:41:00 -0500 Subject: [PATCH] Update: FSS Embedded Read memory allocation logic. Move the internally managed allocation into externally managed allocation. This allows for better memory control and optimization by the caller. The use of `f_memory_array_increase()` is incorrect in several cases. Switch to `f_memory_array_resize()`. Add 2 when resizing to account for the depth position but also an additional element as a minor memory allocation optimization. Get rid of headers that should not be included. This does not address any of the other problems with the FSS Embedded Read functions. --- level_1/fl_fss/c/fss/basic_list.h | 1 - level_1/fl_fss/c/fss/embedded_list.c | 209 +++++++++++----------------- level_1/fl_fss/c/fss/embedded_list.h | 30 +++- level_1/fl_fss/c/fss/extended_list.h | 1 - level_2/fll_fss/c/fss/embedded_list.h | 2 + level_3/fss_read/c/embedded_list/fss_read.c | 11 +- level_3/fss_read/c/main/common/type.c | 12 ++ level_3/fss_read/c/main/common/type.h | 35 +++++ 8 files changed, 169 insertions(+), 132 deletions(-) diff --git a/level_1/fl_fss/c/fss/basic_list.h b/level_1/fl_fss/c/fss/basic_list.h index 2f59af5..892978d 100644 --- a/level_1/fl_fss/c/fss/basic_list.h +++ b/level_1/fl_fss/c/fss/basic_list.h @@ -24,7 +24,6 @@ // FLL-1 includes. #include -#include #ifdef __cplusplus extern "C" { diff --git a/level_1/fl_fss/c/fss/embedded_list.c b/level_1/fl_fss/c/fss/embedded_list.c index 34b20e8..97bf404 100644 --- a/level_1/fl_fss/c/fss/embedded_list.c +++ b/level_1/fl_fss/c/fss/embedded_list.c @@ -10,7 +10,7 @@ extern "C" { #ifndef _di_level_1_parameter_checking_ if (!state) return; - if (!range || !found || !delimits || !comments) { + if (!range || !found || !delimits || !comments || !state->data) { state->status = F_status_set_error(F_parameter); return; @@ -22,34 +22,29 @@ extern "C" { if (state->status == F_data_not) return; if (state->status == F_okay_eos || state->status == F_okay_stop) return; - state->status = f_memory_array_increase(state->step_small, sizeof(f_fss_nest_t), (void **) &found->depth, &found->used, &found->size); - if (F_status_is_error(state->status)) return; + fl_fss_data_embedded_list_t * const cache = (fl_fss_data_embedded_list_t *) state->data; - f_number_unsigneds_t positions_start = f_number_unsigneds_t_initialize; - - state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - if (F_status_is_error(state->status)) return; - - f_ranges_t objects = f_ranges_t_initialize; - - state->status = f_memory_array_increase(state->step_small, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - - if (F_status_is_error(state->status)) { - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); + if (!cache->positions || !cache->objects || !cache->slashes) { + state->status = F_status_set_error(F_parameter); return; } - f_number_unsigneds_t slashes = f_number_unsigneds_t_initialize; + cache->positions->used = 0; + cache->objects->used = 0; + cache->slashes->used = 0; - state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); + state->status = f_memory_array_increase(state->step_small, sizeof(f_fss_nest_t), (void **) &found->depth, &found->used, &found->size); + if (F_status_is_error(state->status)) return; - if (F_status_is_error(state->status)) { - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); + state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &cache->objects->array, &cache->objects->used, &cache->objects->size); + if (F_status_is_error(state->status)) return; - return; - } + state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &cache->positions->array, &cache->positions->used, &cache->positions->size); + if (F_status_is_error(state->status)) return; + + state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &cache->slashes->array, &cache->slashes->used, &cache->slashes->size); + if (F_status_is_error(state->status)) return; const f_number_unsigned_t delimits_used = delimits->used; const f_number_unsigned_t comments_used = comments->used; @@ -67,18 +62,18 @@ extern "C" { f_number_unsigned_t before_list_open = position_previous; - bool is_open = F_false; + uint8_t is_open = F_false; // 0x0 = false, 0x1 = true, 0x2 = false, but there is a delimited comment, comment_delimit is set. uint8_t graph_first = 0x0; // Initialize depth 1 start position. - // Positions_start.used is used as a max depth (such that positions_start.used == max depth + 1). - positions_start.array[0] = range->start; - positions_start.used = 1; + // Positions_start.used is used as a max depth (such that cache->positions->used == max depth + 1). + cache->positions->array[0] = range->start; + cache->positions->used = 1; - slashes.array[0] = 0; - slashes.used = 1; + cache->slashes->array[0] = 0; + cache->slashes->used = 1; while (range->start <= range->stop && range->start < buffer.used) { @@ -104,10 +99,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; return; @@ -115,10 +106,6 @@ extern "C" { } else { if (range->start >= buffer.used || range->start > range->stop) { - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_okay_eos : F_okay_stop; return; @@ -133,7 +120,7 @@ extern "C" { if (buffer.string[range->start] == f_fss_slash_s.string[0]) { slash_first = range->start; slash_last = range->start; - slashes.array[depth] = 1; + cache->slashes->array[depth] = 1; position_previous = range->start++; @@ -148,7 +135,7 @@ extern "C" { if (buffer.string[range->start] == f_fss_slash_s.string[0]) { slash_last = range->start++; - ++slashes.array[depth]; + ++cache->slashes->array[depth]; } else { state->status = f_utf_buffer_increment(buffer, range, 1); @@ -163,10 +150,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; return; @@ -177,10 +160,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; return; @@ -259,10 +238,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; return; @@ -273,10 +248,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; return; @@ -292,24 +263,24 @@ extern "C" { if (is_open) { bool is_object = F_false; - if (slashes.array[depth] % 2 == 0) { + if (cache->slashes->array[depth] % 2 == 0) { is_object = F_true; } range->start = slash_first; - state->status = f_memory_array_increase_by((slashes.array[depth] / 2) + 1, sizeof(f_number_unsigned_t), (void **) &delimits->array, &delimits->used, &delimits->size); + state->status = f_memory_array_increase_by((cache->slashes->array[depth] / 2) + 1, sizeof(f_number_unsigned_t), (void **) &delimits->array, &delimits->used, &delimits->size); if (F_status_is_error(state->status)) break; // Apply slash delimits, only slashes and placeholders should be present. - while (slashes.array[depth]) { + while (cache->slashes->array[depth]) { if (buffer.string[range->start] == f_fss_slash_s.string[0]) { - if (slashes.array[depth] % 2 == 1) { + if (cache->slashes->array[depth] % 2 == 1) { delimits->array[delimits->used++] = range->start; } - --slashes.array[depth]; + --cache->slashes->array[depth]; } // Delimit slashes and placeholders are required to be in the ASCII range. @@ -320,28 +291,39 @@ extern "C" { // When slashes are even, the object is valid and needs to be processed. if (is_object) { - if (++depth > positions_start.size) { - state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - if (F_status_is_error(state->status)) break; + ++depth; - state->status = f_memory_array_increase(state->step_small, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); + if (depth >= cache->objects->size) { + state->status = f_memory_array_resize(depth + 2, sizeof(f_range_t), (void **) &cache->objects->array, &cache->objects->used, &cache->objects->size); if (F_status_is_error(state->status)) break; + } - state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); + if (depth >= cache->positions->size) { + state->status = f_memory_array_resize(depth + 2, sizeof(f_number_unsigned_t), (void **) &cache->positions->array, &cache->positions->used, &cache->positions->size); if (F_status_is_error(state->status)) break; } - if (positions_start.used < depth) { - positions_start.used = depth; - slashes.used = depth; + if (depth >= cache->slashes->size) { + state->status = f_memory_array_resize(depth + 2, sizeof(f_number_unsigned_t), (void **) &cache->slashes->array, &cache->slashes->used, &cache->slashes->size); + if (F_status_is_error(state->status)) break; } - positions_start.array[depth] = newline_last + 1; + cache->objects->array[depth].start = line_start; + cache->objects->array[depth].stop = before_list_open; + cache->positions->array[depth] = newline_last + 1; + cache->slashes->array[depth] = 0; + + if (cache->objects->used < depth) { + cache->objects->used = depth; + } - objects.array[depth].start = line_start; - objects.array[depth].stop = before_list_open; + if (cache->positions->used < depth) { + cache->positions->used = depth; + } - slashes.array[depth] = 0; + if (cache->slashes->used < depth) { + cache->slashes->used = depth; + } } } else { @@ -400,10 +382,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; return; @@ -414,10 +392,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; return; @@ -427,28 +401,37 @@ extern "C" { if (buffer.string[range->start] == f_fss_eol_s.string[0]) { ++depth; - if (depth >= positions_start.size) { - state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); + if (depth >= cache->objects->size) { + state->status = f_memory_array_resize(depth + 2, sizeof(f_range_t), (void **) &cache->objects->array, &cache->objects->used, &cache->objects->size); if (F_status_is_error(state->status)) break; + } - state->status = f_memory_array_increase(state->step_small, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); + if (depth >= cache->positions->size) { + state->status = f_memory_array_resize(depth + 2, sizeof(f_number_unsigned_t), (void **) &cache->positions->array, &cache->positions->used, &cache->positions->size); if (F_status_is_error(state->status)) break; + } - state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); + if (depth >= cache->slashes->size) { + state->status = f_memory_array_resize(depth + 2, sizeof(f_number_unsigned_t), (void **) &cache->slashes->array, &cache->slashes->used, &cache->slashes->size); if (F_status_is_error(state->status)) break; } - if (positions_start.used <= depth) { - positions_start.used = depth + 1; - slashes.used = depth + 1; - } + cache->objects->array[depth].start = line_start; + cache->objects->array[depth].stop = before_list_open; + cache->positions->array[depth] = range->start + 1; + cache->slashes->array[depth] = 0; - positions_start.array[depth] = range->start + 1; + if (cache->objects->used <= depth) { + cache->objects->used = depth + 1; + } - objects.array[depth].start = line_start; - objects.array[depth].stop = before_list_open; + if (cache->positions->used <= depth) { + cache->positions->used = depth + 1; + } - slashes.array[depth] = 0; + if (cache->slashes->used <= depth) { + cache->slashes->used = depth + 1; + } if (graph_first == 0x2) { state->status = f_memory_array_increase(state->step_small, sizeof(f_number_unsigned_t), (void **) &delimits->array, &delimits->used, &delimits->size); @@ -505,10 +488,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; return; @@ -519,10 +498,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; return; @@ -563,10 +538,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; return; @@ -577,10 +548,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; return; @@ -588,10 +555,12 @@ extern "C" { } if (buffer.string[range->start] == f_fss_eol_s.string[0]) { - state->status = f_memory_array_increase(state->step_small, sizeof(f_fss_nest_t), (void **) &found->depth, &found->used, &found->size); - if (F_status_is_error(state->status)) break; + if (depth >= found->used) { + state->status = f_memory_array_resize(depth + 2, sizeof(f_fss_nest_t), (void **) &found->depth, &found->used, &found->size); + if (F_status_is_error(state->status)) break; + } - if (found->depth[depth].used == found->depth[depth].size) { + if (found->depth[depth].used >= found->depth[depth].size) { state->status = f_memory_array_increase(state->step_small, sizeof(f_fss_item_t), (void **) &found->depth[depth].array, &found->depth[depth].used, &found->depth[depth].size); if (F_status_is_error(state->status)) break; } @@ -607,11 +576,11 @@ extern "C" { found->depth[depth].array[position].parent = found->depth[depth - 1].used; // Only assign object positions for nested objects. - found->depth[depth].array[position].object.start = objects.array[depth].start; - found->depth[depth].array[position].object.stop = objects.array[depth].stop; + found->depth[depth].array[position].object.start = cache->objects->array[depth].start; + found->depth[depth].array[position].object.stop = cache->objects->array[depth].stop; } - found->depth[depth].array[position].content.array[0].start = positions_start.array[depth]; + found->depth[depth].array[position].content.array[0].start = cache->positions->array[depth]; found->depth[depth].array[position].content.array[0].stop = newline_last; found->depth[depth].array[position].content.used = 1; @@ -638,10 +607,6 @@ extern "C" { state->status = f_utf_buffer_increment(buffer, range, 1); if (F_status_is_error(state->status)) break; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - if (range->start >= buffer.used) { state->status = F_okay_eos; } else if (range->start > range->stop) { @@ -694,10 +659,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_end_not_nest_eos : F_end_not_nest_stop; return; @@ -708,10 +669,6 @@ extern "C" { delimits->used = delimits_used; comments->used = comments_used; - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - state->status = (range->start >= buffer.used) ? F_data_not_eos : F_data_not_stop; return; @@ -773,10 +730,6 @@ extern "C" { if (F_status_is_error(state->status)) break; } // while - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &positions_start.array, &positions_start.used, &positions_start.size); - f_memory_array_resize(0, sizeof(f_range_t), (void **) &objects.array, &objects.used, &objects.size); - f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &slashes.array, &slashes.used, &slashes.size); - delimits->used = delimits_used; comments->used = comments_used; diff --git a/level_1/fl_fss/c/fss/embedded_list.h b/level_1/fl_fss/c/fss/embedded_list.h index 8564ba0..f1077bc 100644 --- a/level_1/fl_fss/c/fss/embedded_list.h +++ b/level_1/fl_fss/c/fss/embedded_list.h @@ -24,13 +24,39 @@ // FLL-1 includes. #include -#include #ifdef __cplusplus extern "C" { #endif /** + * A structure for use as the state.data for fss-0008 processing. + * + * This is used for caching purposes to help reduce memory allocations. + * + * Properties: + * - objects: A pointer to the objects array. + * - positions: A pointer to the positions array. + * - slashes: A pointer to the slashes array. + */ +#ifndef _di_fl_fss_data_embedded_list_t_ + typedef struct { + f_ranges_t *objects; + f_number_unsigneds_t *positions; + f_number_unsigneds_t *slashes; + } fl_fss_data_embedded_list_t; + + #define fl_fss_data_embedded_list_t_initialize { 0, 0, 0 } + + #define macro_fl_fss_data_embedded_list_t_initialize_1(objects, positions, slashes) { objects, positions, slashes } + + #define macro_fl_fss_data_embedded_list_t_clear(data) \ + data.objects = 0; \ + data.positions = 0; \ + data.slashes = 0; +#endif // _di_fl_fss_data_embedded_list_t_ + +/** * Read an fss-0008 content. * * This will record where delimit placeholders exist but will not apply the delimits. @@ -60,6 +86,8 @@ extern "C" { * There is no "callbacks" structure. * There is no data structure passed to these functions. * + * The state.data must be of type fl_fss_data_embedded_list_t with all properties as valid. + * * When state.interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. diff --git a/level_1/fl_fss/c/fss/extended_list.h b/level_1/fl_fss/c/fss/extended_list.h index a61421d..a6e9468 100644 --- a/level_1/fl_fss/c/fss/extended_list.h +++ b/level_1/fl_fss/c/fss/extended_list.h @@ -24,7 +24,6 @@ // FLL-1 includes. #include -#include #ifdef __cplusplus extern "C" { diff --git a/level_2/fll_fss/c/fss/embedded_list.h b/level_2/fll_fss/c/fss/embedded_list.h index 76c978a..b1b83b5 100644 --- a/level_2/fll_fss/c/fss/embedded_list.h +++ b/level_2/fll_fss/c/fss/embedded_list.h @@ -51,6 +51,8 @@ extern "C" { * There is no "callbacks" structure. * There is no data structure passed to these functions. * + * The state.data must be of type fl_fss_data_embedded_list_t with all properties as valid. + * * When state.interrupt() returns, only F_interrupt and F_interrupt_not are processed. * Error bit designates an error but must be passed along with F_interrupt. * All other statuses are ignored. diff --git a/level_3/fss_read/c/embedded_list/fss_read.c b/level_3/fss_read/c/embedded_list/fss_read.c index ec65d66..77f488c 100644 --- a/level_3/fss_read/c/embedded_list/fss_read.c +++ b/level_3/fss_read/c/embedded_list/fss_read.c @@ -21,7 +21,16 @@ extern "C" { fss_read_main_t * const main = (fss_read_main_t *) void_main; - fll_fss_embedded_list_read(main->setting.buffer, &main->setting.range, &main->setting.nest, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.comments, &main->setting.state); + { + f_state_t state = main->setting.state; + fl_fss_data_embedded_list_t cache = macro_fl_fss_data_embedded_list_t_initialize_1(&main->cache.objects, &main->cache.positions, &main->cache.slashes); + + state.data = (void *) &cache; + + fll_fss_embedded_list_read(main->setting.buffer, &main->setting.range, &main->setting.nest, &main->setting.delimits_object, &main->setting.delimits_content, &main->setting.comments, &state); + + main->setting.state.status = state.status; + } if (F_status_is_error(main->setting.state.status)) { if (F_status_set_fine(main->setting.state.status) == F_interrupt) return; diff --git a/level_3/fss_read/c/main/common/type.c b/level_3/fss_read/c/main/common/type.c index 9483224..de2485c 100644 --- a/level_3/fss_read/c/main/common/type.c +++ b/level_3/fss_read/c/main/common/type.c @@ -4,6 +4,17 @@ extern "C" { #endif +#ifndef _di_fss_read_cache_delete_ + void fss_read_cache_delete(fss_read_cache_t * const cache) { + + if (!cache) return; + + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &cache->positions.array, &cache->positions.used, &cache->positions.size); + f_memory_array_resize(0, sizeof(f_range_t), (void **) &cache->objects.array, &cache->objects.used, &cache->objects.size); + f_memory_array_resize(0, sizeof(f_number_unsigned_t), (void **) &cache->slashes.array, &cache->slashes.used, &cache->slashes.size); + } +#endif // _di_fss_read_cache_delete_ + #ifndef _di_fss_read_depth_delete_ void fss_read_depth_delete(fss_read_depth_t * const depth) { @@ -63,6 +74,7 @@ extern "C" { if (!main) return; fll_program_data_delete(&main->program); + fss_read_cache_delete(&main->cache); fss_read_setting_delete(&main->setting); } #endif // _di_fss_read_main_delete_ diff --git a/level_3/fss_read/c/main/common/type.h b/level_3/fss_read/c/main/common/type.h index b444883..a16e87f 100644 --- a/level_3/fss_read/c/main/common/type.h +++ b/level_3/fss_read/c/main/common/type.h @@ -115,6 +115,23 @@ extern "C" { #endif // _di_fss_read_files_t_ /** + * The FSS Read cache. + * + * positions: A positions array used by the fll_fss_embedded_list_read() function. + * objects: An objects array used by the fll_fss_embedded_list_read() function. + * slashes: A slashes array used by the fll_fss_embedded_list_read() function. + */ +#ifndef _di_fss_read_cache_t_ + typedef struct { + f_number_unsigneds_t positions; + f_ranges_t objects; + f_number_unsigneds_t slashes; + } fss_read_cache_t; + + #define fss_read_cache_t_initialize { f_number_unsigneds_t_initialize, f_ranges_t_initialize, f_number_unsigneds_t_initialize } +#endif // _di_fss_read_cache_t_ + +/** * The FSS read callbacks. * * process_help: Process help (generally printing help). @@ -282,12 +299,14 @@ extern "C" { /** * The main program data as a single structure. * + * cache: The cache data. * callback: The callback data. * program: The main program data. * setting: The settings data. */ #ifndef _di_fss_read_main_t_ typedef struct { + fss_read_cache_t cache; fss_read_callback_t callback; fll_program_data_t program; fss_read_setting_t setting; @@ -295,6 +314,7 @@ extern "C" { #define fss_read_main_t_initialize \ { \ + fss_read_cache_t_initialize, \ fss_read_callback_t_initialize, \ fll_program_data_t_initialize, \ fss_read_setting_t_initialize, \ @@ -302,6 +322,20 @@ extern "C" { #endif // _di_fss_read_main_t_ /** + * Delete the program main setting data. + * + * @param cache + * The cache data. + * + * Must not be NULL. + * + * @see f_memory_array_resize() + */ +#ifndef _di_fss_read_cache_delete_ + extern void fss_read_cache_delete(fss_read_cache_t * const cache); +#endif // _di_fss_read_cache_delete_ + +/** * De-allocate the read depth. * * @param depth @@ -373,6 +407,7 @@ extern "C" { * This does not alter main.setting.state.status. * * @see fll_program_data_delete() + * @see fss_read_cache_delete() * @see fss_read_setting_delete() */ #ifndef _di_fss_read_main_delete_ -- 1.8.3.1