xref: /aosp_15_r20/external/pytorch/torch/csrc/dynamo/cpython_includes.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 #pragma once
2 
3 #include <torch/csrc/utils/python_compat.h>
4 
5 // Problem in CPython includes when mixing core and non-core build
6 // The fix was not backported to 3.12 so this is needed here
7 // https://github.com/python/cpython/issues/105268
8 #if IS_PYTHON_3_12_PLUS
9 #undef _PyGC_FINALIZED
10 #endif
11 
12 // see https://bugs.python.org/issue35886
13 #if PY_VERSION_HEX >= 0x03080000
14 #define Py_BUILD_CORE
15 
16 #ifndef __cplusplus
17 // C-only headers
18 #include <internal/pycore_pystate.h>
19 
20 #endif // __cplusplus
21 
22 #if IS_PYTHON_3_11_PLUS
23 #include <internal/pycore_frame.h>
24 #endif
25 
26 #undef Py_BUILD_CORE
27 #endif // PY_VERSION_HEX >= 0x03080000
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 #if IS_PYTHON_3_13_PLUS
34 #define F_CODE(x) ((PyCodeObject*)(x)->f_executable)
35 #define PREV_INSTR(x) (x)->instr_ptr
36 #else
37 #define F_CODE(x) ((PyCodeObject*)(x)->f_code)
38 #define PREV_INSTR(x) (x)->prev_instr
39 #endif
40 
41 #if IS_PYTHON_3_12_PLUS
42 #define FUNC(x) ((x)->f_funcobj)
43 #else
44 #define FUNC(x) ((x)->f_func)
45 #endif
46 
47 #ifdef __cplusplus
48 } // extern "C"
49 #endif
50