Skip to content

Commit 0e43e7b

Browse files
fix: windows build (uint8 -> char)
1 parent 87ecfbc commit 0e43e7b

File tree

2 files changed

+39
-15
lines changed

2 files changed

+39
-15
lines changed

generate_cffi_definitions.py

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,31 @@ def find_cpp_executable():
563563
cdef = re.sub(r"\bbool\s*\[([^\]]*)\]", r"unsigned char[\1]", cdef)
564564

565565

566+
def fix_windows_type_compatibility(cdef_content):
567+
"""Fix Windows-specific type compatibility issues by converting uint8_t to char
568+
to avoid CFFI size calculation mismatches."""
569+
570+
if platform.system() == "Windows":
571+
print("Applying Windows-specific type fixes...")
572+
573+
# Convert uint8_t to char everywhere for Windows CFFI compatibility
574+
# This prevents size calculation mismatches between CFFI and C compiler
575+
cdef_content = re.sub(r"\buint8_t\b", "char", cdef_content)
576+
577+
# Also convert int8_t to char for consistency (they're the same size)
578+
cdef_content = re.sub(r"\bint8_t\b", "char", cdef_content)
579+
580+
print("Converted uint8_t and int8_t to char for Windows compatibility")
581+
else:
582+
print("Non-Windows platform - keeping original types")
583+
584+
return cdef_content
585+
586+
587+
# Apply Windows type compatibility fixes
588+
cdef = fix_windows_type_compatibility(cdef)
589+
590+
566591
# Fix platform-specific struct fields - create a platform-appropriate struct
567592
# The Smpt_device struct has different fields on different platforms due to
568593
# #ifdef blocks
@@ -583,7 +608,7 @@ def fix_platform_specific_structs(cdef_content):
583608
)
584609

585610
if platform.system() == "Windows":
586-
# Windows version with HANDLE - use flexible struct to avoid size issues
611+
# Windows version with HANDLE - all uint8_t already converted to char
587612
platform_struct = """typedef struct
588613
{
589614
uint32_t packet_length;
@@ -597,8 +622,7 @@ def fix_platform_specific_structs(cdef_content):
597622
char packet_input_buffer_state[100];
598623
} Smpt_device;"""
599624
else:
600-
# Linux/macOS version with descriptor - include
601-
# packet field for size consistency
625+
# Linux/macOS version with descriptor - keep original types
602626
platform_struct = """typedef struct
603627
{
604628
uint32_t packet_length;
@@ -618,7 +642,7 @@ def fix_platform_specific_structs(cdef_content):
618642
)
619643
print(
620644
f"Replaced Smpt_device with {platform.system()}-specific definition "
621-
"(Windows uses flexible struct, Linux uses explicit packet field)"
645+
"(Windows uses char types, Linux uses original types)"
622646
)
623647

624648
return cdef_content

sciencemode/sciencemode.cdef

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
#define SMPT_DL_MAX_BLOCK_BYTES_LENGTH ...
2-
#define SMPT_DL_GUID_STRING_LENGTH ...
3-
#define SMPT_DL_2KHZ 2000
4-
5-
#define SMPT_DL_MAX_FILE_NAME_LENGTH ...
61
#define SMPT_DL_MAX_PATIENT_NAME_LENGTH ...
7-
#define SMPT_DL_MAX_FILE_ID_LENGTH ...
8-
#define SMPT_DL_FILE_SIZE_BYTES ...
9-
#define SMPT_DL_1KHZ ...
10-
#define SMPT_DL_MAX_INVESTIGATOR_NAME_LENGTH ...
2+
#define SMPT_DL_MAX_N_MEASUREMENTS ...
113
#define SMPT_DL_MAX_CHANNELS ...
4+
#define SMPT_DL_1KHZ ...
125
#define SMPT_DL_MAX_STRING_LENGTH ...
13-
#define SMPT_DL_MAX_N_MEASUREMENTS ...
6+
#define SMPT_DL_MAX_BLOCK_BYTES_LENGTH ...
7+
#define SMPT_DL_MAX_FILE_NAME_LENGTH ...
8+
#define SMPT_DL_MAX_INVESTIGATOR_NAME_LENGTH ...
9+
#define SMPT_DL_MAX_SAMPLE_VALUE ...
10+
#define SMPT_DL_2KHZ 2000
11+
12+
#define SMPT_DL_GUID_STRING_LENGTH ...
1413
#define SMPT_DL_4KHZ 4000
1514

16-
#define SMPT_DL_MAX_SAMPLE_VALUE ...
15+
#define SMPT_DL_MAX_FILE_ID_LENGTH ...
16+
#define SMPT_DL_FILE_SIZE_BYTES ...
1717
typedef enum
1818
{
1919
Smpt_Cmd_Ll_Init = ...,

0 commit comments

Comments
 (0)