|
198 | 198 | if sys.platform.startswith("win") |
199 | 199 | else [ |
200 | 200 | "-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 |
204 | 203 | "-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 |
210 | 206 | ] |
211 | 207 | ) |
212 | 208 | + [ |
@@ -489,10 +485,8 @@ def load_library(): # noqa: C901 |
489 | 485 | extra_compile_args.extend( |
490 | 486 | [ |
491 | 487 | "-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 |
496 | 490 | ] |
497 | 491 | ) |
498 | 492 | else: |
@@ -675,18 +669,11 @@ def preprocess_header_manually(header_path): |
675 | 669 | else: |
676 | 670 | asm_definition = "#define __asm__(...)" |
677 | 671 | bool_definitions = """ |
678 | | -#ifndef __bool_true_false_are_defined |
679 | | -#define __bool_true_false_are_defined 1 |
| 672 | +#ifndef _Bool |
680 | 673 | typedef unsigned char _Bool; |
681 | 674 | #endif |
682 | 675 |
|
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 */ |
690 | 677 | """ |
691 | 678 |
|
692 | 679 | essential_types = f""" |
@@ -741,9 +728,9 @@ def try_parse_with_better_args(header_path, header_name): |
741 | 728 | asm_definition = "-D__asm__(...)=" |
742 | 729 | bool_definitions = [ |
743 | 730 | "-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 |
747 | 734 | ] |
748 | 735 |
|
749 | 736 | parsing_attempts = [ |
|
0 commit comments