Skip to content

Commit e71d675

Browse files
committed
Update Python inlined files: 3.12.7 (4.0)
1 parent e9b033f commit e71d675

File tree

22 files changed

+1728
-534
lines changed

22 files changed

+1728
-534
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *
268268
PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *);
269269
PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
270270
PyAPI_FUNC(PyObject *) PyType_GetModuleByDef(PyTypeObject *, PyModuleDef *);
271+
PyAPI_FUNC(PyObject *) PyType_GetDict(PyTypeObject *);
271272

272273
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
273274
PyAPI_FUNC(void) _Py_BreakPoint(void);
@@ -306,7 +307,7 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
306307

307308
PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
308309

309-
/* Safely decref `op` and set `op` to `op2`.
310+
/* Safely decref `dst` and set `dst` to `src`.
310311
*
311312
* As in case of Py_CLEAR "the obvious" code can be deadly:
312313
*

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,47 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha(
10331033
// Helper array used by Py_UNICODE_ISSPACE().
10341034
PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[];
10351035

1036+
// Since splitting on whitespace is an important use case, and
1037+
// whitespace in most situations is solely ASCII whitespace, we
1038+
// optimize for the common case by using a quick look-up table
1039+
// _Py_ascii_whitespace (see below) with an inlined check.
1040+
static inline int Py_UNICODE_ISSPACE(Py_UCS4 ch) {
1041+
if (ch < 128) {
1042+
return _Py_ascii_whitespace[ch];
1043+
}
1044+
return _PyUnicode_IsWhitespace(ch);
1045+
}
1046+
1047+
#define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)
1048+
#define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)
1049+
#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
1050+
#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)
1051+
1052+
#define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch)
1053+
#define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch)
1054+
#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)
1055+
1056+
#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
1057+
#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
1058+
#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
1059+
#define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
1060+
1061+
#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
1062+
#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
1063+
#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)
1064+
1065+
#define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch)
1066+
1067+
static inline int Py_UNICODE_ISALNUM(Py_UCS4 ch) {
1068+
return (Py_UNICODE_ISALPHA(ch)
1069+
|| Py_UNICODE_ISDECIMAL(ch)
1070+
|| Py_UNICODE_ISDIGIT(ch)
1071+
|| Py_UNICODE_ISNUMERIC(ch));
1072+
}
1073+
1074+
1075+
/* === Misc functions ===================================================== */
1076+
10361077
PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int);
10371078

10381079
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/

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

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,26 @@ whose size is determined when the object is allocated.
8585
#define PyVarObject_HEAD_INIT(type, size) \
8686
{ PyObject_HEAD_INIT(type) size },
8787

