Skip to content

Commit c359092

Browse files
fix: bool config
1 parent 6a414d6 commit c359092

File tree

1 file changed

+11
-24
lines changed

1 file changed

+11
-24
lines changed

sciencemode/_cffi.py

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,11 @@
198198
if sys.platform.startswith("win")
199199
else [
200200
"-U_MSC_VER",
201-
# CRITICAL: Define _Bool and bool consistently for BOTH parsing and compilation
202-
# This ensures that when CFFI compiles the C extension, it sees the same
203-
# type definitions that we used during parsing
201+
# More conservative approach: only define what's essential for pycparser
202+
# Let the headers handle their own bool logic to avoid preprocessor conflicts
204203
"-D_Bool=unsigned char",
205-
"-Dbool=unsigned char",
206-
"-Dtrue=1",
207-
"-Dfalse=0",
208-
# Override stdbool.h to prevent inconsistencies
209-
"-D__bool_true_false_are_defined=1",
204+
# Don't override bool/true/false - let headers handle them
205+
# This prevents conflicts with conditional compilation in headers
210206
]
211207
)
212208
+ [
@@ -489,10 +485,8 @@ def load_library(): # noqa: C901
489485
extra_compile_args.extend(
490486
[
491487
"-D_Bool=unsigned char",
492-
"-Dbool=unsigned char",
493-
"-Dtrue=1",
494-
"-Dfalse=0",
495-
"-D__bool_true_false_are_defined=1",
488+
# More conservative: let the headers handle bool/true/false
489+
# Only define what's essential to avoid preprocessor conflicts
496490
]
497491
)
498492
else:
@@ -675,18 +669,11 @@ def preprocess_header_manually(header_path):
675669
else:
676670
asm_definition = "#define __asm__(...)"
677671
bool_definitions = """
678-
#ifndef __bool_true_false_are_defined
679-
#define __bool_true_false_are_defined 1
672+
#ifndef _Bool
680673
typedef unsigned char _Bool;
681674
#endif
682675
683-
#ifndef __cplusplus
684-
#ifndef bool
685-
#define bool _Bool
686-
#define true 1
687-
#define false 0
688-
#endif
689-
#endif
676+
/* More conservative: let headers handle bool/true/false to avoid conflicts */
690677
"""
691678

692679
essential_types = f"""
@@ -741,9 +728,9 @@ def try_parse_with_better_args(header_path, header_name):
741728
asm_definition = "-D__asm__(...)="
742729
bool_definitions = [
743730
"-D_Bool=unsigned char",
744-
"-Dbool=unsigned char",
745-
"-Dtrue=1",
746-
"-Dfalse=0",
731+
# Let the headers handle their own bool/true/false definitions
732+
# to avoid conflicts with conditional compilation
733+
# Only define essentials for pycparser compatibility
747734
]
748735

749736
parsing_attempts = [

0 commit comments

Comments
 (0)