Skip to content

Commit 803dc3b

Browse files
committed
Update Python inlined files: 3.12.7 (4.1)
1 parent e71d675 commit 803dc3b

21 files changed

+964
-141
lines changed

graalpython/com.oracle.graal.python.cext/include/cpython/import.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
1010
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
1111
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
1212

13-
PyAPI_FUNC(void) _PyImport_AcquireLock(void);
14-
PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
13+
PyAPI_FUNC(void) _PyImport_AcquireLock(PyInterpreterState *interp);
14+
PyAPI_FUNC(int) _PyImport_ReleaseLock(PyInterpreterState *interp);
1515

1616
PyAPI_FUNC(int) _PyImport_FixupBuiltin(
1717
PyObject *mod,

graalpython/com.oracle.graal.python.cext/include/cpython/object.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,19 @@
33
#endif
44

55
PyAPI_FUNC(void) _Py_NewReference(PyObject *op);
6+
PyAPI_FUNC(void) _Py_NewReferenceNoTotal(PyObject *op);
67

78
#ifdef Py_TRACE_REFS
89
/* Py_TRACE_REFS is such major surgery that we call external routines. */
910
PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
1011
#endif
1112

1213
#ifdef Py_REF_DEBUG
13-
PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
14+
/* These are useful as debugging aids when chasing down refleaks. */
15+
PyAPI_FUNC(Py_ssize_t) _Py_GetGlobalRefTotal(void);
16+
# define _Py_GetRefTotal() _Py_GetGlobalRefTotal()
17+
PyAPI_FUNC(Py_ssize_t) _Py_GetLegacyRefTotal(void);
18+
PyAPI_FUNC(Py_ssize_t) _PyInterpreterState_GetRefTotal(PyInterpreterState *);
1419
#endif
1520

1621

@@ -507,3 +512,23 @@ Py_DEPRECATED(3.11) typedef int UsingDeprecatedTrashcanMacro;
507512
#define Py_TRASHCAN_SAFE_END(op) \
508513
Py_TRASHCAN_END; \
509514
} while(0);
515+
516+
PyAPI_FUNC(void *) PyObject_GetItemData(PyObject *obj);
517+
518+
PyAPI_FUNC(int) _PyObject_VisitManagedDict(PyObject *obj, visitproc visit, void *arg);
519+
PyAPI_FUNC(void) _PyObject_ClearManagedDict(PyObject *obj);
520+
521+
#define TYPE_MAX_WATCHERS 8
522+
523+
typedef int(*PyType_WatchCallback)(PyTypeObject *);
524+
PyAPI_FUNC(int) PyType_AddWatcher(PyType_WatchCallback callback);
525+
PyAPI_FUNC(int) PyType_ClearWatcher(int watcher_id);
526+
PyAPI_FUNC(int) PyType_Watch(int watcher_id, PyObject *type);
527+
PyAPI_FUNC(int) PyType_Unwatch(int watcher_id, PyObject *type);
528+
529+
/* Attempt to assign a version tag to the given type.
530+
*
531+
* Returns 1 if the type already had a valid version tag or a new one was
532+
* assigned, or 0 if a new tag could not be assigned.
533+
*/
534+
PyAPI_FUNC(int) PyUnstable_Type_AssignVersionTag(PyTypeObject *type);

graalpython/com.oracle.graal.python.cext/include/cpython/pylifecycle.h

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ PyAPI_FUNC(const char *) _Py_gitidentifier(void);
5252
PyAPI_FUNC(const char *) _Py_gitversion(void);
5353

5454
PyAPI_FUNC(int) _Py_IsFinalizing(void);
55+
PyAPI_FUNC(int) _Py_IsInterpreterFinalizing(PyInterpreterState *interp);
5556

5657
/* Random */
5758
PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
@@ -62,4 +63,49 @@ PyAPI_FUNC(int) _Py_CoerceLegacyLocale(int warn);
6263
PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn);
6364
PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
6465

