Skip to content

Commit

Permalink
fix: Resolve MinGW build failures with proper header organization and…
Browse files Browse the repository at this point in the history
… memory barriers

Co-Authored-By: Matt Wong <[email protected]>
  • Loading branch information
devin-ai-integration[bot] and liquidaty committed Dec 18, 2024
1 parent 6d9281f commit 344fbdf
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 42 deletions.
21 changes: 4 additions & 17 deletions app/sheet/handlers_internal.h
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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 */
10 changes: 3 additions & 7 deletions app/sheet/sheet_internal.h
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
51 changes: 33 additions & 18 deletions app/sheet/ui_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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 *);
};

Expand Down

0 comments on commit 344fbdf

Please sign in to comment.