]> Kevux Git Server - fll/commitdiff
Bugfix: Featueless Make array cache is being reset incorrectly in some cases.
authorKevin Day <Kevin@kevux.org>
Thu, 8 May 2025 23:46:36 +0000 (18:46 -0500)
committerKevin Day <Kevin@kevux.org>
Thu, 8 May 2025 23:46:36 +0000 (18:46 -0500)
The functions `fake_build_library_static_object()` and `fake_build_object()` are appending compiler arguments to the arguments cache.
Before this cache gets used, a for loop resets the cache and starts appending to the cache.
The initial data loaded into the cache gets lost without ever being used.

level_3/fake/c/main/build/library.c
level_3/fake/c/main/build/object.c
level_3/fake/c/main/common.c
level_3/fake/c/main/common.h

index 9cc0646c061725dc76e6c6bd4b5fea20870bee53..ef16ea45eb759436d2445b4833993dd0c3dc9ffe 100644 (file)
@@ -627,6 +627,7 @@ extern "C" {
 
     uint8_t i = 0;
     f_number_unsigned_t j = 0;
+    f_number_unsigned_t minimum = 0;
 
     {
       f_string_statics_t * const values[] = {
@@ -649,6 +650,8 @@ extern "C" {
 
             return 0;
           }
+
+          ++minimum;
         } // for
       } // for
     }
@@ -671,7 +674,7 @@ extern "C" {
         fake_string_dynamic_reset(&main->cache_1);
         fake_string_dynamic_reset(&main->cache_2);
         fake_string_dynamic_reset(&main->cache_argument);
-        fake_string_dynamics_reset(&main->cache_arguments);
+        fake_string_dynamics_reset_to(&main->cache_arguments, minimum);
 
         fake_build_path_source_string(data, data_build, &data_build->setting.path_sources_library, &main->cache_1);
         if (F_status_is_error(main->setting.state.status)) break;
@@ -743,8 +746,7 @@ extern "C" {
 
             fake_build_print_verbose_create_directory(&main->program.message, main->cache_argument);
           }
-
-          if (F_status_is_error(main->setting.state.status)) {
+          else if (F_status_is_error(main->setting.state.status)) {
             fake_print_error_file(&main->program.error, macro_fake_f(f_directory_exists), main->cache_argument, f_file_operation_create_s, fll_error_file_type_directory_e);
 
             break;
index a0ec0bb35dcd0dc5256c1e4cc38de61a46748325..36b6704de2392051a45b418e0040deecd9701801 100644 (file)
@@ -32,6 +32,7 @@ extern "C" {
 
     uint8_t i = 0;
     f_number_unsigned_t j = 0;
+    f_number_unsigned_t minimum = 0;
 
     {
       f_string_statics_t * const values[] = {
@@ -49,6 +50,8 @@ extern "C" {
 
           main->setting.state.status = fll_execute_arguments_add(values[i]->array[j], &main->cache_arguments);
           if (F_status_is_error(main->setting.state.status)) break;
+
+          ++minimum;
         } // for
 
         if (F_status_is_error(main->setting.state.status)) {
@@ -78,7 +81,7 @@ extern "C" {
       for (j = 0; j < sources[i]->used && F_status_is_error_not(main->setting.state.status); ++j) {
 
         fake_string_dynamic_reset(&main->cache_argument);
-        fake_string_dynamics_reset(&main->cache_arguments);
+        fake_string_dynamics_reset_to(&main->cache_arguments, minimum);
 
         fake_build_sources_object_add(data, data_build, &sources[i]->array[j]);
 
index f1dc8502aba31d1456e9706355144faea6bdaf9f..7b8b9ab57ae91f86af7f7e896bc7b70963e257f0 100644 (file)
@@ -480,6 +480,31 @@ extern "C" {
   }
 #endif // _di_fake_string_dynamics_reset_
 
+#ifndef _di_fake_string_dynamics_reset_to_
+  void fake_string_dynamics_reset_to(f_string_dynamics_t * const dynamics, const f_number_unsigned_t to) {
+
+    if (!dynamics) return;
+
+    // Shrink an overly long array.
+    if (to < fake_max_over_array_d && dynamics->size > fake_max_over_array_d) {
+      f_memory_arrays_resize(
+        to < fake_allocation_large_d
+          ? fake_allocation_large_d
+          : to,
+        sizeof(f_string_dynamic_t),
+        (void **) &dynamics->array,
+        &dynamics->used,
+        &dynamics->size,
+        &f_string_dynamics_delete_callback
+      );
+    }
+
+    while (dynamics->used > to) {
+      fake_string_dynamic_reset(&dynamics->array[--dynamics->used]);
+    } // while
+  }
+#endif // _di_fake_string_dynamics_reset_to_
+
 #ifndef _di_fake_iki_data_reset_
   void fake_iki_data_reset(f_iki_data_t * const iki_data) {
 
index be07ce7831a8e7f90c51695193aa39f357fc6197..0309e004528205093d5cdd2536f0fc440f20e48b 100644 (file)
@@ -110,6 +110,22 @@ extern "C" {
 #endif // _di_fake_string_dynamics_reset_
 
 /**
+ * Reset the array of strings to a specified size, performing an over-size check and shrinking if necessary.
+ *
+ * This ignores errors when shrinking.
+ *
+ * @param dynamic
+ *   The string to shrink.
+ * @param to
+ *   The number that the dynamics.used is expected to be reset to.
+ *
+ * @see f_memory_array_resize()
+ */
+#ifndef _di_fake_string_dynamics_reset_to_
+  extern void fake_string_dynamics_reset_to(f_string_dynamics_t * const dynamics, const f_number_unsigned_t to);
+#endif // _di_fake_string_dynamics_reset_to_
+
+/**
  * Reset the iki variable data, performing an over-size check and shrinking if necessary.
  *
  * This ignores errors when shrinking.