From 344fbdfd9c3c367e589bcb005d5059fc45d1b271 Mon Sep 17 00:00:00 2001 From: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:50:52 +0000 Subject: [PATCH] fix: Resolve MinGW build failures with proper header organization and memory barriers Co-Authored-By: Matt Wong --- app/sheet/handlers_internal.h | 21 +++------------ app/sheet/sheet_internal.h | 10 +++---- app/sheet/ui_buffer.h | 51 ++++++++++++++++++++++------------- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/app/sheet/handlers_internal.h b/app/sheet/handlers_internal.h index 2c6276ae..7ea567c8 100644 --- a/app/sheet/handlers_internal.h +++ b/app/sheet/handlers_internal.h @@ -1,6 +1,8 @@ #ifndef ZSVSHEET_HANDLER_INTERNAL_H #define ZSVSHEET_HANDLER_INTERNAL_H +#include "ui_buffer.h" // Include this first for all required types + struct zsvsheet_context { const char *subcommand_value; // e.g. "/path/to/myfile.csv" int ch; // key press value from getch() @@ -120,23 +122,8 @@ zsvsheet_status zsvsheet_register_command(int ch, const char *long_name, */ enum zsvsheet_status zsvsheet_push_transformation(zsvsheet_proc_context_t ctx, struct zsvsheet_buffer_transformation_opts opts); -#endif - -/** - * Get information about the buffer's flags and state - */ -struct zsvsheet_buffer_info { - char has_row_num; - size_t rownum_col_offset; -}; - -/** - * Get internal information about the buffer's state - */ -struct zsvsheet_buffer_info_internal { - struct zsvsheet_flags flags; - struct zsvsheet_dimensions dimensions; -}; /** cell formatting **/ zsvsheet_cell_attr_t zsvsheet_cell_profile_attrs(enum zsvsheet_cell_profile_t); + +#endif /* ZSVSHEET_HANDLER_INTERNAL_H */ diff --git a/app/sheet/sheet_internal.h b/app/sheet/sheet_internal.h index 39ef3a90..6415841c 100644 --- a/app/sheet/sheet_internal.h +++ b/app/sheet/sheet_internal.h @@ -1,12 +1,11 @@ #ifndef ZSVSHEET_INTERNAL_H #define ZSVSHEET_INTERNAL_H +#include "ui_buffer.h" + #define ZSVSHEET_ROWNUM_HEADER "Row #" #define ZSVSHEET_ROWNUM_HEADER_LEN strlen(ZSVSHEET_ROWNUM_HEADER) -// Forward declaration -struct zsvsheet_ui_flags; - enum zsvsheet_priv_status { zsvsheet_priv_status_ok = 0, zsvsheet_priv_status_memory, @@ -28,13 +27,10 @@ struct zsvsheet_display_dimensions { size_t footer_span; }; -// Forward declaration of zsv_index -struct zsv_index; - struct zsvsheet_buffer_info_internal { struct zsvsheet_ui_flags flags; struct zsv_index *index; - struct zsvsheet_input_dimensions dimensions; + struct zsvsheet_dimensions dimensions; }; #endif diff --git a/app/sheet/ui_buffer.h b/app/sheet/ui_buffer.h index b413af00..1a9d8a2b 100644 --- a/app/sheet/ui_buffer.h +++ b/app/sheet/ui_buffer.h @@ -8,6 +8,18 @@ // Forward declarations struct zsv_index; struct zsvsheet_input_dimensions; +struct zsvsheet_dimensions; +struct zsvsheet_proc_context; +struct zsv_opts; +typedef struct zsvsheet_cell_attr *zsvsheet_cell_attr_t; +enum zsv_ext_status; +enum zsvsheet_status; + +// Common type definitions +struct zsvsheet_dimensions { + size_t rows; + size_t cols; +}; // Bit positions for flags #define INDEX_READY_BIT 0 @@ -20,36 +32,39 @@ struct zsvsheet_input_dimensions; #define WORKER_ACTIVE_BIT 7 #define WORKER_CANCELLED_BIT 8 +// Flag structure for atomic operations +struct zsvsheet_ui_flags { + _Alignas(sizeof(atomic_uchar)) volatile atomic_uchar flags[2]; // Using 2 bytes to accommodate all bits +}; + +// Row/column position structure +struct zsvsheet_rowcol { + size_t row; + size_t col; +}; + +// Buffer structure forward declaration +struct zsvsheet_ui_buffer; +typedef struct zsvsheet_ui_buffer *zsvsheet_ui_buffer_t; + // Atomic bit field operations static inline void atomic_set_bit(volatile atomic_uchar *addr, int bit) { + atomic_thread_fence(memory_order_acquire); atomic_fetch_or_explicit(addr, 1U << bit, memory_order_release); + atomic_thread_fence(memory_order_release); } static inline void atomic_clear_bit(volatile atomic_uchar *addr, int bit) { + atomic_thread_fence(memory_order_acquire); atomic_fetch_and_explicit(addr, ~(1U << bit), memory_order_release); + atomic_thread_fence(memory_order_release); } static inline int atomic_test_bit(const volatile atomic_uchar *addr, int bit) { + atomic_thread_fence(memory_order_acquire); return !!(atomic_load_explicit((volatile atomic_uchar *)addr, memory_order_acquire) & (1U << bit)); } -// Flag structure for atomic operations -struct zsvsheet_ui_flags { - volatile atomic_uchar flags[2]; // Using 2 bytes to accommodate all bits -}; - -#include "sheet_internal.h" - -// Buffer structure forward declaration -struct zsvsheet_ui_buffer; -typedef struct zsvsheet_ui_buffer *zsvsheet_ui_buffer_t; - -// Row/column position structure -struct zsvsheet_rowcol { - size_t row; - size_t col; -}; - // Buffer structure definition struct zsvsheet_ui_buffer { struct zsvsheet_ui_flags flags; @@ -69,7 +84,7 @@ struct zsvsheet_ui_buffer { struct zsvsheet_rowcol buff_offset; void *buffer; // screen buffer enum zsv_ext_status (*get_cell_attrs)(void *ext_ctx, zsvsheet_cell_attr_t *, size_t start_row, size_t row_count, - size_t col_count); + size_t col_count); zsvsheet_status (*on_newline)(struct zsvsheet_proc_context *); };