65-
PyAPI_FUNC(PyThreadState *) _Py_NewInterpreter(int isolated_subinterpreter);
66+
/* --- PyInterpreterConfig ------------------------------------ */
67+
68+
#define PyInterpreterConfig_DEFAULT_GIL (0)
69+
#define PyInterpreterConfig_SHARED_GIL (1)
70+
#define PyInterpreterConfig_OWN_GIL (2)
71+
72+
typedef struct {
73+
// XXX "allow_object_sharing"? "own_objects"?
74+
int use_main_obmalloc;
75+
int allow_fork;
76+
int allow_exec;
77+
int allow_threads;
78+
int allow_daemon_threads;
79+
int check_multi_interp_extensions;
80+
int gil;
81+
} PyInterpreterConfig;
82+
83+
#define _PyInterpreterConfig_INIT \
84+
{ \
85+
.use_main_obmalloc = 0, \
86+
.allow_fork = 0, \
87+
.allow_exec = 0, \
88+
.allow_threads = 1, \
89+
.allow_daemon_threads = 0, \
90+
.check_multi_interp_extensions = 1, \
91+
.gil = PyInterpreterConfig_OWN_GIL, \
92+
}
93+
94+
#define _PyInterpreterConfig_LEGACY_INIT \
95+
{ \
96+
.use_main_obmalloc = 1, \
97+
.allow_fork = 1, \
98+
.allow_exec = 1, \
99+
.allow_threads = 1, \
100+
.allow_daemon_threads = 1, \
101+
.check_multi_interp_extensions = 0, \
102+
.gil = PyInterpreterConfig_SHARED_GIL, \
103+
}
104+
105+
PyAPI_FUNC(PyStatus) Py_NewInterpreterFromConfig(
106+
PyThreadState **tstate_p,
107+
const PyInterpreterConfig *config);
108+
109+
typedef void (*atexit_datacallbackfunc)(void *);
110+
PyAPI_FUNC(int) _Py_AtExit(
111+
PyInterpreterState *, atexit_datacallbackfunc, void *);

graalpython/com.oracle.graal.python.cext/include/cpython/pystate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ might not be allowed in the current interpreter (i.e. os.fork() would fail).
3131
#define Py_RTFLAGS_EXEC (1UL << 16)
3232

3333

34+
PyAPI_FUNC(int) _PyInterpreterState_HasFeature(PyInterpreterState *interp,
35+
unsigned long feature);
3436

3537

3638
/* private interpreter helpers */

graalpython/com.oracle.graal.python.cext/include/internal/pycore_ceval.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ struct _ceval_runtime_state;
2121

2222

2323
extern void _Py_FinishPendingCalls(PyThreadState *tstate);
24-
extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
25-
extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
24+
extern void _PyEval_InitState(PyInterpreterState *, PyThread_type_lock);
2625
extern void _PyEval_FiniState(struct _ceval_state *ceval);
2726
PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
2827
PyAPI_FUNC(int) _PyEval_AddPendingCall(
2928
PyInterpreterState *interp,
3029
int (*func)(void *),
31-
void *arg);
30+
void *arg,
31+
int mainthreadonly);
3232
PyAPI_FUNC(void) _PyEval_SignalAsyncExc(PyInterpreterState *interp);
3333
#ifdef HAVE_FORK
3434
extern PyStatus _PyEval_ReInitThreads(PyThreadState *tstate);
@@ -96,11 +96,13 @@ _PyEval_Vector(PyThreadState *tstate,
9696
PyObject* const* args, size_t argcount,
9797
PyObject *kwnames);
9898

99-
extern int _PyEval_ThreadsInitialized(struct pyruntimestate *runtime);
100-
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate);
99+
extern int _PyEval_ThreadsInitialized(void);
100+
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate, int own_gil);
101101
extern void _PyEval_FiniGIL(PyInterpreterState *interp);
102102

103-
extern void _PyEval_ReleaseLock(PyThreadState *tstate);
103+
extern void _PyEval_AcquireLock(PyThreadState *tstate);
104+
extern void _PyEval_ReleaseLock(PyInterpreterState *, PyThreadState *);
105+
extern PyThreadState * _PyThreadState_SwapNoGIL(PyThreadState *);
104106

105107
extern void _PyEval_DeactivateOpCache(void);
106108

graalpython/com.oracle.graal.python.cext/include/internal/pycore_frame.h

