diff --git a/include/fsm.h b/include/fsm.h index 8cdd8ef..32cce70 100644 --- a/include/fsm.h +++ b/include/fsm.h @@ -175,6 +175,12 @@ enum fsm_enum_log_source { //----------------------------------------------------------------------------- +#define FILE_SOURCE_NAME_SIZE 40 +#define FUNCTION_SOURCE_NAME_SIZE 40 +#define STRING_VALUE_SIZE 60 +#define LOG_MAX_LENGTH 255 /**< arbitrary */ + + /** * A log unit must include the followings: * @@ -217,12 +223,12 @@ struct fsm_log_t void fsm_init_log (struct fsm_log_t *); void fsm_publish_log (struct fsm_log_t *); void fsm_clear_log (struct fsm_log_t *); -void fsm_clear_log_unit (struct fsm_log_unit_t *); +void fsm_clear_log_unit(struct fsm_log_unit_t *); void fsm_add_log_event (struct fsm_log_t *gg_logs, const char *file_source, const char *function_source, - char *string_value); + const char *string_value); int fsm_get_log_length(struct fsm_log_t *); void fsm_seek_log (struct fsm_log_t *gg_logs, @@ -239,7 +245,7 @@ void fsm_add_log (int severity, int source, const char *file_source, const char *function_source, - char *string_value); + const char *string_value); void fsm_relay_init_log(); void fsm_relay_close_log(); diff --git a/src/fsm/log/manager.c b/src/fsm/log/manager.c index 658b86c..17f0a89 100644 --- a/src/fsm/log/manager.c +++ b/src/fsm/log/manager.c @@ -96,7 +96,7 @@ void fsm_add_log (int severity, int source, const char *file_source, const char *function_source, - char *string_value) + const char *string_value) { if ( diff --git a/src/fsm/log/oper.c b/src/fsm/log/oper.c index b0c672a..9ce7624 100644 --- a/src/fsm/log/oper.c +++ b/src/fsm/log/oper.c @@ -43,9 +43,6 @@ #include #include "../../../include/fsm.h" -static int string_1_size = 40; -static int string_2_size = 40; -static int string_3_size = 50; /** * Inits the log: a double chained list. @@ -104,7 +101,7 @@ void fsm_clear_log_unit (struct fsm_log_unit_t *unit) /** * Adds a log unit (an event) to the log list. * - * *new_unit = malloc (sizeof (fsm_log_unit_struct)); + * new_unit = malloc (sizeof (fsm_log_unit_struct)); * * warn: is never free (as new log units are never removed) * @@ -118,7 +115,7 @@ void fsm_clear_log_unit (struct fsm_log_unit_t *unit) void fsm_add_log_event (struct fsm_log_t *gg_logs, const char *file_source, const char *function_source, - char *string_value) + const char *string_value) { struct timeval tv; gettimeofday (&tv, NULL); @@ -129,30 +126,28 @@ void fsm_add_log_event (struct fsm_log_t *gg_logs, new_unit->yy_dd_mm = tv.tv_sec; new_unit->usec = tv.tv_usec; - new_unit->file_source = malloc(string_1_size * sizeof(char)); - new_unit->function_source = malloc(string_2_size * sizeof(char)); - new_unit->string_value = malloc(string_3_size * sizeof(char)); + new_unit->file_source = malloc(FILE_SOURCE_NAME_SIZE * sizeof(char)); + new_unit->function_source = malloc(FUNCTION_SOURCE_NAME_SIZE * sizeof(char)); + new_unit->string_value = malloc(STRING_VALUE_SIZE * sizeof(char)); - strncpy (new_unit->file_source, file_source, string_1_size - 1); - strncpy (new_unit->function_source, function_source, string_2_size - 1); - strncpy (new_unit->string_value, string_value, string_3_size - 1); + strncpy (new_unit->file_source, file_source, FILE_SOURCE_NAME_SIZE - 1); + strncpy (new_unit->function_source, function_source, FUNCTION_SOURCE_NAME_SIZE - 1); + strncpy (new_unit->string_value, string_value, STRING_VALUE_SIZE - 1); - // first time we log something (don't touch new_unit->prev) + /** first time we log something (don't touch new_unit->prev) */ if (gg_logs->oldest == NULL) - gg_logs->oldest = new_unit; // record the first reference (once) - // not the first time, just update + gg_logs->oldest = new_unit; /**< record the first reference (once) */ + /**< not the first time, just update */ else { new_unit->prev = gg_logs->latest; new_unit->prev->next = new_unit; } - // in any case, update the latest reference + /**< in any case, update the latest reference */ gg_logs->latest = new_unit; } -#define LOG_MAX_LENGTH 255 /**< arbitrary */ - /** * Publishes all the logs chronologically (using the g_lib function: g_message) * @@ -173,7 +168,7 @@ void fsm_publish_log (struct fsm_log_t *gg_logs) strftime(timestamp, LOG_MAX_LENGTH * sizeof(char), "%D %T", localtime(&a_unit->yy_dd_mm)); - g_message ("%s + %-6ld %6d %-28s %-32s %-45s", + g_message ("%s + %-6ld %6d %-28s %-32s %-60s", timestamp, a_unit->usec, nb, @@ -188,16 +183,11 @@ void fsm_publish_log (struct fsm_log_t *gg_logs) } /* - * LEAK SUMMARY: - * - * g_message (+) or printf - * definitely lost: 5,008 bytes in 54 blocks - * indirectly lost: 16,151 bytes in 673 blocks - * - * g_message (-) - * definitely lost: 5,776 bytes in 55 blocks - * indirectly lost: 17,703 bytes in 728 blocks -*/ + * 2024-11-15 VALGRIND: + * LEAK SUMMARY: + * definitely lost: 5,008 bytes in 54 blocks + * indirectly lost: 16,151 bytes in 673 blocks + */ diff --git a/src/widget/main_window/design.c b/src/widget/main_window/design.c index d426bf8..eb33319 100644 --- a/src/widget/main_window/design.c +++ b/src/widget/main_window/design.c @@ -41,7 +41,7 @@ */ void on_toggle_exec_edit (GtkWidget *toggled_button, gpointer user_data) { - fsm_add_log (INFO, BUTTON, "signal", "toggle exec edit()", + fsm_add_log (INFO, BUTTON, "signal", __func__, "flip status request + bell 😇️ gdk_display_beep()"); gdk_display_beep (gdk_display_get_default()); diff --git a/src/widget/manager.c b/src/widget/manager.c index 0a23489..1288104 100644 --- a/src/widget/manager.c +++ b/src/widget/manager.c @@ -83,7 +83,10 @@ void on_app_activation (GtkApplication *app) g_signal_connect(window, "close-request", G_CALLBACK (on_window_close_request), (void *)(long long)window_int_id); - char *temp = util_concat ("window_get_id = ", window_char_id, NULL); + int destination_string_size = 50 * sizeof(char); + char *temp = g_malloc0 (destination_string_size); + temp = strncat (temp, "window_get_id = ", destination_string_size); + temp = strncat (temp, window_char_id, destination_string_size); fsm_add_log (INFO, WIDGETS, "widget/manager", __func__, temp); free(temp);