Skip to content

Commit 9305154

Browse files
committed
Update Python inlined files: 3.12.7 (4.3.1)
1 parent ca26d48 commit 9305154

File tree

7 files changed

+203
-33
lines changed

7 files changed

+203
-33
lines changed

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ typedef struct {
135135
PyObject *co_exceptiontable; /* Byte string encoding exception handling \
136136
table */ \
137137
int co_flags; /* CO_..., see below */ \
138-
short co_warmup; /* Warmup counter for quickening */ \
139-
short _co_linearray_entry_size; /* Size of each entry in _co_linearray */ \
140138
\
141139
/* The rest are not so impactful on performance. */ \
142140
int co_argcount; /* #arguments, except *args */ \
@@ -147,12 +145,12 @@ typedef struct {
147145
\
148146
/* redundant values (derived from co_localsplusnames and \
149147
co_localspluskinds) */ \
150-
int co_nlocalsplus; /* number of local + cell + free variables \
151-
*/ \
148+
int co_nlocalsplus; /* number of local + cell + free variables */ \
149+
int co_framesize; /* Size of frame in words */ \
152150
int co_nlocals; /* number of local variables */ \
153-
int co_nplaincellvars; /* number of non-arg cell variables */ \
154151
int co_ncellvars; /* total number of cell variables */ \
155152
int co_nfreevars; /* number of free variables */ \
153+
uint32_t co_version; /* version number */ \
156154
\
157155
PyObject *co_localsplusnames; /* tuple mapping offsets to names */ \
158156
PyObject *co_localspluskinds; /* Bytes mapping to local kinds (one byte \
@@ -162,8 +160,9 @@ typedef struct {
162160
PyObject *co_qualname; /* unicode (qualname, for reference) */ \
163161
PyObject *co_linetable; /* bytes object that holds location info */ \
164162
PyObject *co_weakreflist; /* to support weakrefs to code objects */ \
165-
PyObject *_co_code; /* cached co_code object/attribute */ \
166-
char *_co_linearray; /* array of line offsets */ \
163+
_PyCoCached *_co_cached; /* cached co_* attributes */ \
164+
uint64_t _co_instrumentation_version; /* current instrumentation version */ \
165+
_PyCoMonitoringData *_co_monitoring; /* Monitoring data */ \
167166
int _co_firsttraceable; /* index of first traceable instruction */ \
168167
/* Scratch space for extra data relating to the code object. \
169168
Type is a void* to keep the format private in codeobject.c to force \
@@ -213,9 +212,18 @@ struct PyCodeObject _PyCode_DEF(1);
213212
PyAPI_DATA(PyTypeObject) PyCode_Type;
214213

215214
#define PyCode_Check(op) Py_IS_TYPE((op), &PyCode_Type)
216-
#define PyCode_GetNumFree(op) ((op)->co_nfreevars)
217-
#define _PyCode_CODE(CO) ((_Py_CODEUNIT *)(CO)->co_code_adaptive)
218215

216+
static inline Py_ssize_t PyCode_GetNumFree(PyCodeObject *op) {
217+
assert(PyCode_Check(op));
218+
return op->co_nfreevars;
219+
}
220+
221+
static inline int PyCode_GetFirstFree(PyCodeObject *op) {
222+
assert(PyCode_Check(op));
223+
return op->co_nlocalsplus - op->co_nfreevars;
224+
}
225+
226+
#define _PyCode_CODE(CO) _Py_RVALUE((_Py_CODEUNIT *)(CO)->co_code_adaptive)
219227
#define _PyCode_NBYTES(CO) (Py_SIZE(CO) * (Py_ssize_t)sizeof(_Py_CODEUNIT))
220228

221229
/* Unstable public interface */

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

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,15 @@ typedef struct _Py_Identifier {
4646
Py_ssize_t index;
4747
} _Py_Identifier;
4848

49-
#if defined(NEEDS_PY_IDENTIFIER) || !defined(Py_BUILD_CORE)
49+
#ifndef Py_BUILD_CORE
5050
// For now we are keeping _Py_IDENTIFIER for continued use
5151
// in non-builtin extensions (and naughty PyPI modules).
5252

53-
#define _Py_static_string_init(value) { .string = value, .index = -1 }
53+
#define _Py_static_string_init(value) { .string = (value), .index = -1 }
5454
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
5555
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
5656

57-
#endif /* NEEDS_PY_IDENTIFIER */
58-
59-
typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
60-
typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
61-
57+
#endif /* !Py_BUILD_CORE */
6258

6359
typedef struct {
6460
/* Number implementations must check *both*
@@ -219,23 +215,37 @@ struct _typeobject {
219215
inquiry tp_is_gc; /* For PyObject_IS_GC */
220216
PyObject *tp_bases;
221217
PyObject *tp_mro; /* method resolution order */
222-
PyObject *tp_cache;
223-
PyObject *tp_subclasses;
224-
PyObject *tp_weaklist;
218+
PyObject *tp_cache; /* no longer used */
219+
void *tp_subclasses; /* for static builtin types this is an index */
220+
PyObject *tp_weaklist; /* not used for static builtin types */
225221
destructor tp_del;
226222

227223
/* Type attribute cache version tag. Added in version 2.6 */
228224
unsigned int tp_version_tag;
229225

230226
destructor tp_finalize;
231227
vectorcallfunc tp_vectorcall;
228+
229+
/* bitset of which type-watchers care about this type */
230+
unsigned char tp_watched;
232231
};
233232

234233
/* This struct is used by the specializer
235234
* It should should be treated as an opaque blob
236235
* by code other than the specializer and interpreter. */
237236
struct _specialization_cache {
237+
// In order to avoid bloating the bytecode with lots of inline caches, the
238+
// members of this structure have a somewhat unique contract. They are set
239+
// by the specialization machinery, and are invalidated by PyType_Modified.
240+
// The rules for using them are as follows:
241+
// - If getitem is non-NULL, then it is the same Python function that
242+
// PyType_Lookup(cls, "__getitem__") would return.
243+
// - If getitem is NULL, then getitem_version is meaningless.
244+
// - If getitem->func_version == getitem_version, then getitem can be called
245+
// with two positional arguments and no keyword arguments, and has neither
246+
// *args nor **kwargs (as required by BINARY_SUBSCR_GETITEM):
238247
PyObject *getitem;
248+
uint32_t getitem_version;
239249
};
240250

241251
/* The *real* layout of a type object when allocated on the heap */
@@ -316,19 +326,24 @@ PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
316326
*
317327
* As in case of Py_CLEAR "the obvious" code can be deadly:
318328
*
319-
* Py_DECREF(op);
320-
* op = op2;
329+
* Py_DECREF(dst);
330+
* dst = src;
321331
*
322332
* The safe way is:
323333
*
324-
* Py_SETREF(op, op2);
334+
* Py_SETREF(dst, src);
335+
*
336+
* That arranges to set `dst` to `src` _before_ decref'ing, so that any code
337+
* triggered as a side-effect of `dst` getting torn down no longer believes
338+
* `dst` points to a valid object.
325339
*
326-
* That arranges to set `op` to `op2` _before_ decref'ing, so that any code
327-
* triggered as a side-effect of `op` getting torn down no longer believes
328-
* `op` points to a valid object.
340+
* Temporary variables are used to only evalutate macro arguments once and so
341+
* avoid the duplication of side effects. _Py_TYPEOF() or memcpy() is used to
342+
* avoid a miscompilation caused by type punning. See Py_CLEAR() comment for
343+
* implementation details about type punning.
329344
*
330-
* Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of
331-
* Py_DECREF.
345+
* The memcpy() implementation does not emit a compiler warning if 'src' has
346+
* not the same type than 'src': any pointer type is accepted for 'src'.
332347
*/
333348

334349
#define Py_SETREF(op, op2) \
@@ -483,7 +498,7 @@ PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);
483498
/* If "cond" is false, then _tstate remains NULL and the deallocator \
484499
* is run normally without involving the trashcan */ \
485500
if (cond) { \
486-
_tstate = PyThreadState_Get(); \
501+
_tstate = _PyThreadState_UncheckedGet(); \
487502
if (_PyTrash_begin(_tstate, _PyObject_CAST(op))) { \
488503
break; \
489504
} \

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
# error "this header file must not be included directly"
33
#endif
44

5-
#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
5+
static inline size_t _PyObject_SIZE(PyTypeObject *type) {
6+
return _Py_STATIC_CAST(size_t, type->tp_basicsize);
7+
}
68

79
/* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a
810
vrbl-size object with nitems items, exclusive of gc overhead (if any). The

graalpython/com.oracle.graal.python.cext/include/exports.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22
#define Py_EXPORTS_H
33

44
#if defined(_WIN32) || defined(__CYGWIN__)
5-
#define Py_IMPORTED_SYMBOL __declspec(dllimport)
6-
#define Py_EXPORTED_SYMBOL __declspec(dllexport)
7-
#define Py_LOCAL_SYMBOL
5+
#if defined(Py_ENABLE_SHARED)
6+
#define Py_IMPORTED_SYMBOL __declspec(dllimport)
7+
#define Py_EXPORTED_SYMBOL __declspec(dllexport)
8+
#define Py_LOCAL_SYMBOL
9+
#else
10+
#define Py_IMPORTED_SYMBOL
11+
#define Py_EXPORTED_SYMBOL
12+
#define Py_LOCAL_SYMBOL
13+
#endif
814
#else
915
/*
1016
* If we only ever used gcc >= 5, we could use __has_attribute(visibility)

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

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,49 @@ extern void _Py_DecRefTotal(PyInterpreterState *);
4646
interp->object_state.reftotal--
4747
#endif
4848

49+
// Increment reference count by n
50+
static inline void _Py_RefcntAdd(PyObject* op, Py_ssize_t n)
51+
{
52+
if (_Py_IsImmortal(op)) {
53+
return;
54+
}
55+
#ifdef Py_REF_DEBUG
56+
_Py_AddRefTotal(_PyInterpreterState_GET(), n);
57+
#endif
58+
op->ob_refcnt += n;
59+
}
60+
#define _Py_RefcntAdd(op, n) _Py_RefcntAdd(_PyObject_CAST(op), n)
61+
62+
static inline void _Py_SetImmortal(PyObject *op)
63+
{
64+
#ifdef Py_DEBUG
65+
// For strings, use _PyUnicode_InternImmortal instead.
66+
if (PyUnicode_CheckExact(op)) {
67+
assert(PyUnicode_CHECK_INTERNED(op) == SSTATE_INTERNED_IMMORTAL
68+
|| PyUnicode_CHECK_INTERNED(op) == SSTATE_INTERNED_IMMORTAL_STATIC);
69+
}
70+
#endif
71+
if (op) {
72+
op->ob_refcnt = _Py_IMMORTAL_REFCNT;
73+
}
74+
}
75+
#define _Py_SetImmortal(op) _Py_SetImmortal(_PyObject_CAST(op))
76+
77+
/* _Py_ClearImmortal() should only be used during runtime finalization. */
78+
static inline void _Py_ClearImmortal(PyObject *op)
79+
{
80+
if (op) {
81+
assert(_Py_IsImmortal(op));
82+
op->ob_refcnt = 1;
83+
Py_DECREF(op);
84+
}
85+
}
86+
#define _Py_ClearImmortal(op) \
87+
do { \
88+
_Py_ClearImmortal(_PyObject_CAST(op)); \
89+
op = NULL; \
90+
} while (0)
91+
4992
static inline void
5093
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
5194
{
@@ -77,6 +120,11 @@ _Py_DECREF_NO_DEALLOC(PyObject *op)
77120
#endif
78121
}
79122

123+
#ifdef Py_REF_DEBUG
124+
# undef _Py_DEC_REFTOTAL
125+
#endif
126+
127+
80128
PyAPI_FUNC(int) _PyType_CheckConsistency(PyTypeObject *type);
81129
PyAPI_FUNC(int) _PyDict_CheckConsistency(PyObject *mp, int check_content);
82130

@@ -218,13 +266,46 @@ extern void _Py_PrintReferences(PyInterpreterState *, FILE *);
218266
extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *);
219267
#endif
220268

269+
270+
/* Return the *address* of the object's weaklist. The address may be
271+
* dereferenced to get the current head of the weaklist. This is useful
272+
* for iterating over the linked list of weakrefs, especially when the
273+
* list is being modified externally (e.g. refs getting removed).
274+
*
275+
* The returned pointer should not be used to change the head of the list
276+
* nor should it be used to add, remove, or swap any refs in the list.
277+
* That is the sole responsibility of the code in weakrefobject.c.
278+
*/
221279
static inline PyObject **
222280
_PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
223281
{
282+
// Essentially _PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET():
224283
Py_ssize_t offset = Py_TYPE(op)->tp_weaklistoffset;
225284
return (PyObject **)((char *)op + offset);
226285
}
227286

287+
/* This is a special case of _PyObject_GET_WEAKREFS_LISTPTR().
288+
* Only the most fundamental lookup path is used.
289+
* Consequently, static types should not be used.
290+
*
291+
* For static builtin types the returned pointer will always point
292+
* to a NULL tp_weaklist. This is fine for any deallocation cases,
293+
* since static types are never deallocated and static builtin types
294+
* are only finalized at the end of runtime finalization.
295+
*
296+
* If the weaklist for static types is actually needed then use
297+
* _PyObject_GET_WEAKREFS_LISTPTR().
298+
*/
299+
static inline PyWeakReference **
300+
_PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET(PyObject *op)
301+
{
302+
assert(!PyType_Check(op) ||
303+
((PyTypeObject *)op)->tp_flags & Py_TPFLAGS_HEAPTYPE);
304+
Py_ssize_t offset = Py_TYPE(op)->tp_weaklistoffset;
305+
return (PyWeakReference **)((char *)op + offset);
306+
}
307+
308+
228309
// Fast inlined version of PyObject_IS_GC()
229310
static inline int
230311
_PyObject_IS_GC(PyObject *obj)

graalpython/com.oracle.graal.python.cext/modules/_sqlite/clinic/connection.c.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,15 @@ static PyObject *
150150
pysqlite_connection_cursor(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
151151
{
152152
PyObject *return_value = NULL;
153+
# define KWTUPLE NULL
154+
153155
static const char * const _keywords[] = {"factory", NULL};
154-
static _PyArg_Parser _parser = {NULL, _keywords, "cursor", 0};
156+
static _PyArg_Parser _parser = {
157+
.keywords = _keywords,
158+
.fname = "cursor",
159+
.kwtuple = KWTUPLE,
160+
};
161+
#undef KWTUPLE
155162
PyObject *argsbuf[1];
156163
Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
157164
PyObject *factory = NULL;
@@ -200,6 +207,7 @@ blobopen(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs, PyO
200207
{
201208
PyObject *return_value = NULL;
202209
# define KWTUPLE NULL
210+
203211
static const char * const _keywords[] = {"", "", "", "readonly", "name", NULL};
204212
static _PyArg_Parser _parser = {
205213
.keywords = _keywords,
@@ -360,6 +368,7 @@ pysqlite_connection_create_function(pysqlite_Connection *self, PyTypeObject *cls
360368
{
361369
PyObject *return_value = NULL;
362370
# define KWTUPLE NULL
371+
363372
static const char * const _keywords[] = {"name", "narg", "func", "deterministic", NULL};
364373
static _PyArg_Parser _parser = {
365374
.keywords = _keywords,
@@ -440,6 +449,7 @@ create_window_function(pysqlite_Connection *self, PyTypeObject *cls, PyObject *c
440449
{
441450
PyObject *return_value = NULL;
442451
# define KWTUPLE NULL
452+
443453
static const char * const _keywords[] = {"", "", "", NULL};
444454
static _PyArg_Parser _parser = {
445455
.keywords = _keywords,
@@ -1126,6 +1136,7 @@ deserialize(pysqlite_Connection *self, PyObject *const *args, Py_ssize_t nargs,
11261136
{
11271137
PyObject *return_value = NULL;
11281138
# define KWTUPLE NULL
1139+
11291140
static const char * const _keywords[] = {"", "name", NULL};
11301141
static _PyArg_Parser _parser = {
11311142
.keywords = _keywords,

0 commit comments

Comments
 (0)