Skip to content

Commit db1910b

Browse files
fix: _cffi fix
1 parent 57d3102 commit db1910b

File tree

1 file changed

+37
-16
lines changed

1 file changed

+37
-16
lines changed

sciencemode/_cffi.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,16 @@
187187
"-D__declspec(x)=",
188188
"-D__forceinline=",
189189
"-D__inline=",
190-
# With improved header guards, we can use consistent bool handling
191-
"-D_Bool=unsigned char",
192-
"-Dbool=unsigned char",
193-
"-Dtrue=1",
194-
"-Dfalse=0",
190+
# For Windows, avoid redefining bool if stdbool.h is available
191+
# Only define if not already defined to avoid macro redefinition warnings
192+
"-D_STDBOOL_H", # Prevent stdbool.h inclusion conflicts
193+
"-D__STDBOOL_H", # Additional header guard
194+
# Windows-specific definitions to ensure proper header parsing
195+
"-D_WIN32",
196+
"-DWIN32",
197+
"-D_WINDOWS",
198+
# Ensure consistent structure definitions by making sure Windows macros are properly defined
199+
"-D_MSC_FULL_VER=190000000",
195200
]
196201
if sys.platform.startswith("win")
197202
else [
@@ -816,7 +821,14 @@ def try_parse_with_better_args(header_path, header_name):
816821
platform_definitions = [
817822
"-D__declspec(x)=",
818823
"-D_WIN32=1",
824+
"-DWIN32=1",
825+
"-D_WINDOWS=1",
819826
"-D_MSC_VER=1900", # Simulate recent MSVC
827+
"-D_MSC_FULL_VER=190000000",
828+
"-D__forceinline=inline",
829+
"-D__inline=inline",
830+
# Ensure Windows structure definitions are consistent
831+
"-DSMPT_EXPORTS", # This might affect how structures are defined
820832
]
821833
elif platform.system() == "Darwin":
822834
asm_definition = "-D__asm__(...)="
@@ -973,13 +985,31 @@ def try_parse_with_better_args(header_path, header_name):
973985
# Add minimal essential types that tests expect with instantiable field definitions
974986
# These provide enough structure for basic testing while being safe to instantiate
975987
# Updated to match actual C structure definitions
988+
# If header parsing completely failed, provide minimal essential structures
989+
# that are required for basic functionality - but make sure they match the real headers!
976990
collector.typedecls.extend(
977991
[
978-
# Basic device structure with essential fields (matches actual Smpt_device)
992+
# Minimal device structure - matches the actual Smpt_device structure
979993
"""typedef struct {
980994
unsigned int packet_length;
981995
unsigned char packet[1200];
982-
unsigned char cmd_list_data[1000];
996+
struct {
997+
unsigned int acks_length;
998+
unsigned int acks_current_index;
999+
struct {
1000+
unsigned char packet_number;
1001+
unsigned short command_number;
1002+
unsigned char result;
1003+
} acks[100];
1004+
unsigned int requests_current_index;
1005+
unsigned int requests_expected_index;
1006+
unsigned int number_of_expected;
1007+
struct {
1008+
unsigned char packet_number;
1009+
unsigned short command_number;
1010+
} requests[100];
1011+
unsigned int new_ack_available;
1012+
} cmd_list;
9831013
signed char current_packet_number;
9841014
char serial_port_name[256];
9851015
unsigned char packet_input_buffer_data[120000];
@@ -998,15 +1028,6 @@ def try_parse_with_better_args(header_path, header_name):
9981028
unsigned char current;
9991029
unsigned char reserved[13];
10001030
} Smpt_ll_channel_config;""",
1001-
# Version acknowledgment structure
1002-
"""typedef struct {
1003-
unsigned char packet_number;
1004-
unsigned char version_major;
1005-
unsigned char version_minor;
1006-
unsigned char version_patch;
1007-
char version_string[64];
1008-
unsigned char reserved[16];
1009-
} Smpt_get_extended_version_ack;""",
10101031
# Generic acknowledgment structure (matches actual Smpt_ack)
10111032
"""typedef struct {
10121033
unsigned char packet_number;

0 commit comments

Comments
 (0)