File indexing completed on 2025-11-19 09:50:40
0001
0002
0003 #ifndef Py_LIMITED_API
0004 #ifndef Py_CODE_H
0005 #define Py_CODE_H
0006
0007 #ifdef __cplusplus
0008 extern "C" {
0009 #endif
0010
0011
0012 #define _PY_MONITORING_LOCAL_EVENTS 10
0013
0014 #define _PY_MONITORING_UNGROUPED_EVENTS 15
0015
0016 #define _PY_MONITORING_EVENTS 17
0017
0018
0019 typedef struct _Py_LocalMonitors {
0020 uint8_t tools[_PY_MONITORING_LOCAL_EVENTS];
0021 } _Py_LocalMonitors;
0022
0023 typedef struct _Py_GlobalMonitors {
0024 uint8_t tools[_PY_MONITORING_UNGROUPED_EVENTS];
0025 } _Py_GlobalMonitors;
0026
0027
0028 typedef struct {
0029 PyObject *_co_code;
0030 PyObject *_co_varnames;
0031 PyObject *_co_cellvars;
0032 PyObject *_co_freevars;
0033 } _PyCoCached;
0034
0035
0036
0037
0038
0039 typedef struct {
0040 uint8_t bytes_per_entry;
0041 uint8_t data[1];
0042 } _PyCoLineInstrumentationData;
0043
0044
0045 typedef struct {
0046 int size;
0047 int capacity;
0048 struct _PyExecutorObject *executors[1];
0049 } _PyExecutorArray;
0050
0051
0052
0053
0054 typedef struct {
0055
0056 _Py_LocalMonitors local_monitors;
0057
0058 _Py_LocalMonitors active_monitors;
0059
0060 uint8_t *tools;
0061
0062 _PyCoLineInstrumentationData *lines;
0063
0064 uint8_t *line_tools;
0065
0066
0067 uint8_t *per_instruction_opcodes;
0068
0069 uint8_t *per_instruction_tools;
0070 } _PyCoMonitoringData;
0071
0072
0073
0074 #define _PyCode_DEF(SIZE) { \
0075 PyObject_VAR_HEAD \
0076 \
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093 \
0094 \
0095 \
0096 \
0097 \
0098 PyObject *co_consts; \
0099 PyObject *co_names; \
0100 PyObject *co_exceptiontable;
0101 \
0102 int co_flags; \
0103 \
0104 \
0105 int co_argcount; \
0106 int co_posonlyargcount; \
0107 int co_kwonlyargcount; \
0108 int co_stacksize; \
0109 int co_firstlineno; \
0110 \
0111
0112 \
0113 int co_nlocalsplus; \
0114 int co_framesize; \
0115 int co_nlocals; \
0116 int co_ncellvars; \
0117 int co_nfreevars; \
0118 uint32_t co_version; \
0119 \
0120 PyObject *co_localsplusnames; \
0121 PyObject *co_localspluskinds;
0122 \
0123 PyObject *co_filename; \
0124 PyObject *co_name; \
0125 PyObject *co_qualname; \
0126 PyObject *co_linetable; \
0127 PyObject *co_weakreflist; \
0128 _PyExecutorArray *co_executors; \
0129 _PyCoCached *_co_cached; \
0130 uintptr_t _co_instrumentation_version; \
0131 _PyCoMonitoringData *_co_monitoring; \
0132 int _co_firsttraceable; \
0133
0134
0135 \
0136 void *co_extra; \
0137 char co_code_adaptive[(SIZE)]; \
0138 }
0139
0140
0141 struct PyCodeObject _PyCode_DEF(1);
0142
0143
0144 #define CO_OPTIMIZED 0x0001
0145 #define CO_NEWLOCALS 0x0002
0146 #define CO_VARARGS 0x0004
0147 #define CO_VARKEYWORDS 0x0008
0148 #define CO_NESTED 0x0010
0149 #define CO_GENERATOR 0x0020
0150
0151
0152
0153 #define CO_COROUTINE 0x0080
0154 #define CO_ITERABLE_COROUTINE 0x0100
0155 #define CO_ASYNC_GENERATOR 0x0200
0156
0157
0158
0159
0160
0161 #define CO_FUTURE_DIVISION 0x20000
0162 #define CO_FUTURE_ABSOLUTE_IMPORT 0x40000
0163 #define CO_FUTURE_WITH_STATEMENT 0x80000
0164 #define CO_FUTURE_PRINT_FUNCTION 0x100000
0165 #define CO_FUTURE_UNICODE_LITERALS 0x200000
0166
0167 #define CO_FUTURE_BARRY_AS_BDFL 0x400000
0168 #define CO_FUTURE_GENERATOR_STOP 0x800000
0169 #define CO_FUTURE_ANNOTATIONS 0x1000000
0170
0171 #define CO_NO_MONITORING_EVENTS 0x2000000
0172
0173
0174
0175
0176 #define PY_PARSER_REQUIRES_FUTURE_KEYWORD
0177
0178 #define CO_MAXBLOCKS 21
0179
0180 PyAPI_DATA(PyTypeObject) PyCode_Type;
0181
0182 #define PyCode_Check(op) Py_IS_TYPE((op), &PyCode_Type)
0183
0184 static inline Py_ssize_t PyCode_GetNumFree(PyCodeObject *op) {
0185 assert(PyCode_Check(op));
0186 return op->co_nfreevars;
0187 }
0188
0189 static inline int PyUnstable_Code_GetFirstFree(PyCodeObject *op) {
0190 assert(PyCode_Check(op));
0191 return op->co_nlocalsplus - op->co_nfreevars;
0192 }
0193
0194 Py_DEPRECATED(3.13) static inline int PyCode_GetFirstFree(PyCodeObject *op) {
0195 return PyUnstable_Code_GetFirstFree(op);
0196 }
0197
0198
0199 PyAPI_FUNC(PyCodeObject *) PyUnstable_Code_New(
0200 int, int, int, int, int, PyObject *, PyObject *,
0201 PyObject *, PyObject *, PyObject *, PyObject *,
0202 PyObject *, PyObject *, PyObject *, int, PyObject *,
0203 PyObject *);
0204
0205 PyAPI_FUNC(PyCodeObject *) PyUnstable_Code_NewWithPosOnlyArgs(
0206 int, int, int, int, int, int, PyObject *, PyObject *,
0207 PyObject *, PyObject *, PyObject *, PyObject *,
0208 PyObject *, PyObject *, PyObject *, int, PyObject *,
0209 PyObject *);
0210
0211
0212 _Py_DEPRECATED_EXTERNALLY(3.12) static inline PyCodeObject *
0213 PyCode_New(
0214 int a, int b, int c, int d, int e, PyObject *f, PyObject *g,
0215 PyObject *h, PyObject *i, PyObject *j, PyObject *k,
0216 PyObject *l, PyObject *m, PyObject *n, int o, PyObject *p,
0217 PyObject *q)
0218 {
0219 return PyUnstable_Code_New(
0220 a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q);
0221 }
0222 _Py_DEPRECATED_EXTERNALLY(3.12) static inline PyCodeObject *
0223 PyCode_NewWithPosOnlyArgs(
0224 int a, int poac, int b, int c, int d, int e, PyObject *f, PyObject *g,
0225 PyObject *h, PyObject *i, PyObject *j, PyObject *k,
0226 PyObject *l, PyObject *m, PyObject *n, int o, PyObject *p,
0227 PyObject *q)
0228 {
0229 return PyUnstable_Code_NewWithPosOnlyArgs(
0230 a, poac, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q);
0231 }
0232
0233
0234 PyAPI_FUNC(PyCodeObject *)
0235 PyCode_NewEmpty(const char *filename, const char *funcname, int firstlineno);
0236
0237
0238
0239
0240 PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
0241
0242 PyAPI_FUNC(int) PyCode_Addr2Location(PyCodeObject *, int, int *, int *, int *, int *);
0243
0244 #define PY_FOREACH_CODE_EVENT(V) \
0245 V(CREATE) \
0246 V(DESTROY)
0247
0248 typedef enum {
0249 #define PY_DEF_EVENT(op) PY_CODE_EVENT_##op,
0250 PY_FOREACH_CODE_EVENT(PY_DEF_EVENT)
0251 #undef PY_DEF_EVENT
0252 } PyCodeEvent;
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264 typedef int (*PyCode_WatchCallback)(
0265 PyCodeEvent event,
0266 PyCodeObject* co);
0267
0268
0269
0270
0271
0272
0273
0274
0275 PyAPI_FUNC(int) PyCode_AddWatcher(PyCode_WatchCallback callback);
0276
0277
0278
0279
0280
0281
0282 PyAPI_FUNC(int) PyCode_ClearWatcher(int watcher_id);
0283
0284
0285 struct _opaque {
0286 int computed_line;
0287 const uint8_t *lo_next;
0288 const uint8_t *limit;
0289 };
0290
0291 typedef struct _line_offsets {
0292 int ar_start;
0293 int ar_end;
0294 int ar_line;
0295 struct _opaque opaque;
0296 } PyCodeAddressRange;
0297
0298
0299
0300
0301 PyAPI_FUNC(int) _PyCode_CheckLineNumber(int lasti, PyCodeAddressRange *bounds);
0302
0303
0304
0305
0306
0307
0308
0309
0310 PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj);
0311
0312 PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
0313 PyObject *names, PyObject *lnotab);
0314
0315 PyAPI_FUNC(int) PyUnstable_Code_GetExtra(
0316 PyObject *code, Py_ssize_t index, void **extra);
0317 PyAPI_FUNC(int) PyUnstable_Code_SetExtra(
0318 PyObject *code, Py_ssize_t index, void *extra);
0319
0320 _Py_DEPRECATED_EXTERNALLY(3.12) static inline int
0321 _PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
0322 {
0323 return PyUnstable_Code_GetExtra(code, index, extra);
0324 }
0325 _Py_DEPRECATED_EXTERNALLY(3.12) static inline int
0326 _PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
0327 {
0328 return PyUnstable_Code_SetExtra(code, index, extra);
0329 }
0330
0331
0332
0333 PyAPI_FUNC(PyObject *) PyCode_GetCode(PyCodeObject *code);
0334
0335 PyAPI_FUNC(PyObject *) PyCode_GetVarnames(PyCodeObject *code);
0336
0337 PyAPI_FUNC(PyObject *) PyCode_GetCellvars(PyCodeObject *code);
0338
0339 PyAPI_FUNC(PyObject *) PyCode_GetFreevars(PyCodeObject *code);
0340
0341 typedef enum _PyCodeLocationInfoKind {
0342
0343 PY_CODE_LOCATION_INFO_SHORT0 = 0,
0344
0345 PY_CODE_LOCATION_INFO_ONE_LINE0 = 10,
0346 PY_CODE_LOCATION_INFO_ONE_LINE1 = 11,
0347 PY_CODE_LOCATION_INFO_ONE_LINE2 = 12,
0348
0349 PY_CODE_LOCATION_INFO_NO_COLUMNS = 13,
0350 PY_CODE_LOCATION_INFO_LONG = 14,
0351 PY_CODE_LOCATION_INFO_NONE = 15
0352 } _PyCodeLocationInfoKind;
0353
0354 #ifdef __cplusplus
0355 }
0356 #endif
0357 #endif
0358 #endif