PHP 8.2.30
Preview: pycore_runtime.h Size: 5.85 KB
//opt/alt/python311/include/python3.11/internal/pycore_runtime.h

#ifndef Py_INTERNAL_RUNTIME_H
#define Py_INTERNAL_RUNTIME_H
#ifdef __cplusplus
extern "C" {
#endif

#ifndef Py_BUILD_CORE
#  error "this header requires Py_BUILD_CORE define"
#endif

#include "pycore_atomic.h"          /* _Py_atomic_address */
#include "pycore_gil.h"             // struct _gil_runtime_state
#include "pycore_global_objects.h"  // struct _Py_global_objects
#include "pycore_interp.h"          // PyInterpreterState
#include "pycore_unicodeobject.h"   // struct _Py_unicode_runtime_ids


/* ceval state */

struct _ceval_runtime_state {
    /* Request for checking signals. It is shared by all interpreters (see
       bpo-40513). Any thread of any interpreter can receive a signal, but only
       the main thread of the main interpreter can handle signals: see
       _Py_ThreadCanHandleSignals(). */
    _Py_atomic_int signals_pending;
    struct _gil_runtime_state gil;
};

/* GIL state */

struct _gilstate_runtime_state {
    /* bpo-26558: Flag to disable PyGILState_Check().
       If set to non-zero, PyGILState_Check() always return 1. */
    int check_enabled;
    /* Assuming the current thread holds the GIL, this is the
       PyThreadState for the current thread. */
    _Py_atomic_address tstate_current;
    /* The single PyInterpreterState used by this process'
       GILState implementation
    */
    /* TODO: Given interp_main, it may be possible to kill this ref */
    PyInterpreterState *autoInterpreterState;
    Py_tss_t autoTSSkey;
};

/* Runtime audit hook state */

typedef struct _Py_AuditHookEntry {
    struct _Py_AuditHookEntry *next;
    Py_AuditHookFunction hookCFunction;
    void *userData;
} _Py_AuditHookEntry;

/* Full Python runtime state */

/* _PyRuntimeState holds the global state for the CPython runtime.
   That data is exposed in the internal API as a static variable (_PyRuntime).
   */
typedef struct pyruntimestate {
    /* Has been initialized to a safe state.

       In order to be effective, this must be set to 0 during or right
       after allocation. */
    int _initialized;

    /* Is running Py_PreInitialize()? */
    int preinitializing;

    /* Is Python preinitialized? Set to 1 by Py_PreInitialize() */
    int preinitialized;

    /* Is Python core initialized? Set to 1 by _Py_InitializeCore() */
    int core_initialized;

    /* Is Python fully initialized? Set to 1 by Py_Initialize() */
    int initialized;

    /* Set by Py_FinalizeEx(). Only reset to NULL if Py_Initialize()
       is called again.

       Use _PyRuntimeState_GetFinalizing() and _PyRuntimeState_SetFinalizing()
       to access it, don't access it directly. */
    _Py_atomic_address _finalizing;

    struct pyinterpreters {
        PyThread_type_lock mutex;
        /* The linked list of interpreters, newest first. */
        PyInterpreterState *head;
        /* The runtime's initial interpreter, which has a special role
           in the operation of the runtime.  It is also often the only
           interpreter. */
        PyInterpreterState *main;
        /* _next_interp_id is an auto-numbered sequence of small
           integers.  It gets initialized in _PyInterpreterState_Init(),
           which is called in Py_Initialize(), and used in
           PyInterpreterState_New().  A negative interpreter ID
           indicates an error occurred.  The main interpreter will
           always have an ID of 0.  Overflow results in a RuntimeError.
           If that becomes a problem later then we can adjust, e.g. by
           using a Python int. */
        int64_t next_id;
    } interpreters;
    // XXX Remove this field once we have a tp_* slot.
    struct _xidregistry {
        PyThread_type_lock mutex;
        struct _xidregitem *head;
    } xidregistry;

    unsigned long main_thread;

#define NEXITFUNCS 32
    void (*exitfuncs[NEXITFUNCS])(void);
    int nexitfuncs;

    struct _ceval_runtime_state ceval;
    struct _gilstate_runtime_state gilstate;

    PyPreConfig preconfig;

    // Audit values must be preserved when Py_Initialize()/Py_Finalize()
    // is called multiple times.
    Py_OpenCodeHookFunction open_code_hook;
    void *open_code_userdata;
    _Py_AuditHookEntry *audit_hook_head;

    struct _Py_unicode_runtime_ids unicode_ids;

    /* All the objects that are shared by the runtime's interpreters. */
    struct _Py_global_objects global_objects;

    /* The following fields are here to avoid allocation during init.
       The data is exposed through _PyRuntimeState pointer fields.
       These fields should not be accessed directly outside of init.

       All other _PyRuntimeState pointer fields are populated when
       needed and default to NULL.

       For now there are some exceptions to that rule, which require
       allocation during init.  These will be addressed on a case-by-case
       basis.  Most notably, we don't pre-allocated the several mutex
       (PyThread_type_lock) fields, because on Windows we only ever get
       a pointer type.
       */

    /* PyInterpreterState.interpreters.main */
    PyInterpreterState _main_interpreter;
} _PyRuntimeState;


/* other API */

PyAPI_DATA(_PyRuntimeState) _PyRuntime;

PyAPI_FUNC(PyStatus) _PyRuntimeState_Init(_PyRuntimeState *runtime);
PyAPI_FUNC(void) _PyRuntimeState_Fini(_PyRuntimeState *runtime);

#ifdef HAVE_FORK
extern PyStatus _PyRuntimeState_ReInitThreads(_PyRuntimeState *runtime);
#endif

/* Initialize _PyRuntimeState.
   Return NULL on success, or return an error message on failure. */
PyAPI_FUNC(PyStatus) _PyRuntime_Initialize(void);

PyAPI_FUNC(void) _PyRuntime_Finalize(void);


static inline PyThreadState*
_PyRuntimeState_GetFinalizing(_PyRuntimeState *runtime) {
    return (PyThreadState*)_Py_atomic_load_relaxed(&runtime->_finalizing);
}

static inline void
_PyRuntimeState_SetFinalizing(_PyRuntimeState *runtime, PyThreadState *tstate) {
    _Py_atomic_store_relaxed(&runtime->_finalizing, (uintptr_t)tstate);
}

#ifdef __cplusplus
}
#endif
#endif /* !Py_INTERNAL_RUNTIME_H */

Directory Contents

Dirs: 0 × Files: 68

Name Size Perms Modified Actions
611 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.10 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
2.96 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
28.63 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
6.40 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
16.58 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
2.38 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
5.92 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
8.48 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.39 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
3.30 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
3.39 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
4.31 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
15.56 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.02 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
2.77 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.21 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
5.55 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
704 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
562 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
842 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
7.23 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.28 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
480 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
7.39 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
413 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
6.73 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.14 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
490 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.53 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.40 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
12.68 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
3.61 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
4.10 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
743 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
5.66 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
6.51 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
562 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.32 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
3.43 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.02 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
392 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
9.80 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
18.54 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
626 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
606 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
2.67 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
2.44 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
206 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
3.42 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
9.21 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
3.62 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
4.15 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
5.85 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
47.94 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
937 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
336 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
937 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
580 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
5.51 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
605 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
3.42 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
2.04 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.13 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
898 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
1.68 KB lrw-r--r-- 2025-10-09 16:16:55
Edit Download
678 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download
740 B lrw-r--r-- 2025-10-09 16:16:55
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).