Lines changed: 80 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ extern "C" {
66

77
#include <stdbool.h>
88
#include <stddef.h>
9+
#include "pycore_code.h" // STATS
910

1011
/* See Objects/frame_layout.md for an explanation of the frame stack
1112
* including explanation of the PyFrameObject and _PyInterpreterFrame
@@ -48,22 +49,26 @@ enum _frameowner {
4849
};
4950

5051
typedef struct _PyInterpreterFrame {
51-
/* "Specials" section */
52-
PyFunctionObject *f_func; /* Strong reference */
53-
PyObject *f_globals; /* Borrowed reference */
54-
PyObject *f_builtins; /* Borrowed reference */
55-
PyObject *f_locals; /* Strong reference, may be NULL */
5652
PyCodeObject *f_code; /* Strong reference */
57-
PyFrameObject *frame_obj; /* Strong reference, may be NULL */
58-
/* Linkage section */
5953
struct _PyInterpreterFrame *previous;
54+
PyObject *f_funcobj; /* Strong reference. Only valid if not on C stack */
55+
PyObject *f_globals; /* Borrowed reference. Only valid if not on C stack */
56+
PyObject *f_builtins; /* Borrowed reference. Only valid if not on C stack */
57+
PyObject *f_locals; /* Strong reference, may be NULL. Only valid if not on C stack */
58+
PyFrameObject *frame_obj; /* Strong reference, may be NULL. Only valid if not on C stack */
6059
// NOTE: This is not necessarily the last instruction started in the given
6160
// frame. Rather, it is the code unit *prior to* the *next* instruction. For
6261
// example, it may be an inline CACHE entry, an instruction we just jumped
6362
// over, or (in the case of a newly-created frame) a totally invalid value:
6463
_Py_CODEUNIT *prev_instr;
65-
int stacktop; /* Offset of TOS from localsplus */
66-
bool is_entry; // Whether this is the "root" frame for the current _PyCFrame.
64+
int stacktop; /* Offset of TOS from localsplus */
65+
/* The return_offset determines where a `RETURN` should go in the caller,
66+
* relative to `prev_instr`.
67+
* It is only meaningful to the callee,
68+
* so it needs to be set in any CALL (to a Python function)
69+
* or SEND (to a coroutine or generator).
70+
* If there is no callee, then it is meaningless. */
71+
uint16_t return_offset;
6772
char owner;
6873
/* Locals and stack */
6974
PyObject *localsplus[1];
@@ -93,7 +98,16 @@ static inline void _PyFrame_StackPush(_PyInterpreterFrame *f, PyObject *value) {
9398
f->stacktop++;
9499
}
95100

96-
#define FRAME_SPECIALS_SIZE ((sizeof(_PyInterpreterFrame)-1)/sizeof(PyObject *))
101+
#define FRAME_SPECIALS_SIZE ((int)((sizeof(_PyInterpreterFrame)-1)/sizeof(PyObject *)))
102+
103+
static inline int
104+
_PyFrame_NumSlotsForCodeObject(PyCodeObject *code)
105+
{
106+
/* This function needs to remain in sync with the calculation of
107+
* co_framesize in Tools/build/deepfreeze.py */
108+
assert(code->co_framesize >= FRAME_SPECIALS_SIZE);
109+
return code->co_framesize - FRAME_SPECIALS_SIZE;
110+
}
97111

98112
void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest);
99113

@@ -102,20 +116,24 @@ void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *dest);
102116
when frame is linked into the frame stack.
103117
*/
104118
static inline void
105-
_PyFrame_InitializeSpecials(
119+
_PyFrame_Initialize(
106120
_PyInterpreterFrame *frame, PyFunctionObject *func,
107-
PyObject *locals, int nlocalsplus)
121+
PyObject *locals, PyCodeObject *code, int null_locals_from)
108122
{
109-
frame->f_func = func;
110-
frame->f_code = (PyCodeObject *)Py_NewRef(func->func_code);
123+
frame->f_funcobj = (PyObject *)func;
124+
frame->f_code = (PyCodeObject *)Py_NewRef(code);
111125
frame->f_builtins = func->func_builtins;
112126
frame->f_globals = func->func_globals;
113-
frame->f_locals = Py_XNewRef(locals);
114-
frame->stacktop = nlocalsplus;
127+
frame->f_locals = locals;
128+
frame->stacktop = code->co_nlocalsplus;
115129
frame->frame_obj = NULL;
116-
frame->prev_instr = _PyCode_CODE(frame->f_code) - 1;
117-
frame->is_entry = false;
130+
frame->prev_instr = _PyCode_CODE(code) - 1;
131+
frame->return_offset = 0;
118132
frame->owner = FRAME_OWNED_BY_THREAD;
133+
134+
for (int i = null_locals_from; i < code->co_nlocalsplus; i++) {
135+
frame->localsplus[i] = NULL;
136+
}
119137
}
120138

121139
/* Gets the pointer to the locals array
@@ -127,10 +145,16 @@ _PyFrame_GetLocalsArray(_PyInterpreterFrame *frame)
127145
return frame->localsplus;
128146
}
129147

148+
/* Fetches the stack pointer, and sets stacktop to -1.
149+
Having stacktop <= 0 ensures that invalid
150+
values are not visible to the cycle GC.
151+
We choose -1 rather than 0 to assist debugging. */
130152
static inline PyObject**
131153
_PyFrame_GetStackPointer(_PyInterpreterFrame *frame)
132154
{
133-
return frame->localsplus+frame->stacktop;
155+
PyObject **sp = frame->localsplus + frame->stacktop;
156+
frame->stacktop = -1;
157+
return sp;
134158
}
135159

136160
static inline void
@@ -154,6 +178,21 @@ _PyFrame_IsIncomplete(_PyInterpreterFrame *frame)
154178
frame->prev_instr < _PyCode_CODE(frame->f_code) + frame->f_code->_co_firsttraceable;
155179
}
156180

