@@ -2172,8 +2172,9 @@ def print_block(
2172
2172
self ,
2173
2173
block : Block ,
2174
2174
* ,
2175
- clinic : Clinic ,
2176
2175
core_includes : bool = False ,
2176
+ limited_capi : bool ,
2177
+ header_includes : dict [str , str ],
2177
2178
) -> None :
2178
2179
input = block .input
2179
2180
output = block .output
@@ -2203,7 +2204,7 @@ def print_block(
2203
2204
2204
2205
output = ''
2205
2206
if core_includes :
2206
- if not clinic . limited_capi :
2207
+ if not limited_capi :
2207
2208
output += textwrap .dedent ("""
2208
2209
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
2209
2210
# include "pycore_gc.h" // PyGC_Head
@@ -2212,12 +2213,10 @@ def print_block(
2212
2213
2213
2214
""" )
2214
2215
2215
- if clinic is not None :
2216
- # Emit optional includes
2217
- for include , reason in sorted (clinic .includes .items ()):
2218
- line = f'#include "{ include } "'
2219
- line = line .ljust (35 ) + f'// { reason } \n '
2220
- output += line
2216
+ # Emit optional "#include" directives for C headers
2217
+ for include , reason in sorted (header_includes .items ()):
2218
+ line = f'#include "{ include } "' .ljust (35 ) + f'// { reason } \n '
2219
+ output += line
2221
2220
2222
2221
input = '' .join (block .input )
2223
2222
output += '' .join (block .output )
@@ -2531,7 +2530,9 @@ def parse(self, input: str) -> str:
2531
2530
self .parsers [dsl_name ] = parsers [dsl_name ](self )
2532
2531
parser = self .parsers [dsl_name ]
2533
2532
parser .parse (block )
2534
- printer .print_block (block , clinic = self )
2533
+ printer .print_block (block ,
2534
+ limited_capi = self .limited_capi ,
2535
+ header_includes = self .includes )
2535
2536
2536
2537
# these are destinations not buffers
2537
2538
for name , destination in self .destinations .items ():
@@ -2546,7 +2547,9 @@ def parse(self, input: str) -> str:
2546
2547
block .input = "dump " + name + "\n "
2547
2548
warn ("Destination buffer " + repr (name ) + " not empty at end of file, emptying." )
2548
2549
printer .write ("\n " )
2549
- printer .print_block (block , clinic = self )
2550
+ printer .print_block (block ,
2551
+ limited_capi = self .limited_capi ,
2552
+ header_includes = self .includes )
2550
2553
continue
2551
2554
2552
2555
if destination .type == 'file' :
@@ -2571,7 +2574,10 @@ def parse(self, input: str) -> str:
2571
2574
2572
2575
block .input = 'preserve\n '
2573
2576
printer_2 = BlockPrinter (self .language )
2574
- printer_2 .print_block (block , core_includes = True , clinic = self )
2577
+ printer_2 .print_block (block ,
2578
+ core_includes = True ,
2579
+ limited_capi = self .limited_capi ,
2580
+ header_includes = self .includes )
2575
2581
write_file (destination .filename , printer_2 .f .getvalue ())
2576
2582
continue
2577
2583
0 commit comments