88+
/*
89+
In 32 bit systems, an object will be marked as immortal by setting all of the
90+
lower 30 bits of the reference count field, which is equal to: 0x3FFFFFFF
91+
92+
Using the lower 30 bits makes the value backwards compatible by allowing
93+
C-Extensions without the updated checks in Py_INCREF and Py_DECREF to safely
94+
increase and decrease the objects reference count. The object would lose its
95+
immortality, but the execution would still be correct.
96+
97+
Reference count increases and decreases will first go through an immortality
98+
check by comparing the reference count field to the immortality reference count.
99+
*/
100+
#define _Py_IMMORTAL_REFCNT (UINT_MAX >> 2)
101+
102+
#define PyVarObject_HEAD_INIT(type, size) \
103+
{ \
104+
PyObject_HEAD_INIT(type) \
105+
(size) \
106+
},
107+
88108
/* PyObject_VAR_HEAD defines the initial segment of all variable-size
89109
* container objects. These end with a declaration of an array with 1
90110
* element, but enough space is malloc'ed so that the array actually
@@ -151,6 +171,15 @@ static inline Py_ssize_t Py_SIZE(PyObject *ob) {
151171
# define Py_SIZE(ob) Py_SIZE(_PyObject_CAST(ob))
152172
#endif
153173

174+
static inline Py_ALWAYS_INLINE int _Py_IsImmortal(PyObject *op)
175+
{
176+
#if SIZEOF_VOID_P > 4
177+
return _Py_CAST(PY_INT32_T, op->ob_refcnt) < 0;
178+
#else
179+
return op->ob_refcnt == _Py_IMMORTAL_REFCNT;
180+
#endif
181+
}
182+
#define _Py_IsImmortal(op) _Py_IsImmortal(_PyObject_CAST(op))
154183

155184
static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
156185
return Py_TYPE(ob) == type;
@@ -161,6 +190,13 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
161190

162191

163192
static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {
193+
// This immortal check is for code that is unaware of immortal objects.
194+
// The runtime tracks these objects and we should avoid as much
195+
// as possible having extensions inadvertently change the refcnt
196+
// of an immortalized object.
197+
if (_Py_IsImmortal(ob)) {
198+
return;
199+
}
164200
ob->ob_refcnt = refcnt;
165201
}
166202
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
@@ -514,11 +550,18 @@ PyAPI_FUNC(void) Py_DecRef(PyObject *);
514550
PyAPI_FUNC(void) _Py_IncRef(PyObject *);
515551
PyAPI_FUNC(void) _Py_DecRef(PyObject *);
516552

517-
static inline void Py_INCREF(PyObject *op)
553+
static inline Py_ALWAYS_INLINE void Py_INCREF(PyObject *op)
518554
{
519-
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030A0000
520-
// Stable ABI for Python 3.10 built in debug mode.
555+
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
556+
// Stable ABI implements Py_INCREF() as a function call on limited C API
557+
// version 3.12 and newer, and on Python built in debug mode. _Py_IncRef()
558+
// was added to Python 3.10.0a7, use Py_IncRef() on older Python versions.
559+
// Py_IncRef() accepts NULL whereas _Py_IncRef() doesn't.
560+
# if Py_LIMITED_API+0 >= 0x030a00A7
521561
_Py_IncRef(op);
562+
# else
563+
Py_IncRef(op);
564+
# endif
522565
#else
523566
// Non-limited C API and limited C API for Python 3.9 and older access
524567
// directly PyObject.ob_refcnt.
@@ -532,11 +575,17 @@ static inline void Py_INCREF(PyObject *op)
532575
# define Py_INCREF(op) Py_INCREF(_PyObject_CAST(op))
533576
#endif
534577

535-
536-
#if defined(Py_REF_DEBUG) && defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030A0000
537-
// Stable ABI for limited C API version 3.10 of Python debug build
578+
#if defined(Py_LIMITED_API) && (Py_LIMITED_API+0 >= 0x030c0000 || defined(Py_REF_DEBUG))
579+
// Stable ABI implements Py_DECREF() as a function call on limited C API
580+
// version 3.12 and newer, and on Python built in debug mode. _Py_DecRef() was
581+
// added to Python 3.10.0a7, use Py_DecRef() on older Python versions.
582+
// Py_DecRef() accepts NULL whereas _Py_IncRef() doesn't.
538583
static inline void Py_DECREF(PyObject *op) {
584+
# if Py_LIMITED_API+0 >= 0x030a00A7
539585
_Py_DecRef(op);
586+
# else
587+
Py_DecRef(op);
588+
# endif
540589
}
541590
#define Py_DECREF(op) Py_DECREF(_PyObject_CAST(op))
542591

@@ -556,10 +605,13 @@ static inline void Py_DECREF(const char *filename, int lineno, PyObject *op)
556605
#define Py_DECREF(op) Py_DECREF(__FILE__, __LINE__, _PyObject_CAST(op))
557606

558607
#else
559-
static inline void Py_DECREF(PyObject *op)
608+
static inline Py_ALWAYS_INLINE void Py_DECREF(PyObject *op)
560609
{
561610
// Non-limited C API and limited C API for Python 3.9 and older access
562611
// directly PyObject.ob_refcnt.
612+
if (_Py_IsImmortal(op)) {
613+
return;
614+
}
563615
if (--op->ob_refcnt == 0) {
564616
_Py_Dealloc(op);
565617
}

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
// MSVC makes static_assert a keyword in C11-17, contrary to the standards.
1616
//
1717
// In C++11 and C2x, static_assert is a keyword, redefining is undefined
18-
// behaviour. So only define if building as C (if __STDC_VERSION__ is defined),
19-
// not C++, and only for C11-17.
18+
// behaviour. So only define if building as C, not C++ (if __cplusplus is
19+
// not defined), and only for C11-17.
2020
#if !defined(static_assert) && (defined(__GNUC__) || defined(__clang__)) \
21-
&& defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
22-
&& __STDC_VERSION__ <= 201710L
21+
&& !defined(__cplusplus) && defined(__STDC_VERSION__) \
22+
&& __STDC_VERSION__ >= 201112L && __STDC_VERSION__ <= 201710L
2323
# define static_assert _Static_assert
2424
#endif
2525

@@ -155,4 +155,9 @@
155155
// For example, "int x; _Py_RVALUE(x) = 1;" fails with a compiler error.
156156
#define _Py_RVALUE(EXPR) ((void)0, (EXPR))
157157

158+
// Return non-zero if the type is signed, return zero if it's unsigned.
159+
// Use "<= 0" rather than "< 0" to prevent the compiler warning:
160+
// "comparison of unsigned expression in '< 0' is always false".
161+
#define _Py_IS_TYPE_SIGNED(type) ((type)(-1) <= 0)
162+
158163
#endif /* Py_PYMACRO_H */

graalpython/com.oracle.graal.python.cext/modules/_bz2.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,6 @@ _bz2_exec(PyObject *module)
781781
if (state->bz2_compressor_type == NULL) {
782782
return -1;
783783
}
784-
785784
if (PyModule_AddType(module, state->bz2_compressor_type) < 0) {
786785
return -1;
787786
}
@@ -791,7 +790,6 @@ _bz2_exec(PyObject *module)
791790
if (state->bz2_decompressor_type == NULL) {
792791
return -1;
793792
}
794-
795793
if (PyModule_AddType(module, state->bz2_decompressor_type) < 0) {
796794
return -1;
797795
}

0 commit comments

Comments
 (0)