181+
static inline _PyInterpreterFrame *
182+
_PyFrame_GetFirstComplete(_PyInterpreterFrame *frame)
183+
{
184+
while (frame && _PyFrame_IsIncomplete(frame)) {
185+
frame = frame->previous;
186+
}
187+
return frame;
188+
}
189+
190+
static inline _PyInterpreterFrame *
191+
_PyThreadState_GetFrame(PyThreadState *tstate)
192+
{
193+
return _PyFrame_GetFirstComplete(tstate->cframe->current_frame);
194+
}
195+
157196
/* For use by _PyFrame_GetFrameObject
158197
Do not call directly. */
159198
PyFrameObject *
@@ -184,50 +223,51 @@ _PyFrame_GetFrameObject(_PyInterpreterFrame *frame)
184223
* frames like the ones in generators and coroutines.
185224
*/
186225
void
187-
_PyFrame_Clear(_PyInterpreterFrame * frame);
226+
_PyFrame_ClearExceptCode(_PyInterpreterFrame * frame);
188227

189228
int
190229
_PyFrame_Traverse(_PyInterpreterFrame *frame, visitproc visit, void *arg);
191230

231+
PyObject *
232+
_PyFrame_GetLocals(_PyInterpreterFrame *frame, int include_hidden);
233+
192234
int
193235
_PyFrame_FastToLocalsWithError(_PyInterpreterFrame *frame);
194236

195237
void
196238
_PyFrame_LocalsToFast(_PyInterpreterFrame *frame, int clear);
197239

198-
extern _PyInterpreterFrame *
199-
_PyThreadState_BumpFramePointerSlow(PyThreadState *tstate, size_t size);
200-
201240
static inline bool
202-
_PyThreadState_HasStackSpace(PyThreadState *tstate, size_t size)
241+
_PyThreadState_HasStackSpace(PyThreadState *tstate, int size)
203242
{
204243
assert(
205244
(tstate->datastack_top == NULL && tstate->datastack_limit == NULL)
206245
||
207246
(tstate->datastack_top != NULL && tstate->datastack_limit != NULL)
208247
);
209248
return tstate->datastack_top != NULL &&
210-
size < (size_t)(tstate->datastack_limit - tstate->datastack_top);
249+
size < tstate->datastack_limit - tstate->datastack_top;
211250
}
212251

213-
static inline _PyInterpreterFrame *
214-
_PyThreadState_BumpFramePointer(PyThreadState *tstate, size_t size)
215-
{
216-
if (_PyThreadState_HasStackSpace(tstate, size)) {
217-
_PyInterpreterFrame *res = (_PyInterpreterFrame *)tstate->datastack_top;
218-
tstate->datastack_top += size;
219-
return res;
220-
}
221-
return _PyThreadState_BumpFramePointerSlow(tstate, size);
222-
}
252+
extern _PyInterpreterFrame *
253+
_PyThreadState_PushFrame(PyThreadState *tstate, size_t size);
223254

224255
void _PyThreadState_PopFrame(PyThreadState *tstate, _PyInterpreterFrame *frame);
225256

226-
/* Consume reference to func */
227-
_PyInterpreterFrame *
228-
_PyFrame_Push(PyThreadState *tstate, PyFunctionObject *func);
229-
230-
int _PyInterpreterFrame_GetLine(_PyInterpreterFrame *frame);
257+
/* Pushes a frame without checking for space.
258+
* Must be guarded by _PyThreadState_HasStackSpace()
259+
* Consumes reference to func. */
260+
static inline _PyInterpreterFrame *
261+
_PyFrame_PushUnchecked(PyThreadState *tstate, PyFunctionObject *func, int null_locals_from)
262+
{
263+
CALL_STAT_INC(frames_pushed);
264+
PyCodeObject *code = (PyCodeObject *)func->func_code;
265+
_PyInterpreterFrame *new_frame = (_PyInterpreterFrame *)tstate->datastack_top;
266+
tstate->datastack_top += code->co_framesize;
267+
assert(tstate->datastack_top < tstate->datastack_limit);
268+
_PyFrame_Initialize(new_frame, func, NULL, code, null_locals_from);
269+
return new_frame;
270+
}
231271

232272
static inline
233273
PyGenObject *_PyFrame_GetGenerator(_PyInterpreterFrame *frame)

graalpython/com.oracle.graal.python.cext/include/internal/pycore_gc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,8 @@ extern void _PyList_ClearFreeList(PyInterpreterState *interp);
176176
extern void _PyDict_ClearFreeList(PyInterpreterState *interp);
177177
extern void _PyAsyncGen_ClearFreeLists(PyInterpreterState *interp);
178178
extern void _PyContext_ClearFreeList(PyInterpreterState *interp);
179+
extern void _Py_ScheduleGC(PyInterpreterState *interp);
180+
extern void _Py_RunGC(PyThreadState *tstate);
179181

180182
#ifdef __cplusplus
181183
}

0 commit comments

Comments
 (0)