Skip to content

Instantly share code, notes, and snippets.

@godlygeek
Created June 26, 2023 17:17
namespace Python3_12 {
constexpr int NEXITFUNCS = 32;
typedef struct
{
void* ctx;
void* (*malloc)(void* ctx, size_t size);
void* (*calloc)(void* ctx, size_t nelem, size_t elsize);
void* (*realloc)(void* ctx, void* ptr, size_t new_size);
void (*free)(void* ctx, void* ptr);
} PyMemAllocatorEx;
typedef struct
{
char api_id;
PyMemAllocatorEx alloc;
} debug_alloc_api_t;
typedef struct
{
void* ctx;
void* (*alloc)(void* ctx, size_t size);
void (*free)(void* ctx, void* ptr, size_t size);
} PyObjectArenaAllocator;
struct _pymem_allocators
{
PyThread_type_lock mutex;
struct
{
PyMemAllocatorEx raw;
PyMemAllocatorEx mem;
PyMemAllocatorEx obj;
} standard;
struct
{
debug_alloc_api_t raw;
debug_alloc_api_t mem;
debug_alloc_api_t obj;
} debug;
PyObjectArenaAllocator obj_arena;
};
struct _obmalloc_global_state
{
int dump_debug_stats;
Py_ssize_t interpreter_leaks;
};
struct pyhash_runtime_state
{
struct
{
int fd;
dev_t st_dev;
ino_t st_ino;
} urandom_cache;
};
struct _time_runtime_state
{
int ticks_per_second_initialized;
long ticks_per_second;
};
struct _pythread_runtime_state
{
int initialized;
struct
{
pthread_condattr_t* ptr;
pthread_condattr_t val;
} _condattr_monotonic;
};
struct _signals_runtime_state
{
volatile struct
{
_Py_atomic_int tripped;
_Py_atomic_address func;
} handlers[NSIG];
volatile struct
{
sig_atomic_t fd;
int warn_on_full_buffer;
} wakeup;
_Py_atomic_int is_tripped;
PyObject* default_handler;
PyObject* ignore_handler;
int unhandled_keyboard_interrupt;
};
typedef struct
{
Py_ssize_t length;
wchar_t** items;
} PyWideStringList;
struct _expr
{
int kind;
union {
struct
{
int op;
void* values;
} BoolOp;
struct
{
void* target;
void* value;
} NamedExpr;
struct
{
void* left;
int op;
void* right;
} BinOp;
struct
{
int op;
void* operand;
} UnaryOp;
struct
{
void* args;
void* body;
} Lambda;
struct
{
void* test;
void* body;
void* orelse;
} IfExp;
struct
{
void* keys;
void* values;
} Dict;
struct
{
void* elts;
} Set;
struct
{
void* elt;
void* generators;
} ListComp;
struct
{
void* elt;
void* generators;
} SetComp;
struct
{
void* key;
void* value;
void* generators;
} DictComp;
struct
{
void* elt;
void* generators;
} GeneratorExp;
struct
{
void* value;
} Await;
struct
{
void* value;
} Yield;
struct
{
void* value;
} YieldFrom;
struct
{
void* left;
void* ops;
void* comparators;
} Compare;
struct
{
void* func;
void* args;
void* keywords;
} Call;
struct
{
void* value;
int conversion;
void* format_spec;
} FormattedValue;
struct
{
void* values;
} JoinedStr;
struct
{
void* value;
void* kind;
} Constant;
struct
{
void* value;
void* attr;
int ctx;
} Attribute;
struct
{
void* value;
void* slice;
int ctx;
} Subscript;
struct
{
void* value;
int ctx;
} Starred;
struct
{
void* id;
int ctx;
} Name;
struct
{
void* elts;
int ctx;
} List;
struct
{
void* elts;
int ctx;
} Tuple;
struct
{
void* lower;
void* upper;
void* step;
} Slice;
} v;
int lineno;
int col_offset;
int end_lineno;
int end_col_offset;
};
struct _parser_runtime_state
{
// FIXME This has a different layout when Py_DEBUG is defined
int _not_used;
struct _expr dummy_name;
};
typedef void (*atexit_callbackfunc)(void);
struct _atexit_runtime_state
{
PyThread_type_lock mutex;
atexit_callbackfunc callbacks[NEXITFUNCS];
int ncallbacks;
};
struct _import_runtime_state
{
void* inittab;
Py_ssize_t last_module_index;
struct
{
PyThreadState main_tstate;
PyThread_type_lock mutex;
PyObject* dict;
} extensions;
const char* pkgcontext;
};
typedef enum {
PERF_STATUS_FAILED = -1,
PERF_STATUS_NO_INIT = 0,
PERF_STATUS_OK = 1,
} perf_status_t;
struct trampoline_api_st
{
void* (*init_state)(void);
void (*write_state)(void* state, const void* code_addr, unsigned int code_size, PyCodeObject* code);
int (*free_state)(void* state);
void* state;
};
template<int py_have_perf_trampoline>
struct _ceval_runtime_state_perf
{
perf_status_t status;
Py_ssize_t extra_code_index;
struct code_arena_st* code_arena;
struct trampoline_api_st trampoline_api;
void* map_file;
};
template<>
struct _ceval_runtime_state_perf<0>
{
int _not_used;
};
template<int py_have_perf_trampoline>
struct _ceval_runtime_state
{
_ceval_runtime_state_perf<py_have_perf_trampoline> perf;
_Py_atomic_int signals_pending;
struct Python3_8::_pending_calls pending_mainthread;
};
struct _gilstate_runtime_state {
int check_enabled;
PyInterpreterState *autoInterpreterState;
};
typedef struct pyruntimestate
{
int _initialized;
int preinitializing;
int preinitialized;
int core_initialized;
int initialized;
PyThreadState* _finalizing;
struct _pymem_allocators allocators;
struct _obmalloc_global_state obmalloc;
struct pyhash_runtime_state pyhash_state;
struct _time_runtime_state time;
struct _pythread_runtime_state threads;
struct _signals_runtime_state signals;
struct pyinterpreters
{
PyThread_type_lock mutex;
PyInterpreterState* head;
PyInterpreterState* main;
int64_t next_id;
} interpreters;
struct _xidregistry
{
PyThread_type_lock mutex;
struct _xidregitem* head;
} xidregistry;
unsigned long main_thread;
_Py_tss_t autoTSSkey;
_Py_tss_t trashTSSkey;
PyWideStringList orig_argv;
struct _parser_runtime_state parser;
struct _atexit_runtime_state atexit;
struct _import_runtime_state imports;
struct _ceval_runtime_state<1> ceval;
struct _gilstate_runtime_state gilstate;
int gc; // This is fake, but is here for compatibility
} PyRuntimeState;
} // namespace Python3_12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment