@@ -44,6 +44,7 @@ def make_string_literal(b: bytes) -> str:
4444CO_FAST_CELL = 0x40
4545CO_FAST_FREE = 0x80
4646
47+ next_code_version = 1
4748
4849def get_localsplus (code : types .CodeType ):
4950 a = collections .defaultdict (int )
@@ -227,6 +228,7 @@ def generate_unicode(self, name: str, s: str) -> str:
227228
228229
229230 def generate_code (self , name : str , code : types .CodeType ) -> str :
231+ global next_code_version
230232 # The ordering here matches PyCode_NewWithPosOnlyArgs()
231233 # (but see below).
232234 co_consts = self .generate (name + "_consts" , code .co_consts )
@@ -268,6 +270,8 @@ def generate_code(self, name: str, code: types.CodeType) -> str:
268270 self .write (f".co_nplaincellvars = { nplaincellvars } ," )
269271 self .write (f".co_ncellvars = { ncellvars } ," )
270272 self .write (f".co_nfreevars = { nfreevars } ," )
273+ self .write (f".co_version = { next_code_version } ," )
274+ next_code_version += 1
271275 self .write (f".co_localsplusnames = { co_localsplusnames } ," )
272276 self .write (f".co_localspluskinds = { co_localspluskinds } ," )
273277 self .write (f".co_filename = { co_filename } ," )
@@ -461,6 +465,7 @@ def generate(args: list[str], output: TextIO) -> None:
461465 with printer .block (f"if ({ p } < 0)" ):
462466 printer .write ("return -1;" )
463467 printer .write ("return 0;" )
468+ printer .write (f"\n uint32_t _Py_next_func_version = { next_code_version } ;\n " )
464469 if verbose :
465470 print (f"Cache hits: { printer .hits } , misses: { printer .misses } " )
466471
0 commit comments