Do some minor cleanup with the allocation functions.
The *_delete_simple() and *_destroy_simple() macros need to always set size to 0, because they are always ignoring the return status.
Also move the relating check outside of the for loop for performance reasons.
Minor cleanups in memory functions.
Add additional parameter checks to the memory create functions.
Add additional size and length checks in the memory delete and destroy functions.
Fix bug in f_macro_memory_structure_macro_increment() where if condition is obviously wrong (two '>' checks are used against each other!).
Change behavior to increment against "used" instead of "size", more consistently.
Rewrite the *_increase() and *_increase_by() functions due to bugs and inconsistencies.
Only use variables when needed for performance and resource reasons.
Get rid of the F_array_too_large on success behavior as the current design doesn't handle the cases where both F_array_too_large and an error occurs afterwards.
Fix mistake in controller program where I forgot to actually set the allocated sizes.
Use counter instead of pointer for entry item in controller program.
In some cases, use fl_string_dynamic_terminate_after() instead of fl_string_dynamic_terminate() (there will likely be more of these changes).
#define f_macro_fss_nameds_t_delete(status, sets) \
status = F_none; \
sets.used = sets.size; \
- while (sets.used > 0) { \
+ while (sets.used) { \
sets.used--; \
f_macro_fss_named_t_delete(status, sets.array[sets.used]); \
if (status != F_none) break; \
#define f_macro_fss_nameds_t_destroy(status, sets) \
status = F_none; \
sets.used = sets.size; \
- while (sets.used > 0) { \
+ while (sets.used) { \
sets.used--; \
f_macro_fss_named_t_destroy(status, sets.array[sets.used]); \
if (status != F_none) break; \
while (sets.used > 0) { \
sets.used--; \
f_macro_fss_named_t_delete_simple(sets.array[sets.used]); \
- if (!sets.used) { \
- if (f_memory_delete((void **) & sets.array, sizeof(f_fss_named_t), sets.size)) { \
- sets.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & sets.array, sizeof(f_fss_named_t), sets.size); \
+ sets.size = 0;
/**
* Destroy a fss content sets.
while (sets.used > 0) { \
sets.used--; \
f_macro_fss_named_t_destroy_simple(sets.array[sets.used]); \
- if (!sets.used) { \
- if (f_memory_destroy((void **) & sets.array, sizeof(f_fss_named_t), sets.size)) { \
- sets.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & sets.array, sizeof(f_fss_named_t), sets.size); \
+ sets.size = 0;
/**
* Resize a fss content sets.
#define f_macro_fss_items_t_delete(status, items) \
status = F_none; \
items.used = items.size; \
- while (items.used > 0) { \
+ while (items.used) { \
items.used--; \
f_macro_fss_item_t_delete(status, items.array[items.used]); \
if (status != F_none) break; \
#define f_macro_fss_items_t_destroy(status, items) \
status = F_none; \
items.used = items.size; \
- while (items.used > 0) { \
+ while (items.used) { \
items.used--; \
f_macro_fss_item_t_destroy(status, items.array[items.used]); \
if (status != F_none) break; \
*/
#define f_macro_fss_items_t_delete_simple(items) \
items.used = items.size; \
- while (items.used > 0) { \
+ while (items.used) { \
items.used--; \
f_macro_fss_item_t_delete_simple(items.array[items.used]); \
- if (!items.used) { \
- if (f_memory_delete((void **) & items.array, sizeof(f_fss_item_t), items.size)) { \
- items.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & items.array, sizeof(f_fss_item_t), items.size); \
+ items.size = 0;
/**
* Destroy a fss items.
while (items.used > 0) { \
items.used--; \
f_macro_fss_item_t_destroy_simple(status, items.array[items.used]); \
- if (!items.used) { \
- if (f_memory_destroy((void **) & items.array, sizeof(f_fss_item_t), items.size)) { \
- items.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & items.array, sizeof(f_fss_item_t), items.size); \
+ items.size = 0;
/**
* Resize a fss items.
#define f_macro_fss_nest_t_delete(status, nest) \
status = F_none; \
nest.used = nest.size; \
- while (nest.used > 0) { \
+ while (nest.used) { \
nest.used--; \
f_macro_fss_items_t_delete(status, nest.depth[nest.used]); \
if (status != F_none) break; \
#define f_macro_fss_nest_t_destroy(status, nest) \
status = F_none; \
nest.used = nest.size; \
- while (nest.used > 0) { \
+ while (nest.used) { \
nest.used--; \
f_macro_fss_items_t_destroy(status, nest.depth[nest.used]); \
if (status != F_none) break; \
*/
#define f_macro_fss_nest_t_delete_simple(nest) \
nest.used = nest.size; \
- while (nest.used > 0) { \
+ while (nest.used) { \
nest.used--; \
f_macro_fss_items_t_delete_simple(nest.depth[nest.used]); \
- if (!nest.used) { \
- if (f_memory_delete((void **) & nest.depth, sizeof(f_fss_items_t), nest.size)) { \
- nest.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & nest.depth, sizeof(f_fss_items_t), nest.size); \
+ nest.size = 0;
/**
* Destroy a fss content nest.
while (nest.used > 0) { \
nest.used--; \
f_macro_fss_items_t_destroy_simple(nest.depth[nest.used]); \
- if (!nest.used) { \
- if (f_memory_destroy((void **) & nest.depth, sizeof(f_fss_items_t), nest.size)) { \
- nest.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & nest.depth, sizeof(f_fss_items_t), nest.size); \
+ nest.size = 0;
/**
* Resize a fss content nest.
#define f_macro_fss_nests_t_delete(nests) \
status = F_none; \
nests.used = nests.size; \
- while (nests.used > 0) { \
+ while (nests.used) { \
nests.used--; \
f_macro_fss_nest_t_delete(status, nests.array[nests.used]); \
if (status != F_none) break; \
#define f_macro_fss_nests_t_destroy(nests) \
status = F_none; \
nests.used = nests.size; \
- while (nests.used > 0) { \
+ while (nests.used) { \
nests.used--; \
f_macro_fss_nest_t_destroy(status, nests.array[nests.used]); \
if (status != F_none) break; \
*/
#define f_macro_fss_nests_t_delete_simple(nests) \
nests.used = nests.size; \
- while (nests.used > 0) { \
+ while (nests.used) { \
nests.used--; \
f_macro_fss_nest_t_delete_simple(nests.array[nests.used]); \
- if (!nests.used) { \
- if (f_memory_delete((void **) & nests.array, sizeof(f_fss_nest_t), nests.size)) { \
- nests.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & nests.array, sizeof(f_fss_nest_t), nests.size); \
+ nests.size = 0;
/**
* Destroy a fss content nests.
*/
#define f_macro_fss_nests_t_destroy_simple(nests) \
nests.used = nests.size; \
- while (nests.used > 0) { \
+ while (nests.used) { \
nests.used--; \
f_macro_fss_nest_t_destroy_simple(nests.array[nests.used]); \
- if (!nests.used) { \
- if (f_memory_destroy((void **) & nests.array, sizeof(f_fss_nest_t), nests.size)) { \
- nests.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & nests.array, sizeof(f_fss_nest_t), nests.size); \
+ nests.size = 0;
/**
* Resize a fss content nests.
#define f_macro_fss_sets_t_delete(status, sets) \
status = F_none; \
sets.used = sets.size; \
- while (sets.used > 0) { \
+ while (sets.used) { \
sets.used--; \
f_macro_fss_set_t_delete(status, sets.array[sets.used]); \
if (status != F_none) break; \
#define f_macro_fss_sets_t_destroy(status, sets) \
status = F_none; \
sets.used = sets.size; \
- while (sets.used > 0) { \
+ while (sets.used) { \
sets.used--; \
f_macro_fss_set_t_destroy(status, sets.array[sets.used]); \
if (status != F_none) break; \
*/
#define f_macro_fss_sets_t_delete_simple(sets) \
sets.used = sets.size; \
- while (sets.used > 0) { \
+ while (sets.used) { \
sets.used--; \
f_macro_fss_set_t_delete_simple(sets.array[sets.used]); \
- if (!sets.used) { \
- if (f_memory_delete((void **) & sets.array, sizeof(f_fss_set_t), sets.size)) { \
- sets.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & sets.array, sizeof(f_fss_set_t), sets.size); \
+ sets.size = 0;
/**
* Destroy a fss content sets.
while (sets.used > 0) { \
sets.used--; \
f_macro_fss_set_t_destroy_simple(sets.array[sets.used]); \
- if (!sets.used) { \
- if (f_memory_destroy((void **) & sets.array, sizeof(f_fss_set_t), sets.size)) { \
- sets.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & sets.array, sizeof(f_fss_set_t), sets.size); \
+ sets.size = 0;
/**
* Resize a fss content sets.
#define f_macro_fss_set_quotes_t_delete(status, sets) \
status = F_none; \
sets.used = sets.size; \
- while (sets.used > 0) { \
+ while (sets.used) { \
sets.used--; \
f_macro_fss_set_quote_t_delete(status, sets.array[sets.used]); \
if (status != F_none) break; \
#define f_macro_fss_set_quotes_t_destroy(status, sets) \
status = F_none; \
sets.used = sets.size; \
- while (sets.used > 0) { \
+ while (sets.used) { \
sets.used--; \
f_macro_fss_set_quote_t_destroy(status, sets.array[sets.used]); \
if (status != F_none) break; \
*/
#define f_macro_fss_set_quotes_t_delete_simple(sets) \
sets.used = sets.size; \
- while (sets.used > 0) { \
+ while (sets.used) { \
sets.used--; \
f_macro_fss_set_quote_t_delete_simple(sets.array[sets.used]); \
- if (!sets.used) { \
- if (f_memory_delete((void **) & sets.array, sizeof(f_fss_set_quote_t), sets.size)) { \
- sets.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & sets.array, sizeof(f_fss_set_quote_t), sets.size); \
+ sets.size = 0;
/**
* Destroy a fss content sets.
while (sets.used > 0) { \
sets.used--; \
f_macro_fss_set_quote_t_destroy_simple(sets.array[sets.used]); \
- if (!sets.used) { \
- if (f_memory_destroy((void **) & sets.array, sizeof(f_fss_set_quote_t), sets.size)) { \
- sets.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & sets.array, sizeof(f_fss_set_quote_t), sets.size); \
+ sets.size = 0;
/**
* Resize a fss content sets.
#endif
#ifndef _di_f_memory_new_
- f_return_status f_memory_new(void **pointer, const f_memory_size_t type, const f_memory_length length) {
+ f_return_status f_memory_new(void **pointer, const f_memory_size_t size, const f_memory_length length) {
#ifndef _di_level_0_parameter_checking_
- if (type <= 0) return F_status_set_error(F_parameter);
+ if (size <= 0) return F_status_set_error(F_parameter);
+ if (length <= 0) return F_status_set_error(F_parameter);
if (!pointer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
// prevent double-allocations.
- if (*pointer != 0) return F_none;
+ if (*pointer) return F_none;
- // Some people use malloc(type * length) to produce the same results.
+ // Some people use malloc(size * length) to produce the same results.
// This has been observed to sometimes causes an increase in L1/L2 cache misses (0.02% L1 increase, 0.01% L2 increase).
- *pointer = calloc(type, length);
+ *pointer = calloc(size, length);
if (*pointer) {
return F_none;
}
#endif // _di_f_memory_new_
-#if ! ( defined (_di_f_memory_delete_) || defined (_f_memory_FORCE_secure_memory_) )
- f_return_status f_memory_delete(void **pointer, const f_memory_size_t type, const f_memory_length length) {
+#if !(defined(_di_f_memory_delete_) || defined(_f_memory_FORCE_secure_memory_))
+ f_return_status f_memory_delete(void **pointer, const f_memory_size_t size, const f_memory_length length) {
#ifndef _di_level_0_parameter_checking_
if (!pointer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
// prevent double-frees.
- if (!*pointer) return F_none;
+ if (!*pointer || !size || !length) return F_none;
free(*pointer);
// it has been deallocated, so reset the pointer.
- if (*pointer != 0) *pointer = 0;
+ *pointer = 0;
return F_none;
}
-#endif // ! ( defined (_di_f_memory_delete_) || defined (_f_memory_FORCE_secure_memory_) )
+#endif // !(defined(_di_f_memory_delete_) || defined(_f_memory_FORCE_secure_memory_))
-#if ! ( defined (_di_f_memory_destroy_) || defined (_f_memory_FORCE_fast_memory_) )
- f_return_status f_memory_destroy(void **pointer, const f_memory_size_t type, const f_memory_length length) {
+#if !(defined(_di_f_memory_destroy_) || defined(_f_memory_FORCE_fast_memory_))
+ f_return_status f_memory_destroy(void **pointer, const f_memory_size_t size, const f_memory_length length) {
#ifndef _di_level_0_parameter_checking_
if (length < 0) return F_status_set_error(F_parameter);
- if (type <= 0) return F_status_set_error(F_parameter);
+ if (size <= 0) return F_status_set_error(F_parameter);
if (!pointer) return F_status_set_error(F_parameter);
#endif // _di_level_0_parameter_checking_
// prevent double-frees.
- if (!*pointer) return F_none;
+ if (!*pointer || !size || !length) return F_none;
if (length > 0) {
- memset(*pointer, 0, type * length);
+ memset(*pointer, 0, size * length);
}
free(*pointer);
// it has been deallocated, so reset the pointer.
- if (*pointer != 0) *pointer = 0;
+ *pointer = 0;
return F_none;
}
-#endif // ! ( defined (_di_f_memory_destroy_) || defined (_f_memory_FORCE_fast_memory_) )
+#endif // !(defined(_di_f_memory_destroy_) || defined(_f_memory_FORCE_fast_memory_))
-#if ! ( defined (_di_f_memory_resize_) || defined (_f_memory_FORCE_secure_memory_) )
- f_return_status f_memory_resize(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length) {
+#if !(defined(_di_f_memory_resize_) || defined(_f_memory_FORCE_secure_memory_))
+ f_return_status f_memory_resize(void **pointer, const f_memory_size_t size, const f_memory_length old_length, const f_memory_length new_length) {
#ifndef _di_level_0_parameter_checking_
- if (type <= 0) return F_status_set_error(F_parameter);
+ if (size <= 0) return F_status_set_error(F_parameter);
if (old_length < 0) return F_status_set_error(F_parameter);
if (new_length < 0) return F_status_set_error(F_parameter);
if (!pointer) return F_status_set_error(F_parameter);
// don't be wasteful.
if (old_length == new_length) return F_none;
- if (*pointer != 0) {
+ if (*pointer) {
void *new_pointer = 0;
// allocate new space
if (new_length > 0) {
- new_pointer = realloc(*pointer, type * new_length);
+ new_pointer = realloc(*pointer, size * new_length);
}
else {
free(*pointer);
// it has been deallocated, so reset the pointer
- if (*pointer != 0) *pointer = 0;
+ *pointer = 0;
return F_none;
}
if (new_pointer) {
if (new_pointer != *pointer) {
if (new_length > old_length) {
- // uint8_t * is of a data type size of 1, casting it to uint8_t should result in a single-length increment.
+ // uint8_t * is of a data size size of 1, casting it to uint8_t should result in a single-length increment.
// this is done to avoid problems with (void *) having arithmetic issues.
- memset(((uint8_t *) new_pointer) + (type * old_length), 0, type * (new_length - old_length));
+ memset(((uint8_t *) new_pointer) + (size * old_length), 0, size * (new_length - old_length));
}
*pointer = new_pointer;
}
}
else if (new_length > 0) {
- *pointer = calloc(type, new_length);
+ *pointer = calloc(size, new_length);
if (*pointer) {
return F_none;
return F_status_set_error(F_memory_reallocation);
}
-#endif // ! ( defined (_di_f_memory_resize_) || defined (_f_memory_FORCE_secure_memory_) )
+#endif // !(defined(_di_f_memory_resize_) || defined(_f_memory_FORCE_secure_memory_))
-#if ! ( defined (_di_f_memory_adjust_) || defined (_f_memory_FORCE_fast_memory_) )
- f_return_status f_memory_adjust(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length) {
+#if !(defined(_di_f_memory_adjust_) || defined(_f_memory_FORCE_fast_memory_))
+ f_return_status f_memory_adjust(void **pointer, const f_memory_size_t size, const f_memory_length old_length, const f_memory_length new_length) {
#ifndef _di_level_0_parameter_checking_
- if (type <= 0) return F_status_set_error(F_parameter);
+ if (size <= 0) return F_status_set_error(F_parameter);
if (old_length < 0) return F_status_set_error(F_parameter);
if (new_length < 0) return F_status_set_error(F_parameter);
if (!pointer) return F_status_set_error(F_parameter);
// don't be wasteful
if (old_length == new_length) return F_none;
- if (*pointer != 0) {
+ if (*pointer) {
void *new_pointer = 0;
if (old_length > 0) {
if (new_length < old_length) {
- // uint8_t * is of a data type size of 1, casting it to uint8_t should result in a single-length increment.
+ // uint8_t * is of a data size size of 1, casting it to uint8_t should result in a single-length increment.
// this is done to avoid problems with (void *) having arithmetic issues.
- memset(((uint8_t *) *pointer) + new_length, 0, type * (old_length - new_length));
+ memset(((uint8_t *) *pointer) + new_length, 0, size * (old_length - new_length));
}
}
// allocate new space.
if (new_length > 0) {
- new_pointer = realloc(*pointer, type * new_length);
+ new_pointer = realloc(*pointer, size * new_length);
}
else {
free(*pointer);
// it has been deallocated, so reset the pointer
- if (*pointer != 0) *pointer = 0;
+ *pointer = 0;
return F_none;
}
if (new_pointer) {
if (new_pointer != *pointer) {
if (new_length > old_length) {
- // uint8_t * is of a data type size of 1, casting it to bool should result in a single-length increment.
+ // uint8_t * is of a data size size of 1, casting it to bool should result in a single-length increment.
// this is done to avoid problems with (void *) having arithmetic issues.
- memset(((uint8_t *) new_pointer) + (type * old_length), 0, type * (new_length - old_length));
+ memset(((uint8_t *) new_pointer) + (size * old_length), 0, size * (new_length - old_length));
}
*pointer = new_pointer;
}
}
else if (new_length > 0) {
- *pointer = calloc(type, new_length);
+ *pointer = calloc(size, new_length);
if (*pointer) {
return F_none;
return F_status_set_error(F_memory_reallocation);
}
-#endif // ! ( defined (_di_f_memory_adjust_) || defined (_f_memory_FORCE_fast_memory_) )
+#endif // !(defined(_di_f_memory_adjust_) || defined(_f_memory_FORCE_fast_memory_))
#ifdef __cplusplus
} // extern "C"
*
* @param pointer
* A pointer that will be updated to the address of the newly allocated memory.
- * @param type
- * The block size, in bytes (type * length = allocated size).
+ * @param size
+ * The block size, in bytes (size * length = allocated size).
+ * Must be greater than 0.
* @param length
* The total number of blocks to be allocated.
+ * Must be greater than 0.
*
* @return
* F_none on success.
* @see calloc()
*/
#ifndef _di_f_memory_new_
- extern f_return_status f_memory_new(void **pointer, const f_memory_size_t type, const f_memory_length length);
+ extern f_return_status f_memory_new(void **pointer, const f_memory_size_t size, const f_memory_length length);
#endif // _di_f_memory_new_
/**
*
* @param pointer
* A pointer to the address that will be freed.
- * @param type
- * The block size, in bytes (type * length = allocated size).
+ * @param size
+ * The block size, in bytes (size * length = allocated size).
+ * If size is 0 then no delete is performed.
* @param length
* The total number of blocks to be allocated.
+ * If length is 0 then no delete is performed.
*
* @return
* F_none on success.
*
* @see free()
*/
-#if ! ( defined (_di_f_memory_delete_) || defined (_f_memory_FORCE_secure_memory_) )
- extern f_return_status f_memory_delete(void **pointer, const f_memory_size_t type, const f_memory_length length);
-#endif // ! ( defined (_di_f_memory_delete_) || defined (_f_memory_FORCE_secure_memory_) )
+#if !(defined(_di_f_memory_delete_) || defined(_f_memory_FORCE_secure_memory_))
+ extern f_return_status f_memory_delete(void **pointer, const f_memory_size_t size, const f_memory_length length);
+#endif // !(defined(_di_f_memory_delete_) || defined(_f_memory_FORCE_secure_memory_))
/**
* Securely deletes some dynamically allocated data.
*
* @param pointer
* A pointer to the address that will be freed.
- * @param type
- * The block size, in bytes (type * length = allocated size).
+ * @param size
+ * The block size, in bytes (size * length = allocated size).
+ * If size is 0 then no delete is performed.
* @param length
* The total number of blocks to be allocated.
+ * If length is 0 then no delete is performed.
*
* @return
* F_none on success.
* @see free()
* @see memset()
*/
-#if ! ( defined (_di_f_memory_destroy_) || defined (_f_memory_FORCE_fast_memory_) )
- extern f_return_status f_memory_destroy(void **pointer, const f_memory_size_t type, const f_memory_length length);
-#endif // ! ( defined (_di_f_memory_destroy_) || defined (_f_memory_FORCE_fast_memory_) )
+#if !(defined(_di_f_memory_destroy_) || defined(_f_memory_FORCE_fast_memory_))
+ extern f_return_status f_memory_destroy(void **pointer, const f_memory_size_t size, const f_memory_length length);
+#endif // !(defined(_di_f_memory_destroy_) || defined(_f_memory_FORCE_fast_memory_))
/**
* Resize dynamically allocated data.
*
* @param pointer
* A pointer to the address that will be resized.
- * @param type
- * The block size, in bytes (type * length = allocated size).
+ * @param size
+ * The block size, in bytes (size * length = allocated size).
* @param old_length
* The total number of blocks representing the length to be resized from.
* @param new_length
* @see memset()
* @see realloc()
*/
-#if ! ( defined (_di_f_memory_resize_) || defined (_f_memory_FORCE_secure_memory_) )
- extern f_return_status f_memory_resize(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length);
-#endif // ! ( defined (_di_f_memory_resize_) || defined (_f_memory_FORCE_secure_memory_) )
+#if !(defined(_di_f_memory_resize_) || defined(_f_memory_FORCE_secure_memory_))
+ extern f_return_status f_memory_resize(void **pointer, const f_memory_size_t size, const f_memory_length old_length, const f_memory_length new_length);
+#endif // !(defined(_di_f_memory_resize_) || defined(_f_memory_FORCE_secure_memory_))
/**
* Securely resize dynamically allocated data.
*
* @param pointer
* A pointer to the address that will be resized.
- * @param type
- * The block size, in bytes (type * length = allocated size).
+ * @param size
+ * The block size, in bytes (size * length = allocated size).
* @param old_length
* The total number of blocks representing the length to be resized from.
* @param new_length
* @see memset()
* @see realloc()
*/
-#if ! ( defined (_di_f_memory_adjust_) || defined (_f_memory_FORCE_fast_memory_) )
- extern f_return_status f_memory_adjust(void **pointer, const f_memory_size_t type, const f_memory_length old_length, const f_memory_length new_length);
+#if !(defined(_di_f_memory_adjust_) || defined(_f_memory_FORCE_fast_memory_))
+ extern f_return_status f_memory_adjust(void **pointer, const f_memory_size_t size, const f_memory_length old_length, const f_memory_length new_length);
#endif // _di_f_memory_adjust_
#ifdef __cplusplus
*/
#ifndef _di_f_macro_memory_structure_delete_simple_
#define f_macro_memory_structure_t_delete_simple(structure, type) \
- if (f_memory_delete((void **) & structure.array, sizeof(type), structure.size) == F_none) { \
- structure.size = 0; \
- structure.used = 0; \
- }
+ f_memory_delete((void **) & structure.array, sizeof(type), structure.size); \
+ structure.size = 0; \
+ structure.used = 0;
#endif // _di_f_macro_memory_structure_delete_simple_
/**
*/
#ifndef _di_f_macro_memory_structure_destroy_simple_
#define f_macro_memory_structure_t_destroy_simple(structure, type) \
- if (f_memory_destroy((void **) & structure.array, sizeof(type), structure.size) == F_none) { \
- structure.size = 0; \
- structure.used = 0; \
- }
+ f_memory_destroy((void **) & structure.array, sizeof(type), structure.size); \
+ structure.size = 0; \
+ structure.used = 0;
#endif // _di_f_macro_memory_structure_destroy_simple_
/**
#define f_macro_memory_structures_t_delete(status, structures, type_structure, type_structures) \
status = F_none; \
structures.used = structures.size; \
- while (structures.used > 0) { \
+ while (structures.used) { \
structures.used--; \
f_macro_memory_structure_t_delete(status, structures.array[structures.used], type_structure); \
if (status != F_none) break; \
#define f_macro_memory_structures_t_destroy(status, structures, type_structure, type_structures) \
status = F_none; \
structures.used = structures.size; \
- while (structures.used > 0) { \
+ while (structures.used) { \
structures.used--; \
f_macro_memory_structure_t_destroy(status, structures.array[structures.used], type_structure); \
if (status != F_none) break; \
#ifndef _di_f_macro_memory_structures_delete_simple_
#define f_macro_memory_structures_t_delete_simple(structures, type_structure, type_structures) \
structures.used = structures.size; \
- while (structures.used > 0) { \
+ while (structures.used) { \
structures.used--; \
f_macro_memory_structure_t_delete_simple(structures.array[structures.used], type_structure); \
} \
- if (!structures.used) { \
- if (f_memory_delete((void **) & structures.array, sizeof(type_structures), structures.size)) { \
- structures.size = 0; \
- } \
- }
+ f_memory_delete((void **) & structures.array, sizeof(type_structures), structures.size); \
+ structures.size = 0;
#endif // _di_f_macro_memory_structures_delete_simple_
/**
#ifndef _di_f_macro_memory_structures_destroy_simple_
#define f_macro_memory_structures_t_destroy_simple(structures, type_structure, type_structures) \
structures.used = structures.size; \
- while (structures.used > 0) { \
+ while (structures.used) { \
structures.used--; \
f_macro_memory_structure_t_destroy_simple(structures.array[structures.used], type_structure); \
} \
- if (!structures.used) { \
- if (f_memory_destroy((void **) & structures.array, sizeof(type_structures), structures.size)) { \
- structures.size = 0; \
- } \
- }
+ f_memory_destroy((void **) & structures.array, sizeof(type_structures), structures.size); \
+ structures.size = 0;
#endif // _di_f_macro_memory_structures_destroy_simple_
/**
#define f_macro_memory_structure_macro_increment(status, structure, step, step_default, macro_resize, error_too_large) \
if (structure.used + step > structure.size) { \
if (structure.used + step_default > f_array_length_t_size) { \
- if (structure.used + step > structure.size > f_array_length_t_size) { \
+ if (structure.used + step > f_array_length_t_size) { \
status = F_status_set_error(error_too_large); \
} \
else { \
- macro_resize(status, structure, structure.size + step); \
+ macro_resize(status, structure, structure.used + step); \
} \
} \
else { \
#define f_macro_string_dynamics_t_delete(status, dynamics) \
status = F_none; \
dynamics.used = dynamics.size; \
- while (dynamics.used > 0) { \
+ while (dynamics.used) { \
dynamics.used--; \
f_macro_string_dynamic_t_delete(status, dynamics.array[dynamics.used]); \
if (status != F_none) break; \
#define f_macro_string_dynamics_t_destroy(status, dynamics) \
status = F_none; \
dynamics.used = dynamics.size; \
- while (dynamics.used > 0) { \
+ while (dynamics.used) { \
dynamics.used--; \
f_macro_string_dynamic_t_destroy(status, dynamics.array[dynamics.used]); \
if (status != F_none) break; \
#define f_macro_string_dynamics_t_delete_simple(dynamics) \
dynamics.used = dynamics.size; \
- while (dynamics.used > 0) { \
+ while (dynamics.used) { \
dynamics.used--; \
f_macro_string_dynamic_t_delete_simple(dynamics.array[dynamics.used]); \
- if (!dynamics.used) { \
- if (f_memory_delete((void **) & dynamics.array, sizeof(f_string_dynamic_t), dynamics.size)) { \
- dynamics.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & dynamics.array, sizeof(f_string_dynamic_t), dynamics.size); \
+ dynamics.size = 0;
#define f_macro_string_dynamics_t_destroy_simple(dynamics) \
dynamics.used = dynamics.size; \
while (dynamics.used > 0) { \
dynamics.used--; \
f_macro_string_dynamic_t_destroy_simple(dynamics.array[dynamics.used]); \
- if (!dynamics.used) { \
- if (f_memory_destroy((void **) & dynamics.array, sizeof(f_string_dynamic_t), dynamics.size)) { \
- dynamics.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & dynamics.array, sizeof(f_string_dynamic_t), dynamics.size); \
+ dynamics.size = 0;
#define f_macro_string_dynamics_t_resize(status, dynamics, new_length) \
status = F_none; \
#define f_macro_string_maps_t_delete(status, maps) \
status = F_none; \
maps.used = maps.size; \
- while (maps.used > 0) { \
+ while (maps.used) { \
maps.used--; \
f_macro_string_map_t_delete(status, maps.array[maps.used]); \
if (status != F_none) break; \
#define f_macro_string_maps_t_destroy(status, maps) \
status = F_none; \
maps.used = maps.size; \
- while (maps.used > 0) { \
+ while (maps.used) { \
maps.used--; \
f_macro_string_map_t_destroy(status, maps.array[maps.used]); \
if (status != F_none) break; \
#define f_macro_string_maps_t_delete_simple(maps) \
maps.used = maps.size; \
- while (maps.used > 0) { \
+ while (maps.used) { \
maps.used--; \
f_macro_string_map_t_delete_simple(maps.array[maps.used]); \
- if (!maps.used) { \
- if (f_memory_delete((void **) & maps.array, sizeof(f_string_map_t), maps.size)) { \
- maps.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & maps.array, sizeof(f_string_map_t), maps.size); \
+ maps.size = 0;
#define f_macro_string_maps_t_destroy_simple(maps) \
maps.used = maps.size; \
- while (maps.used > 0) { \
+ while (maps.used) { \
maps.used--; \
f_macro_string_map_t_destroy_simple(maps.array[maps.used]); \
- if (!maps.used) { \
- if (f_memory_destroy((void **) & maps.array, sizeof(f_string_map_t), maps.size)) { \
- maps.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & maps.array, sizeof(f_string_map_t), maps.size); \
+ maps.size = 0;
#define f_macro_string_maps_t_resize(status, maps, new_length) \
status = F_none; \
#define f_macro_string_map_multis_t_delete(status, maps) \
status = F_none; \
maps.used = maps.size; \
- while (maps.used > 0) { \
+ while (maps.used) { \
maps.used--; \
f_macro_string_map_multi_t_delete(status, maps.array[maps.used]); \
if (status != F_none) break; \
#define f_macro_string_map_multis_t_destroy(status, maps) \
status = F_none; \
maps.used = maps.size; \
- while (maps.used > 0) { \
+ while (maps.used) { \
maps.used--; \
f_macro_string_map_multi_t_destroy(status, maps.array[maps.used]); \
if (status != F_none) break; \
#define f_macro_string_map_multis_t_delete_simple(maps) \
maps.used = maps.size; \
- while (maps.used > 0) { \
+ while (maps.used) { \
maps.used--; \
f_macro_string_map_multi_t_delete_simple(maps.array[maps.used]); \
- if (!maps.used) { \
- if (f_memory_delete((void **) & maps.array, sizeof(f_string_map_multi_t), maps.size)) { \
- maps.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & maps.array, sizeof(f_string_map_multi_t), maps.size); \
+ maps.size = 0;
#define f_macro_string_map_multis_t_destroy_simple(maps) \
maps.used = maps.size; \
- while (maps.used > 0) { \
+ while (maps.used) { \
maps.used--; \
f_macro_string_map_multi_t_destroy_simple(maps.array[maps.used]); \
- if (!maps.used) { \
- if (f_memory_destroy((void **) & maps.array, sizeof(f_string_map_multi_t), maps.size)) { \
- maps.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_destroy((void **) & maps.array, sizeof(f_string_map_multi_t), maps.size); \
+ maps.size = 0;
#define f_macro_string_map_multis_t_resize(status, maps, new_length) \
status = F_none; \
#if !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
f_return_status private_fl_fss_delimits_increase(f_fss_delimits_t *delimits) {
- f_status_t status = F_none;
if (delimits->used + 1 > delimits->size) {
- if (delimits->size + f_fss_default_allocation_step > f_string_length_t_size) {
- if (delimits->size + 1 > f_string_length_t_size) {
- return F_status_set_error(F_string_too_large);
+ f_array_length_t size = delimits->used + f_fss_default_allocation_step;
+
+ if (size > f_array_length_t_size) {
+ if (delimits->used + 1 > f_array_length_t_size) {
+ return F_status_set_error(F_array_too_large);
}
- f_macro_fss_delimits_t_resize(status, (*delimits), (delimits->size + 1));
- }
- else {
- f_macro_fss_delimits_t_resize(status, (*delimits), (delimits->size + f_fss_default_allocation_step));
+ size = f_string_length_t_size;
}
+
+ f_status_t status = F_none;
+
+ f_macro_fss_delimits_t_resize(status, (*delimits), size);
+
+ return status;
}
- return status;
+ return F_none;
}
#endif // !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
#if !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
f_return_status private_fl_fss_delimits_increase_by(const f_string_length_t amount, f_fss_delimits_t *delimits) {
- f_status_t status = F_none;
if (delimits->used + amount > delimits->size) {
- if (delimits->size + amount > f_string_length_t_size) {
- return F_status_set_error(F_string_too_large);
+ if (delimits->used + amount > f_array_length_t_size) {
+ return F_status_set_error(F_array_too_large);
}
- f_macro_fss_delimits_t_resize(status, (*delimits), (delimits->size + amount));
+ f_status_t status = F_none;
+
+ f_macro_fss_delimits_t_resize(status, (*delimits), delimits->used + amount);
+
+ return status;
}
- return status;
+ return F_none;
}
#endif // !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
#if !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
f_return_status private_fl_fss_destination_increase(f_string_dynamic_t *destination) {
- f_status_t status = F_none;
- if (destination->size + f_fss_default_allocation_step > f_string_length_t_size) {
- if (destination->size == f_string_length_t_size) {
- return F_status_set_error(F_string_too_large);
+ if (destination->used + 1 > destination->size) {
+ f_array_length_t size = destination->used + f_fss_default_allocation_step;
+
+ if (size > f_string_length_t_size) {
+ if (destination->used + 1 > f_string_length_t_size) {
+ return F_status_set_error(F_string_too_large);
+ }
+
+ size = f_string_length_t_size;
}
- f_macro_string_dynamic_t_resize(status, (*destination), f_string_length_t_size);
- return F_string_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_dynamic_t_resize(status, (*destination), size);
+
+ return status;
}
- f_macro_string_dynamic_t_resize(status, (*destination), destination->size + f_fss_default_allocation_step);
- return status;
+ return F_none;
}
#endif // !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
#if !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
f_return_status private_fl_fss_destination_increase_by(const f_string_length_t amount, f_string_dynamic_t *destination) {
- f_status_t status = F_none;
- if (destination->size + amount > f_string_length_t_size) {
- if (destination->size == f_string_length_t_size) {
+ if (destination->used + amount > destination->size) {
+ if (destination->used + amount > f_string_length_t_size) {
return F_status_set_error(F_string_too_large);
}
- f_macro_string_dynamic_t_resize(status, (*destination), f_string_length_t_size);
- return F_string_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_dynamic_t_resize(status, (*destination), destination->used + amount);
+
+ return status;
}
- f_macro_string_dynamic_t_resize(status, (*destination), destination->size + amount);
- return status;
+ return F_none;
}
#endif // !defined(_di_fl_fss_basic_object_write_string_) || !defined(_di_fl_fss_basic_content_write_string_) || !defined(_di_fl_fss_basic_list_object_write_string_) || !defined(_di_fl_fss_basic_list_content_write_string_) || !defined(_di_fl_fss_extended_object_write_string_) || !defined(_di_fl_fss_extended_content_write_string_) || !defined(_di_fl_fss_extended_list_object_write_string_) || !defined(_di_fl_fss_extended_list_content_write_string_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
#if !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
f_return_status private_fl_fss_nest_increase(f_fss_nest_t *nest) {
- f_status_t status = F_none;
if (nest->used + 1 > nest->size) {
- if (nest->size + f_fss_default_allocation_step > f_array_length_t_size) {
- if (nest->size + 1 > f_array_length_t_size) {
+ f_array_length_t size = nest->used + f_fss_default_allocation_step;
+
+ if (size > f_string_length_t_size) {
+ if (nest->used + 1 > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- f_macro_fss_nest_t_resize(status, (*nest), (nest->size + 1));
- }
- else {
- f_macro_fss_nest_t_resize(status, (*nest), (nest->size + f_fss_default_allocation_step));
+ size = f_array_length_t_size;
}
+
+ f_status_t status = F_none;
+
+ f_macro_fss_nest_t_resize(status, (*nest), size);
+
+ return status;
}
- return status;
+ return F_none;
}
#endif // !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
#if !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_basic_content_read_) || !defined(_di_fl_fss_extended_object_read_) || !defined(_di_fl_fss_extended_content_read_) || !defined(_di_fl_fss_basic_list_object_read_) || !defined(_di_fl_fss_basic_list_content_read_) || !defined(_di_fl_fss_extended_list_object_read_) || !defined(_di_fl_fss_extended_list_content_read_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
f_return_status private_fl_fss_ranges_increase(f_string_ranges_t *ranges) {
- f_status_t status = F_none;
if (ranges->used + 1 > ranges->size) {
- if (ranges->size + f_fss_default_allocation_step > f_array_length_t_size) {
- if (ranges->size + 1 > f_array_length_t_size) {
+ f_array_length_t size = ranges->used + f_fss_default_allocation_step;
+
+ if (size > f_string_length_t_size) {
+ if (ranges->used + 1 > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- f_macro_string_ranges_t_resize(status, (*ranges), (ranges->size + 1));
- }
- else {
- f_macro_string_ranges_t_resize(status, (*ranges), (ranges->size + f_fss_default_allocation_step));
+ size = f_array_length_t_size;
}
+
+ f_status_t status = F_none;
+
+ f_macro_string_ranges_t_resize(status, (*ranges), size);
+
+ return status;
}
- return status;
+ return F_none;
}
#endif // !defined(_di_fl_fss_basic_object_read_) || !defined(_di_fl_fss_basic_content_read_) || !defined(_di_fl_fss_extended_object_read_) || !defined(_di_fl_fss_extended_content_read_) || !defined(_di_fl_fss_basic_list_object_read_) || !defined(_di_fl_fss_basic_list_content_read_) || !defined(_di_fl_fss_extended_list_object_read_) || !defined(_di_fl_fss_extended_list_content_read_) || !defined(_di_fl_fss_embedded_list_object_read_) || !defined(_di_fl_fss_embedded_list_content_read_)
* @return
* F_none on success.
* F_memory_reallocation (with error bit) on reallocation error.
- * F_array_too_large (with error bit) if appended string length is too large to store in the delimits.
+ * F_array_too_large (with error bit) if new length is larger than max array length.
*
* @see fl_fss_basic_content_write_string()
* @see fl_fss_basic_object_write_string()
* @return
* F_none on success.
* F_memory_reallocation (with error bit) on reallocation error.
- * F_array_too_large (with error bit) if increased string length is too large to store in the delimits.
+ * F_array_too_large (with error bit) if new length is larger than max array length.
*
* @see fl_fss_basic_content_write_string()
* @see fl_fss_basic_object_write_string()
*
* @return
* F_none on success.
- * F_string_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
- * F_string_too_large (with error bit) if the new array length is too large.
+ * F_string_too_large (with error bit) if new length is larger than max string length.
*
* @see fl_fss_basic_content_write_string()
* @see fl_fss_basic_object_write_string()
*
* @return
* F_none on success.
- * F_string_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
- * F_string_too_large (with error bit) if the new array length is too large.
+ * F_string_too_large (with error bit) if new length is larger than max string length.
*
* @see fl_fss_basic_content_write_string()
* @see fl_fss_basic_object_write_string()
* @return
* F_none on success.
* F_memory_reallocation (with error bit) on reallocation error.
- * F_array_too_large (with error bit) if increased array length is too large to store in the range.
+ * F_array_too_large (with error bit) if new length is larger than max array length.
*
* @see fl_fss_embedded_list_object_read()
* @see fl_fss_embedded_list_content_read()
* @return
* F_none on success.
* F_memory_reallocation (with error bit) on reallocation error.
- * F_array_too_large (with error bit) if increased array length is too large to store in the range.
+ * F_array_too_large (with error bit) if new length is larger than max array length.
*
* @see fl_fss_basic_object_read()
* @see fl_fss_basic_content_read()
#if !defined(_di_fl_string_dynamic_increase_by_) || !defined(_di_fl_string_append_) || !defined(_di_fl_string_dynamic_append_) || !defined(_di_fl_string_append_mash_) || !defined(_di_fl_string_dynamic_mash_) || !defined(_di_fl_string_append_nulless_) || !defined(_di_fl_string_dynamic_append_nulless_) || !defined(_di_fl_string_mash_nulless_) || !defined(_di_fl_string_dynamic_mash_nulless_) || !defined(_di_fl_string_prepend_) || !defined(_di_fl_string_dynamic_prepend_) || !defined(_di_fl_string_prepend_nulless_) || !defined(_di_fl_string_dynamic_prepend_nulless_)
f_return_status private_fl_string_dynamic_increase_by(const f_string_length_t amount, f_string_dynamic_t *string) {
- f_status_t status = F_none;
- if (string->size + amount > f_string_length_t_size) {
- if (string->size == f_string_length_t_size) {
+ if (string->used + amount > string->size) {
+ if (string->used + amount > f_string_length_t_size) {
return F_status_set_error(F_string_too_large);
}
- f_macro_string_dynamic_t_resize(status, (*string), f_string_length_t_size);
- return F_string_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_dynamic_t_resize(status, (*string), string->used + amount);
+
+ return status;
}
- f_macro_string_dynamic_t_resize(status, (*string), string->size + amount);
- return status;
+ return F_none;
}
#endif // !defined(_di_fl_string_dynamic_increase_by_) || !defined(_di_fl_string_append_) || !defined(_di_fl_string_dynamic_append_) || !defined(_di_fl_string_append_mash_) || !defined(_di_fl_string_dynamic_mash_) || !defined(_di_fl_string_append_nulless_) || !defined(_di_fl_string_dynamic_append_nulless_) || !defined(_di_fl_string_mash_nulless_) || !defined(_di_fl_string_dynamic_mash_nulless_) || !defined(_di_fl_string_prepend_) || !defined(_di_fl_string_dynamic_prepend_) || !defined(_di_fl_string_prepend_nulless_) || !defined(_di_fl_string_dynamic_prepend_nulless_)
if (!string) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- f_status_t status = F_none;
+ if (string->used + 1 > string->size) {
+ f_array_length_t size = string->used + f_memory_default_allocation_step;
+
+ if (size > f_string_length_t_size) {
+ if (string->used + 1 > f_string_length_t_size) {
+ return F_status_set_error(F_string_too_large);
+ }
- if (string->size + f_memory_default_allocation_step > f_string_length_t_size) {
- if (string->size == f_string_length_t_size) {
- return F_status_set_error(F_string_too_large);
+ size = f_string_length_t_size;
}
- f_macro_string_dynamic_t_resize(status, (*string), f_string_length_t_size);
- return F_string_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_dynamic_t_resize(status, (*string), size);
+
+ return status;
}
- f_macro_string_dynamic_t_resize(status, (*string), string->size + f_memory_default_allocation_step);
- return status;
+ return F_none;
}
#endif // _di_fl_string_dynamic_increase_
#ifndef _di_fl_string_dynamic_increase_by_
f_return_status fl_string_dynamic_increase_by(const f_string_length_t amount, f_string_dynamic_t *string) {
#ifndef _di_level_1_parameter_checking_
- if (!amount) return F_status_set_error(F_parameter);
if (!string) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
if (!strings) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- f_status_t status = F_none;
+ if (strings->used + 1 > strings->size) {
+ f_array_length_t size = strings->used + f_memory_default_allocation_step;
- if (strings->size + f_memory_default_allocation_step > f_array_length_t_size) {
- if (strings->size == f_array_length_t_size) {
- return F_status_set_error(F_array_too_large);
+ if (size > f_array_length_t_size) {
+ if (strings->used + 1 > f_array_length_t_size) {
+ return F_status_set_error(F_array_too_large);
+ }
+
+ size = f_array_length_t_size;
}
- f_macro_string_dynamics_t_resize(status, (*strings), f_array_length_t_size);
- return F_array_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_dynamics_t_resize(status, (*strings), size);
+
+ return status;
}
- f_macro_string_dynamics_t_resize(status, (*strings), strings->size + f_memory_default_allocation_step);
- return status;
+ return F_none;
}
#endif // _di_fl_string_dynamics_increase_
#ifndef _di_fl_string_dynamics_increase_by_
f_return_status fl_string_dynamics_increase_by(const f_array_length_t amount, f_string_dynamics_t *strings) {
#ifndef _di_level_1_parameter_checking_
- if (!amount) return F_status_set_error(F_parameter);
if (!strings) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- f_status_t status = F_none;
-
- if (strings->size + amount > f_array_length_t_size) {
- if (strings->size == f_array_length_t_size) {
+ if (strings->used + amount > strings->size) {
+ if (strings->used + amount > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- f_macro_string_dynamics_t_resize(status, (*strings), f_array_length_t_size);
- return F_array_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_dynamics_t_resize(status, (*strings), strings->used + amount);
+
+ return status;
}
- f_macro_string_dynamics_t_resize(status, (*strings), strings->size + amount);
- return status;
+ return F_none;
}
#endif // _di_fl_string_dynamics_increase_by_
if (!lengths) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- f_status_t status = F_none;
+ if (lengths->used + 1 > lengths->size) {
+ f_array_length_t size = lengths->used + f_memory_default_allocation_step;
- if (lengths->size + f_memory_default_allocation_step > f_array_length_t_size) {
- if (lengths->size == f_array_length_t_size) {
- return F_status_set_error(F_array_too_large);
+ if (size > f_array_length_t_size) {
+ if (lengths->used + 1 > f_array_length_t_size) {
+ return F_status_set_error(F_array_too_large);
+ }
+
+ size = f_array_length_t_size;
}
- f_macro_string_lengths_t_resize(status, (*lengths), f_array_length_t_size);
- return F_array_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_lengths_t_resize(status, (*lengths), size);
+
+ return status;
}
- f_macro_string_lengths_t_resize(status, (*lengths), lengths->size + f_memory_default_allocation_step);
- return status;
+ return F_none;
}
#endif // _di_fl_string_lengths_increase_
if (!lengths) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- f_status_t status = F_none;
-
- if (lengths->size + amount > f_array_length_t_size) {
- if (lengths->size == f_array_length_t_size) {
+ if (lengths->used + amount > lengths->size) {
+ if (lengths->used + amount > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- f_macro_string_lengths_t_resize(status, (*lengths), f_array_length_t_size);
- return F_array_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_lengths_t_resize(status, (*lengths), lengths->used + amount);
+
+ return status;
}
- f_macro_string_lengths_t_resize(status, (*lengths), lengths->size + amount);
- return status;
+ return F_none;
}
#endif // _di_fl_string_lengths_increase_by_
if (!maps) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- f_status_t status = F_none;
+ if (maps->used + 1 > maps->size) {
+ f_array_length_t size = maps->used + f_memory_default_allocation_step;
- if (maps->size + f_memory_default_allocation_step > f_array_length_t_size) {
- if (maps->size == f_array_length_t_size) {
- return F_status_set_error(F_array_too_large);
+ if (size > f_array_length_t_size) {
+ if (maps->used + 1 > f_array_length_t_size) {
+ return F_status_set_error(F_array_too_large);
+ }
+
+ size = f_array_length_t_size;
}
- f_macro_string_maps_t_resize(status, (*maps), f_array_length_t_size);
- return F_array_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_maps_t_resize(status, (*maps), size);
+
+ return status;
}
- f_macro_string_maps_t_resize(status, (*maps), maps->size + f_memory_default_allocation_step);
- return status;
+ return F_none;
}
#endif // _di_fl_string_maps_increase_
if (!maps) return F_status_set_error(F_parameter);
#endif // _di_level_1_parameter_checking_
- f_status_t status = F_none;
-
- if (maps->size + amount > f_array_length_t_size) {
- if (maps->size == f_array_length_t_size) {
+ if (maps->used + amount > maps->size) {
+ if (maps->used + amount > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- f_macro_string_maps_t_resize(status, (*maps), f_array_length_t_size);
- return F_array_too_large;
+ f_status_t status = F_none;
+
+ f_macro_string_maps_t_resize(status, (*maps), maps->used + amount);
+
+ return status;
}
- f_macro_string_maps_t_resize(status, (*maps), maps->size + amount);
- return status;
+ return F_none;
}
#endif // _di_fl_string_maps_increase_by_
*
* @return
* F_none on success.
- * F_string_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
* F_parameter (with error bit) if a parameter is invalid.
*
* @return
* F_none on success.
- * F_string_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
* F_parameter (with error bit) if a parameter is invalid.
*
* @return
* F_none on success.
- * F_array_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
* F_parameter (with error bit) if a parameter is invalid.
*
* @return
* F_none on success.
- * F_array_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
* F_parameter (with error bit) if a parameter is invalid.
*
* @return
* F_none on success.
- * F_array_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
* F_parameter (with error bit) if a parameter is invalid.
*
* @return
* F_none on success.
- * F_array_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
* F_parameter (with error bit) if a parameter is invalid.
*
* @return
* F_none on success.
- * F_array_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
* F_parameter (with error bit) if a parameter is invalid.
*
* @return
* F_none on success.
- * F_array_too_large on success, but the requested length is too large for the buffer.
* F_memory_allocation (with error bit) on memory allocation error.
* F_memory_reallocation (with error bit) on memory reallocation error.
* F_parameter (with error bit) if a parameter is invalid.
#define macro_controller_rule_actions_t_delete_simple(actions) \
actions.used = actions.size; \
- while (actions.used > 0) { \
+ while (actions.used) { \
actions.used--; \
macro_controller_rule_action_t_delete_simple(actions.array[actions.used]); \
- if (!actions.used) { \
- if (f_memory_delete((void **) & actions.array, sizeof(controller_rule_action_t), actions.size)) { \
- actions.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & actions.array, sizeof(controller_rule_action_t), actions.size); \
+ actions.size = 0;
#endif // _di_controller_rule_actions_t_
#ifndef _di_controller_rule_item_t_
#define macro_controller_rule_items_t_delete_simple(items) \
items.used = items.size; \
- while (items.used > 0) { \
+ while (items.used) { \
items.used--; \
macro_controller_rule_item_t_delete_simple(items.array[items.used]); \
- if (!items.used) { \
- if (f_memory_delete((void **) & items.array, sizeof(controller_rule_item_t), items.size)) { \
- items.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & items.array, sizeof(controller_rule_item_t), items.size); \
+ items.size = 0;
#endif // _di_controller_rule_items_t_
#ifndef _di_controller_rule_t_
#define macro_controller_rules_t_delete_simple(rules) \
rules.used = rules.size; \
- while (rules.used > 0) { \
+ while (rules.used) { \
rules.used--; \
macro_controller_rule_t_delete_simple(rules.array[rules.used]); \
- if (!rules.used) { \
- if (f_memory_delete((void **) & rules.array, sizeof(controller_rule_t), rules.size)) { \
- rules.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & rules.array, sizeof(controller_rule_t), rules.size); \
+ rules.size = 0;
#endif // _di_controller_rules_t_
#ifndef _di_controller_entry_action_t_
#define macro_controller_entry_actions_t_delete_simple(actions) \
actions.used = actions.size; \
- while (actions.used > 0) { \
+ while (actions.used) { \
actions.used--; \
macro_controller_entry_action_t_delete_simple(actions.array[actions.used]); \
- if (!actions.used) { \
- if (f_memory_delete((void **) & actions.array, sizeof(controller_entry_action_t), actions.size)) { \
- actions.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & actions.array, sizeof(controller_entry_action_t), actions.size); \
+ actions.size = 0;
#endif // _di_controller_entry_actions_t_
#ifndef _di_controller_entry_item_t_
#define macro_controller_entry_items_t_delete_simple(items) \
items.used = items.size; \
- while (items.used > 0) { \
+ while (items.used) { \
items.used--; \
macro_controller_entry_item_t_delete_simple(items.array[items.used]); \
- if (!items.used) { \
- if (f_memory_delete((void **) & items.array, sizeof(controller_entry_item_t), items.size)) { \
- items.size = 0; \
- } \
- } \
- }
+ } \
+ f_memory_delete((void **) & items.array, sizeof(controller_entry_item_t), items.size); \
+ items.size = 0;
#endif // _di_controller_entry_items_t_
#ifndef _di_controller_entry_t_
#ifndef _di_controller_entry_actions_increase_by_
f_return_status controller_entry_actions_increase_by(const f_array_length_t amount, controller_entry_actions_t *actions) {
- f_status_t status = F_none;
- f_string_length_t size = actions->size + amount;
- if (size > f_array_length_t_size) {
- if (actions->size == f_array_length_t_size) {
+ if (actions->used + amount > actions->size) {
+ if (actions->used + amount > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- size = actions->size;
- status = F_array_too_large;
- }
+ const f_status_t status = f_memory_resize((void **) & actions->array, sizeof(controller_entry_action_t), actions->size, actions->used + amount);
- const f_status_t status_resize = f_memory_resize((void **) & actions->array, sizeof(controller_entry_action_t), actions->size, size);
- if (F_status_is_error(status_resize)) return status_resize;
+ if (F_status_is_error_not(status)) {
+ actions->size = actions->used + amount;
+ }
- actions->size = size;
- return status;
+ return status;
+ }
+
+ return F_none;
}
#endif // _di_controller_entry_actions_increase_by_
f_status_t status_action = F_none;
actions->used = 0;
- cache->object_actions.used = 0;
- cache->content_actions.used = 0;
+
+ cache->object_actions.used = cache->object_actions.size;
+
+ while (cache->object_actions.used) {
+ cache->object_actions.used--;
+ cache->object_actions.array[cache->object_actions.used].start = 1;
+ cache->object_actions.array[cache->object_actions.used].stop = 0;
+ } // while
+
+ cache->content_actions.used = cache->content_actions.size;
+
+ while (cache->content_actions.used) {
+ cache->content_actions.used--;
+ cache->content_actions.array[cache->content_actions.used].used = 0;
+ } // while
{
f_string_range_t range = content_range;
#ifndef _di_controller_entry_items_increase_by_
f_return_status controller_entry_items_increase_by(const f_array_length_t amount, controller_entry_items_t *items) {
- f_status_t status = F_none;
- f_string_length_t size = items->size + amount;
- if (size > f_array_length_t_size) {
- if (items->size == f_array_length_t_size) {
+ if (items->used + amount > items->size) {
+ if (items->used + amount > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- size = items->size;
- status = F_array_too_large;
- }
+ const f_status_t status = f_memory_resize((void **) & items->array, sizeof(controller_entry_item_t), items->size, items->used + amount);
- const f_status_t status_resize = f_memory_resize((void **) & items->array, sizeof(controller_entry_items_t), items->size, size);
- if (F_status_is_error(status_resize)) return status_resize;
+ if (F_status_is_error_not(status)) {
+ items->size = items->used + amount;
+ }
- items->size = size;
- return status;
+ return status;
+ }
+
+ return F_none;
}
#endif // _di_controller_entry_items_increase_by_
}
}
- if (F_status_is_error_not(status) && cache->object_actions.used) {
+ if (F_status_is_error_not(status) && cache->object_items.used) {
status = controller_entry_items_increase_by(cache->object_items.used, &entry->items);
if (F_status_is_error(status)) {
// 0x1 = main found, 0x2 = found existing.
uint8_t code = 0;
- controller_entry_item_t *item = 0;
f_string_range_t *range = 0;
+ f_array_length_t at = 0;
f_array_length_t i = 0;
f_array_length_t j = 0;
code -= 0x2;
}
+ at = 0;
range = 0;
cache->line_action = 0;
cache->object_actions.used = 0;
- cache->buffer_file.used = 0;
cache->buffer_path.used = 0;
cache->name_action.used = 0;
break;
}
- status = fl_string_dynamic_terminate(&cache->name_item);
+ status = fl_string_dynamic_terminate_after(&cache->name_item);
if (F_status_is_error(status)) {
- fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate", F_true);
+ fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate_after", F_true);
break;
}
if (fl_string_dynamic_compare_string(controller_string_main, cache->name_item, controller_string_main_length) == F_equal_to) {
code |= 0x1;
- item = &entry->items.array[0];
+ at = 0;
if (!entry->items.used) {
entry->items.used = 1;
}
}
else if (entry->items.used) {
- item = &entry->items.array[entry->items.used++];
+ at = entry->items.used++;
}
else {
// skip position 0, which is reserved for "main".
- item = &entry->items.array[1];
+ at = 1;
entry->items.used = 2;
}
- item->line = cache->line_item;
+ entry->items.array[at].line = cache->line_item;
- status = fl_string_dynamic_append(cache->name_item, &item->name);
+ status = fl_string_dynamic_append(cache->name_item, &entry->items.array[at].name);
if (F_status_is_error(status)) {
fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_append", F_true);
break;
}
- status = fl_string_dynamic_terminate(&item->name);
+ status = fl_string_dynamic_terminate_after(&entry->items.array[at].name);
if (F_status_is_error(status)) {
- fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate", F_true);
+ fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate_after", F_true);
break;
}
- status = controller_entry_actions_read(data, setting, *range, cache, &item->actions);
+ status = controller_entry_actions_read(data, setting, *range, cache, &entry->items.array[at].actions);
if (F_status_is_error(status)) {
controller_entry_error_print(data.error, *cache);
break;
}
- status = fl_string_dynamic_terminate(&cache->name_item);
+ status = fl_string_dynamic_terminate_after(&cache->name_item);
if (F_status_is_error(status)) {
- fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate", F_true);
+ fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate_after", F_true);
break;
}
break;
}
- status = fl_string_dynamic_terminate(&cache->name_item);
+ status = fl_string_dynamic_terminate_after(&cache->name_item);
if (F_status_is_error(status)) {
- fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate", F_true);
+ fll_error_print(data.error, F_status_set_fine(status), "fl_string_dynamic_terminate_after", F_true);
break;
}
*
* @return
* F_none on success.
- * F_array_too_large on success, but requested size is too small (resize is smaller than requested length).
+ * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
*
* Errors (with error bit) from: f_memory_resize().
*
*
* @return
* F_none on success.
- * F_array_too_large on success, but requested size is too small (resize is smaller than requested length).
+ * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
*
* Errors (with error bit) from: f_memory_resize().
*
#ifndef _di_controller_rule_actions_increase_by_
f_return_status controller_rule_actions_increase_by(const f_array_length_t amount, controller_rule_actions_t *actions) {
- f_status_t status = F_none;
- f_string_length_t size = actions->size + amount;
- if (size > f_array_length_t_size) {
- if (actions->size == f_array_length_t_size) {
+ if (actions->used + amount > actions->size) {
+ if (actions->used + amount > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- size = actions->size;
- status = F_array_too_large;
- }
+ const f_status_t status = f_memory_resize((void **) & actions->array, sizeof(controller_rule_action_t), actions->size, actions->used + amount);
- const f_status_t status_resize = f_memory_resize((void **) & actions->array, sizeof(controller_rule_action_t), actions->size, size);
- if (F_status_is_error(status_resize)) return status_resize;
+ if (F_status_is_error_not(status)) {
+ actions->size = actions->used + amount;
+ }
- actions->size = size;
- return status;
+ return status;
+ }
+
+ return F_none;
}
#endif // _di_controller_rule_actions_increase_by_
#ifndef _di_controller_rule_items_increase_by_
f_return_status controller_rule_items_increase_by(const f_array_length_t amount, controller_rule_items_t *items) {
- f_status_t status = F_none;
- f_string_length_t size = items->size + amount;
- if (size > f_array_length_t_size) {
- if (items->size == f_array_length_t_size) {
+ if (items->used + amount > items->size) {
+ if (items->used + amount > f_array_length_t_size) {
return F_status_set_error(F_array_too_large);
}
- size = items->size;
- status = F_array_too_large;
- }
+ const f_status_t status = f_memory_resize((void **) & items->array, sizeof(controller_rule_item_t), items->size, items->used + amount);
- const f_status_t status_resize = f_memory_resize((void **) & items->array, sizeof(controller_rule_item_t), items->size, size);
- if (F_status_is_error(status_resize)) return status_resize;
+ if (F_status_is_error_not(status)) {
+ items->size = items->used + amount;
+ }
- items->size = size;
- return status;
+ return status;
+ }
+
+ return F_none;
}
#endif // _di_controller_rule_items_increase_by_
*
* @return
* F_none on success.
- * F_array_too_large on success, but requested size is too small (resize is smaller than requested length).
+ * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
*
* Errors (with error bit) from: f_memory_resize().
*/
*
* @return
* F_none on success.
- * F_array_too_large on success, but requested size is too small (resize is smaller than requested length).
+ * F_array_too_large (with error bit) if the resulting new size is bigger than the max array length.
*
* Errors (with error bit) from: f_memory_resize().
*