@@ -563,6 +563,31 @@ def find_cpp_executable():
563563cdef = 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
0 commit comments