From: Kevin Day Date: Tue, 18 Jul 2023 04:56:33 +0000 (-0500) Subject: Progress: Add memory array allocation functionality and begin to use it where possible. X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=b0d12f282b13823900f30cac20bd0a6f2c8bc6cd;p=fll Progress: Add memory array allocation functionality and begin to use it where possible. The pattern for handling the standard array structure is now well established. Provide a memory array functionality for handling the most basic form. This should reduce repeated code where possible. It would be interesting if this reduces the size of the resulting binary but with inline optimizations it may be possible that this actually increases the size of the resulting binary. Update the comments and tests. There are a lot of files that will need to be updated to use these new functions. Most of these are in the f_type_array project. --- diff --git a/build/level_0/settings b/build/level_0/settings index 2125c29..d6222c8 100644 --- a/build/level_0/settings +++ b/build/level_0/settings @@ -48,7 +48,8 @@ build_sources_library fss.c fss/common.c fss/item.c fss/named.c fss/nest.c fss/q build_sources_library fss/private-item.c fss/private-named.c fss/private-nest.c fss/private-set.c fss/private-set_quote.c fss/private-simple_packet.c build_sources_library iki.c iki/common.c iki/data.c private-iki.c iki/private-data.c build_sources_library limit.c limit/set.c limit/value.c limit/private-set.c limit/private-value.c -build_sources_library memory.c private-memory.c memory/structure.c +build_sources_library memory.c memory/array.c memory/structure.c +build_sources_library private-memory.c memory/private-array.c build_sources_library network.c build_sources_library parse.c parse/utf.c build_sources_library path.c private-path.c path/common.c @@ -106,7 +107,7 @@ build_sources_headers file.h file/common.h file/stream.h build_sources_headers fss.h fss/common.h fss/item.h fss/named.h fss/nest.h fss/quote.h fss/set.h fss/set_quote.h fss/simple_packet.h build_sources_headers iki.h iki/common.h iki/data.h build_sources_headers limit.h limit/set.h limit/value.h -build_sources_headers memory.h memory/structure.h memory/common.h +build_sources_headers memory.h memory/array.h memory/common.h memory/structure.h build_sources_headers network.h network/common.h build_sources_headers parse.h parse/utf.h build_sources_headers path.h path/common.h diff --git a/build/monolithic/settings b/build/monolithic/settings index 01034ce..e60f0d7 100644 --- a/build/monolithic/settings +++ b/build/monolithic/settings @@ -48,7 +48,8 @@ build_sources_library level_0/fss.c level_0/fss/common.c level_0/fss/item.c leve build_sources_library level_0/fss/private-item.c level_0/fss/private-named.c level_0/fss/private-nest.c level_0/fss/private-set.c level_0/fss/private-set_quote.c level_0/fss/private-simple_packet.c build_sources_library level_0/iki.c level_0/iki/common.c level_0/iki/data.c level_0/private-iki.c level_0/iki/private-data.c build_sources_library level_0/limit.c level_0/limit/set.c level_0/limit/value.c level_0/limit/private-set.c level_0/limit/private-value.c -build_sources_library level_0/memory.c level_0/private-memory.c level_0/memory/structure.c +build_sources_library level_0/memory.c level_0/memory/array.c level_0/memory/structure.c +build_sources_library level_0/private-memory.c level_0/memory/private-array.c build_sources_library level_0/network.c build_sources_library level_0/parse.c level_0/parse/utf.c build_sources_library level_0/path.c level_0/private-path.c level_0/path/common.c @@ -128,7 +129,7 @@ build_sources_headers level_0/file.h level_0/file/common.h level_0/file/stream.h build_sources_headers level_0/fss.h level_0/fss/common.h level_0/fss/item.h level_0/fss/named.h level_0/fss/nest.h level_0/fss/quote.h level_0/fss/set.h level_0/fss/set_quote.h level_0/fss/simple_packet.h build_sources_headers level_0/iki.h level_0/iki/common.h level_0/iki/data.h build_sources_headers level_0/limit.h level_0/limit/set.h level_0/limit/value.h -build_sources_headers level_0/memory.h level_0/memory/structure.h level_0/memory/common.h +build_sources_headers level_0/memory.h level_0/memory/array.h level_0/memory/common.h level_0/memory/structure.h build_sources_headers level_0/network.h level_0/network/common.h build_sources_headers level_0/parse.h level_0/parse/utf.h build_sources_headers level_0/path.h level_0/path/common.h diff --git a/build/stand_alone/fake.config.h b/build/stand_alone/fake.config.h index 3143057..1e63de8 100644 --- a/build/stand_alone/fake.config.h +++ b/build/stand_alone/fake.config.h @@ -639,11 +639,22 @@ #define _di_f_fss_simple_packet_d_ #define _di_f_fss_simple_packet_identify_ #define _di_f_fss_simple_packet_ranges_adjust_ +#define _di_f_fss_simple_packet_ranges_append_ +#define _di_f_fss_simple_packet_ranges_append_all_ #define _di_f_fss_simple_packet_ranges_decimate_by_ #define _di_f_fss_simple_packet_ranges_decrease_by_ #define _di_f_fss_simple_packet_ranges_increase_ #define _di_f_fss_simple_packet_ranges_increase_by_ #define _di_f_fss_simple_packet_ranges_resize_ +#define _di_f_fss_simple_packet_rangess_adjust_ +#define _di_f_fss_simple_packet_rangess_append_ +#define _di_f_fss_simple_packet_rangess_append_all_ +#define _di_f_fss_simple_packet_rangess_decimate_by_ +#define _di_f_fss_simple_packet_rangess_decrease_by_ +#define _di_f_fss_simple_packet_rangess_increase_ +#define _di_f_fss_simple_packet_rangess_increase_by_ +#define _di_f_fss_simple_packet_rangess_resize_ +#define _di_f_fss_simple_packet_rangess_t_ #define _di_f_fss_simple_packet_ranges_t_ #define _di_f_fss_simple_packet_range_t_ //#define _di_f_fss_skip_past_delimit_ @@ -1163,6 +1174,12 @@ //#define _di_fl_print_warning_s_ #define _di_f_memory_adjust_ +#define _di_f_memory_array_adjust_ +#define _di_f_memory_array_decimate_by_ +#define _di_f_memory_array_decrease_by_ +#define _di_f_memory_array_increase_ +#define _di_f_memory_array_increase_by_ +#define _di_f_memory_array_resize_ //#define _di_f_memory_default_d_ //#define _di_f_memory_delete_ #define _di_f_memory_destroy_ diff --git a/level_0/f_fss/c/fss/private-simple_packet.c b/level_0/f_fss/c/fss/private-simple_packet.c index 348d5e1..b9f45e2 100644 --- a/level_0/f_fss/c/fss/private-simple_packet.c +++ b/level_0/f_fss/c/fss/private-simple_packet.c @@ -5,37 +5,61 @@ extern "C" { #endif -#if !defined(_di_f_fss_simple_packet_ranges_adjust_) || !defined(_di_f_fss_simple_packet_ranges_decimate_by_) - f_status_t private_f_fss_simple_packet_ranges_adjust(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t * const simple_packet_ranges) { +#if !defined(_di_f_fss_simple_packet_ranges_append_) || !defined(_di_f_fss_simple_packet_rangess_append_) + extern f_status_t private_f_fss_simple_packet_ranges_append(const f_fss_simple_packet_range_t source, f_fss_simple_packet_ranges_t *destination) { - const f_status_t status = f_memory_adjust(simple_packet_ranges->size, length, sizeof(f_fss_simple_packet_range_t), (void **) & simple_packet_ranges->array); + const f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_fss_simple_packet_range_t), (void **) &destination->array, &destination->used, &destination->size); if (F_status_is_error(status)) return status; - simple_packet_ranges->size = length; - - if (simple_packet_ranges->used > simple_packet_ranges->size) { - simple_packet_ranges->used = length; - } + destination->array[destination->used++] = source; return F_none; } -#endif // !defined(_di_f_fss_simple_packet_ranges_adjust_) || !defined(_di_f_fss_simple_packet_ranges_decimate_by_) +#endif // !defined(_di_f_fss_simple_packet_ranges_append_) || !defined(_di_f_fss_simple_packet_rangess_append_) -#if !defined(_di_f_fss_simple_packet_ranges_decrease_by_) || !defined(_di_f_fss_simple_packet_ranges_increase_) || !defined(_di_f_fss_simple_packet_ranges_increase_by_) || !defined(_di_f_fss_simple_packet_ranges_resize_) - f_status_t private_f_fss_simple_packet_ranges_resize(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t * const simple_packet_ranges) { +#if !defined(_di_f_fss_simple_packet_ranges_append_) || !defined(_di_f_fss_simple_packet_ranges_append_all_) || !defined(_di_f_fss_simple_packet_rangess_append_all_) + extern f_status_t private_f_fss_simple_packet_ranges_append_all(const f_fss_simple_packet_ranges_t source, f_fss_simple_packet_ranges_t *destination) { - const f_status_t status = f_memory_resize(simple_packet_ranges->size, length, sizeof(f_fss_simple_packet_range_t), (void **) & simple_packet_ranges->array); + const f_status_t status = f_memory_array_increase_by(source.used, sizeof(f_fss_simple_packet_range_t), (void **) &destination->array, &destination->used, &destination->size); if (F_status_is_error(status)) return status; - simple_packet_ranges->size = length; - - if (simple_packet_ranges->used > simple_packet_ranges->size) { - simple_packet_ranges->used = length; - } + for (f_number_unsigned_t i = 0; i < source.used; ++i) { + destination->array[destination->used++] = source.array[i]; + } // for return F_none; } -#endif // !defined(_di_f_fss_simple_packet_ranges_decrease_by_) || !defined(_di_f_fss_simple_packet_ranges_increase_) || !defined(_di_f_fss_simple_packet_ranges_increase_by_) || !defined(_di_f_fss_simple_packet_ranges_resize_) +#endif // !defined(_di_f_fss_simple_packet_ranges_append_) || !defined(_di_f_fss_simple_packet_ranges_append_all_) || !defined(_di_f_fss_simple_packet_rangess_append_all_) + +#if !defined(_di_f_fss_simple_packet_rangess_adjust_) || !defined(_di_f_fss_simple_packet_rangess_decimate_by_) + f_status_t private_f_fss_simple_packet_rangess_adjust(const f_number_unsigned_t length, f_fss_simple_packet_rangess_t *rangess) { + + f_status_t status = F_none; + + for (f_number_unsigned_t i = length; i < rangess->size; ++i) { + + status = f_memory_array_adjust(0, sizeof(f_fss_simple_packet_range_t), (void **) &rangess->array[i].array, &rangess->array[i].used, &rangess->array[i].size); + if (F_status_is_error(status)) return status; + } // for + + return f_memory_array_adjust(length, sizeof(f_fss_simple_packet_ranges_t), (void **) &rangess->array, &rangess->used, &rangess->size); + } +#endif // !defined(_di_f_fss_simple_packet_rangess_adjust_) || !defined(_di_f_fss_simple_packet_rangess_decimate_by_) + +#if !defined(_di_f_fss_simple_packet_rangess_decrease_by_) || !defined(_di_f_fss_simple_packet_rangess_increase_) || !defined(_di_f_fss_simple_packet_rangess_increase_by_) || !defined(_di_f_fss_simple_packet_rangess_resize_) + f_status_t private_f_fss_simple_packet_rangess_resize(const f_number_unsigned_t length, f_fss_simple_packet_rangess_t *rangess) { + + f_status_t status = F_none; + + for (f_number_unsigned_t i = length; i < rangess->size; ++i) { + + status = f_memory_array_resize(0, sizeof(f_fss_simple_packet_range_t), (void **) &rangess->array[i].array, &rangess->array[i].used, &rangess->array[i].size); + if (F_status_is_error(status)) return status; + } // for + + return f_memory_array_resize(length, sizeof(f_fss_simple_packet_ranges_t), (void **) &rangess->array, &rangess->used, &rangess->size); + } +#endif // !defined(_di_f_fss_simple_packet_rangess_decrease_by_) || !defined(_di_f_fss_simple_packet_rangess_increase_) || !defined(_di_f_fss_simple_packet_rangess_increase_by_) || !defined(_di_f_fss_simple_packet_rangess_resize_) #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_fss/c/fss/private-simple_packet.h b/level_0/f_fss/c/fss/private-simple_packet.h index e41e417..b30df70 100644 --- a/level_0/f_fss/c/fss/private-simple_packet.h +++ b/level_0/f_fss/c/fss/private-simple_packet.h @@ -16,70 +16,109 @@ extern "C" { #endif /** - * Private implementation for resizing. + * Private implementation for appending the range array. + * + * Intended to be shared to each of the different implementation variations. + * + * @param source + * The source range to append. + * @param destination + * The destination lengths the source is appended onto. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_fss_simple_packet_ranges_append() + * @see f_fss_simple_packet_rangess_append() + */ +#if !defined(_di_f_fss_simple_packet_ranges_append_) || !defined(_di_f_fss_simple_packet_rangess_append_) + extern f_status_t private_f_fss_simple_packet_ranges_append(const f_fss_simple_packet_range_t source, f_fss_simple_packet_ranges_t *destination) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_fss_simple_packet_ranges_append_) || !defined(_di_f_fss_simple_packet_rangess_append_) + +/** + * Private implementation for appending the range array. + * + * Intended to be shared to each of the different implementation variations. + * + * @param source + * The source ranges to append. + * @param destination + * The destination lengths the source is appended onto. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_resize() + * @see f_fss_simple_packet_ranges_append_all() + * @see f_fss_simple_packet_rangess_append() + * @see f_fss_simple_packet_rangess_append_all() + */ +#if !defined(_di_f_fss_simple_packet_ranges_append_) || !defined(_di_f_fss_simple_packet_ranges_append_all_) || !defined(_di_f_fss_simple_packet_rangess_append_all_) + extern f_status_t private_f_fss_simple_packet_ranges_append_all(const f_fss_simple_packet_ranges_t source, f_fss_simple_packet_ranges_t *destination) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_fss_simple_packet_ranges_append_) || !defined(_di_f_fss_simple_packet_ranges_append_all_) || !defined(_di_f_fss_simple_packet_rangess_append_all_) + +/** + * Private implementation for resizing the rangess array. * * Intended to be shared to each of the different implementation variations. * * @param length - * The new size to use. - * @param simple_packet_ranges - * The simple_packet_ranges to adjust. + * The length to adjust to. + * @param rangess + * The rangess array to adjust. * * @return * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). * - * Errors (with error bit) from: macro_f_string_rangess_t_adjust(). - * Errors (with error bit) from: macro_f_string_ranges_t_adjust(). - * Errors (with error bit) from: macro_f_uint8s_t_adjust(). - * Errors (with error bit) from: macro_f_uint8ss_t_adjust(). - * Errors (with error bit) from: f_memory_adjust(). + * F_array_too_large (with error bit) if new length is larger than max array length. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. * - * @see macro_f_string_rangess_t_adjust() - * @see macro_f_string_ranges_t_adjust() - * @see macro_f_uint8s_t_adjust() - * @see macro_f_uint8ss_t_adjust() + * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_destroy(). * - * @see f_fss_simple_packet_ranges_adjust() - * @see f_fss_simple_packet_ranges_decimate_by() - * @see f_memory_adjust() + * @see f_fss_simple_packet_rangess_adjust() + * @see f_fss_simple_packet_rangess_decimate_by() */ -#if !defined(_di_f_fss_simple_packet_ranges_adjust_) || !defined(_di_f_fss_simple_packet_ranges_decimate_by_) - extern f_status_t private_f_fss_simple_packet_ranges_adjust(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t * const simple_packet_ranges) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_fss_simple_packet_ranges_adjust_) || !defined(_di_f_fss_simple_packet_ranges_decimate_by_) +#if !defined(_di_f_fss_simple_packet_rangess_adjust_) || !defined(_di_f_fss_simple_packet_rangess_decimate_by_) + extern f_status_t private_f_fss_simple_packet_rangess_adjust(const f_number_unsigned_t length, f_fss_simple_packet_rangess_t *rangess) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_fss_simple_packet_rangess_adjust_) || !defined(_di_f_fss_simple_packet_rangess_decimate_by_) /** - * Private implementation for resizing. + * Private implementation for resizing the rangess array. * * Intended to be shared to each of the different implementation variations. * * @param length - * The new size to use. - * @param simple_packet_ranges - * The simple_packet_ranges to resize. + * The length to resize to. + * @param rangess + * The rangess array to resize. * * @return * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). * - * Errors (with error bit) from: macro_f_string_rangess_t_resize(). - * Errors (with error bit) from: macro_f_string_ranges_t_resize(). - * Errors (with error bit) from: macro_f_uint8s_t_resize(). - * Errors (with error bit) from: macro_f_uint8ss_t_resize(). - * Errors (with error bit) from: f_memory_resize(). + * F_array_too_large (with error bit) if new length is larger than max array length. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. * - * @see macro_f_string_rangess_t_resize() - * @see macro_f_string_ranges_t_resize() - * @see macro_f_uint8s_t_resize() - * @see macro_f_uint8ss_t_resize() + * Errors (with error bit) from: f_memory_delete(). + * Errors (with error bit) from: f_memory_resize(). * - * @see f_fss_simple_packet_ranges_decrease_by() - * @see f_fss_simple_packet_ranges_increase() - * @see f_fss_simple_packet_ranges_increase_by() - * @see f_fss_simple_packet_ranges_resize() - * @see f_memory_resize() + * @see f_fss_simple_packet_rangess_decrease_by() + * @see f_fss_simple_packet_rangess_increase() + * @see f_fss_simple_packet_rangess_increase_by() + * @see f_fss_simple_packet_rangess_resize() */ -#if !defined(_di_f_fss_simple_packet_ranges_decrease_by_) || !defined(_di_f_fss_simple_packet_ranges_increase_) || !defined(_di_f_fss_simple_packet_ranges_increase_by_) || !defined(_di_f_fss_simple_packet_ranges_resize_) - extern f_status_t private_f_fss_simple_packet_ranges_resize(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t * const simple_packet_ranges) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_fss_simple_packet_ranges_decrease_by_) || !defined(_di_f_fss_simple_packet_ranges_increase_) || !defined(_di_f_fss_simple_packet_ranges_increase_by_) || !defined(_di_f_fss_simple_packet_ranges_resize_) +#if !defined(_di_f_fss_simple_packet_rangess_decrease_by_) || !defined(_di_f_fss_simple_packet_rangess_increase_) || !defined(_di_f_fss_simple_packet_rangess_increase_by_) || !defined(_di_f_fss_simple_packet_rangess_resize_) + extern f_status_t private_f_fss_simple_packet_rangess_resize(const f_number_unsigned_t length, f_fss_simple_packet_rangess_t *rangess) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_fss_simple_packet_rangess_decrease_by_) || !defined(_di_f_fss_simple_packet_rangess_increase_) || !defined(_di_f_fss_simple_packet_rangess_increase_by_) || !defined(_di_f_fss_simple_packet_rangess_resize_) #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_fss/c/fss/simple_packet.c b/level_0/f_fss/c/fss/simple_packet.c index 39c8c20..d7ec68f 100644 --- a/level_0/f_fss/c/fss/simple_packet.c +++ b/level_0/f_fss/c/fss/simple_packet.c @@ -58,90 +58,195 @@ extern "C" { #endif // _di_f_fss_simple_packet_identify_ #ifndef _di_f_fss_simple_packet_ranges_adjust_ - f_status_t f_fss_simple_packet_ranges_adjust(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t * const simple_packet_ranges) { + f_status_t f_fss_simple_packet_ranges_adjust(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t *ranges) { #ifndef _di_level_0_parameter_checking_ - if (!simple_packet_ranges) return F_status_set_error(F_parameter); + if (!ranges) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_fss_simple_packet_ranges_adjust(length, simple_packet_ranges); + return f_memory_array_adjust(length, sizeof(f_fss_simple_packet_range_t), (void **) &ranges->array, &ranges->used, &ranges->size); } #endif // _di_f_fss_simple_packet_ranges_adjust_ -#ifndef _di_f_fss_simple_packet_ranges_decimate_by_ - f_status_t f_fss_simple_packet_ranges_decimate_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t * const simple_packet_ranges) { +#ifndef _di_f_fss_simple_packet_ranges_append_ + f_status_t f_fss_simple_packet_ranges_append(const f_fss_simple_packet_range_t source, f_fss_simple_packet_ranges_t *destination) { #ifndef _di_level_0_parameter_checking_ - if (!simple_packet_ranges) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - if (simple_packet_ranges->size > amount) return private_f_fss_simple_packet_ranges_adjust(simple_packet_ranges->size - amount, simple_packet_ranges); + return private_f_fss_simple_packet_ranges_append(source, destination); + } +#endif // _di_f_fss_simple_packet_ranges_append_ + +#ifndef _di_f_fss_simple_packet_ranges_append_all_ + f_status_t f_fss_simple_packet_ranges_append_all(const f_fss_simple_packet_ranges_t source, f_fss_simple_packet_ranges_t *destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; - return private_f_fss_simple_packet_ranges_adjust(0, simple_packet_ranges); + return private_f_fss_simple_packet_ranges_append_all(source, destination); + } +#endif // _di_f_fss_simple_packet_ranges_append_all_ + +#ifndef _di_f_fss_simple_packet_ranges_decimate_by_ + f_status_t f_fss_simple_packet_ranges_decimate_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t *ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return f_memory_array_decimate_by(amount, sizeof(f_fss_simple_packet_range_t), (void **) &ranges->array, &ranges->used, &ranges->size); } #endif // _di_f_fss_simple_packet_ranges_decimate_by_ #ifndef _di_f_fss_simple_packet_ranges_decrease_by_ - f_status_t f_fss_simple_packet_ranges_decrease_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t * const simple_packet_ranges) { + f_status_t f_fss_simple_packet_ranges_decrease_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t *ranges) { #ifndef _di_level_0_parameter_checking_ - if (!simple_packet_ranges) return F_status_set_error(F_parameter); + if (!ranges) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - if (simple_packet_ranges->size > amount) return private_f_fss_simple_packet_ranges_resize(simple_packet_ranges->size - amount, simple_packet_ranges); - - return private_f_fss_simple_packet_ranges_resize(0, simple_packet_ranges); + return f_memory_array_decrease_by(amount, sizeof(f_fss_simple_packet_range_t), (void **) &ranges->array, &ranges->used, &ranges->size); } #endif // _di_f_fss_simple_packet_ranges_decrease_by_ #ifndef _di_f_fss_simple_packet_ranges_increase_ - f_status_t f_fss_simple_packet_ranges_increase(const f_number_unsigned_t step, f_fss_simple_packet_ranges_t * const simple_packet_ranges) { + f_status_t f_fss_simple_packet_ranges_increase(const f_number_unsigned_t step, f_fss_simple_packet_ranges_t *ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return f_memory_array_increase(step, sizeof(f_fss_simple_packet_range_t), (void **) &ranges->array, &ranges->used, &ranges->size); + } +#endif // _di_f_fss_simple_packet_ranges_increase_ + +#ifndef _di_f_fss_simple_packet_ranges_increase_by_ + f_status_t f_fss_simple_packet_ranges_increase_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t *ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return f_memory_array_increase_by(amount, sizeof(f_fss_simple_packet_range_t), (void **) &ranges->array, &ranges->used, &ranges->size); + } +#endif // _di_f_fss_simple_packet_ranges_increase_by_ + +#ifndef _di_f_fss_simple_packet_ranges_resize_ + f_status_t f_fss_simple_packet_ranges_resize(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t *ranges) { + #ifndef _di_level_0_parameter_checking_ + if (!ranges) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return f_memory_array_resize(length, sizeof(f_fss_simple_packet_range_t), (void **) &ranges->array, &ranges->used, &ranges->size); + } +#endif // _di_f_fss_simple_packet_ranges_resize_ + +#ifndef _di_f_fss_simple_packet_rangess_adjust_ + f_status_t f_fss_simple_packet_rangess_adjust(const f_number_unsigned_t length, f_fss_simple_packet_rangess_t *rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_fss_simple_packet_rangess_adjust(length, rangess); + } +#endif // _di_f_fss_simple_packet_rangess_adjust_ + +#ifndef _di_f_fss_simple_packet_rangess_append_ + f_status_t f_fss_simple_packet_rangess_append(const f_fss_simple_packet_ranges_t source, f_fss_simple_packet_rangess_t *destination) { #ifndef _di_level_0_parameter_checking_ - if (!simple_packet_ranges) return F_status_set_error(F_parameter); + if (!destination) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (step && simple_packet_ranges->used + 1 > simple_packet_ranges->size) { - f_number_unsigned_t size = simple_packet_ranges->used + step; + if (!source.used) return F_data_not; + + f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_fss_simple_packet_ranges_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; + + status = private_f_fss_simple_packet_ranges_append_all(source, &destination->array[destination->used]); + if (F_status_is_error(status)) return status; - if (size > F_number_t_size_unsigned_d) { - if (simple_packet_ranges->used + 1 > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + ++destination->used; - size = F_number_t_size_unsigned_d; + return F_none; + } +#endif // _di_f_fss_simple_packet_rangess_append_ + +#ifndef _di_f_fss_simple_packet_rangess_append_all_ + f_status_t f_fss_simple_packet_rangess_append_all(const f_fss_simple_packet_rangess_t source, f_fss_simple_packet_rangess_t *destination) { + #ifndef _di_level_0_parameter_checking_ + if (!destination) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!source.used) return F_data_not; + + f_status_t status = f_memory_array_increase(source.used, sizeof(f_fss_simple_packet_ranges_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; + + for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { + + destination->array[destination->used].used = 0; + + if (source.array[i].used) { + status = private_f_fss_simple_packet_ranges_append_all(source.array[i], &destination->array[destination->used]); + if (F_status_is_error(status)) return status; } + } // for - return private_f_fss_simple_packet_ranges_resize(size, simple_packet_ranges); - } + return F_none; + } +#endif // _di_f_fss_simple_packet_rangess_append_all_ - return F_data_not; +#ifndef _di_f_fss_simple_packet_rangess_decimate_by_ + f_status_t f_fss_simple_packet_rangess_decimate_by(const f_number_unsigned_t amount, f_fss_simple_packet_rangess_t *rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + return private_f_fss_simple_packet_rangess_adjust((rangess->size > amount) ? rangess->size - amount : 0, rangess); } -#endif // _di_f_fss_simple_packet_ranges_increase_ +#endif // _di_f_fss_simple_packet_rangess_decimate_by_ -#ifndef _di_f_fss_simple_packet_ranges_increase_by_ - f_status_t f_fss_simple_packet_ranges_increase_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t * const simple_packet_ranges) { +#ifndef _di_f_fss_simple_packet_rangess_decrease_by_ + f_status_t f_fss_simple_packet_rangess_decrease_by(const f_number_unsigned_t amount, f_fss_simple_packet_rangess_t *rangess) { #ifndef _di_level_0_parameter_checking_ - if (!simple_packet_ranges) return F_status_set_error(F_parameter); + if (!rangess) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ if (!amount) return F_data_not; - if (simple_packet_ranges->used + amount > simple_packet_ranges->size) { - if (simple_packet_ranges->used + amount > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + return private_f_fss_simple_packet_rangess_resize((rangess->size > amount) ? rangess->size - amount : 0, rangess); + } +#endif // _di_f_fss_simple_packet_rangess_decrease_by_ - return private_f_fss_simple_packet_ranges_resize(simple_packet_ranges->used + amount, simple_packet_ranges); - } +#ifndef _di_f_fss_simple_packet_rangess_increase_ + f_status_t f_fss_simple_packet_rangess_increase(const f_number_unsigned_t step, f_fss_simple_packet_rangess_t *rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ - return F_data_not; + return f_memory_array_increase(step, sizeof(f_fss_simple_packet_ranges_t), (void **) &rangess->array, &rangess->used, &rangess->size); } -#endif // _di_f_fss_simple_packet_ranges_increase_by_ +#endif // _di_f_fss_simple_packet_rangess_increase_ -#ifndef _di_f_fss_simple_packet_ranges_resize_ - f_status_t f_fss_simple_packet_ranges_resize(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t * const simple_packet_ranges) { +#ifndef _di_f_fss_simple_packet_rangess_increase_by_ + f_status_t f_fss_simple_packet_rangess_increase_by(const f_number_unsigned_t amount, f_fss_simple_packet_rangess_t *rangess) { #ifndef _di_level_0_parameter_checking_ - if (!simple_packet_ranges) return F_status_set_error(F_parameter); + if (!rangess) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_fss_simple_packet_ranges_resize(length, simple_packet_ranges); + return f_memory_array_increase_by(amount, sizeof(f_fss_simple_packet_ranges_t), (void **) &rangess->array, &rangess->used, &rangess->size); } -#endif // _di_f_fss_simple_packet_ranges_resize_ +#endif // _di_f_fss_simple_packet_rangess_increase_by_ + +#ifndef _di_f_fss_simple_packet_rangess_resize_ + f_status_t f_fss_simple_packet_rangess_resize(const f_number_unsigned_t length, f_fss_simple_packet_rangess_t *rangess) { + #ifndef _di_level_0_parameter_checking_ + if (!rangess) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + return private_f_fss_simple_packet_rangess_resize(length, rangess); + } +#endif // _di_f_fss_simple_packet_rangess_resize_ #ifdef __cplusplus } // extern "C" diff --git a/level_0/f_fss/c/fss/simple_packet.h b/level_0/f_fss/c/fss/simple_packet.h index 787d950..c09d7cd 100644 --- a/level_0/f_fss/c/fss/simple_packet.h +++ b/level_0/f_fss/c/fss/simple_packet.h @@ -99,6 +99,41 @@ extern "C" { #endif // _di_f_fss_simple_packet_ranges_t_ /** + * This holds an array of f_fss_simple_packet_ranges_t. + * + * Properties: + * - array: An array of f_fss_simple_packet_ranges_t. + * - size: Total amount of allocated space. + * - used: Total number of allocated spaces used. + */ +#ifndef _di_f_fss_simple_packet_rangess_t_ + typedef struct { + f_fss_simple_packet_ranges_t *array; + + f_number_unsigned_t size; + f_number_unsigned_t used; + } f_fss_simple_packet_rangess_t; + + #define f_fss_simple_packet_rangess_t_initialize { 0, 0, 0 } + + #define macro_f_fss_simple_packet_rangess_t_initialize_1(array, size, used) { array, size, used } + #define macro_f_fss_simple_packet_rangess_t_initialize_2(array, length) { array, length, length } + + #define macro_f_fss_simple_packet_rangess_t_clear(simple_packet_rangess) macro_f_memory_structure_t_clear(simple_packet_ranges.objects) + + #define macro_f_fss_simple_packet_rangess_t_resize(status, simple_packet_rangess, length) status = f_fss_simple_packet_rangess_resize(length, &simple_packet_rangess); + #define macro_f_fss_simple_packet_rangess_t_adjust(status, simple_packet_rangess, length) status = f_fss_simple_packet_rangess_adjust(length, &simple_packet_rangess); + + #define macro_f_fss_simple_packet_rangess_t_delete_simple(simple_packet_rangess) f_fss_simple_packet_rangess_resize(0, &simple_packet_rangess); + #define macro_f_fss_simple_packet_rangess_t_destroy_simple(simple_packet_rangess) f_fss_simple_packet_rangess_adjust(0, &simple_packet_rangess); + + #define macro_f_fss_simple_packet_rangess_t_increase(status, step, simple_packet_rangess) status = f_fss_simple_packet_rangess_increase(step, &simple_packet_rangess); + #define macro_f_fss_simple_packet_rangess_t_increase_by(status, simple_packet_rangess, amount) status = f_fss_simple_packet_rangess_increase_by(amount, &simple_packet_rangess); + #define macro_f_fss_simple_packet_rangess_t_decrease_by(status, simple_packet_rangess, amount) status = f_fss_simple_packet_rangess_decrease_by(amount, &simple_packet_rangess); + #define macro_f_fss_simple_packet_rangess_t_decimate_by(status, simple_packet_rangess, amount) status = f_fss_simple_packet_rangess_decimate_by(amount, &simple_packet_rangess); +#endif // _di_f_fss_simple_packet_rangess_t_ + +/** * Identify the ranges representing the different parts of the FSS-000F (Simple Packet). * * @param buffer @@ -121,133 +156,398 @@ extern "C" { #endif // _di_f_fss_simple_packet_identify_ /** - * Resize the simple_packet_range array. + * Resize the ranges array. * * @param length * The new size to use. - * @param simple_packet_ranges - * The simple_packet_ranges array to resize. + * @param ranges + * The ranges array to resize. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * - * F_memory_not (with error bit) on out of memory. * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_fss_simple_packet_ranges_adjust_ - extern f_status_t f_fss_simple_packet_ranges_adjust(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t * const simple_packet_ranges); + extern f_status_t f_fss_simple_packet_ranges_adjust(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t *ranges); #endif // _di_f_fss_simple_packet_ranges_adjust_ /** - * Resize the simple_packet_range array to a smaller size. + * Append the single source range onto the destination. + * + * @param source + * The source range to append. + * @param destination + * The destination ranges the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * Success from f_memory_array_resize(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() + */ +#ifndef _di_f_fss_simple_packet_ranges_append_ + extern f_status_t f_fss_simple_packet_ranges_append(const f_fss_simple_packet_range_t source, f_fss_simple_packet_ranges_t *destination); +#endif // _di_f_fss_simple_packet_ranges_append_ + +/** + * Append the source ranges onto the destination. + * + * @param source + * The source ranges to append. + * @param destination + * The destination ranges the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * Success from f_memory_array_resize(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() + */ +#ifndef _di_f_fss_simple_packet_ranges_append_all_ + extern f_status_t f_fss_simple_packet_ranges_append_all(const f_fss_simple_packet_ranges_t source, f_fss_simple_packet_ranges_t *destination); +#endif // _di_f_fss_simple_packet_ranges_append_all_ + +/** + * Resize the ranges array to a smaller size. * * This will resize making the array smaller based on (size - given length). * If the given length is too small, then the resize will fail. - * This will not shrink the size to less than 0. + * This will not shrink the size to les than 0. * * @param amount * A positive number representing how much to decimate the size by. - * @param simple_packet_ranges - * The simple_packet_ranges array to resize. + * @param ranges + * The ranges array to resize. * * @return - * F_none on success. + * @return + * Success from f_memory_array_decimate_by(). * - * F_memory_not (with error bit) on out of memory. * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_decimate_by(). + * + * @see f_memory_array_decimate_by() */ #ifndef _di_f_fss_simple_packet_ranges_decimate_by_ - extern f_status_t f_fss_simple_packet_ranges_decimate_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t * const simple_packet_ranges); + extern f_status_t f_fss_simple_packet_ranges_decimate_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t *ranges); #endif // _di_f_fss_simple_packet_ranges_decimate_by_ /** - * Resize the simple_packet_range array to a smaller size. + * Resize the ranges array to a smaller size. * * This will resize making the array smaller based on (size - given length). * If the given length is too small, then the resize will fail. - * This will not shrink the size to less than 0. + * This will not shrink the size to les than 0. * * @param amount * A positive number representing how much to decrease the size by. - * @param simple_packet_ranges - * The simple_packet_ranges array to resize. + * @param ranges + * The ranges array to resize. * * @return - * F_none on success. + * Success from f_memory_array_decrease_by(). * - * F_memory_not (with error bit) on out of memory. * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_decrease_by(). + * + * @see f_memory_array_decrease_by() */ #ifndef _di_f_fss_simple_packet_ranges_decrease_by_ - extern f_status_t f_fss_simple_packet_ranges_decrease_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t * const simple_packet_ranges); + extern f_status_t f_fss_simple_packet_ranges_decrease_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t *ranges); #endif // _di_f_fss_simple_packet_ranges_decrease_by_ /** - * Increase the size of the simple_packet_ranges array, but only if necessary. + * Increase the size of the ranges array, but only if necesary. * - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. + * If the given length is too large for the buffer, then attempt to range max buffer size (F_number_t_size_unsigned_d). + * If already range to the maximum buffer size, then the resize will fail. * * @param step * The allocation step to use. * Must be greater than 0. - * @param simple_packet_ranges - * The simple_packet_ranges array to resize. + * @param ranges + * The ranges array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * Success from f_memory_array_increase(). * - * F_array_too_large (with error bit) if the new array length is too large. - * F_memory_not (with error bit) on out of memory. * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_increase(). + * + * @see f_memory_array_increase() */ #ifndef _di_f_fss_simple_packet_ranges_increase_ - extern f_status_t f_fss_simple_packet_ranges_increase(const f_number_unsigned_t step, f_fss_simple_packet_ranges_t * const simple_packet_ranges); + extern f_status_t f_fss_simple_packet_ranges_increase(const f_number_unsigned_t step, f_fss_simple_packet_ranges_t *ranges); #endif // _di_f_fss_simple_packet_ranges_increase_ /** - * Resize the simple_packet_ranges array to a larger size. + * Resize the ranges array to a larger size. * * This will resize making the array larger based on the given length. - * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). - * If already set to the maximum buffer size, then the resize will fail. + * If the given length is too large for the buffer, then attempt to range max buffer size (F_number_t_size_unsigned_d). + * If already range to the maximum buffer size, then the resize will fail. * * @param amount * A positive number representing how much to increase the size by. - * @param simple_packet_ranges - * The simple_packet_ranges array to resize. + * @param ranges + * The ranges array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * Success from f_memory_array_increase_by(). * - * F_memory_not (with error bit) on out of memory. * F_parameter (with error bit) if a parameter is invalid. - * F_array_too_large (with error bit) if the new array length is too large. + * + * Errors (with error bit) from: f_memory_array_increase_by(). + * + * @see f_memory_array_increase_by() */ #ifndef _di_f_fss_simple_packet_ranges_increase_by_ - extern f_status_t f_fss_simple_packet_ranges_increase_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t * const simple_packet_ranges); + extern f_status_t f_fss_simple_packet_ranges_increase_by(const f_number_unsigned_t amount, f_fss_simple_packet_ranges_t *ranges); #endif // _di_f_fss_simple_packet_ranges_increase_by_ /** - * Resize the simple_packet_ranges array. + * Resize the ranges array. * * @param length * The new size to use. - * @param simple_packet_ranges - * The simple_packet_ranges array to adjust. + * @param ranges + * The ranges array to adjust. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * - * F_memory_not (with error bit) on out of memory. * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_fss_simple_packet_ranges_resize_ - extern f_status_t f_fss_simple_packet_ranges_resize(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t * const simple_packet_ranges); + extern f_status_t f_fss_simple_packet_ranges_resize(const f_number_unsigned_t length, f_fss_simple_packet_ranges_t *ranges); #endif // _di_f_fss_simple_packet_ranges_resize_ +/** + * Resize the rangess array. + * + * @param length + * The new size to use. + * @param rangess + * The rangess array to resize. + * + * @return + * Success from f_memory_array_adjust(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_adjust(). + * + * @see f_memory_array_adjust() + */ +#ifndef _di_f_fss_simple_packet_rangess_adjust_ + extern f_status_t f_fss_simple_packet_rangess_adjust(const f_number_unsigned_t length, f_fss_simple_packet_rangess_t *rangess); +#endif // _di_f_fss_simple_packet_rangess_adjust_ + +/** + * Append the single source ranges onto the destination. + * + * @param source + * The source ranges to append. + * @param destination + * The destination ranges the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * Success from f_memory_array_resize(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() + */ +#ifndef _di_f_fss_simple_packet_rangess_append_ + extern f_status_t f_fss_simple_packet_rangess_append(const f_fss_simple_packet_ranges_t source, f_fss_simple_packet_rangess_t *destination); +#endif // _di_f_fss_simple_packet_rangess_append_ + +/** + * Append the source rangess onto the destination. + * + * @param source + * The source rangess to append. + * @param destination + * The destination ranges the source is appended onto. + * + * @return + * F_none on success. + * F_data_not on success, but there is nothing to append (size == 0). + * + * Success from f_memory_array_resize(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() + */ +#ifndef _di_f_fss_simple_packet_rangess_append_all_ + extern f_status_t f_fss_simple_packet_rangess_append_all(const f_fss_simple_packet_rangess_t source, f_fss_simple_packet_rangess_t *destination); +#endif // _di_f_fss_simple_packet_rangess_append_all_ + +/** + * Resize the rangess array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param rangess + * The rangess array to resize. + * + * @return + * F_data_not on success, but the amount to decrease by is 0. + * + * Success from f_memory_array_decimate_by(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_decimate_by(). + * + * @see f_memory_array_decimate_by() + */ +#ifndef _di_f_fss_simple_packet_rangess_decimate_by_ + extern f_status_t f_fss_simple_packet_rangess_decimate_by(const f_number_unsigned_t amount, f_fss_simple_packet_rangess_t *rangess); +#endif // _di_f_fss_simple_packet_rangess_decimate_by_ + +/** + * Resize the rangess array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param rangess + * The rangess array to resize. + * + * @return + * F_data_not on success, but the amount to decrease by is 0. + * + * Success from f_memory_array_decrease_by(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_decrease_by(). + * + * @see f_memory_array_decrease_by() + */ +#ifndef _di_f_fss_simple_packet_rangess_decrease_by_ + extern f_status_t f_fss_simple_packet_rangess_decrease_by(const f_number_unsigned_t amount, f_fss_simple_packet_rangess_t *rangess); +#endif // _di_f_fss_simple_packet_rangess_decrease_by_ + +/** + * Increase the size of the rangess array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to range max buffer size (F_number_t_size_unsigned_d). + * If already range to the maximum buffer size, then the resize will fail. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param rangess + * The rangess array to resize. + * + * @return + * Success from f_memory_array_increase(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_increase(). + * + * @see f_memory_array_increase() + */ +#ifndef _di_f_fss_simple_packet_rangess_increase_ + extern f_status_t f_fss_simple_packet_rangess_increase(const f_number_unsigned_t step, f_fss_simple_packet_rangess_t *rangess); +#endif // _di_f_fss_simple_packet_rangess_increase_ + +/** + * Resize the rangess array to a larger size. + * + * This will resize making the array larger based on the given length. + * If the given length is too large for the buffer, then attempt to range max buffer size (F_number_t_size_unsigned_d). + * If already range to the maximum buffer size, then the resize will fail. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param rangess + * The rangess array to resize. + * + * @return + * Success from f_memory_array_increase_by(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_increase_by(). + * + * @see f_memory_array_increase_by() + */ +#ifndef _di_f_fss_simple_packet_rangess_increase_by_ + extern f_status_t f_fss_simple_packet_rangess_increase_by(const f_number_unsigned_t amount, f_fss_simple_packet_rangess_t *rangess); +#endif // _di_f_fss_simple_packet_rangess_increase_by_ + +/** + * Resize the rangess array. + * + * @param length + * The new size to use. + * @param rangess + * The rangess array to adjust. + * + * @return + * Success from f_memory_array_resize(). + * + * F_parameter (with error bit) if a parameter is invalid. + * + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() + */ +#ifndef _di_f_fss_simple_packet_rangess_resize_ + extern f_status_t f_fss_simple_packet_rangess_resize(const f_number_unsigned_t length, f_fss_simple_packet_rangess_t *rangess); +#endif // _di_f_fss_simple_packet_rangess_resize_ + #ifdef __cplusplus } // extern "C" #endif diff --git a/level_0/f_fss/c/private-fss.c b/level_0/f_fss/c/private-fss.c deleted file mode 100644 index be126fd..0000000 --- a/level_0/f_fss/c/private-fss.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "fss.h" -#include "private-fss.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/level_0/f_fss/c/private-fss.h b/level_0/f_fss/c/private-fss.h deleted file mode 100644 index 97fad1e..0000000 --- a/level_0/f_fss/c/private-fss.h +++ /dev/null @@ -1,22 +0,0 @@ -/** - * FLL - Level 0 - * - * Project: FSS - * API Version: 0.7 - * Licenses: lgpl-2.1-or-later - * - * These are provided for internal reduction in redundant code. - * These should not be exposed/used outside of this project. - */ -#ifndef _PRIVATE_F_fss_h -#define _PRIVATE_F_fss_h - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // _PRIVATE_F_fss_h diff --git a/level_0/f_limit/c/limit/private-set.c b/level_0/f_limit/c/limit/private-set.c index 8f056e2..d5ca779 100644 --- a/level_0/f_limit/c/limit/private-set.c +++ b/level_0/f_limit/c/limit/private-set.c @@ -6,29 +6,11 @@ extern "C" { #endif -#if !defined(_di_f_limit_sets_adjust_) || !defined(_di_f_limit_sets_decimate_by_) - f_status_t private_f_limit_sets_adjust(const f_number_unsigned_t length, f_limit_sets_t *sets) { - - const f_status_t status = f_memory_adjust(sets->size, length, sizeof(f_limit_set_t), (void **) & sets->array); - if (F_status_is_error(status)) return status; - - sets->size = length; - - if (sets->used > sets->size) { - sets->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_limit_sets_adjust_) || !defined(_di_f_limit_sets_decimate_by_) - #if !defined(_di_f_limit_sets_append_) || !defined(_di_f_limit_setss_append_) extern f_status_t private_f_limit_sets_append(const f_limit_set_t source, f_limit_sets_t *destination) { - if (destination->used + 1 > destination->size) { - const f_status_t status = private_f_limit_sets_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } + const f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_limit_set_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; destination->array[destination->used++] = source; @@ -39,10 +21,8 @@ extern "C" { #if !defined(_di_f_limit_sets_append_) || !defined(_di_f_limit_sets_append_all_) || !defined(_di_f_limit_setss_append_all_) extern f_status_t private_f_limit_sets_append_all(const f_limit_sets_t source, f_limit_sets_t *destination) { - if (destination->used + source.used > destination->size) { - const f_status_t status = private_f_limit_sets_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } + const f_status_t status = f_memory_array_increase_by(source.used, sizeof(f_limit_set_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; for (f_number_unsigned_t i = 0; i < source.used; ++i) { destination->array[destination->used++] = source.array[i]; @@ -52,22 +32,6 @@ extern "C" { } #endif // !defined(_di_f_limit_sets_append_) || !defined(_di_f_limit_sets_append_all_) || !defined(_di_f_limit_setss_append_all_) -#if !defined(_di_f_limit_sets_resize_) || !defined(_di_f_limit_sets_append_) || !defined(_di_f_limit_sets_decimate_by_) || !defined(_di_f_limit_setss_append_) - f_status_t private_f_limit_sets_resize(const f_number_unsigned_t length, f_limit_sets_t *sets) { - - const f_status_t status = f_memory_resize(sets->size, length, sizeof(f_limit_set_t), (void **) & sets->array); - if (F_status_is_error(status)) return status; - - sets->size = length; - - if (sets->used > sets->size) { - sets->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_limit_sets_resize_) || !defined(_di_f_limit_sets_append_) || !defined(_di_f_limit_sets_decimate_by_) || !defined(_di_f_limit_setss_append_) - #if !defined(_di_f_limit_setss_adjust_) || !defined(_di_f_limit_setss_decimate_by_) f_status_t private_f_limit_setss_adjust(const f_number_unsigned_t length, f_limit_setss_t *setss) { @@ -75,23 +39,11 @@ extern "C" { for (f_number_unsigned_t i = length; i < setss->size; ++i) { - status = f_memory_destroy(setss->array[i].size, sizeof(f_limit_sets_t), (void **) & setss->array[i].array); + status = f_memory_array_adjust(0, sizeof(f_limit_set_t), (void **) &setss->array[i].array, &setss->array[i].used, &setss->array[i].size); if (F_status_is_error(status)) return status; - - setss->array[i].size = 0; - setss->array[i].used = 0; } // for - status = f_memory_adjust(setss->size, length, sizeof(f_limit_sets_t), (void **) & setss->array); - if (F_status_is_error(status)) return status; - - setss->size = length; - - if (setss->used > setss->size) { - setss->used = length; - } - - return F_none; + return f_memory_array_adjust(length, sizeof(f_limit_sets_t), (void **) &setss->array, &setss->used, &setss->size); } #endif // !defined(_di_f_limit_setss_adjust_) || !defined(_di_f_limit_setss_decimate_by_) @@ -102,23 +54,11 @@ extern "C" { for (f_number_unsigned_t i = length; i < setss->size; ++i) { - status = f_memory_delete(setss->array[i].size, sizeof(f_limit_sets_t), (void **) & setss->array[i].array); + status = f_memory_array_resize(0, sizeof(f_limit_set_t), (void **) &setss->array[i].array, &setss->array[i].used, &setss->array[i].size); if (F_status_is_error(status)) return status; - - setss->array[i].size = 0; - setss->array[i].used = 0; } // for - status = f_memory_resize(setss->size, length, sizeof(f_limit_sets_t), (void **) & setss->array); - if (F_status_is_error(status)) return status; - - setss->size = length; - - if (setss->used > setss->size) { - setss->used = length; - } - - return F_none; + return f_memory_array_resize(length, sizeof(f_limit_sets_t), (void **) &setss->array, &setss->used, &setss->size); } #endif // !defined(_di_f_limit_setss_decrease_by_) || !defined(_di_f_limit_setss_increase_) || !defined(_di_f_limit_setss_increase_by_) || !defined(_di_f_limit_setss_resize_) diff --git a/level_0/f_limit/c/limit/private-set.h b/level_0/f_limit/c/limit/private-set.h index 75e2299..66ddb25 100644 --- a/level_0/f_limit/c/limit/private-set.h +++ b/level_0/f_limit/c/limit/private-set.h @@ -16,29 +16,6 @@ extern "C" { #endif /** - * Private implementation for resizing the sets array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param sets - * The sets array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_limit_sets_adjust() - * @see f_limit_sets_decimate_by() - */ -#if !defined(_di_f_limit_sets_adjust_) || !defined(_di_f_limit_sets_decimate_by_) - extern f_status_t private_f_limit_sets_adjust(const f_number_unsigned_t length, f_limit_sets_t *sets) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_limit_sets_adjust_) || !defined(_di_f_limit_sets_decimate_by_) - -/** * Private implementation for appending the set array. * * Intended to be shared to each of the different implementation variations. @@ -86,31 +63,6 @@ extern "C" { #endif // !defined(_di_f_limit_sets_append_) || !defined(_di_f_limit_sets_append_all_) || !defined(_di_f_limit_setss_append_all_) /** - * Private implementation for resizing the sets array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param sets - * The sets array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_limit_sets_resize() - * @see f_limit_sets_append() - * @see f_limit_sets_decimate_by() - * @see f_limit_setss_append() - */ -#if !defined(_di_f_limit_sets_resize_) || !defined(_di_f_limit_sets_append_) || !defined(_di_f_limit_sets_decimate_by_) || !defined(_di_f_limit_setss_append_) - extern f_status_t private_f_limit_sets_resize(const f_number_unsigned_t length, f_limit_sets_t *sets) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_limit_sets_resize_) || !defined(_di_f_limit_sets_append_) || !defined(_di_f_limit_sets_decimate_by_) || !defined(_di_f_limit_setss_append_) - -/** * Private implementation for resizing the setss array. * * Intended to be shared to each of the different implementation variations. diff --git a/level_0/f_limit/c/limit/private-value.c b/level_0/f_limit/c/limit/private-value.c index be69994..105ddf1 100644 --- a/level_0/f_limit/c/limit/private-value.c +++ b/level_0/f_limit/c/limit/private-value.c @@ -6,29 +6,11 @@ extern "C" { #endif -#if !defined(_di_f_limit_values_adjust_) || !defined(_di_f_limit_values_decimate_by_) - f_status_t private_f_limit_values_adjust(const f_number_unsigned_t length, f_limit_values_t *values) { - - const f_status_t status = f_memory_adjust(values->size, length, sizeof(f_limit_value_t), (void **) & values->array); - if (F_status_is_error(status)) return status; - - values->size = length; - - if (values->used > values->size) { - values->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_limit_values_adjust_) || !defined(_di_f_limit_values_decimate_by_) - #if !defined(_di_f_limit_values_append_) || !defined(_di_f_limit_valuess_append_) extern f_status_t private_f_limit_values_append(const f_limit_value_t source, f_limit_values_t *destination) { - if (destination->used + 1 > destination->size) { - const f_status_t status = private_f_limit_values_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } + const f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_limit_value_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; destination->array[destination->used++] = source; @@ -39,10 +21,8 @@ extern "C" { #if !defined(_di_f_limit_values_append_) || !defined(_di_f_limit_values_append_all_) || !defined(_di_f_limit_valuess_append_all_) extern f_status_t private_f_limit_values_append_all(const f_limit_values_t source, f_limit_values_t *destination) { - if (destination->used + source.used > destination->size) { - const f_status_t status = private_f_limit_values_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } + const f_status_t status = f_memory_array_increase_by(source.used, sizeof(f_limit_value_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; for (f_number_unsigned_t i = 0; i < source.used; ++i) { destination->array[destination->used++] = source.array[i]; @@ -52,22 +32,6 @@ extern "C" { } #endif // !defined(_di_f_limit_values_append_) || !defined(_di_f_limit_values_append_all_) || !defined(_di_f_limit_valuess_append_all_) -#if !defined(_di_f_limit_values_resize_) || !defined(_di_f_limit_values_append_) || !defined(_di_f_limit_values_decimate_by_) || !defined(_di_f_limit_valuess_append_) - f_status_t private_f_limit_values_resize(const f_number_unsigned_t length, f_limit_values_t *values) { - - const f_status_t status = f_memory_resize(values->size, length, sizeof(f_limit_value_t), (void **) & values->array); - if (F_status_is_error(status)) return status; - - values->size = length; - - if (values->used > values->size) { - values->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_limit_values_resize_) || !defined(_di_f_limit_values_append_) || !defined(_di_f_limit_values_decimate_by_) || !defined(_di_f_limit_valuess_append_) - #if !defined(_di_f_limit_valuess_adjust_) || !defined(_di_f_limit_valuess_decimate_by_) f_status_t private_f_limit_valuess_adjust(const f_number_unsigned_t length, f_limit_valuess_t *valuess) { @@ -75,23 +39,11 @@ extern "C" { for (f_number_unsigned_t i = length; i < valuess->size; ++i) { - status = f_memory_destroy(valuess->array[i].size, sizeof(f_limit_values_t), (void **) & valuess->array[i].array); + status = f_memory_array_adjust(0, sizeof(f_limit_value_t), (void **) &valuess->array[i].array, &valuess->array[i].used, &valuess->array[i].size); if (F_status_is_error(status)) return status; - - valuess->array[i].size = 0; - valuess->array[i].used = 0; } // for - status = f_memory_adjust(valuess->size, length, sizeof(f_limit_values_t), (void **) & valuess->array); - if (F_status_is_error(status)) return status; - - valuess->size = length; - - if (valuess->used > valuess->size) { - valuess->used = length; - } - - return F_none; + return f_memory_array_adjust(length, sizeof(f_limit_values_t), (void **) &valuess->array, &valuess->used, &valuess->size); } #endif // !defined(_di_f_limit_valuess_adjust_) || !defined(_di_f_limit_valuess_decimate_by_) @@ -102,23 +54,11 @@ extern "C" { for (f_number_unsigned_t i = length; i < valuess->size; ++i) { - status = f_memory_delete(valuess->array[i].size, sizeof(f_limit_values_t), (void **) & valuess->array[i].array); + status = f_memory_array_resize(0, sizeof(f_limit_value_t), (void **) &valuess->array[i].array, &valuess->array[i].used, &valuess->array[i].size); if (F_status_is_error(status)) return status; - - valuess->array[i].size = 0; - valuess->array[i].used = 0; } // for - status = f_memory_resize(valuess->size, length, sizeof(f_limit_values_t), (void **) & valuess->array); - if (F_status_is_error(status)) return status; - - valuess->size = length; - - if (valuess->used > valuess->size) { - valuess->used = length; - } - - return F_none; + return f_memory_array_resize(length, sizeof(f_limit_values_t), (void **) &valuess->array, &valuess->used, &valuess->size); } #endif // !defined(_di_f_limit_valuess_decrease_by_) || !defined(_di_f_limit_valuess_increase_) || !defined(_di_f_limit_valuess_increase_by_) || !defined(_di_f_limit_valuess_resize_) diff --git a/level_0/f_limit/c/limit/private-value.h b/level_0/f_limit/c/limit/private-value.h index 57cca27..c905bce 100644 --- a/level_0/f_limit/c/limit/private-value.h +++ b/level_0/f_limit/c/limit/private-value.h @@ -16,29 +16,6 @@ extern "C" { #endif /** - * Private implementation for resizing the values array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param values - * The values array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_limit_values_adjust() - * @see f_limit_values_decimate_by() - */ -#if !defined(_di_f_limit_values_adjust_) || !defined(_di_f_limit_values_decimate_by_) - extern f_status_t private_f_limit_values_adjust(const f_number_unsigned_t length, f_limit_values_t *values) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_limit_values_adjust_) || !defined(_di_f_limit_values_decimate_by_) - -/** * Private implementation for appending the value array. * * Intended to be shared to each of the different implementation variations. @@ -86,31 +63,6 @@ extern "C" { #endif // !defined(_di_f_limit_values_append_) || !defined(_di_f_limit_values_append_all_) || !defined(_di_f_limit_valuess_append_all_) /** - * Private implementation for resizing the values array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param values - * The values array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_limit_values_resize() - * @see f_limit_values_append() - * @see f_limit_values_decimate_by() - * @see f_limit_valuess_append() - */ -#if !defined(_di_f_limit_values_resize_) || !defined(_di_f_limit_values_append_) || !defined(_di_f_limit_values_decimate_by_) || !defined(_di_f_limit_valuess_append_) - extern f_status_t private_f_limit_values_resize(const f_number_unsigned_t length, f_limit_values_t *values) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_limit_values_resize_) || !defined(_di_f_limit_values_append_) || !defined(_di_f_limit_values_decimate_by_) || !defined(_di_f_limit_valuess_append_) - -/** * Private implementation for resizing the valuess array. * * Intended to be shared to each of the different implementation variations. diff --git a/level_0/f_limit/c/limit/set.c b/level_0/f_limit/c/limit/set.c index 6b619c2..1e78b77 100644 --- a/level_0/f_limit/c/limit/set.c +++ b/level_0/f_limit/c/limit/set.c @@ -12,7 +12,7 @@ extern "C" { if (!sets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_limit_sets_adjust(length, sets); + return f_memory_array_adjust(length, sizeof(f_limit_set_t), (void **) &sets->array, &sets->used, &sets->size); } #endif // _di_f_limit_sets_adjust_ @@ -44,13 +44,7 @@ extern "C" { if (!sets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (sets->size > amount) { - return private_f_limit_sets_adjust(sets->size - amount, sets); - } - - return private_f_limit_sets_adjust(0, sets); + return f_memory_array_decimate_by(amount, sizeof(f_limit_set_t), (void **) &sets->array, &sets->used, &sets->size); } #endif // _di_f_limit_sets_decimate_by_ @@ -60,13 +54,7 @@ extern "C" { if (!sets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (sets->size > amount) { - return private_f_limit_sets_resize(sets->size - amount, sets); - } - - return private_f_limit_sets_resize(0, sets); + return f_memory_array_decrease_by(amount, sizeof(f_limit_set_t), (void **) &sets->array, &sets->used, &sets->size); } #endif // _di_f_limit_sets_decrease_by_ @@ -76,21 +64,7 @@ extern "C" { if (!sets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (step && sets->used + 1 > sets->size) { - f_number_unsigned_t size = sets->used + step; - - if (size > F_number_t_size_unsigned_d) { - if (sets->used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_number_t_size_unsigned_d; - } - - return private_f_limit_sets_resize(size, sets); - } - - return F_data_not; + return f_memory_array_increase(step, sizeof(f_limit_set_t), (void **) &sets->array, &sets->used, &sets->size); } #endif // _di_f_limit_sets_increase_ @@ -100,17 +74,7 @@ extern "C" { if (!sets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (sets->used + amount > sets->size) { - if (sets->used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_limit_sets_resize(sets->used + amount, sets); - } - - return F_data_not; + return f_memory_array_increase_by(amount, sizeof(f_limit_set_t), (void **) &sets->array, &sets->used, &sets->size); } #endif // _di_f_limit_sets_increase_by_ @@ -120,7 +84,7 @@ extern "C" { if (!sets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_limit_sets_resize(length, sets); + return f_memory_array_resize(length, sizeof(f_limit_set_t), (void **) &sets->array, &sets->used, &sets->size); } #endif // _di_f_limit_sets_resize_ @@ -142,12 +106,8 @@ extern "C" { if (!source.used) return F_data_not; - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_limit_setss_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_limit_sets_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; status = private_f_limit_sets_append_all(source, &destination->array[destination->used]); if (F_status_is_error(status)) return status; @@ -166,12 +126,8 @@ extern "C" { if (!source.used) return F_data_not; - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_limit_setss_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase(source.used, sizeof(f_limit_sets_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { @@ -195,11 +151,7 @@ extern "C" { if (!amount) return F_data_not; - if (setss->size > amount) { - return private_f_limit_setss_adjust(setss->size - amount, setss); - } - - return private_f_limit_setss_adjust(0, setss); + return private_f_limit_setss_adjust((setss->size > amount) ? setss->size - amount : 0, setss); } #endif // _di_f_limit_setss_decimate_by_ @@ -211,11 +163,7 @@ extern "C" { if (!amount) return F_data_not; - if (setss->size > amount) { - return private_f_limit_setss_resize(setss->size - amount, setss); - } - - return private_f_limit_setss_resize(0, setss); + return private_f_limit_setss_resize((setss->size > amount) ? setss->size - amount : 0, setss); } #endif // _di_f_limit_setss_decrease_by_ @@ -225,21 +173,7 @@ extern "C" { if (!setss) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (step && setss->used + 1 > setss->size) { - f_number_unsigned_t size = setss->used + step; - - if (size > F_number_t_size_unsigned_d) { - if (setss->used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_number_t_size_unsigned_d; - } - - return private_f_limit_setss_resize(size, setss); - } - - return F_data_not; + return f_memory_array_increase(step, sizeof(f_limit_sets_t), (void **) &setss->array, &setss->used, &setss->size); } #endif // _di_f_limit_setss_increase_ @@ -249,17 +183,7 @@ extern "C" { if (!setss) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (setss->used + amount > setss->size) { - if (setss->used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_limit_setss_resize(setss->used + amount, setss); - } - - return F_data_not; + return f_memory_array_increase_by(amount, sizeof(f_limit_sets_t), (void **) &setss->array, &setss->used, &setss->size); } #endif // _di_f_limit_setss_increase_by_ diff --git a/level_0/f_limit/c/limit/set.h b/level_0/f_limit/c/limit/set.h index 6ee1098..b0f2560 100644 --- a/level_0/f_limit/c/limit/set.h +++ b/level_0/f_limit/c/limit/set.h @@ -117,11 +117,13 @@ extern "C" { * The sets array to resize. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_limit_sets_adjust_ extern f_status_t f_limit_sets_adjust(const f_number_unsigned_t length, f_limit_sets_t *sets); @@ -139,9 +141,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_limit_sets_append_ extern f_status_t f_limit_sets_append(const f_limit_set_t source, f_limit_sets_t *destination); @@ -159,9 +167,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_limit_sets_append_all_ extern f_status_t f_limit_sets_append_all(const f_limit_sets_t source, f_limit_sets_t *destination); @@ -180,12 +194,14 @@ extern "C" { * The sets array to resize. * * @return - * F_none on success. - * F_data_not if amount is 0. + * @return + * Success from f_memory_array_decimate_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_array_decimate_by(). + * + * @see f_memory_array_decimate_by() */ #ifndef _di_f_limit_sets_decimate_by_ extern f_status_t f_limit_sets_decimate_by(const f_number_unsigned_t amount, f_limit_sets_t *sets); @@ -204,11 +220,13 @@ extern "C" { * The sets array to resize. * * @return - * F_none on success. + * Success from f_memory_array_decrease_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_decrease_by(). + * + * @see f_memory_array_decrease_by() */ #ifndef _di_f_limit_sets_decrease_by_ extern f_status_t f_limit_sets_decrease_by(const f_number_unsigned_t amount, f_limit_sets_t *sets); @@ -227,13 +245,13 @@ extern "C" { * The sets array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * Success from f_memory_array_increase(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase(). + * + * @see f_memory_array_increase() */ #ifndef _di_f_limit_sets_increase_ extern f_status_t f_limit_sets_increase(const f_number_unsigned_t step, f_limit_sets_t *sets); @@ -252,13 +270,13 @@ extern "C" { * The sets array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * Success from f_memory_array_increase_by(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * + * @see f_memory_array_increase_by() */ #ifndef _di_f_limit_sets_increase_by_ extern f_status_t f_limit_sets_increase_by(const f_number_unsigned_t amount, f_limit_sets_t *sets); @@ -273,11 +291,13 @@ extern "C" { * The sets array to adjust. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_limit_sets_resize_ extern f_status_t f_limit_sets_resize(const f_number_unsigned_t length, f_limit_sets_t *sets); @@ -292,12 +312,13 @@ extern "C" { * The setss array to resize. * * @return - * F_none on success. + * Success from f_memory_array_adjust(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_memory_destroy(). + * Errors (with error bit) from: f_memory_array_adjust(). + * + * @see f_memory_array_adjust() */ #ifndef _di_f_limit_setss_adjust_ extern f_status_t f_limit_setss_adjust(const f_number_unsigned_t length, f_limit_setss_t *setss); @@ -315,9 +336,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_limit_setss_append_ extern f_status_t f_limit_setss_append(const f_limit_sets_t source, f_limit_setss_t *destination); @@ -335,9 +362,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_limit_setss_append_all_ extern f_status_t f_limit_setss_append_all(const f_limit_setss_t source, f_limit_setss_t *destination); @@ -356,13 +389,15 @@ extern "C" { * The setss array to resize. * * @return - * F_none on success. - * F_data_not if amount is 0. + * F_data_not on success, but the amount to decrease by is 0. + * + * Success from f_memory_array_decimate_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_memory_destroy(). + * Errors (with error bit) from: f_memory_array_decimate_by(). + * + * @see f_memory_array_decimate_by() */ #ifndef _di_f_limit_setss_decimate_by_ extern f_status_t f_limit_setss_decimate_by(const f_number_unsigned_t amount, f_limit_setss_t *setss); @@ -381,12 +416,15 @@ extern "C" { * The setss array to resize. * * @return - * F_none on success. + * F_data_not on success, but the amount to decrease by is 0. + * + * Success from f_memory_array_decrease_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_delete(). - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_decrease_by(). + * + * @see f_memory_array_decrease_by() */ #ifndef _di_f_limit_setss_decrease_by_ extern f_status_t f_limit_setss_decrease_by(const f_number_unsigned_t amount, f_limit_setss_t *setss); @@ -405,13 +443,13 @@ extern "C" { * The setss array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * Success from f_memory_array_increase(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase(). + * + * @see f_memory_array_increase() */ #ifndef _di_f_limit_setss_increase_ extern f_status_t f_limit_setss_increase(const f_number_unsigned_t step, f_limit_setss_t *setss); @@ -430,13 +468,13 @@ extern "C" { * The setss array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * Success from f_memory_array_increase_by(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * + * @see f_memory_array_increase_by() */ #ifndef _di_f_limit_setss_increase_by_ extern f_status_t f_limit_setss_increase_by(const f_number_unsigned_t amount, f_limit_setss_t *setss); @@ -451,12 +489,13 @@ extern "C" { * The setss array to adjust. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_delete(). - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_limit_setss_resize_ extern f_status_t f_limit_setss_resize(const f_number_unsigned_t length, f_limit_setss_t *setss); diff --git a/level_0/f_limit/c/limit/value.c b/level_0/f_limit/c/limit/value.c index 173f702..f1e3d4c 100644 --- a/level_0/f_limit/c/limit/value.c +++ b/level_0/f_limit/c/limit/value.c @@ -12,7 +12,7 @@ extern "C" { if (!values) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_limit_values_adjust(length, values); + return f_memory_array_adjust(length, sizeof(f_limit_value_t), (void **) &values->array, &values->used, &values->size); } #endif // _di_f_limit_values_adjust_ @@ -44,13 +44,7 @@ extern "C" { if (!values) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (values->size > amount) { - return private_f_limit_values_adjust(values->size - amount, values); - } - - return private_f_limit_values_adjust(0, values); + return f_memory_array_decimate_by(amount, sizeof(f_limit_value_t), (void **) &values->array, &values->used, &values->size); } #endif // _di_f_limit_values_decimate_by_ @@ -60,13 +54,7 @@ extern "C" { if (!values) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (values->size > amount) { - return private_f_limit_values_resize(values->size - amount, values); - } - - return private_f_limit_values_resize(0, values); + return f_memory_array_decrease_by(amount, sizeof(f_limit_value_t), (void **) &values->array, &values->used, &values->size); } #endif // _di_f_limit_values_decrease_by_ @@ -76,21 +64,7 @@ extern "C" { if (!values) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (step && values->used + 1 > values->size) { - f_number_unsigned_t size = values->used + step; - - if (size > F_number_t_size_unsigned_d) { - if (values->used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_number_t_size_unsigned_d; - } - - return private_f_limit_values_resize(size, values); - } - - return F_data_not; + return f_memory_array_increase(step, sizeof(f_limit_value_t), (void **) &values->array, &values->used, &values->size); } #endif // _di_f_limit_values_increase_ @@ -100,17 +74,7 @@ extern "C" { if (!values) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (values->used + amount > values->size) { - if (values->used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_limit_values_resize(values->used + amount, values); - } - - return F_data_not; + return f_memory_array_increase_by(amount, sizeof(f_limit_value_t), (void **) &values->array, &values->used, &values->size); } #endif // _di_f_limit_values_increase_by_ @@ -120,7 +84,7 @@ extern "C" { if (!values) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_limit_values_resize(length, values); + return f_memory_array_resize(length, sizeof(f_limit_value_t), (void **) &values->array, &values->used, &values->size); } #endif // _di_f_limit_values_resize_ @@ -142,12 +106,8 @@ extern "C" { if (!source.used) return F_data_not; - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_limit_valuess_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_limit_values_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; status = private_f_limit_values_append_all(source, &destination->array[destination->used]); if (F_status_is_error(status)) return status; @@ -166,12 +126,8 @@ extern "C" { if (!source.used) return F_data_not; - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_limit_valuess_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase(source.used, sizeof(f_limit_values_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { @@ -195,11 +151,7 @@ extern "C" { if (!amount) return F_data_not; - if (valuess->size > amount) { - return private_f_limit_valuess_adjust(valuess->size - amount, valuess); - } - - return private_f_limit_valuess_adjust(0, valuess); + return private_f_limit_valuess_adjust((valuess->size > amount) ? valuess->size - amount : 0, valuess); } #endif // _di_f_limit_valuess_decimate_by_ @@ -211,11 +163,7 @@ extern "C" { if (!amount) return F_data_not; - if (valuess->size > amount) { - return private_f_limit_valuess_resize(valuess->size - amount, valuess); - } - - return private_f_limit_valuess_resize(0, valuess); + return private_f_limit_valuess_resize((valuess->size > amount) ? valuess->size - amount : 0, valuess); } #endif // _di_f_limit_valuess_decrease_by_ @@ -225,21 +173,7 @@ extern "C" { if (!valuess) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (step && valuess->used + 1 > valuess->size) { - f_number_unsigned_t size = valuess->used + step; - - if (size > F_number_t_size_unsigned_d) { - if (valuess->used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_number_t_size_unsigned_d; - } - - return private_f_limit_valuess_resize(size, valuess); - } - - return F_data_not; + return f_memory_array_increase(step, sizeof(f_limit_values_t), (void **) &valuess->array, &valuess->used, &valuess->size); } #endif // _di_f_limit_valuess_increase_ @@ -249,17 +183,7 @@ extern "C" { if (!valuess) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (valuess->used + amount > valuess->size) { - if (valuess->used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_limit_valuess_resize(valuess->used + amount, valuess); - } - - return F_data_not; + return f_memory_array_increase_by(amount, sizeof(f_limit_values_t), (void **) &valuess->array, &valuess->used, &valuess->size); } #endif // _di_f_limit_valuess_increase_by_ diff --git a/level_0/f_limit/c/limit/value.h b/level_0/f_limit/c/limit/value.h index f3e139d..7768e51 100644 --- a/level_0/f_limit/c/limit/value.h +++ b/level_0/f_limit/c/limit/value.h @@ -113,11 +113,13 @@ extern "C" { * The values array to resize. * * @return - * F_none on success. + * Success from f_memory_array_adjust(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_array_adjust(). + * + * @see f_memory_array_adjust() */ #ifndef _di_f_limit_values_adjust_ extern f_status_t f_limit_values_adjust(const f_number_unsigned_t length, f_limit_values_t *values); @@ -135,9 +137,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_limit_values_append_ extern f_status_t f_limit_values_append(const f_limit_value_t source, f_limit_values_t *destination); @@ -155,9 +163,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_limit_values_append_all_ extern f_status_t f_limit_values_append_all(const f_limit_values_t source, f_limit_values_t *destination); @@ -176,12 +190,13 @@ extern "C" { * The values array to resize. * * @return - * F_none on success. - * F_data_not if amount is 0. + * Success from f_memory_array_decimate_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_array_decimate_by(). + * + * @see f_memory_array_decimate_by() */ #ifndef _di_f_limit_values_decimate_by_ extern f_status_t f_limit_values_decimate_by(const f_number_unsigned_t amount, f_limit_values_t *values); @@ -200,11 +215,13 @@ extern "C" { * The values array to resize. * * @return - * F_none on success. + * Success from f_memory_array_decrease_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_decrease_by(). + * + * @see f_memory_array_decrease_by() */ #ifndef _di_f_limit_values_decrease_by_ extern f_status_t f_limit_values_decrease_by(const f_number_unsigned_t amount, f_limit_values_t *values); @@ -223,13 +240,13 @@ extern "C" { * The values array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * Success from f_memory_array_increase(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase(). + * + * @see f_memory_array_increase() */ #ifndef _di_f_limit_values_increase_ extern f_status_t f_limit_values_increase(const f_number_unsigned_t step, f_limit_values_t *values); @@ -248,13 +265,13 @@ extern "C" { * The values array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * Success from f_memory_array_increase_by(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * + * @see f_memory_array_increase_by() */ #ifndef _di_f_limit_values_increase_by_ extern f_status_t f_limit_values_increase_by(const f_number_unsigned_t amount, f_limit_values_t *values); @@ -269,11 +286,13 @@ extern "C" { * The values array to adjust. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_limit_values_resize_ extern f_status_t f_limit_values_resize(const f_number_unsigned_t length, f_limit_values_t *values); @@ -288,12 +307,13 @@ extern "C" { * The valuess array to resize. * * @return - * F_none on success. + * Success from f_memory_array_adjust(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_memory_destroy(). + * Errors (with error bit) from: f_memory_array_adjust(). + * + * @see f_memory_array_adjust() */ #ifndef _di_f_limit_valuess_adjust_ extern f_status_t f_limit_valuess_adjust(const f_number_unsigned_t length, f_limit_valuess_t *valuess); @@ -311,9 +331,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_limit_valuess_append_ extern f_status_t f_limit_valuess_append(const f_limit_values_t source, f_limit_valuess_t *destination); @@ -331,9 +357,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_limit_valuess_append_all_ extern f_status_t f_limit_valuess_append_all(const f_limit_valuess_t source, f_limit_valuess_t *destination); @@ -352,13 +384,15 @@ extern "C" { * The valuess array to resize. * * @return - * F_none on success. - * F_data_not if amount is 0. + * F_data_not on success, but the amount to decrease by is 0. + * + * Success from f_memory_array_decimate_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_memory_destroy(). + * Errors (with error bit) from: f_memory_array_decimate_by(). + * + * @see f_memory_array_decimate_by() */ #ifndef _di_f_limit_valuess_decimate_by_ extern f_status_t f_limit_valuess_decimate_by(const f_number_unsigned_t amount, f_limit_valuess_t *valuess); @@ -377,12 +411,15 @@ extern "C" { * The valuess array to resize. * * @return - * F_none on success. + * F_data_not on success, but the amount to decrease by is 0. + * + * Success from f_memory_array_decrease_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_delete(). - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_decrease_by(). + * + * @see f_memory_array_decrease_by() */ #ifndef _di_f_limit_valuess_decrease_by_ extern f_status_t f_limit_valuess_decrease_by(const f_number_unsigned_t amount, f_limit_valuess_t *valuess); @@ -401,13 +438,13 @@ extern "C" { * The valuess array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * Success from f_memory_array_increase(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase(). + * + * @see f_memory_array_increase() */ #ifndef _di_f_limit_valuess_increase_ extern f_status_t f_limit_valuess_increase(const f_number_unsigned_t step, f_limit_valuess_t *valuess); @@ -426,13 +463,13 @@ extern "C" { * The valuess array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * Success from f_memory_array_increase_by(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * + * @see f_memory_array_increase_by() */ #ifndef _di_f_limit_valuess_increase_by_ extern f_status_t f_limit_valuess_increase_by(const f_number_unsigned_t amount, f_limit_valuess_t *valuess); @@ -447,12 +484,13 @@ extern "C" { * The valuess array to adjust. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_delete(). - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_limit_valuess_resize_ extern f_status_t f_limit_valuess_resize(const f_number_unsigned_t length, f_limit_valuess_t *valuess); diff --git a/level_0/f_memory/c/memory.h b/level_0/f_memory/c/memory.h index d285ad4..b3b9045 100644 --- a/level_0/f_memory/c/memory.h +++ b/level_0/f_memory/c/memory.h @@ -21,6 +21,7 @@ // FLL-0 memory includes. #include +#include #include #ifdef __cplusplus diff --git a/level_0/f_memory/c/memory/array.c b/level_0/f_memory/c/memory/array.c new file mode 100644 index 0000000..198dcee --- /dev/null +++ b/level_0/f_memory/c/memory/array.c @@ -0,0 +1,115 @@ +#include "../memory.h" +#include "private-array.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _di_f_memory_array_adjust_ + f_status_t f_memory_array_adjust(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + #ifndef _di_level_0_parameter_checking_ + if (!array) return F_status_set_error(F_parameter); + if (!used) return F_status_set_error(F_parameter); + if (!size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + + return private_f_memory_array_adjust(length, width, array, used, size); + } +#endif // _di_f_memory_array_adjust_ + +#ifndef _di_f_memory_array_decimate_by_ + f_status_t f_memory_array_decimate_by(const f_number_unsigned_t amount, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + #ifndef _di_level_0_parameter_checking_ + if (!array) return F_status_set_error(F_parameter); + if (!used) return F_status_set_error(F_parameter); + if (!size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + if (*size > amount) return private_f_memory_array_adjust(*size - amount, width, array, used, size); + + return private_f_memory_array_adjust(0, width, array, used, size); + } +#endif // _di_f_memory_array_decimate_by_ + +#ifndef _di_f_memory_array_decrease_by_ + f_status_t f_memory_array_decrease_by(const f_number_unsigned_t amount, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + #ifndef _di_level_0_parameter_checking_ + if (!array) return F_status_set_error(F_parameter); + if (!used) return F_status_set_error(F_parameter); + if (!size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + if (*size > amount) return private_f_memory_array_resize(*size - amount, width, array, used, size); + + return private_f_memory_array_resize(0, width, array, used, size); + } +#endif // _di_f_memory_array_decrease_by_ + +#ifndef _di_f_memory_array_increase_ + f_status_t f_memory_array_increase(const f_number_unsigned_t step, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + #ifndef _di_level_0_parameter_checking_ + if (!array) return F_status_set_error(F_parameter); + if (!used) return F_status_set_error(F_parameter); + if (!size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (step && *used + 1 > *size) { + f_number_unsigned_t length = *used + step; + + if (step > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + + if (*size > F_number_t_size_unsigned_d) { + if (*used + 1 > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + if (*used + length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + + length = F_number_t_size_unsigned_d; + } + + return private_f_memory_array_resize(length, width, array, used, size); + } + + return F_data_not; + } +#endif // _di_f_memory_array_increase_ + +#ifndef _di_f_memory_array_increase_by_ + f_status_t f_memory_array_increase_by(const f_number_unsigned_t amount, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + #ifndef _di_level_0_parameter_checking_ + if (!array) return F_status_set_error(F_parameter); + if (!used) return F_status_set_error(F_parameter); + if (!size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (!amount) return F_data_not; + + if (*used + amount > *size) { + if (*used + amount > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + + return private_f_memory_array_resize(*used + amount, width, array, used, size); + } + + return F_data_not; + } +#endif // _di_f_memory_array_increase_by_ + +#ifndef _di_f_memory_array_resize_ + f_status_t f_memory_array_resize(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + #ifndef _di_level_0_parameter_checking_ + if (!array) return F_status_set_error(F_parameter); + if (!used) return F_status_set_error(F_parameter); + if (!size) return F_status_set_error(F_parameter); + #endif // _di_level_0_parameter_checking_ + + if (length > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); + + return private_f_memory_array_resize(length, width, array, used, size); + } +#endif // _di_f_memory_array_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_memory/c/memory/array.h b/level_0/f_memory/c/memory/array.h new file mode 100644 index 0000000..29ef8a0 --- /dev/null +++ b/level_0/f_memory/c/memory/array.h @@ -0,0 +1,213 @@ +/** + * FLL - Level 0 + * + * Project: Memory + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Defines memory array data. + * + * This is auto-included by memory.h and should not need to be explicitly included. + */ +#ifndef _F_memory_array_h +#define _F_memory_array_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Resize the memory array. + * + * This function is only useful for simple structures of the form "{ array, used, size }" where the array is a simple type. + * If the simple type that is "array" requires additional memory manipulation on allocation or de-allocation, then do not use this function. + * + * @param length + * The new size to use. + * @param width + * The size of the structure represented by array. + * The word "width" is used due to conflicts of already using "length" and "size". + * @param array + * The structure.array to resize. + * @param used + * The structure.used. + * @param size + * The structure.size. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_memory_array_adjust_ + extern f_status_t f_memory_array_adjust(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +#endif // _di_f_memory_array_adjust_ + +/** + * Resize the memory array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * This function is only useful for simple structures of the form "{ array, used, size }" where the array is a simple type. + * If the simple type that is "array" requires additional memory manipulation on allocation or de-allocation, then do not use this function. + * + * @param amount + * A positive number representing how much to decimate the size by. + * @param width + * The size of the structure represented by array. + * The word "width" is used due to conflicts of already using "length" and "size". + * @param array + * The structure.array to resize. + * @param used + * The structure.used. + * @param size + * The structure.size. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_memory_array_decimate_by_ + extern f_status_t f_memory_array_decimate_by(const f_number_unsigned_t amount, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +#endif // _di_f_memory_array_decimate_by_ + +/** + * Resize the memory array to a smaller size. + * + * This will resize making the array smaller based on (size - given length). + * If the given length is too small, then the resize will fail. + * This will not shrink the size to less than 0. + * + * This function is only useful for simple structures of the form "{ array, used, size }" where the array is a simple type. + * If the simple type that is "array" requires additional memory manipulation on allocation or de-allocation, then do not use this function. + * + * @param amount + * A positive number representing how much to decrease the size by. + * @param width + * The size of the structure represented by array. + * The word "width" is used due to conflicts of already using "length" and "size". + * @param array + * The structure.array to resize. + * @param used + * The structure.used. + * @param size + * The structure.size. + * + * @return + * F_none on success. + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_memory_array_decrease_by_ + extern f_status_t f_memory_array_decrease_by(const f_number_unsigned_t amount, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +#endif // _di_f_memory_array_decrease_by_ + +/** + * Increase the size of the memory array, but only if necessary. + * + * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * This function is only useful for simple structures of the form "{ array, used, size }" where the array is a simple type. + * If the simple type that is "array" requires additional memory manipulation on allocation or de-allocation, then do not use this function. + * + * @param step + * The allocation step to use. + * Must be greater than 0. + * @param width + * The size of the structure represented by array. + * The word "width" is used due to conflicts of already using "length" and "size". + * @param array + * The structure.array to resize. + * @param used + * The structure.used. + * @param size + * The structure.size. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_memory_array_increase_ + extern f_status_t f_memory_array_increase(const f_number_unsigned_t step, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +#endif // _di_f_memory_array_increase_ + +/** + * Resize the memory array to a larger size. + * + * This will resize making the array larger based on the given length. + * If the given length is too large for the buffer, then attempt to set max buffer size (F_number_t_size_unsigned_d). + * If already set to the maximum buffer size, then the resize will fail. + * + * This function is only useful for simple structures of the form "{ array, used, size }" where the array is a simple type. + * If the simple type that is "array" requires additional memory manipulation on allocation or de-allocation, then do not use this function. + * + * @param amount + * A positive number representing how much to increase the size by. + * @param width + * The size of the structure represented by array. + * The word "width" is used due to conflicts of already using "length" and "size". + * @param array + * The structure.array to resize. + * @param used + * The structure.used. + * @param size + * The structure.size. + * + * @return + * F_none on success. + * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + * F_array_too_large (with error bit) if the new array length is too large. + */ +#ifndef _di_f_memory_array_increase_by_ + extern f_status_t f_memory_array_increase_by(const f_number_unsigned_t amount, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +#endif // _di_f_memory_array_increase_by_ + +/** + * Resize the memory array. + * + * This function is only useful for simple structures of the form "{ array, used, size }" where the array is a simple type. + * If the simple type that is "array" requires additional memory manipulation on allocation or de-allocation, then do not use this function. + * + * @param length + * The new size to use. + * @param width + * The size of the structure represented by array. + * The word "width" is used due to conflicts of already using "length" and "size". + * @param array + * The structure.array to resize. + * @param used + * The structure.used. + * @param size + * The structure.size. + * + * @return + * F_none on success. + * + * F_array_too_large (with error bit) if the new array length is too large. + * F_memory_not (with error bit) on out of memory. + * F_parameter (with error bit) if a parameter is invalid. + */ +#ifndef _di_f_memory_array_resize_ + extern f_status_t f_memory_array_resize(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size); +#endif // _di_f_memory_array_resize_ + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _F_memory_array_h diff --git a/level_0/f_memory/c/memory/private-array.c b/level_0/f_memory/c/memory/private-array.c new file mode 100644 index 0000000..f5850f6 --- /dev/null +++ b/level_0/f_memory/c/memory/private-array.c @@ -0,0 +1,42 @@ +#include "../memory.h" +#include "private-array.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#if !defined(_di_f_memory_array_adjust_) || !defined(_di_f_memory_array_decimate_by_) + f_status_t private_f_memory_array_adjust(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + + const f_status_t status = f_memory_adjust(*size, length, width, array); + if (F_status_is_error(status)) return status; + + *size = length; + + if (*used > *size) { + *used = length; + } + + return F_none; + } +#endif // !defined(_di_f_memory_array_adjust_) || !defined(_di_f_memory_array_decimate_by_) + +#if !defined(_di_f_memory_array_decrease_by_) || !defined(_di_f_memory_array_increase_) || !defined(_di_f_memory_array_increase_by_) || !defined(_di_f_memory_array_resize_) + f_status_t private_f_memory_array_resize(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) { + + const f_status_t status = f_memory_resize(*size, length, width, array); + if (F_status_is_error(status)) return status; + + *size = length; + + if (*used > *size) { + *used = length; + } + + return F_none; + } +#endif // !defined(_di_f_memory_array_decrease_by_) || !defined(_di_f_memory_array_increase_) || !defined(_di_f_memory_array_increase_by_) || !defined(_di_f_memory_array_resize_) + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_memory/c/memory/private-array.h b/level_0/f_memory/c/memory/private-array.h new file mode 100644 index 0000000..261f860 --- /dev/null +++ b/level_0/f_memory/c/memory/private-array.h @@ -0,0 +1,84 @@ +/** + * FLL - Level 0 + * + * Project: Memory + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * These are provided for internal reduction in redundant code. + * These should not be exposed/used outside of this project. + */ +#ifndef _PRIVATE_F_memory_array_h +#define _PRIVATE_F_memory_array_h + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param width + * The size of the structure represented by array. + * The word "width" is used due to conflicts of already using "length" and "size". + * @param array + * The structure.array to adjust. + * @param used + * The structure.used. + * @param size + * The structure.size. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_adjust(). + * + * @see f_memory_array_adjust() + * @see f_memory_array_decimate_by() + * @see f_memory_adjust() + */ +#if !defined(_di_f_memory_array_adjust_) || !defined(_di_f_memory_array_decimate_by_) + extern f_status_t private_f_memory_array_adjust(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_memory_array_adjust_) || !defined(_di_f_memory_array_decimate_by_) + +/** + * Private implementation for resizing. + * + * Intended to be shared to each of the different implementation variations. + * + * @param length + * The new size to use. + * @param width + * The size of the structure represented by array. + * The word "width" is used due to conflicts of already using "length" and "size". + * @param array + * The structure.array to resize. + * @param used + * The structure.used. + * @param size + * The structure.size. + * + * @return + * F_none on success. + * + * Errors (with error bit) from: f_memory_resize(). + * + * @see f_memory_array_decrease_by() + * @see f_memory_array_increase() + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() + * @see f_memory_resize() + */ +#if !defined(_di_f_memory_array_decrease_by_) || !defined(_di_f_memory_array_increase_) || !defined(_di_f_memory_array_increase_by_) || !defined(_di_f_memory_array_resize_) + extern f_status_t private_f_memory_array_resize(const f_number_unsigned_t length, const size_t width, void ** array, f_number_unsigned_t * const used, f_number_unsigned_t * const size) F_attribute_visibility_internal_d; +#endif // !defined(_di_f_memory_array_decrease_by_) || !defined(_di_f_memory_array_increase_) || !defined(_di_f_memory_array_increase_by_) || !defined(_di_f_memory_array_resize_) + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // _PRIVATE_F_memory_array_h diff --git a/level_0/f_memory/c/memory/structure.c b/level_0/f_memory/c/memory/structure.c index 0e5b228..9099b9a 100644 --- a/level_0/f_memory/c/memory/structure.c +++ b/level_0/f_memory/c/memory/structure.c @@ -30,9 +30,7 @@ extern "C" { if (!size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (amount && *size) { - return private_f_memory_structure_adjust(amount <= *size ? *size - amount : 0, type_size, structure, used, size); - } + if (amount && *size) return private_f_memory_structure_adjust(amount <= *size ? *size - amount : 0, type_size, structure, used, size); return F_data_not; } @@ -47,9 +45,7 @@ extern "C" { if (!size) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (amount && *size) { - return private_f_memory_structure_resize(amount <= *size ? *size - amount : 0, type_size, structure, used, size); - } + if (amount && *size) return private_f_memory_structure_resize(amount <= *size ? *size - amount : 0, type_size, structure, used, size); return F_data_not; } @@ -69,9 +65,7 @@ extern "C" { f_number_unsigned_t length_new = *used + step; if (length_new > F_number_t_size_unsigned_d) { - if (*used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } + if (*used + 1 > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); length_new = F_number_t_size_unsigned_d; } @@ -93,9 +87,7 @@ extern "C" { #endif // _di_level_0_parameter_checking_ if (amount && *used + amount > *size) { - if (*used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } + if (*used + amount > F_number_t_size_unsigned_d) return F_status_set_error(F_array_too_large); return private_f_memory_structure_resize(*used + amount, type_size, structure, used, size); } diff --git a/level_0/f_memory/data/build/settings b/level_0/f_memory/data/build/settings index d3030ea..55426ad 100644 --- a/level_0/f_memory/data/build/settings +++ b/level_0/f_memory/data/build/settings @@ -31,9 +31,10 @@ build_language c build_libraries -lc -build_sources_library memory.c private-memory.c memory/structure.c +build_sources_library memory.c memory/array.c memory/structure.c +build_sources_library private-memory.c memory/private-array.c -build_sources_headers memory.h memory/common.h memory/structure.h +build_sources_headers memory.h memory/array.h memory/common.h memory/structure.h build_script yes build_shared yes diff --git a/level_0/f_memory/data/build/settings-tests b/level_0/f_memory/data/build/settings-tests index dd5dcc4..d60609a 100644 --- a/level_0/f_memory/data/build/settings-tests +++ b/level_0/f_memory/data/build/settings-tests @@ -24,6 +24,7 @@ build_libraries -lc -lcmocka build_libraries-individual -lf_memory build_sources_program test-memory-adjust.c test-memory-delete.c test-memory-destroy.c test-memory-new_aligned.c test-memory-new.c test-memory-resize.c test-memory.c +build_sources_program test-memory-array_adjust.c test-memory-array_decimate_by.c test-memory-array_decrease_by.c test-memory-array_increase.c test-memory-array_increase_by.c test-memory-array_resize.c build_script no build_shared yes diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_adjust.c b/level_0/f_memory/tests/unit/c/test-memory-array_adjust.c new file mode 100644 index 0000000..e41538b --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_adjust.c @@ -0,0 +1,80 @@ +#include "test-memory.h" +#include "test-memory-array_adjust.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_memory_array_adjust__parameter_checking(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_adjust(length, sizeof(int), 0, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_adjust(length, sizeof(int), 0, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_adjust(length, sizeof(int), (void **) &data.array, 0, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_adjust(length, sizeof(int), (void **) &data.array, &data.used, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + assert_null(data.array); +} + +void test__f_memory_array_adjust__returns_array_too_large(void **state) { + + const f_number_unsigned_t length = F_number_t_size_unsigned_d + 1; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_adjust(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_array_too_large)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } +} + +void test__f_memory_array_adjust__works(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_adjust(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + free((void *) data.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_adjust.h b/level_0/f_memory/tests/unit/c/test-memory-array_adjust.h new file mode 100644 index 0000000..ecbbab2 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_adjust.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test set quote adjust in the fss project. + */ +#ifndef _TEST__F_fss__simple_packet_range_adjust +#define _TEST__F_fss__simple_packet_range_adjust + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_memory_array_adjust() + */ +extern void test__f_memory_array_adjust__parameter_checking(void **state); + +/** + * Test that the function returns F_array_too_large. + * + * @see f_memory_array_adjust() + */ +extern void test__f_memory_array_adjust__returns_array_too_large(void **state); + +/** + * Test that the function works. + * + * @see f_memory_array_adjust() + */ +extern void test__f_memory_array_adjust__works(void **state); + +#endif // _TEST__F_fss__simple_packet_range_adjust diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_decimate_by.c b/level_0/f_memory/tests/unit/c/test-memory-array_decimate_by.c new file mode 100644 index 0000000..50eaf74 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_decimate_by.c @@ -0,0 +1,97 @@ +#include "test-memory.h" +#include "test-memory-array_decimate_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_memory_array_decimate_by__parameter_checking(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_decimate_by(length, sizeof(int), 0, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_decimate_by(length, sizeof(int), 0, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_decimate_by(length, sizeof(int), (void **) &data.array, 0, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_decimate_by(length, sizeof(int), (void **) &data.array, &data.used, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + assert_null(data.array); +} + +void test__f_memory_array_decimate_by__returns_data_not(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + { + const f_status_t status = f_memory_array_decimate_by(0, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_data_not); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + free((void *) data.array); +} + +void test__f_memory_array_decimate_by__works(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + { + const f_status_t status = f_memory_array_decimate_by(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + assert_null(data.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_decimate_by.h b/level_0/f_memory/tests/unit/c/test-memory-array_decimate_by.h new file mode 100644 index 0000000..8293270 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_decimate_by.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test set quote decimate by in the fss project. + */ +#ifndef _TEST__F_fss__simple_packet_range_decimate_by +#define _TEST__F_fss__simple_packet_range_decimate_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_memory_array_decimate_by() + */ +extern void test__f_memory_array_decimate_by__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_memory_array_decimate_by() + */ +extern void test__f_memory_array_decimate_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_memory_array_decimate_by() + */ +extern void test__f_memory_array_decimate_by__works(void **state); + +#endif // _TEST__F_fss__simple_packet_range_decimate_by diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_decrease_by.c b/level_0/f_memory/tests/unit/c/test-memory-array_decrease_by.c new file mode 100644 index 0000000..2d9e320 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_decrease_by.c @@ -0,0 +1,97 @@ +#include "test-memory.h" +#include "test-memory-array_decrease_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_memory_array_decrease_by__parameter_checking(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_decrease_by(length, sizeof(int), 0, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_decrease_by(length, sizeof(int), 0, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_decrease_by(length, sizeof(int), (void **) &data.array, 0, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_decrease_by(length, sizeof(int), (void **) &data.array, &data.used, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + assert_null(data.array); +} + +void test__f_memory_array_decrease_by__returns_data_not(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + { + const f_status_t status = f_memory_array_decrease_by(0, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_data_not); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + free((void *) data.array); +} + +void test__f_memory_array_decrease_by__works(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + { + const f_status_t status = f_memory_array_decrease_by(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + assert_null(data.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_decrease_by.h b/level_0/f_memory/tests/unit/c/test-memory-array_decrease_by.h new file mode 100644 index 0000000..f8d6081 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_decrease_by.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test set quote decrease by in the fss project. + */ +#ifndef _TEST__F_fss__simple_packet_range_decrease_by +#define _TEST__F_fss__simple_packet_range_decrease_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_memory_array_decrease_by() + */ +extern void test__f_memory_array_decrease_by__parameter_checking(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_memory_array_decrease_by() + */ +extern void test__f_memory_array_decrease_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_memory_array_decrease_by() + */ +extern void test__f_memory_array_decrease_by__works(void **state); + +#endif // _TEST__F_fss__simple_packet_range_decrease_by diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_increase.c b/level_0/f_memory/tests/unit/c/test-memory-array_increase.c new file mode 100644 index 0000000..777124b --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_increase.c @@ -0,0 +1,113 @@ +#include "test-memory.h" +#include "test-memory-array_increase.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_memory_array_increase__parameter_checking(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_increase(length, sizeof(int), 0, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_increase(length, sizeof(int), 0, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_increase(length, sizeof(int), (void **) &data.array, 0, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_increase(length, sizeof(int), (void **) &data.array, &data.used, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + assert_null(data.array); +} + +void test__f_memory_array_increase__returns_array_too_large(void **state) { + + const f_number_unsigned_t length = F_number_t_size_unsigned_d + 1; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_increase(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_array_too_large)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } +} + +void test__f_memory_array_increase__returns_data_not(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + { + const f_status_t status = f_memory_array_increase(0, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_data_not); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + free((void *) data.array); +} + +void test__f_memory_array_increase__works(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + { + data.used = length; + + const f_status_t status = f_memory_array_increase(1, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, length); + assert_int_equal(data.size, length + 1); + } + + free((void *) data.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_increase.h b/level_0/f_memory/tests/unit/c/test-memory-array_increase.h new file mode 100644 index 0000000..912b2e8 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_increase.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test set quote increase in the fss project. + */ +#ifndef _TEST__F_fss__simple_packet_range_increase +#define _TEST__F_fss__simple_packet_range_increase + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_memory_array_increase() + */ +extern void test__f_memory_array_increase__parameter_checking(void **state); + +/** + * Test that the function returns F_array_too_large. + * + * @see f_memory_array_increase() + */ +extern void test__f_memory_array_increase__returns_array_too_large(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_memory_array_increase() + */ +extern void test__f_memory_array_increase__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_memory_array_increase() + */ +extern void test__f_memory_array_increase__works(void **state); + +#endif // _TEST__F_fss__simple_packet_range_increase diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_increase_by.c b/level_0/f_memory/tests/unit/c/test-memory-array_increase_by.c new file mode 100644 index 0000000..1240d95 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_increase_by.c @@ -0,0 +1,114 @@ +#include "test-memory.h" +#include "test-memory-array_increase_by.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_memory_array_increase_by__parameter_checking(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_increase_by(length, sizeof(int), 0, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_increase_by(length, sizeof(int), 0, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_increase_by(length, sizeof(int), (void **) &data.array, 0, &data.size); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + { + const f_status_t status = f_memory_array_increase_by(length, sizeof(int), (void **) &data.array, &data.used, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + assert_null(data.array); +} + +void test__f_memory_array_increase_by__returns_array_too_large(void **state) { + + const f_number_unsigned_t length = F_number_t_size_unsigned_d + 1; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_increase_by(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_array_too_large)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } +} + +void test__f_memory_array_increase_by__returns_data_not(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + { + const f_status_t status = f_memory_array_increase_by(0, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_data_not); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + free((void *) data.array); +} + +void test__f_memory_array_increase_by__works(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + { + data.used = length; + + const f_status_t status = f_memory_array_increase_by(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, length); + assert_int_equal(data.size, length * 2); + } + + free((void *) data.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_increase_by.h b/level_0/f_memory/tests/unit/c/test-memory-array_increase_by.h new file mode 100644 index 0000000..37db2d1 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_increase_by.h @@ -0,0 +1,41 @@ +/** + * FLL - Level 0 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test set quote increase by in the fss project. + */ +#ifndef _TEST__F_fss__simple_packet_range_increase_by +#define _TEST__F_fss__simple_packet_range_increase_by + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_memory_array_increase_by() + */ +extern void test__f_memory_array_increase_by__parameter_checking(void **state); + +/** + * Test that the function returns F_array_too_large. + * + * @see f_memory_array_increase_by() + */ +extern void test__f_memory_array_increase_by__returns_array_too_large(void **state); + +/** + * Test that the function returns F_data_not. + * + * @see f_memory_array_increase_by() + */ +extern void test__f_memory_array_increase_by__returns_data_not(void **state); + +/** + * Test that the function works. + * + * @see f_memory_array_increase_by() + */ +extern void test__f_memory_array_increase_by__works(void **state); + +#endif // _TEST__F_fss__simple_packet_range_increase_by diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_resize.c b/level_0/f_memory/tests/unit/c/test-memory-array_resize.c new file mode 100644 index 0000000..16787c1 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_resize.c @@ -0,0 +1,56 @@ +#include "test-memory.h" +#include "test-memory-array_resize.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void test__f_memory_array_resize__parameter_checking(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), 0, 0, 0); + + assert_int_equal(status, F_status_set_error(F_parameter)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } + + assert_null(data.array); +} + +void test__f_memory_array_resize__returns_array_too_large(void **state) { + + const f_number_unsigned_t length = F_number_t_size_unsigned_d + 1; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_status_set_error(F_array_too_large)); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, 0); + } +} + +void test__f_memory_array_resize__works(void **state) { + + const int length = 5; + test_memory_array_t data = test_memory_array_t_initialize; + + { + const f_status_t status = f_memory_array_resize(length, sizeof(int), (void **) &data.array, &data.used, &data.size); + + assert_int_equal(status, F_none); + assert_int_equal(data.used, 0); + assert_int_equal(data.size, length); + } + + free((void *) data.array); +} + +#ifdef __cplusplus +} // extern "C" +#endif diff --git a/level_0/f_memory/tests/unit/c/test-memory-array_resize.h b/level_0/f_memory/tests/unit/c/test-memory-array_resize.h new file mode 100644 index 0000000..5703ab7 --- /dev/null +++ b/level_0/f_memory/tests/unit/c/test-memory-array_resize.h @@ -0,0 +1,34 @@ +/** + * FLL - Level 0 + * + * Project: FSS + * API Version: 0.7 + * Licenses: lgpl-2.1-or-later + * + * Test set quote resize in the fss project. + */ +#ifndef _TEST__F_fss__simple_packet_range_resize +#define _TEST__F_fss__simple_packet_range_resize + +/** + * Test that the function correctly fails on invalid parameter. + * + * @see f_memory_array_resize() + */ +extern void test__f_memory_array_resize__parameter_checking(void **state); + +/** + * Test that the function returns F_array_too_large. + * + * @see f_memory_array_resize() + */ +extern void test__f_memory_array_resize__returns_array_too_large(void **state); + +/** + * Test that the function works. + * + * @see f_memory_array_resize() + */ +extern void test__f_memory_array_resize__works(void **state); + +#endif // _TEST__F_fss__simple_packet_range_resize diff --git a/level_0/f_memory/tests/unit/c/test-memory.c b/level_0/f_memory/tests/unit/c/test-memory.c index e45960e..16e96c5 100644 --- a/level_0/f_memory/tests/unit/c/test-memory.c +++ b/level_0/f_memory/tests/unit/c/test-memory.c @@ -34,12 +34,36 @@ int main(void) { cmocka_unit_test(test__f_memory_resize__works), + cmocka_unit_test(test__f_memory_array_adjust__returns_array_too_large), + cmocka_unit_test(test__f_memory_array_increase__returns_array_too_large), + cmocka_unit_test(test__f_memory_array_increase_by__returns_array_too_large), + cmocka_unit_test(test__f_memory_array_resize__returns_array_too_large), + + cmocka_unit_test(test__f_memory_array_decimate_by__returns_data_not), + cmocka_unit_test(test__f_memory_array_decrease_by__returns_data_not), + cmocka_unit_test(test__f_memory_array_increase__returns_data_not), + cmocka_unit_test(test__f_memory_array_increase_by__returns_data_not), + + cmocka_unit_test(test__f_memory_array_adjust__works), + cmocka_unit_test(test__f_memory_array_decimate_by__works), + cmocka_unit_test(test__f_memory_array_decrease_by__works), + cmocka_unit_test(test__f_memory_array_increase__works), + cmocka_unit_test(test__f_memory_array_increase_by__works), + cmocka_unit_test(test__f_memory_array_resize__works), + #ifndef _di_level_0_parameter_checking_ cmocka_unit_test(test__f_memory_adjust__parameter_checking), cmocka_unit_test(test__f_memory_delete__parameter_checking), cmocka_unit_test(test__f_memory_destroy__parameter_checking), cmocka_unit_test(test__f_memory_new__parameter_checking), cmocka_unit_test(test__f_memory_resize__parameter_checking), + + cmocka_unit_test(test__f_memory_array_adjust__parameter_checking), + cmocka_unit_test(test__f_memory_array_decimate_by__parameter_checking), + cmocka_unit_test(test__f_memory_array_decrease_by__parameter_checking), + cmocka_unit_test(test__f_memory_array_increase__parameter_checking), + cmocka_unit_test(test__f_memory_array_increase_by__parameter_checking), + cmocka_unit_test(test__f_memory_array_resize__parameter_checking), #endif // _di_level_0_parameter_checking_ }; diff --git a/level_0/f_memory/tests/unit/c/test-memory.h b/level_0/f_memory/tests/unit/c/test-memory.h index 5307d50..6f792d2 100644 --- a/level_0/f_memory/tests/unit/c/test-memory.h +++ b/level_0/f_memory/tests/unit/c/test-memory.h @@ -24,6 +24,12 @@ // Test includes. #include "test-memory-adjust.h" +#include "test-memory-array_adjust.h" +#include "test-memory-array_decimate_by.h" +#include "test-memory-array_decrease_by.h" +#include "test-memory-array_increase.h" +#include "test-memory-array_increase_by.h" +#include "test-memory-array_resize.h" #include "test-memory-delete.h" #include "test-memory-destroy.h" #include "test-memory-new.h" @@ -35,6 +41,17 @@ extern "C" { #endif /** + * A structure used for testing the memory array functions. + */ +typedef struct { + int *array; + f_number_unsigned_t used; + f_number_unsigned_t size; +} test_memory_array_t; + +#define test_memory_array_t_initialize { 0, 0, 0 } + +/** * Perform any setup operations. * * @param state diff --git a/level_0/f_socket/c/socket/private-socket.c b/level_0/f_socket/c/socket/private-socket.c index 76cbe66..ebf90a8 100644 --- a/level_0/f_socket/c/socket/private-socket.c +++ b/level_0/f_socket/c/socket/private-socket.c @@ -5,29 +5,11 @@ extern "C" { #endif -#if !defined(_di_f_sockets_adjust_) || !defined(_di_f_sockets_decimate_by_) - f_status_t private_f_sockets_adjust(const f_number_unsigned_t length, f_sockets_t * const sockets) { - - const f_status_t status = f_memory_adjust(sockets->size, length, sizeof(f_socket_t), (void **) & sockets->array); - if (F_status_is_error(status)) return status; - - sockets->size = length; - - if (sockets->used > sockets->size) { - sockets->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_sockets_adjust_) || !defined(_di_f_sockets_decimate_by_) - #if !defined(_di_f_sockets_append_) || !defined(_di_f_socketss_append_) extern f_status_t private_f_sockets_append(const f_socket_t source, f_sockets_t * const destination) { - if (destination->used + 1 > destination->size) { - const f_status_t status = private_f_sockets_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } + const f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_socket_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; destination->array[destination->used++] = source; @@ -38,12 +20,8 @@ extern "C" { #if !defined(_di_f_sockets_append_) || !defined(_di_f_sockets_append_all_) || !defined(_di_f_socketss_append_all_) extern f_status_t private_f_sockets_append_all(const f_sockets_t source, f_sockets_t * const destination) { - - - if (destination->used + source.used > destination->size) { - const f_status_t status = private_f_sockets_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } + const f_status_t status = f_memory_array_increase_by(source.used, sizeof(f_socket_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; for (f_number_unsigned_t i = 0; i < source.used; ++i) { destination->array[destination->used++] = source.array[i]; @@ -53,22 +31,6 @@ extern "C" { } #endif // !defined(_di_f_sockets_append_) || !defined(_di_f_sockets_append_all_) || !defined(_di_f_socketss_append_all_) -#if !defined(_di_f_sockets_resize_) || !defined(_di_f_sockets_append_) || !defined(_di_f_sockets_decrease_by_) || !defined(_di_f_socketss_append_) - f_status_t private_f_sockets_resize(const f_number_unsigned_t length, f_sockets_t * const sockets) { - - const f_status_t status = f_memory_resize(sockets->size, length, sizeof(f_socket_t), (void **) & sockets->array); - if (F_status_is_error(status)) return status; - - sockets->size = length; - - if (sockets->used > sockets->size) { - sockets->used = length; - } - - return F_none; - } -#endif // !defined(_di_f_sockets_resize_) || !defined(_di_f_sockets_append_) || !defined(_di_f_sockets_decrease_by_) || !defined(_di_f_socketss_append_) - #if !defined(_di_f_socketss_adjust_) || !defined(_di_f_socketss_decimate_by_) f_status_t private_f_socketss_adjust(const f_number_unsigned_t length, f_socketss_t * const socketss) { @@ -76,23 +38,11 @@ extern "C" { for (f_number_unsigned_t i = length; i < socketss->size; ++i) { - status = f_memory_destroy(socketss->array[i].size, sizeof(f_socket_t), (void **) & socketss->array[i].array); + status = f_memory_array_adjust(0, sizeof(f_socket_t), (void **) &socketss->array[i].array, &socketss->array[i].used, &socketss->array[i].size); if (F_status_is_error(status)) return status; - - socketss->array[i].size = 0; - socketss->array[i].used = 0; } // for - status = f_memory_adjust(socketss->size, length, sizeof(f_sockets_t), (void **) & socketss->array); - if (F_status_is_error(status)) return status; - - socketss->size = length; - - if (socketss->used > socketss->size) { - socketss->used = length; - } - - return F_none; + return f_memory_array_adjust(length, sizeof(f_sockets_t), (void **) &socketss->array, &socketss->used, &socketss->size); } #endif // !defined(_di_f_socketss_adjust_) || !defined(_di_f_socketss_decimate_by_) @@ -103,23 +53,11 @@ extern "C" { for (f_number_unsigned_t i = length; i < socketss->size; ++i) { - status = f_memory_delete(socketss->array[i].size, sizeof(f_socket_t), (void **) & socketss->array[i].array); + status = f_memory_array_resize(0, sizeof(f_socket_t), (void **) &socketss->array[i].array, &socketss->array[i].used, &socketss->array[i].size); if (F_status_is_error(status)) return status; - - socketss->array[i].size = 0; - socketss->array[i].used = 0; } // for - status = f_memory_resize(socketss->size, length, sizeof(f_sockets_t), (void **) & socketss->array); - if (F_status_is_error(status)) return status; - - socketss->size = length; - - if (socketss->used > socketss->size) { - socketss->used = length; - } - - return F_none; + return f_memory_array_resize(length, sizeof(f_sockets_t), (void **) &socketss->array, &socketss->used, &socketss->size); } #endif // !defined(_di_f_socketss_decrease_by_) || !defined(_di_f_socketss_increase_) || !defined(_di_f_socketss_increase_by_) || !defined(_di_f_socketss_resize_) diff --git a/level_0/f_socket/c/socket/private-socket.h b/level_0/f_socket/c/socket/private-socket.h index 04a62cb..d86d434 100644 --- a/level_0/f_socket/c/socket/private-socket.h +++ b/level_0/f_socket/c/socket/private-socket.h @@ -16,29 +16,6 @@ extern "C" { #endif /** - * Private implementation for resizing the sockets array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param sockets - * The sockets array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_adjust(). - * - * @see f_sockets_adjust() - * @see f_sockets_decimate_by() - */ -#if !defined(_di_f_sockets_adjust_) || !defined(_di_f_sockets_decimate_by_) - extern f_status_t private_f_sockets_adjust(const f_number_unsigned_t length, f_sockets_t * const sockets) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_sockets_adjust_) || !defined(_di_f_sockets_decimate_by_) - -/** * Private implementation for appending the socket array. * * Intended to be shared to each of the different implementation variations. @@ -86,31 +63,6 @@ extern "C" { #endif // !defined(_di_f_sockets_append_) || !defined(_di_f_sockets_append_all_) || !defined(_di_f_socketss_append_all_) /** - * Private implementation for resizing the sockets array. - * - * Intended to be shared to each of the different implementation variations. - * - * @param length - * The length to adjust to. - * @param sockets - * The sockets array to adjust. - * - * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). - * - * Errors (with error bit) from: f_memory_resize(). - * - * @see f_sockets_resize() - * @see f_sockets_append() - * @see f_sockets_decrease_by() - * @see f_socketss_append() - */ -#if !defined(_di_f_sockets_resize_) || !defined(_di_f_sockets_append_) || !defined(_di_f_sockets_decrease_by_) || !defined(_di_f_socketss_append_) - extern f_status_t private_f_sockets_resize(const f_number_unsigned_t length, f_sockets_t * const sockets) F_attribute_visibility_internal_d; -#endif // !defined(_di_f_sockets_resize_) || !defined(_di_f_sockets_append_) || !defined(_di_f_sockets_decrease_by_) || !defined(_di_f_socketss_append_) - -/** * Private implementation for resizing the socketss array. * * Intended to be shared to each of the different implementation variations. diff --git a/level_0/f_socket/c/socket/socket.c b/level_0/f_socket/c/socket/socket.c index 6c97e53..9607688 100644 --- a/level_0/f_socket/c/socket/socket.c +++ b/level_0/f_socket/c/socket/socket.c @@ -12,7 +12,7 @@ extern "C" { if (!sockets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_sockets_adjust(length, sockets); + return f_memory_array_adjust(length, sizeof(f_socket_t), (void **) &sockets->array, &sockets->used, &sockets->size); } #endif // _di_f_sockets_adjust_ @@ -44,13 +44,7 @@ extern "C" { if (!sockets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (sockets->size - amount > 0) { - return private_f_sockets_adjust(sockets->size - amount, sockets); - } - - return private_f_sockets_adjust(0, sockets); + return f_memory_array_decimate_by(amount, sizeof(f_socket_t), (void **) &sockets->array, &sockets->used, &sockets->size); } #endif // _di_f_sockets_decimate_by_ @@ -60,13 +54,7 @@ extern "C" { if (!sockets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (sockets->size - amount > 0) { - return private_f_sockets_resize(sockets->size - amount, sockets); - } - - return private_f_sockets_resize(0, sockets); + return f_memory_array_decrease_by(amount, sizeof(f_socket_t), (void **) &sockets->array, &sockets->used, &sockets->size); } #endif // _di_f_sockets_decrease_by_ @@ -76,21 +64,7 @@ extern "C" { if (!sockets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (step && sockets->used + 1 > sockets->size) { - f_number_unsigned_t size = sockets->used + step; - - if (size > F_number_t_size_unsigned_d) { - if (sockets->used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_number_t_size_unsigned_d; - } - - return private_f_sockets_resize(size, sockets); - } - - return F_data_not; + return f_memory_array_increase(step, sizeof(f_socket_t), (void **) &sockets->array, &sockets->used, &sockets->size); } #endif // _di_f_sockets_increase_ @@ -100,17 +74,7 @@ extern "C" { if (!sockets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (sockets->used + amount > sockets->size) { - if (sockets->used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_sockets_resize(sockets->used + amount, sockets); - } - - return F_data_not; + return f_memory_array_increase_by(amount, sizeof(f_socket_t), (void **) &sockets->array, &sockets->used, &sockets->size); } #endif // _di_f_sockets_increase_by_ @@ -120,7 +84,7 @@ extern "C" { if (!sockets) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - return private_f_sockets_resize(length, sockets); + return f_memory_array_resize(length, sizeof(f_socket_t), (void **) &sockets->array, &sockets->used, &sockets->size); } #endif // _di_f_sockets_resize_ @@ -142,12 +106,8 @@ extern "C" { if (!source.used) return F_data_not; - f_status_t status = F_none; - - if (destination->used + 1 > destination->size) { - status = private_f_socketss_resize(destination->used + F_memory_default_allocation_small_d, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase(F_memory_default_allocation_small_d, sizeof(f_sockets_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; status = private_f_sockets_append_all(source, &destination->array[destination->used]); if (F_status_is_error(status)) return status; @@ -166,12 +126,8 @@ extern "C" { if (!source.used) return F_data_not; - f_status_t status = F_none; - - if (destination->used + source.used > destination->size) { - status = private_f_socketss_resize(destination->used + source.used, destination); - if (F_status_is_error(status)) return status; - } + f_status_t status = f_memory_array_increase_by(source.used, sizeof(f_sockets_t), (void **) &destination->array, &destination->used, &destination->size); + if (F_status_is_error(status)) return status; for (f_number_unsigned_t i = 0; i < source.used; ++i, ++destination->used) { @@ -195,11 +151,7 @@ extern "C" { if (!amount) return F_data_not; - if (socketss->size - amount > 0) { - return private_f_socketss_adjust(socketss->size - amount, socketss); - } - - return private_f_socketss_adjust(0, socketss); + return private_f_socketss_adjust((socketss->size - amount > 0) ? socketss->size - amount : 0, socketss); } #endif // _di_f_socketss_decimate_by_ @@ -211,11 +163,7 @@ extern "C" { if (!amount) return F_data_not; - if (socketss->size - amount > 0) { - return private_f_socketss_resize(socketss->size - amount, socketss); - } - - return private_f_socketss_resize(0, socketss); + return private_f_socketss_resize((socketss->size - amount > 0) ? socketss->size - amount : 0, socketss); } #endif // _di_f_socketss_decrease_by_ @@ -225,21 +173,7 @@ extern "C" { if (!socketss) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (step && socketss->used + 1 > socketss->size) { - f_number_unsigned_t size = socketss->used + step; - - if (size > F_number_t_size_unsigned_d) { - if (socketss->used + 1 > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - size = F_number_t_size_unsigned_d; - } - - return private_f_socketss_resize(size, socketss); - } - - return F_data_not; + return f_memory_array_increase(step, sizeof(f_sockets_t), (void **) &socketss->array, &socketss->used, &socketss->size); } #endif // _di_f_socketss_increase_ @@ -249,17 +183,7 @@ extern "C" { if (!socketss) return F_status_set_error(F_parameter); #endif // _di_level_0_parameter_checking_ - if (!amount) return F_data_not; - - if (socketss->used + amount > socketss->size) { - if (socketss->used + amount > F_number_t_size_unsigned_d) { - return F_status_set_error(F_array_too_large); - } - - return private_f_socketss_resize(socketss->used + amount, socketss); - } - - return F_data_not; + return f_memory_array_increase_by(amount, sizeof(f_sockets_t), (void **) &socketss->array, &socketss->used, &socketss->size); } #endif // _di_f_socketss_increase_by_ diff --git a/level_0/f_socket/c/socket/socket.h b/level_0/f_socket/c/socket/socket.h index 31eff3b..a110148 100644 --- a/level_0/f_socket/c/socket/socket.h +++ b/level_0/f_socket/c/socket/socket.h @@ -25,11 +25,13 @@ extern "C" { * The string sockets array to resize. * * @return - * F_none on success. + * Success from f_memory_array_adjust(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_array_adjust(). + * + * @see f_memory_array_adjust() */ #ifndef _di_f_sockets_adjust_ extern f_status_t f_sockets_adjust(const f_number_unsigned_t length, f_sockets_t * const sockets); @@ -47,9 +49,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_sockets_append_ extern f_status_t f_sockets_append(const f_socket_t source, f_sockets_t * const destination); @@ -67,9 +75,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_sockets_append_all_ extern f_status_t f_sockets_append_all(const f_sockets_t source, f_sockets_t * const destination); @@ -88,12 +102,13 @@ extern "C" { * The string sockets array to resize. * * @return - * F_none on success. - * F_data_not if amount is 0. + * Success from f_memory_array_decimate_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). + * Errors (with error bit) from: f_memory_array_decimate_by(). + * + * @see f_memory_array_decimate_by() */ #ifndef _di_f_sockets_decimate_by_ extern f_status_t f_sockets_decimate_by(const f_number_unsigned_t amount, f_sockets_t * const sockets); @@ -112,12 +127,13 @@ extern "C" { * The string sockets array to resize. * * @return - * F_none on success. - * F_data_not if amount is 0. + * Success from f_memory_array_decrease_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_decrease_by(). + * + * @see f_memory_array_decrease_by() */ #ifndef _di_f_sockets_decrease_by_ extern f_status_t f_sockets_decrease_by(const f_number_unsigned_t amount, f_sockets_t * const sockets); @@ -136,13 +152,13 @@ extern "C" { * The string sockets array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * Success from f_memory_array_increase(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase(). + * + * @see f_memory_array_increase() */ #ifndef _di_f_sockets_increase_ extern f_status_t f_sockets_increase(const f_number_unsigned_t step, f_sockets_t * const sockets); @@ -161,13 +177,13 @@ extern "C" { * The string sockets array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * Success from f_memory_array_increase_by(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * + * @see f_memory_array_increase_by() */ #ifndef _di_f_sockets_increase_by_ extern f_status_t f_sockets_increase_by(const f_number_unsigned_t amount, f_sockets_t * const sockets); @@ -182,11 +198,13 @@ extern "C" { * The string sockets array to adjust. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_sockets_resize_ extern f_status_t f_sockets_resize(const f_number_unsigned_t length, f_sockets_t * const sockets); @@ -224,9 +242,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_socketss_append_ extern f_status_t f_socketss_append(const f_sockets_t source, f_socketss_t * const destination); @@ -244,9 +268,15 @@ extern "C" { * F_none on success. * F_data_not on success, but there is nothing to append (size == 0). * + * Success from f_memory_array_resize(). + * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_increase_by() + * @see f_memory_array_resize() */ #ifndef _di_f_socketss_append_all_ extern f_status_t f_socketss_append_all(const f_socketss_t source, f_socketss_t * const destination); @@ -265,12 +295,15 @@ extern "C" { * The string socketss array to resize. * * @return - * F_none on success. + * F_data_not on success, but the amount to decrease by is 0. + * + * Success from f_memory_array_decimate_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_adjust(). - * Errors (with error bit) from: f_memory_destroy(). + * Errors (with error bit) from: f_memory_array_decimate_by(). + * + * @see f_memory_array_decimate_by() */ #ifndef _di_f_socketss_decimate_by_ extern f_status_t f_socketss_decimate_by(const f_number_unsigned_t amount, f_socketss_t * const socketss); @@ -289,12 +322,15 @@ extern "C" { * The string socketss array to resize. * * @return - * F_none on success. + * F_data_not on success, but the amount to decrease by is 0. + * + * Success from f_memory_array_decrease_by(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_delete(). - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_decrease_by(). + * + * @see f_memory_array_decrease_by() */ #ifndef _di_f_socketss_decrease_by_ extern f_status_t f_socketss_decrease_by(const f_number_unsigned_t amount, f_socketss_t * const socketss); @@ -313,13 +349,13 @@ extern "C" { * The string socketss array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + 1 <= size). + * Success from f_memory_array_increase(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase(). + * + * @see f_memory_array_increase() */ #ifndef _di_f_socketss_increase_ extern f_status_t f_socketss_increase(const f_number_unsigned_t step, f_socketss_t * const socketss); @@ -338,13 +374,13 @@ extern "C" { * The string socketss array to resize. * * @return - * F_none on success. - * F_data_not on success, but there is no reason to increase size (used + amount <= size). + * Success from f_memory_array_increase_by(). * - * F_array_too_large (with error bit) if the new array length is too large. * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_increase_by(). + * + * @see f_memory_array_increase_by() */ #ifndef _di_f_socketss_increase_by_ extern f_status_t f_socketss_increase_by(const f_number_unsigned_t amount, f_socketss_t * const socketss); @@ -359,12 +395,13 @@ extern "C" { * The string socketss array to adjust. * * @return - * F_none on success. + * Success from f_memory_array_resize(). * * F_parameter (with error bit) if a parameter is invalid. * - * Errors (with error bit) from: f_memory_delete(). - * Errors (with error bit) from: f_memory_resize(). + * Errors (with error bit) from: f_memory_array_resize(). + * + * @see f_memory_array_resize() */ #ifndef _di_f_socketss_resize_ extern f_status_t f_socketss_resize(const f_number_unsigned_t length, f_socketss_t * const socketss);