Skip to content

Commit bcdd593

Browse files
committed
Update Python inlined files: 3.12.7 (4.4)
1 parent 9305154 commit bcdd593

File tree

10 files changed

+1099
-433
lines changed

10 files changed

+1099
-433
lines changed

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

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,20 +345,46 @@ PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
345345
* The memcpy() implementation does not emit a compiler warning if 'src' has
346346
* not the same type than 'src': any pointer type is accepted for 'src'.
347347
*/
348-
349-
#define Py_SETREF(op, op2) \
350-
do { \
351-
PyObject *_py_tmp = _PyObject_CAST(op); \
352-
(op) = (op2); \
353-
Py_DECREF(_py_tmp); \
348+
#ifdef _Py_TYPEOF
349+
#define Py_SETREF(dst, src) \
350+
do { \
351+
_Py_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \
352+
_Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
353+
*_tmp_dst_ptr = (src); \
354+
Py_DECREF(_tmp_old_dst); \
355+
} while (0)
356+
#else
357+
#define Py_SETREF(dst, src) \
358+
do { \
359+
PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
360+
PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
361+
PyObject *_tmp_src = _PyObject_CAST(src); \
362+
memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
363+
Py_DECREF(_tmp_old_dst); \
354364
} while (0)
365+
#endif
355366

356-
#define Py_XSETREF(op, op2) \
357-
do { \
358-
PyObject *_py_tmp = _PyObject_CAST(op); \
359-
(op) = (op2); \
360-
Py_XDECREF(_py_tmp); \
367+
/* Py_XSETREF() is a variant of Py_SETREF() that uses Py_XDECREF() instead of
368+
* Py_DECREF().
369+
*/
370+
#ifdef _Py_TYPEOF
371+
#define Py_XSETREF(dst, src) \
372+
do { \
373+
_Py_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \
374+
_Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
375+
*_tmp_dst_ptr = (src); \
376+
Py_XDECREF(_tmp_old_dst); \
377+
} while (0)
378+
#else
379+
#define Py_XSETREF(dst, src) \
380+
do { \
381+
PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
382+
PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
383+
PyObject *_tmp_src = _PyObject_CAST(src); \
384+
memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
385+
Py_XDECREF(_tmp_old_dst); \
361386
} while (0)
387+
#endif
362388

363389

364390
PyAPI_DATA(PyTypeObject) _PyNone_Type;

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@ static inline size_t _PyObject_SIZE(PyTypeObject *type) {
2020
# error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"
2121
#endif
2222

23-
#define _PyObject_VAR_SIZE(typeobj, nitems) \
24-
_Py_SIZE_ROUND_UP((typeobj)->tp_basicsize + \
25-
(nitems)*(typeobj)->tp_itemsize, \
26-
SIZEOF_VOID_P)
23+
static inline size_t _PyObject_VAR_SIZE(PyTypeObject *type, Py_ssize_t nitems) {
24+
size_t size = _Py_STATIC_CAST(size_t, type->tp_basicsize);
25+
size += _Py_STATIC_CAST(size_t, nitems) * _Py_STATIC_CAST(size_t, type->tp_itemsize);
26+
return _Py_SIZE_ROUND_UP(size, SIZEOF_VOID_P);
27+
}
2728

2829

2930
/* This example code implements an object constructor with a custom

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

Lines changed: 70 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,25 @@ extern "C" {
1414
#include "pycore_pystate.h" // _PyInterpreterState_GET()
1515
#include "pycore_runtime.h" // _PyRuntime
1616

17-
#define _PyObject_IMMORTAL_INIT(type) \
18-
{ \
19-
.ob_refcnt = 999999999, \
20-
.ob_type = type, \
21-
}
22-
#define _PyVarObject_IMMORTAL_INIT(type, size) \
23-
{ \
24-
.ob_base = _PyObject_IMMORTAL_INIT(type), \
25-
.ob_size = size, \
26-
}
17+
/* We need to maintain an internal copy of Py{Var}Object_HEAD_INIT to avoid
18+
designated initializer conflicts in C++20. If we use the deinition in
19+
object.h, we will be mixing designated and non-designated initializers in
20+
pycore objects which is forbiddent in C++20. However, if we then use
21+
designated initializers in object.h then Extensions without designated break.
22+
Furthermore, we can't use designated initializers in Extensions since these
23+
are not supported pre-C++20. Thus, keeping an internal copy here is the most
24+
backwards compatible solution */
25+
#define _PyObject_HEAD_INIT(type) \
26+
{ \
27+
_PyObject_EXTRA_INIT \
28+
.ob_refcnt = _Py_IMMORTAL_REFCNT, \
29+
.ob_type = (type) \
30+
},
31+
#define _PyVarObject_HEAD_INIT(type, size) \
32+
{ \
33+
.ob_base = _PyObject_HEAD_INIT(type) \
34+
.ob_size = size \
35+
},
2736

2837
PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
2938
const char *func,
@@ -92,6 +101,10 @@ static inline void _Py_ClearImmortal(PyObject *op)
92101
static inline void
93102
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
94103
{
104+
if (_Py_IsImmortal(op)) {
105+
return;
106+
}
107+
_Py_DECREF_STAT_INC();
95108
#ifdef Py_REF_DEBUG
96109
_Py_DEC_REFTOTAL(_PyInterpreterState_GET());
97110
#endif
@@ -109,6 +122,10 @@ _Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
109122
static inline void
110123
_Py_DECREF_NO_DEALLOC(PyObject *op)
111124
{
125+
if (_Py_IsImmortal(op)) {
126+
return;
127+
}
128+
_Py_DECREF_STAT_INC();
112129
#ifdef Py_REF_DEBUG
113130
_Py_DEC_REFTOTAL(_PyInterpreterState_GET());
114131
#endif
@@ -279,6 +296,13 @@ extern void _Py_PrintReferenceAddresses(PyInterpreterState *, FILE *);
279296
static inline PyObject **
280297
_PyObject_GET_WEAKREFS_LISTPTR(PyObject *op)
281298
{
299+
if (PyType_Check(op) &&
300+
((PyTypeObject *)op)->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
301+
PyInterpreterState *interp = _PyInterpreterState_GET();
302+
static_builtin_state *state = _PyStaticType_GetState(
303+
interp, (PyTypeObject *)op);
304+
return _PyStaticType_GET_WEAKREFS_LISTPTR(state);
305+
}
282306
// Essentially _PyObject_GET_WEAKREFS_LISTPTR_FROM_OFFSET():
283307
Py_ssize_t offset = Py_TYPE(op)->tp_weaklistoffset;
284308
return (PyObject **)((char *)op + offset);
@@ -322,7 +346,7 @@ static inline size_t
322346
_PyType_PreHeaderSize(PyTypeObject *tp)
323347
{
324348
return _PyType_IS_GC(tp) * sizeof(PyGC_Head) +
325-
_PyType_HasFeature(tp, Py_TPFLAGS_MANAGED_DICT) * 2 * sizeof(PyObject *);
349+
_PyType_HasFeature(tp, Py_TPFLAGS_PREHEADER) * 2 * sizeof(PyObject *);
326350
}
327351

328352
void _PyObject_GC_Link(PyObject *op);
@@ -333,10 +357,6 @@ extern int _Py_CheckSlotResult(
333357
const char *slot_name,
334358
int success);
335359

336-
// PyType_Ready() must be called if _PyType_IsReady() is false.
337-
// See also the Py_TPFLAGS_READY flag.
338-
#define _PyType_IsReady(type) ((type)->tp_dict != NULL)
339-
340360
// Test if a type supports weak references
341361
static inline int _PyType_SUPPORTS_WEAKREFS(PyTypeObject *type) {
342362
return (type->tp_weaklistoffset != 0);
@@ -350,30 +370,50 @@ extern int _PyObject_StoreInstanceAttribute(PyObject *obj, PyDictValues *values,
350370
PyObject * _PyObject_GetInstanceAttribute(PyObject *obj, PyDictValues *values,
351371
PyObject *name);
352372

353-
static inline PyDictValues **_PyObject_ValuesPointer(PyObject *obj)
373+
typedef union {
374+
PyObject *dict;
375+
/* Use a char* to generate a warning if directly assigning a PyDictValues */
376+
char *values;
377+
} PyDictOrValues;
378+
379+
static inline PyDictOrValues *
380+
_PyObject_DictOrValuesPointer(PyObject *obj)
354381
{
355382
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
356-
return ((PyDictValues **)obj)-4;
383+
return ((PyDictOrValues *)obj)-3;
384+
}
385+
386+
static inline int
387+
_PyDictOrValues_IsValues(PyDictOrValues dorv)
388+
{
389+
return ((uintptr_t)dorv.values) & 1;
357390
}
358391

359-
static inline PyObject **_PyObject_ManagedDictPointer(PyObject *obj)
392+
static inline PyDictValues *
393+
_PyDictOrValues_GetValues(PyDictOrValues dorv)
360394
{
361-
assert(Py_TYPE(obj)->tp_flags & Py_TPFLAGS_MANAGED_DICT);
362-
return ((PyObject **)obj)-3;
395+
assert(_PyDictOrValues_IsValues(dorv));
396+
return (PyDictValues *)(dorv.values + 1);
397+
}
398+
399+
static inline PyObject *
400+
_PyDictOrValues_GetDict(PyDictOrValues dorv)
401+
{
402+
assert(!_PyDictOrValues_IsValues(dorv));
403+
return dorv.dict;
404+
}
405+
406+
static inline void
407+
_PyDictOrValues_SetValues(PyDictOrValues *ptr, PyDictValues *values)
408+
{
409+
ptr->values = ((char *)values) - 1;
363410
}
364411

365-
#define MANAGED_DICT_OFFSET (((int)sizeof(PyObject *))*-3)
412+
#define MANAGED_WEAKREF_OFFSET (((Py_ssize_t)sizeof(PyObject *))*-4)
366413

367-
extern PyObject ** _PyObject_DictPointer(PyObject *);
368-
extern int _PyObject_VisitInstanceAttributes(PyObject *self, visitproc visit, void *arg);
369-
extern void _PyObject_ClearInstanceAttributes(PyObject *self);
370-
extern void _PyObject_FreeInstanceAttributes(PyObject *self);
414+
extern PyObject ** _PyObject_ComputedDictPointer(PyObject *);
415+
extern void _PyObject_FreeInstanceAttributes(PyObject *obj);
371416
extern int _PyObject_IsInstanceDictEmpty(PyObject *);
372-
extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
373-
374-
// Access macro to the members which are floating "behind" the object
375-
#define _PyHeapType_GET_MEMBERS(etype) \
376-
((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
377417

378418
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *);
379419

0 commit comments

Comments
 (0)