aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Include/cpython
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2024-02-12 07:53:52 +0300
committershadchin <shadchin@yandex-team.com>2024-02-12 08:07:36 +0300
commitce1b7ca3171f9158180640c6a02a74b4afffedea (patch)
treee47c1e8391b1b0128262c1e9b1e6ed4c8fff2348 /contrib/tools/python3/src/Include/cpython
parent57350d96f030db90f220ce50ee591d5c5d403df7 (diff)
downloadydb-ce1b7ca3171f9158180640c6a02a74b4afffedea.tar.gz
Update Python from 3.11.8 to 3.12.2
Diffstat (limited to 'contrib/tools/python3/src/Include/cpython')
-rw-r--r--contrib/tools/python3/src/Include/cpython/abstract.h25
-rw-r--r--contrib/tools/python3/src/Include/cpython/bytearrayobject.h8
-rw-r--r--contrib/tools/python3/src/Include/cpython/bytesobject.h8
-rw-r--r--contrib/tools/python3/src/Include/cpython/cellobject.h19
-rw-r--r--contrib/tools/python3/src/Include/cpython/ceval.h11
-rw-r--r--contrib/tools/python3/src/Include/cpython/classobject.h38
-rw-r--r--contrib/tools/python3/src/Include/cpython/code.h213
-rw-r--r--contrib/tools/python3/src/Include/cpython/compile.h19
-rw-r--r--contrib/tools/python3/src/Include/cpython/context.h6
-rw-r--r--contrib/tools/python3/src/Include/cpython/dictobject.h42
-rw-r--r--contrib/tools/python3/src/Include/cpython/floatobject.h10
-rw-r--r--contrib/tools/python3/src/Include/cpython/funcobject.h111
-rw-r--r--contrib/tools/python3/src/Include/cpython/genobject.h15
-rw-r--r--contrib/tools/python3/src/Include/cpython/import.h5
-rw-r--r--contrib/tools/python3/src/Include/cpython/initconfig.h7
-rw-r--r--contrib/tools/python3/src/Include/cpython/interpreteridobject.h11
-rw-r--r--contrib/tools/python3/src/Include/cpython/listobject.h10
-rw-r--r--contrib/tools/python3/src/Include/cpython/longintrepr.h40
-rw-r--r--contrib/tools/python3/src/Include/cpython/longobject.h5
-rw-r--r--contrib/tools/python3/src/Include/cpython/memoryobject.h52
-rw-r--r--contrib/tools/python3/src/Include/cpython/methodobject.h20
-rw-r--r--contrib/tools/python3/src/Include/cpython/modsupport.h9
-rw-r--r--contrib/tools/python3/src/Include/cpython/object.h144
-rw-r--r--contrib/tools/python3/src/Include/cpython/objimpl.h16
-rw-r--r--contrib/tools/python3/src/Include/cpython/odictobject.h12
-rw-r--r--contrib/tools/python3/src/Include/cpython/picklebufobject.h2
-rw-r--r--contrib/tools/python3/src/Include/cpython/pydebug.h36
-rw-r--r--contrib/tools/python3/src/Include/cpython/pyerrors.h37
-rw-r--r--contrib/tools/python3/src/Include/cpython/pyframe.h18
-rw-r--r--contrib/tools/python3/src/Include/cpython/pylifecycle.h48
-rw-r--r--contrib/tools/python3/src/Include/cpython/pystate.h134
-rw-r--r--contrib/tools/python3/src/Include/cpython/pythonrun.h28
-rw-r--r--contrib/tools/python3/src/Include/cpython/pytime.h8
-rw-r--r--contrib/tools/python3/src/Include/cpython/setobject.h9
-rw-r--r--contrib/tools/python3/src/Include/cpython/tupleobject.h10
-rw-r--r--contrib/tools/python3/src/Include/cpython/unicodeobject.h442
-rw-r--r--contrib/tools/python3/src/Include/cpython/warnings.h2
-rw-r--r--contrib/tools/python3/src/Include/cpython/weakrefobject.h4
38 files changed, 1030 insertions, 604 deletions
diff --git a/contrib/tools/python3/src/Include/cpython/abstract.h b/contrib/tools/python3/src/Include/cpython/abstract.h
index d276669312..3b27aab2fc 100644
--- a/contrib/tools/python3/src/Include/cpython/abstract.h
+++ b/contrib/tools/python3/src/Include/cpython/abstract.h
@@ -50,23 +50,18 @@ PyAPI_FUNC(PyObject *) _PyObject_MakeTpCall(
PyObject *const *args, Py_ssize_t nargs,
PyObject *keywords);
-#define PY_VECTORCALL_ARGUMENTS_OFFSET \
- (_Py_STATIC_CAST(size_t, 1) << (8 * sizeof(size_t) - 1))
-
+// PyVectorcall_NARGS() is exported as a function for the stable ABI.
+// Here (when we are not using the stable ABI), the name is overridden to
+// call a static inline function for best performance.
+#define PyVectorcall_NARGS(n) _PyVectorcall_NARGS(n)
static inline Py_ssize_t
-PyVectorcall_NARGS(size_t n)
+_PyVectorcall_NARGS(size_t n)
{
return n & ~PY_VECTORCALL_ARGUMENTS_OFFSET;
}
PyAPI_FUNC(vectorcallfunc) PyVectorcall_Function(PyObject *callable);
-PyAPI_FUNC(PyObject *) PyObject_Vectorcall(
- PyObject *callable,
- PyObject *const *args,
- size_t nargsf,
- PyObject *kwnames);
-
// Backwards compatibility aliases for API that was provisional in Python 3.8
#define _PyObject_Vectorcall PyObject_Vectorcall
#define _PyObject_VectorcallMethod PyObject_VectorcallMethod
@@ -84,10 +79,6 @@ PyAPI_FUNC(PyObject *) PyObject_VectorcallDict(
size_t nargsf,
PyObject *kwargs);
-/* Call "callable" (which must support vectorcall) with positional arguments
- "tuple" and keyword arguments "dict". "dict" may also be NULL */
-PyAPI_FUNC(PyObject *) PyVectorcall_Call(PyObject *callable, PyObject *tuple, PyObject *dict);
-
// Same as PyObject_Vectorcall(), except without keyword arguments
PyAPI_FUNC(PyObject *) _PyObject_FastCall(
PyObject *func,
@@ -96,10 +87,6 @@ PyAPI_FUNC(PyObject *) _PyObject_FastCall(
PyAPI_FUNC(PyObject *) PyObject_CallOneArg(PyObject *func, PyObject *arg);
-PyAPI_FUNC(PyObject *) PyObject_VectorcallMethod(
- PyObject *name, PyObject *const *args,
- size_t nargsf, PyObject *kwnames);
-
static inline PyObject *
PyObject_CallMethodNoArgs(PyObject *self, PyObject *name)
{
@@ -176,7 +163,7 @@ PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
/* Assume tp_as_sequence and sq_item exist and that 'i' does not
need to be corrected for a negative index. */
#define PySequence_ITEM(o, i)\
- ( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
+ ( Py_TYPE(o)->tp_as_sequence->sq_item((o), (i)) )
#define PY_ITERSEARCH_COUNT 1
#define PY_ITERSEARCH_INDEX 2
diff --git a/contrib/tools/python3/src/Include/cpython/bytearrayobject.h b/contrib/tools/python3/src/Include/cpython/bytearrayobject.h
index 5114169c28..9ba176eb2d 100644
--- a/contrib/tools/python3/src/Include/cpython/bytearrayobject.h
+++ b/contrib/tools/python3/src/Include/cpython/bytearrayobject.h
@@ -25,14 +25,10 @@ static inline char* PyByteArray_AS_STRING(PyObject *op)
}
return _PyByteArray_empty_string;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyByteArray_AS_STRING(self) PyByteArray_AS_STRING(_PyObject_CAST(self))
-#endif
+#define PyByteArray_AS_STRING(self) PyByteArray_AS_STRING(_PyObject_CAST(self))
static inline Py_ssize_t PyByteArray_GET_SIZE(PyObject *op) {
PyByteArrayObject *self = _PyByteArray_CAST(op);
return Py_SIZE(self);
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyByteArray_GET_SIZE(self) PyByteArray_GET_SIZE(_PyObject_CAST(self))
-#endif
+#define PyByteArray_GET_SIZE(self) PyByteArray_GET_SIZE(_PyObject_CAST(self))
diff --git a/contrib/tools/python3/src/Include/cpython/bytesobject.h b/contrib/tools/python3/src/Include/cpython/bytesobject.h
index 53343661f0..e982031c10 100644
--- a/contrib/tools/python3/src/Include/cpython/bytesobject.h
+++ b/contrib/tools/python3/src/Include/cpython/bytesobject.h
@@ -36,17 +36,13 @@ static inline char* PyBytes_AS_STRING(PyObject *op)
{
return _PyBytes_CAST(op)->ob_sval;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyBytes_AS_STRING(op) PyBytes_AS_STRING(_PyObject_CAST(op))
-#endif
+#define PyBytes_AS_STRING(op) PyBytes_AS_STRING(_PyObject_CAST(op))
static inline Py_ssize_t PyBytes_GET_SIZE(PyObject *op) {
PyBytesObject *self = _PyBytes_CAST(op);
return Py_SIZE(self);
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyBytes_GET_SIZE(self) PyBytes_GET_SIZE(_PyObject_CAST(self))
-#endif
+#define PyBytes_GET_SIZE(self) PyBytes_GET_SIZE(_PyObject_CAST(self))
/* _PyBytes_Join(sep, x) is like sep.join(x). sep must be PyBytesObject*,
x must be an iterable object. */
diff --git a/contrib/tools/python3/src/Include/cpython/cellobject.h b/contrib/tools/python3/src/Include/cpython/cellobject.h
index e07f9d1de7..47a6a49149 100644
--- a/contrib/tools/python3/src/Include/cpython/cellobject.h
+++ b/contrib/tools/python3/src/Include/cpython/cellobject.h
@@ -15,14 +15,27 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyCell_Type;
-#define PyCell_Check(op) Py_IS_TYPE(op, &PyCell_Type)
+#define PyCell_Check(op) Py_IS_TYPE((op), &PyCell_Type)
PyAPI_FUNC(PyObject *) PyCell_New(PyObject *);
PyAPI_FUNC(PyObject *) PyCell_Get(PyObject *);
PyAPI_FUNC(int) PyCell_Set(PyObject *, PyObject *);
-#define PyCell_GET(op) (((PyCellObject *)(op))->ob_ref)
-#define PyCell_SET(op, v) _Py_RVALUE(((PyCellObject *)(op))->ob_ref = (v))
+static inline PyObject* PyCell_GET(PyObject *op) {
+ PyCellObject *cell;
+ assert(PyCell_Check(op));
+ cell = _Py_CAST(PyCellObject*, op);
+ return cell->ob_ref;
+}
+#define PyCell_GET(op) PyCell_GET(_PyObject_CAST(op))
+
+static inline void PyCell_SET(PyObject *op, PyObject *value) {
+ PyCellObject *cell;
+ assert(PyCell_Check(op));
+ cell = _Py_CAST(PyCellObject*, op);
+ cell->ob_ref = value;
+}
+#define PyCell_SET(op, value) PyCell_SET(_PyObject_CAST(op), (value))
#ifdef __cplusplus
}
diff --git a/contrib/tools/python3/src/Include/cpython/ceval.h b/contrib/tools/python3/src/Include/cpython/ceval.h
index 9d4eeafb42..a9616bd6a4 100644
--- a/contrib/tools/python3/src/Include/cpython/ceval.h
+++ b/contrib/tools/python3/src/Include/cpython/ceval.h
@@ -3,8 +3,10 @@
#endif
PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
+PyAPI_FUNC(void) PyEval_SetProfileAllThreads(Py_tracefunc, PyObject *);
PyAPI_DATA(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);
+PyAPI_FUNC(void) PyEval_SetTraceAllThreads(Py_tracefunc, PyObject *);
PyAPI_FUNC(int) _PyEval_SetTrace(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
/* Helper to look up a builtin object */
@@ -20,7 +22,14 @@ PyAPI_FUNC(PyObject *) _PyEval_EvalFrameDefault(PyThreadState *tstate, struct _P
PyAPI_FUNC(void) _PyEval_SetSwitchInterval(unsigned long microseconds);
PyAPI_FUNC(unsigned long) _PyEval_GetSwitchInterval(void);
-PyAPI_FUNC(Py_ssize_t) _PyEval_RequestCodeExtraIndex(freefunc);
+PyAPI_FUNC(int) _PyEval_MakePendingCalls(PyThreadState *);
+
+PyAPI_FUNC(Py_ssize_t) PyUnstable_Eval_RequestCodeExtraIndex(freefunc);
+// Old name -- remove when this API changes:
+_Py_DEPRECATED_EXTERNALLY(3.12) static inline Py_ssize_t
+_PyEval_RequestCodeExtraIndex(freefunc f) {
+ return PyUnstable_Eval_RequestCodeExtraIndex(f);
+}
PyAPI_FUNC(int) _PyEval_SliceIndex(PyObject *, Py_ssize_t *);
PyAPI_FUNC(int) _PyEval_SliceIndexNotNone(PyObject *, Py_ssize_t *);
diff --git a/contrib/tools/python3/src/Include/cpython/classobject.h b/contrib/tools/python3/src/Include/cpython/classobject.h
index 80df8842eb..d7c9ddd133 100644
--- a/contrib/tools/python3/src/Include/cpython/classobject.h
+++ b/contrib/tools/python3/src/Include/cpython/classobject.h
@@ -19,19 +19,27 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyMethod_Type;
-#define PyMethod_Check(op) Py_IS_TYPE(op, &PyMethod_Type)
+#define PyMethod_Check(op) Py_IS_TYPE((op), &PyMethod_Type)
PyAPI_FUNC(PyObject *) PyMethod_New(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyMethod_Function(PyObject *);
PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
-/* Macros for direct access to these values. Type checks are *not*
- done, so use with care. */
-#define PyMethod_GET_FUNCTION(meth) \
- (((PyMethodObject *)meth) -> im_func)
-#define PyMethod_GET_SELF(meth) \
- (((PyMethodObject *)meth) -> im_self)
+#define _PyMethod_CAST(meth) \
+ (assert(PyMethod_Check(meth)), _Py_CAST(PyMethodObject*, meth))
+
+/* Static inline functions for direct access to these values.
+ Type checks are *not* done, so use with care. */
+static inline PyObject* PyMethod_GET_FUNCTION(PyObject *meth) {
+ return _PyMethod_CAST(meth)->im_func;
+}
+#define PyMethod_GET_FUNCTION(meth) PyMethod_GET_FUNCTION(_PyObject_CAST(meth))
+
+static inline PyObject* PyMethod_GET_SELF(PyObject *meth) {
+ return _PyMethod_CAST(meth)->im_self;
+}
+#define PyMethod_GET_SELF(meth) PyMethod_GET_SELF(_PyObject_CAST(meth))
typedef struct {
PyObject_HEAD
@@ -40,15 +48,21 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyInstanceMethod_Type;
-#define PyInstanceMethod_Check(op) Py_IS_TYPE(op, &PyInstanceMethod_Type)
+#define PyInstanceMethod_Check(op) Py_IS_TYPE((op), &PyInstanceMethod_Type)
PyAPI_FUNC(PyObject *) PyInstanceMethod_New(PyObject *);
PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
-/* Macros for direct access to these values. Type checks are *not*
- done, so use with care. */
-#define PyInstanceMethod_GET_FUNCTION(meth) \
- (((PyInstanceMethodObject *)meth) -> func)
+#define _PyInstanceMethod_CAST(meth) \
+ (assert(PyInstanceMethod_Check(meth)), \
+ _Py_CAST(PyInstanceMethodObject*, meth))
+
+/* Static inline function for direct access to these values.
+ Type checks are *not* done, so use with care. */
+static inline PyObject* PyInstanceMethod_GET_FUNCTION(PyObject *meth) {
+ return _PyInstanceMethod_CAST(meth)->func;
+}
+#define PyInstanceMethod_GET_FUNCTION(meth) PyInstanceMethod_GET_FUNCTION(_PyObject_CAST(meth))
#ifdef __cplusplus
}
diff --git a/contrib/tools/python3/src/Include/cpython/code.h b/contrib/tools/python3/src/Include/cpython/code.h
index 7006060cc7..03834b20c3 100644
--- a/contrib/tools/python3/src/Include/cpython/code.h
+++ b/contrib/tools/python3/src/Include/cpython/code.h
@@ -3,10 +3,29 @@
#ifndef Py_LIMITED_API
#ifndef Py_CODE_H
#define Py_CODE_H
+
#ifdef __cplusplus
extern "C" {
#endif
+/* Count of all local monitoring events */
+#define _PY_MONITORING_LOCAL_EVENTS 10
+/* Count of all "real" monitoring events (not derived from other events) */
+#define _PY_MONITORING_UNGROUPED_EVENTS 15
+/* Count of all monitoring events */
+#define _PY_MONITORING_EVENTS 17
+
+/* Tables of which tools are active for each monitored event. */
+/* For 3.12 ABI compatibility this is over sized */
+typedef struct _Py_LocalMonitors {
+ /* Only _PY_MONITORING_LOCAL_EVENTS of these are used */
+ uint8_t tools[_PY_MONITORING_UNGROUPED_EVENTS];
+} _Py_LocalMonitors;
+
+typedef struct _Py_GlobalMonitors {
+ uint8_t tools[_PY_MONITORING_UNGROUPED_EVENTS];
+} _Py_GlobalMonitors;
+
/* Each instruction in a code object is a fixed-width value,
* currently 2 bytes: 1-byte opcode + 1-byte oparg. The EXTENDED_ARG
* opcode allows for larger values but the current limit is 3 uses
@@ -16,20 +35,74 @@ extern "C" {
* 2**32 - 1, rather than INT_MAX.
*/
-typedef uint16_t _Py_CODEUNIT;
+typedef union {
+ uint16_t cache;
+ struct {
+ uint8_t code;
+ uint8_t arg;
+ } op;
+} _Py_CODEUNIT;
-#ifdef WORDS_BIGENDIAN
-# define _Py_OPCODE(word) ((word) >> 8)
-# define _Py_OPARG(word) ((word) & 255)
-# define _Py_MAKECODEUNIT(opcode, oparg) (((opcode)<<8)|(oparg))
-#else
-# define _Py_OPCODE(word) ((word) & 255)
-# define _Py_OPARG(word) ((word) >> 8)
-# define _Py_MAKECODEUNIT(opcode, oparg) ((opcode)|((oparg)<<8))
-#endif
-// Use "unsigned char" instead of "uint8_t" here to avoid illegal aliasing:
-#define _Py_SET_OPCODE(word, opcode) (((unsigned char *)&(word))[0] = (opcode))
+/* These macros only remain defined for compatibility. */
+#define _Py_OPCODE(word) ((word).op.code)
+#define _Py_OPARG(word) ((word).op.arg)
+
+static inline _Py_CODEUNIT
+_py_make_codeunit(uint8_t opcode, uint8_t oparg)
+{
+ // No designated initialisers because of C++ compat
+ _Py_CODEUNIT word;
+ word.op.code = opcode;
+ word.op.arg = oparg;
+ return word;
+}
+
+static inline void
+_py_set_opcode(_Py_CODEUNIT *word, uint8_t opcode)
+{
+ word->op.code = opcode;
+}
+
+#define _Py_MAKE_CODEUNIT(opcode, oparg) _py_make_codeunit((opcode), (oparg))
+#define _Py_SET_OPCODE(word, opcode) _py_set_opcode(&(word), (opcode))
+
+
+typedef struct {
+ PyObject *_co_code;
+ PyObject *_co_varnames;
+ PyObject *_co_cellvars;
+ PyObject *_co_freevars;
+} _PyCoCached;
+
+/* Ancilliary data structure used for instrumentation.
+ Line instrumentation creates an array of
+ these. One entry per code unit.*/
+typedef struct {
+ uint8_t original_opcode;
+ int8_t line_delta;
+} _PyCoLineInstrumentationData;
+
+/* Main data structure used for instrumentation.
+ * This is allocated when needed for instrumentation
+ */
+typedef struct {
+ /* Monitoring specific to this code object */
+ _Py_LocalMonitors local_monitors;
+ /* Monitoring that is active on this code object */
+ _Py_LocalMonitors active_monitors;
+ /* The tools that are to be notified for events for the matching code unit */
+ uint8_t *tools;
+ /* Information to support line events */
+ _PyCoLineInstrumentationData *lines;
+ /* The tools that are to be notified for line events for the matching code unit */
+ uint8_t *line_tools;
+ /* Information to support instruction events */
+ /* The underlying instructions, which can themselves be instrumented */
+ uint8_t *per_instruction_opcodes;
+ /* The tools that are to be notified for instruction events for the matching code unit */
+ uint8_t *per_instruction_tools;
+} _PyCoMonitoringData;
// To avoid repeating ourselves in deepfreeze.py, all PyCodeObject members are
// defined in this macro:
@@ -62,8 +135,6 @@ typedef uint16_t _Py_CODEUNIT;
PyObject *co_exceptiontable; /* Byte string encoding exception handling \
table */ \
int co_flags; /* CO_..., see below */ \
- short co_warmup; /* Warmup counter for quickening */ \
- short _co_linearray_entry_size; /* Size of each entry in _co_linearray */ \
\
/* The rest are not so impactful on performance. */ \
int co_argcount; /* #arguments, except *args */ \
@@ -74,12 +145,12 @@ typedef uint16_t _Py_CODEUNIT;
\
/* redundant values (derived from co_localsplusnames and \
co_localspluskinds) */ \
- int co_nlocalsplus; /* number of local + cell + free variables \
- */ \
+ int co_nlocalsplus; /* number of local + cell + free variables */ \
+ int co_framesize; /* Size of frame in words */ \
int co_nlocals; /* number of local variables */ \
- int co_nplaincellvars; /* number of non-arg cell variables */ \
int co_ncellvars; /* total number of cell variables */ \
int co_nfreevars; /* number of free variables */ \
+ uint32_t co_version; /* version number */ \
\
PyObject *co_localsplusnames; /* tuple mapping offsets to names */ \
PyObject *co_localspluskinds; /* Bytes mapping to local kinds (one byte \
@@ -89,8 +160,9 @@ typedef uint16_t _Py_CODEUNIT;
PyObject *co_qualname; /* unicode (qualname, for reference) */ \
PyObject *co_linetable; /* bytes object that holds location info */ \
PyObject *co_weakreflist; /* to support weakrefs to code objects */ \
- PyObject *_co_code; /* cached co_code object/attribute */ \
- char *_co_linearray; /* array of line offsets */ \
+ _PyCoCached *_co_cached; /* cached co_* attributes */ \
+ uint64_t _co_instrumentation_version; /* current instrumentation version */ \
+ _PyCoMonitoringData *_co_monitoring; /* Monitoring data */ \
int _co_firsttraceable; /* index of first traceable instruction */ \
/* Scratch space for extra data relating to the code object. \
Type is a void* to keep the format private in codeobject.c to force \
@@ -139,24 +211,55 @@ struct PyCodeObject _PyCode_DEF(1);
PyAPI_DATA(PyTypeObject) PyCode_Type;
-#define PyCode_Check(op) Py_IS_TYPE(op, &PyCode_Type)
-#define PyCode_GetNumFree(op) ((op)->co_nfreevars)
-#define _PyCode_CODE(CO) ((_Py_CODEUNIT *)(CO)->co_code_adaptive)
+#define PyCode_Check(op) Py_IS_TYPE((op), &PyCode_Type)
+
+static inline Py_ssize_t PyCode_GetNumFree(PyCodeObject *op) {
+ assert(PyCode_Check(op));
+ return op->co_nfreevars;
+}
+
+static inline int PyCode_GetFirstFree(PyCodeObject *op) {
+ assert(PyCode_Check(op));
+ return op->co_nlocalsplus - op->co_nfreevars;
+}
+
+#define _PyCode_CODE(CO) _Py_RVALUE((_Py_CODEUNIT *)(CO)->co_code_adaptive)
#define _PyCode_NBYTES(CO) (Py_SIZE(CO) * (Py_ssize_t)sizeof(_Py_CODEUNIT))
-/* Public interface */
-PyAPI_FUNC(PyCodeObject *) PyCode_New(
+/* Unstable public interface */
+PyAPI_FUNC(PyCodeObject *) PyUnstable_Code_New(
int, int, int, int, int, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, int, PyObject *,
PyObject *);
-PyAPI_FUNC(PyCodeObject *) PyCode_NewWithPosOnlyArgs(
+PyAPI_FUNC(PyCodeObject *) PyUnstable_Code_NewWithPosOnlyArgs(
int, int, int, int, int, int, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, PyObject *,
PyObject *, PyObject *, PyObject *, int, PyObject *,
PyObject *);
/* same as struct above */
+// Old names -- remove when this API changes:
+_Py_DEPRECATED_EXTERNALLY(3.12) static inline PyCodeObject *
+PyCode_New(
+ int a, int b, int c, int d, int e, PyObject *f, PyObject *g,
+ PyObject *h, PyObject *i, PyObject *j, PyObject *k,
+ PyObject *l, PyObject *m, PyObject *n, int o, PyObject *p,
+ PyObject *q)
+{
+ return PyUnstable_Code_New(
+ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q);
+}
+_Py_DEPRECATED_EXTERNALLY(3.12) static inline PyCodeObject *
+PyCode_NewWithPosOnlyArgs(
+ int a, int poac, int b, int c, int d, int e, PyObject *f, PyObject *g,
+ PyObject *h, PyObject *i, PyObject *j, PyObject *k,
+ PyObject *l, PyObject *m, PyObject *n, int o, PyObject *p,
+ PyObject *q)
+{
+ return PyUnstable_Code_NewWithPosOnlyArgs(
+ a, poac, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q);
+}
/* Creates a new empty code object with the specified source location. */
PyAPI_FUNC(PyCodeObject *)
@@ -169,6 +272,46 @@ PyAPI_FUNC(int) PyCode_Addr2Line(PyCodeObject *, int);
PyAPI_FUNC(int) PyCode_Addr2Location(PyCodeObject *, int, int *, int *, int *, int *);
+#define PY_FOREACH_CODE_EVENT(V) \
+ V(CREATE) \
+ V(DESTROY)
+
+typedef enum {
+ #define PY_DEF_EVENT(op) PY_CODE_EVENT_##op,
+ PY_FOREACH_CODE_EVENT(PY_DEF_EVENT)
+ #undef PY_DEF_EVENT
+} PyCodeEvent;
+
+
+/*
+ * A callback that is invoked for different events in a code object's lifecycle.
+ *
+ * The callback is invoked with a borrowed reference to co, after it is
+ * created and before it is destroyed.
+ *
+ * If the callback sets an exception, it must return -1. Otherwise
+ * it should return 0.
+ */
+typedef int (*PyCode_WatchCallback)(
+ PyCodeEvent event,
+ PyCodeObject* co);
+
+/*
+ * Register a per-interpreter callback that will be invoked for code object
+ * lifecycle events.
+ *
+ * Returns a handle that may be passed to PyCode_ClearWatcher on success,
+ * or -1 and sets an error if no more handles are available.
+ */
+PyAPI_FUNC(int) PyCode_AddWatcher(PyCode_WatchCallback callback);
+
+/*
+ * Clear the watcher associated with the watcher_id handle.
+ *
+ * Returns 0 on success or -1 if no watcher exists for the provided id.
+ */
+PyAPI_FUNC(int) PyCode_ClearWatcher(int watcher_id);
+
/* for internal use only */
struct _opaque {
int computed_line;
@@ -200,11 +343,21 @@ PyAPI_FUNC(PyObject*) _PyCode_ConstantKey(PyObject *obj);
PyAPI_FUNC(PyObject*) PyCode_Optimize(PyObject *code, PyObject* consts,
PyObject *names, PyObject *lnotab);
-
-PyAPI_FUNC(int) _PyCode_GetExtra(PyObject *code, Py_ssize_t index,
- void **extra);
-PyAPI_FUNC(int) _PyCode_SetExtra(PyObject *code, Py_ssize_t index,
- void *extra);
+PyAPI_FUNC(int) PyUnstable_Code_GetExtra(
+ PyObject *code, Py_ssize_t index, void **extra);
+PyAPI_FUNC(int) PyUnstable_Code_SetExtra(
+ PyObject *code, Py_ssize_t index, void *extra);
+// Old names -- remove when this API changes:
+_Py_DEPRECATED_EXTERNALLY(3.12) static inline int
+_PyCode_GetExtra(PyObject *code, Py_ssize_t index, void **extra)
+{
+ return PyUnstable_Code_GetExtra(code, index, extra);
+}
+_Py_DEPRECATED_EXTERNALLY(3.12) static inline int
+_PyCode_SetExtra(PyObject *code, Py_ssize_t index, void *extra)
+{
+ return PyUnstable_Code_SetExtra(code, index, extra);
+}
/* Equivalent to getattr(code, 'co_code') in Python.
Returns a strong reference to a bytes object. */
diff --git a/contrib/tools/python3/src/Include/cpython/compile.h b/contrib/tools/python3/src/Include/cpython/compile.h
index 518a376499..f5a62a8ec6 100644
--- a/contrib/tools/python3/src/Include/cpython/compile.h
+++ b/contrib/tools/python3/src/Include/cpython/compile.h
@@ -31,11 +31,26 @@ typedef struct {
#define _PyCompilerFlags_INIT \
(PyCompilerFlags){.cf_flags = 0, .cf_feature_version = PY_MINOR_VERSION}
+/* source location information */
+typedef struct {
+ int lineno;
+ int end_lineno;
+ int col_offset;
+ int end_col_offset;
+} _PyCompilerSrcLocation;
+
+#define SRC_LOCATION_FROM_AST(n) \
+ (_PyCompilerSrcLocation){ \
+ .lineno = (n)->lineno, \
+ .end_lineno = (n)->end_lineno, \
+ .col_offset = (n)->col_offset, \
+ .end_col_offset = (n)->end_col_offset }
+
/* Future feature support */
typedef struct {
- int ff_features; /* flags set by future statements */
- int ff_lineno; /* line number of last future statement */
+ int ff_features; /* flags set by future statements */
+ _PyCompilerSrcLocation ff_location; /* location of last future statement */
} PyFutureFeatures;
#define FUTURE_NESTED_SCOPES "nested_scopes"
diff --git a/contrib/tools/python3/src/Include/cpython/context.h b/contrib/tools/python3/src/Include/cpython/context.h
index 4db079f763..9879fc7192 100644
--- a/contrib/tools/python3/src/Include/cpython/context.h
+++ b/contrib/tools/python3/src/Include/cpython/context.h
@@ -15,9 +15,9 @@ PyAPI_DATA(PyTypeObject) PyContextToken_Type;
typedef struct _pycontexttokenobject PyContextToken;
-#define PyContext_CheckExact(o) Py_IS_TYPE(o, &PyContext_Type)
-#define PyContextVar_CheckExact(o) Py_IS_TYPE(o, &PyContextVar_Type)
-#define PyContextToken_CheckExact(o) Py_IS_TYPE(o, &PyContextToken_Type)
+#define PyContext_CheckExact(o) Py_IS_TYPE((o), &PyContext_Type)
+#define PyContextVar_CheckExact(o) Py_IS_TYPE((o), &PyContextVar_Type)
+#define PyContextToken_CheckExact(o) Py_IS_TYPE((o), &PyContextToken_Type)
PyAPI_FUNC(PyObject *) PyContext_New(void);
diff --git a/contrib/tools/python3/src/Include/cpython/dictobject.h b/contrib/tools/python3/src/Include/cpython/dictobject.h
index 033eaeb4c9..ddada92202 100644
--- a/contrib/tools/python3/src/Include/cpython/dictobject.h
+++ b/contrib/tools/python3/src/Include/cpython/dictobject.h
@@ -16,7 +16,11 @@ typedef struct {
/* Dictionary version: globally unique, value change each time
the dictionary is modified */
+#ifdef Py_BUILD_CORE
uint64_t ma_version_tag;
+#else
+ Py_DEPRECATED(3.12) uint64_t ma_version_tag;
+#endif
PyDictKeysObject *ma_keys;
@@ -46,7 +50,14 @@ PyAPI_FUNC(int) _PyDict_Next(
PyObject *mp, Py_ssize_t *pos, PyObject **key, PyObject **value, Py_hash_t *hash);
/* Get the number of items of a dictionary. */
-#define PyDict_GET_SIZE(mp) (assert(PyDict_Check(mp)),((PyDictObject *)mp)->ma_used)
+static inline Py_ssize_t PyDict_GET_SIZE(PyObject *op) {
+ PyDictObject *mp;
+ assert(PyDict_Check(op));
+ mp = _Py_CAST(PyDictObject*, op);
+ return mp->ma_used;
+}
+#define PyDict_GET_SIZE(op) PyDict_GET_SIZE(_PyObject_CAST(op))
+
PyAPI_FUNC(int) _PyDict_Contains_KnownHash(PyObject *, PyObject *, Py_hash_t);
PyAPI_FUNC(int) _PyDict_ContainsId(PyObject *, _Py_Identifier *);
PyAPI_FUNC(PyObject *) _PyDict_NewPresized(Py_ssize_t minused);
@@ -76,3 +87,32 @@ typedef struct {
PyAPI_FUNC(PyObject *) _PyDictView_New(PyObject *, PyTypeObject *);
PyAPI_FUNC(PyObject *) _PyDictView_Intersect(PyObject* self, PyObject *other);
+
+/* Dictionary watchers */
+
+#define PY_FOREACH_DICT_EVENT(V) \
+ V(ADDED) \
+ V(MODIFIED) \
+ V(DELETED) \
+ V(CLONED) \
+ V(CLEARED) \
+ V(DEALLOCATED)
+
+typedef enum {
+ #define PY_DEF_EVENT(EVENT) PyDict_EVENT_##EVENT,
+ PY_FOREACH_DICT_EVENT(PY_DEF_EVENT)
+ #undef PY_DEF_EVENT
+} PyDict_WatchEvent;
+
+// Callback to be invoked when a watched dict is cleared, dealloced, or modified.
+// In clear/dealloc case, key and new_value will be NULL. Otherwise, new_value will be the
+// new value for key, NULL if key is being deleted.
+typedef int(*PyDict_WatchCallback)(PyDict_WatchEvent event, PyObject* dict, PyObject* key, PyObject* new_value);
+
+// Register/unregister a dict-watcher callback
+PyAPI_FUNC(int) PyDict_AddWatcher(PyDict_WatchCallback callback);
+PyAPI_FUNC(int) PyDict_ClearWatcher(int watcher_id);
+
+// Mark given dictionary as "watched" (callback will be called if it is modified)
+PyAPI_FUNC(int) PyDict_Watch(int watcher_id, PyObject* dict);
+PyAPI_FUNC(int) PyDict_Unwatch(int watcher_id, PyObject* dict);
diff --git a/contrib/tools/python3/src/Include/cpython/floatobject.h b/contrib/tools/python3/src/Include/cpython/floatobject.h
index 7795d9f83f..127093098b 100644
--- a/contrib/tools/python3/src/Include/cpython/floatobject.h
+++ b/contrib/tools/python3/src/Include/cpython/floatobject.h
@@ -7,9 +7,15 @@ typedef struct {
double ob_fval;
} PyFloatObject;
-// Macro version of PyFloat_AsDouble() trading safety for speed.
+#define _PyFloat_CAST(op) \
+ (assert(PyFloat_Check(op)), _Py_CAST(PyFloatObject*, op))
+
+// Static inline version of PyFloat_AsDouble() trading safety for speed.
// It doesn't check if op is a double object.
-#define PyFloat_AS_DOUBLE(op) (((PyFloatObject *)(op))->ob_fval)
+static inline double PyFloat_AS_DOUBLE(PyObject *op) {
+ return _PyFloat_CAST(op)->ob_fval;
+}
+#define PyFloat_AS_DOUBLE(op) PyFloat_AS_DOUBLE(_PyObject_CAST(op))
PyAPI_FUNC(int) PyFloat_Pack2(double x, char *p, int le);
diff --git a/contrib/tools/python3/src/Include/cpython/funcobject.h b/contrib/tools/python3/src/Include/cpython/funcobject.h
index 99ac6008f8..6f78f5868d 100644
--- a/contrib/tools/python3/src/Include/cpython/funcobject.h
+++ b/contrib/tools/python3/src/Include/cpython/funcobject.h
@@ -41,6 +41,7 @@ typedef struct {
PyObject *func_weakreflist; /* List of weak references */
PyObject *func_module; /* The __module__ attribute, can be anything */
PyObject *func_annotations; /* Annotations, a dict or NULL */
+ PyObject *func_typeparams; /* Tuple of active type variables or NULL */
vectorcallfunc vectorcall;
/* Version number for use by specializer.
* Can set to non-zero when we want to specialize.
@@ -48,7 +49,8 @@ typedef struct {
* defaults
* kwdefaults (only if the object changes, not the contents of the dict)
* code
- * annotations */
+ * annotations
+ * vectorcall function pointer */
uint32_t func_version;
/* Invariant:
@@ -60,7 +62,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyFunction_Type;
-#define PyFunction_Check(op) Py_IS_TYPE(op, &PyFunction_Type)
+#define PyFunction_Check(op) Py_IS_TYPE((op), &PyFunction_Type)
PyAPI_FUNC(PyObject *) PyFunction_New(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_NewWithQualName(PyObject *, PyObject *, PyObject *);
@@ -69,6 +71,7 @@ PyAPI_FUNC(PyObject *) PyFunction_GetGlobals(PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetModule(PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetDefaults(PyObject *);
PyAPI_FUNC(int) PyFunction_SetDefaults(PyObject *, PyObject *);
+PyAPI_FUNC(void) PyFunction_SetVectorcall(PyFunctionObject *, vectorcallfunc);
PyAPI_FUNC(PyObject *) PyFunction_GetKwDefaults(PyObject *);
PyAPI_FUNC(int) PyFunction_SetKwDefaults(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) PyFunction_GetClosure(PyObject *);
@@ -82,22 +85,45 @@ PyAPI_FUNC(PyObject *) _PyFunction_Vectorcall(
size_t nargsf,
PyObject *kwnames);
-/* Macros for direct access to these values. Type checks are *not*
- done, so use with care. */
-#define PyFunction_GET_CODE(func) \
- (((PyFunctionObject *)func) -> func_code)
-#define PyFunction_GET_GLOBALS(func) \
- (((PyFunctionObject *)func) -> func_globals)
-#define PyFunction_GET_MODULE(func) \
- (((PyFunctionObject *)func) -> func_module)
-#define PyFunction_GET_DEFAULTS(func) \
- (((PyFunctionObject *)func) -> func_defaults)
-#define PyFunction_GET_KW_DEFAULTS(func) \
- (((PyFunctionObject *)func) -> func_kwdefaults)
-#define PyFunction_GET_CLOSURE(func) \
- (((PyFunctionObject *)func) -> func_closure)
-#define PyFunction_GET_ANNOTATIONS(func) \
- (((PyFunctionObject *)func) -> func_annotations)
+#define _PyFunction_CAST(func) \
+ (assert(PyFunction_Check(func)), _Py_CAST(PyFunctionObject*, func))
+
+/* Static inline functions for direct access to these values.
+ Type checks are *not* done, so use with care. */
+static inline PyObject* PyFunction_GET_CODE(PyObject *func) {
+ return _PyFunction_CAST(func)->func_code;
+}
+#define PyFunction_GET_CODE(func) PyFunction_GET_CODE(_PyObject_CAST(func))
+
+static inline PyObject* PyFunction_GET_GLOBALS(PyObject *func) {
+ return _PyFunction_CAST(func)->func_globals;
+}
+#define PyFunction_GET_GLOBALS(func) PyFunction_GET_GLOBALS(_PyObject_CAST(func))
+
+static inline PyObject* PyFunction_GET_MODULE(PyObject *func) {
+ return _PyFunction_CAST(func)->func_module;
+}
+#define PyFunction_GET_MODULE(func) PyFunction_GET_MODULE(_PyObject_CAST(func))
+
+static inline PyObject* PyFunction_GET_DEFAULTS(PyObject *func) {
+ return _PyFunction_CAST(func)->func_defaults;
+}
+#define PyFunction_GET_DEFAULTS(func) PyFunction_GET_DEFAULTS(_PyObject_CAST(func))
+
+static inline PyObject* PyFunction_GET_KW_DEFAULTS(PyObject *func) {
+ return _PyFunction_CAST(func)->func_kwdefaults;
+}
+#define PyFunction_GET_KW_DEFAULTS(func) PyFunction_GET_KW_DEFAULTS(_PyObject_CAST(func))
+
+static inline PyObject* PyFunction_GET_CLOSURE(PyObject *func) {
+ return _PyFunction_CAST(func)->func_closure;
+}
+#define PyFunction_GET_CLOSURE(func) PyFunction_GET_CLOSURE(_PyObject_CAST(func))
+
+static inline PyObject* PyFunction_GET_ANNOTATIONS(PyObject *func) {
+ return _PyFunction_CAST(func)->func_annotations;
+}
+#define PyFunction_GET_ANNOTATIONS(func) PyFunction_GET_ANNOTATIONS(_PyObject_CAST(func))
/* The classmethod and staticmethod types lives here, too */
PyAPI_DATA(PyTypeObject) PyClassMethod_Type;
@@ -106,6 +132,55 @@ PyAPI_DATA(PyTypeObject) PyStaticMethod_Type;
PyAPI_FUNC(PyObject *) PyClassMethod_New(PyObject *);
PyAPI_FUNC(PyObject *) PyStaticMethod_New(PyObject *);
+#define PY_FOREACH_FUNC_EVENT(V) \
+ V(CREATE) \
+ V(DESTROY) \
+ V(MODIFY_CODE) \
+ V(MODIFY_DEFAULTS) \
+ V(MODIFY_KWDEFAULTS)
+
+typedef enum {
+ #define PY_DEF_EVENT(EVENT) PyFunction_EVENT_##EVENT,
+ PY_FOREACH_FUNC_EVENT(PY_DEF_EVENT)
+ #undef PY_DEF_EVENT
+} PyFunction_WatchEvent;
+
+/*
+ * A callback that is invoked for different events in a function's lifecycle.
+ *
+ * The callback is invoked with a borrowed reference to func, after it is
+ * created and before it is modified or destroyed. The callback should not
+ * modify func.
+ *
+ * When a function's code object, defaults, or kwdefaults are modified the
+ * callback will be invoked with the respective event and new_value will
+ * contain a borrowed reference to the new value that is about to be stored in
+ * the function. Otherwise the third argument is NULL.
+ *
+ * If the callback returns with an exception set, it must return -1. Otherwise
+ * it should return 0.
+ */
+typedef int (*PyFunction_WatchCallback)(
+ PyFunction_WatchEvent event,
+ PyFunctionObject *func,
+ PyObject *new_value);
+
+/*
+ * Register a per-interpreter callback that will be invoked for function lifecycle
+ * events.
+ *
+ * Returns a handle that may be passed to PyFunction_ClearWatcher on success,
+ * or -1 and sets an error if no more handles are available.
+ */
+PyAPI_FUNC(int) PyFunction_AddWatcher(PyFunction_WatchCallback callback);
+
+/*
+ * Clear the watcher associated with the watcher_id handle.
+ *
+ * Returns 0 on success or -1 if no watcher exists for the supplied id.
+ */
+PyAPI_FUNC(int) PyFunction_ClearWatcher(int watcher_id);
+
#ifdef __cplusplus
}
#endif
diff --git a/contrib/tools/python3/src/Include/cpython/genobject.h b/contrib/tools/python3/src/Include/cpython/genobject.h
index 40eaa19d3f..7856481b5d 100644
--- a/contrib/tools/python3/src/Include/cpython/genobject.h
+++ b/contrib/tools/python3/src/Include/cpython/genobject.h
@@ -13,8 +13,6 @@ extern "C" {
and coroutine objects. */
#define _PyGenObject_HEAD(prefix) \
PyObject_HEAD \
- /* The code object backing the generator */ \
- PyCodeObject *prefix##_code; \
/* List of weak reference. */ \
PyObject *prefix##_weakreflist; \
/* Name of the generator. */ \
@@ -28,7 +26,7 @@ extern "C" {
char prefix##_running_async; \
/* The frame */ \
int8_t prefix##_frame_state; \
- PyObject *prefix##_iframe[1];
+ PyObject *prefix##_iframe[1]; \
typedef struct {
/* The gi_ prefix is intended to remind of generator-iterator. */
@@ -37,8 +35,8 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyGen_Type;
-#define PyGen_Check(op) PyObject_TypeCheck(op, &PyGen_Type)
-#define PyGen_CheckExact(op) Py_IS_TYPE(op, &PyGen_Type)
+#define PyGen_Check(op) PyObject_TypeCheck((op), &PyGen_Type)
+#define PyGen_CheckExact(op) Py_IS_TYPE((op), &PyGen_Type)
PyAPI_FUNC(PyObject *) PyGen_New(PyFrameObject *);
PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
@@ -46,6 +44,7 @@ PyAPI_FUNC(PyObject *) PyGen_NewWithQualName(PyFrameObject *,
PyAPI_FUNC(int) _PyGen_SetStopIterationValue(PyObject *);
PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
+PyAPI_FUNC(PyCodeObject *) PyGen_GetCode(PyGenObject *gen);
/* --- PyCoroObject ------------------------------------------------------- */
@@ -57,7 +56,7 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyCoro_Type;
PyAPI_DATA(PyTypeObject) _PyCoroWrapper_Type;
-#define PyCoro_CheckExact(op) Py_IS_TYPE(op, &PyCoro_Type)
+#define PyCoro_CheckExact(op) Py_IS_TYPE((op), &PyCoro_Type)
PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
PyObject *name, PyObject *qualname);
@@ -76,7 +75,9 @@ PyAPI_DATA(PyTypeObject) _PyAsyncGenAThrow_Type;
PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
PyObject *name, PyObject *qualname);
-#define PyAsyncGen_CheckExact(op) Py_IS_TYPE(op, &PyAsyncGen_Type)
+#define PyAsyncGen_CheckExact(op) Py_IS_TYPE((op), &PyAsyncGen_Type)
+
+#define PyAsyncGenASend_CheckExact(op) Py_IS_TYPE((op), &_PyAsyncGenASend_Type)
#undef _PyGenObject_HEAD
diff --git a/contrib/tools/python3/src/Include/cpython/import.h b/contrib/tools/python3/src/Include/cpython/import.h
index a69b4f34de..2bca4ade4c 100644
--- a/contrib/tools/python3/src/Include/cpython/import.h
+++ b/contrib/tools/python3/src/Include/cpython/import.h
@@ -10,8 +10,8 @@ PyAPI_FUNC(PyObject *) _PyImport_GetModuleId(_Py_Identifier *name);
PyAPI_FUNC(int) _PyImport_SetModule(PyObject *name, PyObject *module);
PyAPI_FUNC(int) _PyImport_SetModuleString(const char *name, PyObject* module);
-PyAPI_FUNC(void) _PyImport_AcquireLock(void);
-PyAPI_FUNC(int) _PyImport_ReleaseLock(void);
+PyAPI_FUNC(void) _PyImport_AcquireLock(PyInterpreterState *interp);
+PyAPI_FUNC(int) _PyImport_ReleaseLock(PyInterpreterState *interp);
PyAPI_FUNC(int) _PyImport_FixupBuiltin(
PyObject *mod,
@@ -25,6 +25,7 @@ struct _inittab {
const char *name; /* ASCII encoded string */
PyObject* (*initfunc)(void);
};
+// This is not used after Py_Initialize() is called.
PyAPI_DATA(struct _inittab *) PyImport_Inittab;
PyAPI_FUNC(int) PyImport_ExtendInittab(struct _inittab *newtab);
diff --git a/contrib/tools/python3/src/Include/cpython/initconfig.h b/contrib/tools/python3/src/Include/cpython/initconfig.h
index 3b6d59389f..cbae97f12f 100644
--- a/contrib/tools/python3/src/Include/cpython/initconfig.h
+++ b/contrib/tools/python3/src/Include/cpython/initconfig.h
@@ -25,6 +25,7 @@ PyAPI_FUNC(PyStatus) PyStatus_Exit(int exitcode);
PyAPI_FUNC(int) PyStatus_IsError(PyStatus err);
PyAPI_FUNC(int) PyStatus_IsExit(PyStatus err);
PyAPI_FUNC(int) PyStatus_Exception(PyStatus err);
+PyAPI_FUNC(PyObject *) _PyErr_SetFromPyStatus(PyStatus status);
/* --- PyWideStringList ------------------------------------------------ */
@@ -142,6 +143,7 @@ typedef struct PyConfig {
unsigned long hash_seed;
int faulthandler;
int tracemalloc;
+ int perf_profiling;
int import_time;
int code_debug_ranges;
int show_ref_count;
@@ -177,6 +179,7 @@ typedef struct PyConfig {
wchar_t *check_hash_pycs_mode;
int use_frozen_modules;
int safe_path;
+ int int_max_str_digits;
/* --- Path configuration inputs ------------ */
int pathconfig_warnings;
@@ -211,10 +214,6 @@ typedef struct PyConfig {
// If equal to 0, stop Python initialization before the "main" phase.
int _init_main;
- // If non-zero, disallow threads, subprocesses, and fork.
- // Default: 0.
- int _isolated_interpreter;
-
// If non-zero, we believe we're running from a source tree.
int _is_python_build;
} PyConfig;
diff --git a/contrib/tools/python3/src/Include/cpython/interpreteridobject.h b/contrib/tools/python3/src/Include/cpython/interpreteridobject.h
new file mode 100644
index 0000000000..5076584209
--- /dev/null
+++ b/contrib/tools/python3/src/Include/cpython/interpreteridobject.h
@@ -0,0 +1,11 @@
+#ifndef Py_CPYTHON_INTERPRETERIDOBJECT_H
+# error "this header file must not be included directly"
+#endif
+
+/* Interpreter ID Object */
+
+PyAPI_DATA(PyTypeObject) _PyInterpreterID_Type;
+
+PyAPI_FUNC(PyObject *) _PyInterpreterID_New(int64_t);
+PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
+PyAPI_FUNC(PyInterpreterState *) _PyInterpreterID_LookUp(PyObject *);
diff --git a/contrib/tools/python3/src/Include/cpython/listobject.h b/contrib/tools/python3/src/Include/cpython/listobject.h
index 1add8213e0..8fa82122d8 100644
--- a/contrib/tools/python3/src/Include/cpython/listobject.h
+++ b/contrib/tools/python3/src/Include/cpython/listobject.h
@@ -34,18 +34,14 @@ static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) {
PyListObject *list = _PyList_CAST(op);
return Py_SIZE(list);
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
-#endif
+#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))
-#define PyList_GET_ITEM(op, index) (_PyList_CAST(op)->ob_item[index])
+#define PyList_GET_ITEM(op, index) (_PyList_CAST(op)->ob_item[(index)])
static inline void
PyList_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
PyListObject *list = _PyList_CAST(op);
list->ob_item[index] = value;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
#define PyList_SET_ITEM(op, index, value) \
- PyList_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value))
-#endif
+ PyList_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
diff --git a/contrib/tools/python3/src/Include/cpython/longintrepr.h b/contrib/tools/python3/src/Include/cpython/longintrepr.h
index 6d52427508..692c69ba76 100644
--- a/contrib/tools/python3/src/Include/cpython/longintrepr.h
+++ b/contrib/tools/python3/src/Include/cpython/longintrepr.h
@@ -79,9 +79,14 @@ typedef long stwodigits; /* signed variant of twodigits */
aware that ints abuse ob_size's sign bit.
*/
-struct _longobject {
- PyObject_VAR_HEAD
+typedef struct _PyLongValue {
+ uintptr_t lv_tag; /* Number of digits, sign and flags */
digit ob_digit[1];
+} _PyLongValue;
+
+struct _longobject {
+ PyObject_HEAD
+ _PyLongValue long_value;
};
PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
@@ -89,6 +94,37 @@ PyAPI_FUNC(PyLongObject *) _PyLong_New(Py_ssize_t);
/* Return a copy of src. */
PyAPI_FUNC(PyObject *) _PyLong_Copy(PyLongObject *src);
+PyAPI_FUNC(PyLongObject *)
+_PyLong_FromDigits(int negative, Py_ssize_t digit_count, digit *digits);
+
+
+/* Inline some internals for speed. These should be in pycore_long.h
+ * if user code didn't need them inlined. */
+
+#define _PyLong_SIGN_MASK 3
+#define _PyLong_NON_SIZE_BITS 3
+
+
+static inline int
+_PyLong_IsCompact(const PyLongObject* op) {
+ assert(PyType_HasFeature((op)->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS));
+ return op->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS);
+}
+
+#define PyUnstable_Long_IsCompact _PyLong_IsCompact
+
+static inline Py_ssize_t
+_PyLong_CompactValue(const PyLongObject *op)
+{
+ assert(PyType_HasFeature((op)->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS));
+ assert(PyUnstable_Long_IsCompact(op));
+ Py_ssize_t sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
+ return sign * (Py_ssize_t)op->long_value.ob_digit[0];
+}
+
+#define PyUnstable_Long_CompactValue _PyLong_CompactValue
+
+
#ifdef __cplusplus
}
#endif
diff --git a/contrib/tools/python3/src/Include/cpython/longobject.h b/contrib/tools/python3/src/Include/cpython/longobject.h
index 1a73799d65..90cc0f267a 100644
--- a/contrib/tools/python3/src/Include/cpython/longobject.h
+++ b/contrib/tools/python3/src/Include/cpython/longobject.h
@@ -93,3 +93,8 @@ PyAPI_FUNC(PyObject *) _PyLong_GCD(PyObject *, PyObject *);
PyAPI_FUNC(PyObject *) _PyLong_Rshift(PyObject *, size_t);
PyAPI_FUNC(PyObject *) _PyLong_Lshift(PyObject *, size_t);
+
+
+PyAPI_FUNC(int) PyUnstable_Long_IsCompact(const PyLongObject* op);
+PyAPI_FUNC(Py_ssize_t) PyUnstable_Long_CompactValue(const PyLongObject* op);
+
diff --git a/contrib/tools/python3/src/Include/cpython/memoryobject.h b/contrib/tools/python3/src/Include/cpython/memoryobject.h
new file mode 100644
index 0000000000..3837fa8c6a
--- /dev/null
+++ b/contrib/tools/python3/src/Include/cpython/memoryobject.h
@@ -0,0 +1,52 @@
+#ifndef Py_CPYTHON_MEMORYOBJECT_H
+# error "this header file must not be included directly"
+#endif
+
+PyAPI_DATA(PyTypeObject) _PyManagedBuffer_Type;
+
+/* The structs are declared here so that macros can work, but they shouldn't
+ be considered public. Don't access their fields directly, use the macros
+ and functions instead! */
+#define _Py_MANAGED_BUFFER_RELEASED 0x001 /* access to exporter blocked */
+#define _Py_MANAGED_BUFFER_FREE_FORMAT 0x002 /* free format */
+
+typedef struct {
+ PyObject_HEAD
+ int flags; /* state flags */
+ Py_ssize_t exports; /* number of direct memoryview exports */
+ Py_buffer master; /* snapshot buffer obtained from the original exporter */
+} _PyManagedBufferObject;
+
+
+/* memoryview state flags */
+#define _Py_MEMORYVIEW_RELEASED 0x001 /* access to master buffer blocked */
+#define _Py_MEMORYVIEW_C 0x002 /* C-contiguous layout */
+#define _Py_MEMORYVIEW_FORTRAN 0x004 /* Fortran contiguous layout */
+#define _Py_MEMORYVIEW_SCALAR 0x008 /* scalar: ndim = 0 */
+#define _Py_MEMORYVIEW_PIL 0x010 /* PIL-style layout */
+#define _Py_MEMORYVIEW_RESTRICTED 0x020 /* Disallow new references to the memoryview's buffer */
+
+typedef struct {
+ PyObject_VAR_HEAD
+ _PyManagedBufferObject *mbuf; /* managed buffer */
+ Py_hash_t hash; /* hash value for read-only views */
+ int flags; /* state flags */
+ Py_ssize_t exports; /* number of buffer re-exports */
+ Py_buffer view; /* private copy of the exporter's view */
+ PyObject *weakreflist;
+ Py_ssize_t ob_array[1]; /* shape, strides, suboffsets */
+} PyMemoryViewObject;
+
+#define _PyMemoryView_CAST(op) _Py_CAST(PyMemoryViewObject*, op)
+
+/* Get a pointer to the memoryview's private copy of the exporter's buffer. */
+static inline Py_buffer* PyMemoryView_GET_BUFFER(PyObject *op) {
+ return (&_PyMemoryView_CAST(op)->view);
+}
+#define PyMemoryView_GET_BUFFER(op) PyMemoryView_GET_BUFFER(_PyObject_CAST(op))
+
+/* Get a pointer to the exporting object (this may be NULL!). */
+static inline PyObject* PyMemoryView_GET_BASE(PyObject *op) {
+ return _PyMemoryView_CAST(op)->view.obj;
+}
+#define PyMemoryView_GET_BASE(op) PyMemoryView_GET_BASE(_PyObject_CAST(op))
diff --git a/contrib/tools/python3/src/Include/cpython/methodobject.h b/contrib/tools/python3/src/Include/cpython/methodobject.h
index 54a61cfd07..d541e15494 100644
--- a/contrib/tools/python3/src/Include/cpython/methodobject.h
+++ b/contrib/tools/python3/src/Include/cpython/methodobject.h
@@ -31,8 +31,8 @@ typedef struct {
PyAPI_DATA(PyTypeObject) PyCMethod_Type;
-#define PyCMethod_CheckExact(op) Py_IS_TYPE(op, &PyCMethod_Type)
-#define PyCMethod_Check(op) PyObject_TypeCheck(op, &PyCMethod_Type)
+#define PyCMethod_CheckExact(op) Py_IS_TYPE((op), &PyCMethod_Type)
+#define PyCMethod_Check(op) PyObject_TypeCheck((op), &PyCMethod_Type)
/* Static inline functions for direct access to these values.
@@ -40,9 +40,7 @@ PyAPI_DATA(PyTypeObject) PyCMethod_Type;
static inline PyCFunction PyCFunction_GET_FUNCTION(PyObject *func) {
return _PyCFunctionObject_CAST(func)->m_ml->ml_meth;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(_PyObject_CAST(func))
-#endif
+#define PyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(_PyObject_CAST(func))
static inline PyObject* PyCFunction_GET_SELF(PyObject *func_obj) {
PyCFunctionObject *func = _PyCFunctionObject_CAST(func_obj);
@@ -51,16 +49,12 @@ static inline PyObject* PyCFunction_GET_SELF(PyObject *func_obj) {
}
return func->m_self;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyCFunction_GET_SELF(func) PyCFunction_GET_SELF(_PyObject_CAST(func))
-#endif
+#define PyCFunction_GET_SELF(func) PyCFunction_GET_SELF(_PyObject_CAST(func))
static inline int PyCFunction_GET_FLAGS(PyObject *func) {
return _PyCFunctionObject_CAST(func)->m_ml->ml_flags;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyCFunction_GET_FLAGS(func) PyCFunction_GET_FLAGS(_PyObject_CAST(func))
-#endif
+#define PyCFunction_GET_FLAGS(func) PyCFunction_GET_FLAGS(_PyObject_CAST(func))
static inline PyTypeObject* PyCFunction_GET_CLASS(PyObject *func_obj) {
PyCFunctionObject *func = _PyCFunctionObject_CAST(func_obj);
@@ -69,6 +63,4 @@ static inline PyTypeObject* PyCFunction_GET_CLASS(PyObject *func_obj) {
}
return _Py_NULL;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyCFunction_GET_CLASS(func) PyCFunction_GET_CLASS(_PyObject_CAST(func))
-#endif
+#define PyCFunction_GET_CLASS(func) PyCFunction_GET_CLASS(_PyObject_CAST(func))
diff --git a/contrib/tools/python3/src/Include/cpython/modsupport.h b/contrib/tools/python3/src/Include/cpython/modsupport.h
index 205e174243..2259291aff 100644
--- a/contrib/tools/python3/src/Include/cpython/modsupport.h
+++ b/contrib/tools/python3/src/Include/cpython/modsupport.h
@@ -34,11 +34,13 @@ PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
#define _PyArg_NoPositional(funcname, args) \
((args) == NULL || _PyArg_NoPositional((funcname), (args)))
+#define _Py_ANY_VARARGS(n) ((n) == PY_SSIZE_T_MAX)
+
PyAPI_FUNC(void) _PyArg_BadArgument(const char *, const char *, const char *, PyObject *);
PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
Py_ssize_t, Py_ssize_t);
#define _PyArg_CheckPositional(funcname, nargs, min, max) \
- ((!ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \
+ ((!_Py_ANY_VARARGS(max) && (min) <= (nargs) && (nargs) <= (max)) \
|| _PyArg_CheckPositional((funcname), (nargs), (min), (max)))
PyAPI_FUNC(PyObject **) _Py_VaBuildStack(
@@ -49,6 +51,7 @@ PyAPI_FUNC(PyObject **) _Py_VaBuildStack(
Py_ssize_t *p_nargs);
typedef struct _PyArg_Parser {
+ int initialized;
const char *format;
const char * const *keywords;
const char *fname;
@@ -98,11 +101,9 @@ PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg(
#define _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
(((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
- (minpos) <= (nargs) && (nargs) <= (maxpos) && args != NULL) ? (args) : \
+ (minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? (args) : \
_PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \
(minpos), (maxpos), (minkw), (buf)))
PyAPI_FUNC(PyObject *) _PyModule_CreateInitialized(PyModuleDef*, int apiver);
PyAPI_FUNC(int) _PyModule_Add(PyObject *, const char *, PyObject *);
-
-PyAPI_DATA(const char *) _Py_PackageContext;
diff --git a/contrib/tools/python3/src/Include/cpython/object.h b/contrib/tools/python3/src/Include/cpython/object.h
index b018dabf9d..ae7f780a93 100644
--- a/contrib/tools/python3/src/Include/cpython/object.h
+++ b/contrib/tools/python3/src/Include/cpython/object.h
@@ -3,6 +3,7 @@
#endif
PyAPI_FUNC(void) _Py_NewReference(PyObject *op);
+PyAPI_FUNC(void) _Py_NewReferenceNoTotal(PyObject *op);
#ifdef Py_TRACE_REFS
/* Py_TRACE_REFS is such major surgery that we call external routines. */
@@ -10,7 +11,11 @@ PyAPI_FUNC(void) _Py_ForgetReference(PyObject *);
#endif
#ifdef Py_REF_DEBUG
-PyAPI_FUNC(Py_ssize_t) _Py_GetRefTotal(void);
+/* These are useful as debugging aids when chasing down refleaks. */
+PyAPI_FUNC(Py_ssize_t) _Py_GetGlobalRefTotal(void);
+# define _Py_GetRefTotal() _Py_GetGlobalRefTotal()
+PyAPI_FUNC(Py_ssize_t) _Py_GetLegacyRefTotal(void);
+PyAPI_FUNC(Py_ssize_t) _PyInterpreterState_GetRefTotal(PyInterpreterState *);
#endif
@@ -41,22 +46,15 @@ typedef struct _Py_Identifier {
Py_ssize_t index;
} _Py_Identifier;
-#if defined(NEEDS_PY_IDENTIFIER) || !defined(Py_BUILD_CORE)
+#ifndef Py_BUILD_CORE
// For now we are keeping _Py_IDENTIFIER for continued use
// in non-builtin extensions (and naughty PyPI modules).
-#define _Py_static_string_init(value) { .string = value, .index = -1 }
+#define _Py_static_string_init(value) { .string = (value), .index = -1 }
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)
-#endif /* NEEDS_PY_IDENTIFIER */
-
-typedef int (*getbufferproc)(PyObject *, Py_buffer *, int);
-typedef void (*releasebufferproc)(PyObject *, Py_buffer *);
-
-typedef PyObject *(*vectorcallfunc)(PyObject *callable, PyObject *const *args,
- size_t nargsf, PyObject *kwnames);
-
+#endif /* !Py_BUILD_CORE */
typedef struct {
/* Number implementations must check *both*
@@ -217,9 +215,9 @@ struct _typeobject {
inquiry tp_is_gc; /* For PyObject_IS_GC */
PyObject *tp_bases;
PyObject *tp_mro; /* method resolution order */
- PyObject *tp_cache;
- PyObject *tp_subclasses;
- PyObject *tp_weaklist;
+ PyObject *tp_cache; /* no longer used */
+ void *tp_subclasses; /* for static builtin types this is an index */
+ PyObject *tp_weaklist; /* not used for static builtin types */
destructor tp_del;
/* Type attribute cache version tag. Added in version 2.6 */
@@ -227,13 +225,27 @@ struct _typeobject {
destructor tp_finalize;
vectorcallfunc tp_vectorcall;
+
+ /* bitset of which type-watchers care about this type */
+ unsigned char tp_watched;
};
/* This struct is used by the specializer
* It should should be treated as an opaque blob
* by code other than the specializer and interpreter. */
struct _specialization_cache {
+ // In order to avoid bloating the bytecode with lots of inline caches, the
+ // members of this structure have a somewhat unique contract. They are set
+ // by the specialization machinery, and are invalidated by PyType_Modified.
+ // The rules for using them are as follows:
+ // - If getitem is non-NULL, then it is the same Python function that
+ // PyType_Lookup(cls, "__getitem__") would return.
+ // - If getitem is NULL, then getitem_version is meaningless.
+ // - If getitem->func_version == getitem_version, then getitem can be called
+ // with two positional arguments and no keyword arguments, and has neither
+ // *args nor **kwargs (as required by BINARY_SUBSCR_GETITEM):
PyObject *getitem;
+ uint32_t getitem_version;
};
/* The *real* layout of a type object when allocated on the heap */
@@ -271,6 +283,7 @@ PyAPI_FUNC(PyTypeObject *) _PyType_CalculateMetaclass(PyTypeObject *, PyObject *
PyAPI_FUNC(PyObject *) _PyType_GetDocFromInternalDoc(const char *, const char *);
PyAPI_FUNC(PyObject *) _PyType_GetTextSignatureFromInternalDoc(const char *, const char *);
PyAPI_FUNC(PyObject *) PyType_GetModuleByDef(PyTypeObject *, PyModuleDef *);
+PyAPI_FUNC(PyObject *) PyType_GetDict(PyTypeObject *);
PyAPI_FUNC(int) PyObject_Print(PyObject *, FILE *, int);
PyAPI_FUNC(void) _Py_BreakPoint(void);
@@ -309,38 +322,69 @@ _PyObject_GenericSetAttrWithDict(PyObject *, PyObject *,
PyAPI_FUNC(PyObject *) _PyObject_FunctionStr(PyObject *);
-/* Safely decref `op` and set `op` to `op2`.
+/* Safely decref `dst` and set `dst` to `src`.
*
* As in case of Py_CLEAR "the obvious" code can be deadly:
*
- * Py_DECREF(op);
- * op = op2;
+ * Py_DECREF(dst);
+ * dst = src;
*
* The safe way is:
*
- * Py_SETREF(op, op2);
+ * Py_SETREF(dst, src);
+ *
+ * That arranges to set `dst` to `src` _before_ decref'ing, so that any code
+ * triggered as a side-effect of `dst` getting torn down no longer believes
+ * `dst` points to a valid object.
*
- * That arranges to set `op` to `op2` _before_ decref'ing, so that any code
- * triggered as a side-effect of `op` getting torn down no longer believes
- * `op` points to a valid object.
+ * Temporary variables are used to only evalutate macro arguments once and so
+ * avoid the duplication of side effects. _Py_TYPEOF() or memcpy() is used to
+ * avoid a miscompilation caused by type punning. See Py_CLEAR() comment for
+ * implementation details about type punning.
*
- * Py_XSETREF is a variant of Py_SETREF that uses Py_XDECREF instead of
- * Py_DECREF.
+ * The memcpy() implementation does not emit a compiler warning if 'src' has
+ * not the same type than 'src': any pointer type is accepted for 'src'.
*/
-
-#define Py_SETREF(op, op2) \
- do { \
- PyObject *_py_tmp = _PyObject_CAST(op); \
- (op) = (op2); \
- Py_DECREF(_py_tmp); \
+#ifdef _Py_TYPEOF
+#define Py_SETREF(dst, src) \
+ do { \
+ _Py_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \
+ _Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
+ *_tmp_dst_ptr = (src); \
+ Py_DECREF(_tmp_old_dst); \
+ } while (0)
+#else
+#define Py_SETREF(dst, src) \
+ do { \
+ PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
+ PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
+ PyObject *_tmp_src = _PyObject_CAST(src); \
+ memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
+ Py_DECREF(_tmp_old_dst); \
} while (0)
+#endif
-#define Py_XSETREF(op, op2) \
- do { \
- PyObject *_py_tmp = _PyObject_CAST(op); \
- (op) = (op2); \
- Py_XDECREF(_py_tmp); \
+/* Py_XSETREF() is a variant of Py_SETREF() that uses Py_XDECREF() instead of
+ * Py_DECREF().
+ */
+#ifdef _Py_TYPEOF
+#define Py_XSETREF(dst, src) \
+ do { \
+ _Py_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \
+ _Py_TYPEOF(dst) _tmp_old_dst = (*_tmp_dst_ptr); \
+ *_tmp_dst_ptr = (src); \
+ Py_XDECREF(_tmp_old_dst); \
+ } while (0)
+#else
+#define Py_XSETREF(dst, src) \
+ do { \
+ PyObject **_tmp_dst_ptr = _Py_CAST(PyObject**, &(dst)); \
+ PyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
+ PyObject *_tmp_src = _PyObject_CAST(src); \
+ memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(PyObject*)); \
+ Py_XDECREF(_tmp_old_dst); \
} while (0)
+#endif
PyAPI_DATA(PyTypeObject) _PyNone_Type;
@@ -385,9 +429,9 @@ _PyObject_DebugTypeStats(FILE *out);
#endif
#define _PyObject_ASSERT_WITH_MSG(obj, expr, msg) \
- _PyObject_ASSERT_FROM(obj, expr, msg, __FILE__, __LINE__, __func__)
+ _PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
#define _PyObject_ASSERT(obj, expr) \
- _PyObject_ASSERT_WITH_MSG(obj, expr, NULL)
+ _PyObject_ASSERT_WITH_MSG((obj), expr, NULL)
#define _PyObject_ASSERT_FAILED_MSG(obj, msg) \
_PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
@@ -480,7 +524,7 @@ PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);
/* If "cond" is false, then _tstate remains NULL and the deallocator \
* is run normally without involving the trashcan */ \
if (cond) { \
- _tstate = PyThreadState_Get(); \
+ _tstate = _PyThreadState_UncheckedGet(); \
if (_PyTrash_begin(_tstate, _PyObject_CAST(op))) { \
break; \
} \
@@ -493,8 +537,8 @@ PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);
} while (0);
#define Py_TRASHCAN_BEGIN(op, dealloc) \
- Py_TRASHCAN_BEGIN_CONDITION(op, \
- _PyTrash_cond(_PyObject_CAST(op), (destructor)dealloc))
+ Py_TRASHCAN_BEGIN_CONDITION((op), \
+ _PyTrash_cond(_PyObject_CAST(op), (destructor)(dealloc)))
/* The following two macros, Py_TRASHCAN_SAFE_BEGIN and
* Py_TRASHCAN_SAFE_END, are deprecated since version 3.11 and
@@ -505,7 +549,27 @@ Py_DEPRECATED(3.11) typedef int UsingDeprecatedTrashcanMacro;
#define Py_TRASHCAN_SAFE_BEGIN(op) \
do { \
UsingDeprecatedTrashcanMacro cond=1; \
- Py_TRASHCAN_BEGIN_CONDITION(op, cond);
+ Py_TRASHCAN_BEGIN_CONDITION((op), cond);
#define Py_TRASHCAN_SAFE_END(op) \
Py_TRASHCAN_END; \
} while(0);
+
+PyAPI_FUNC(void *) PyObject_GetItemData(PyObject *obj);
+
+PyAPI_FUNC(int) _PyObject_VisitManagedDict(PyObject *obj, visitproc visit, void *arg);
+PyAPI_FUNC(void) _PyObject_ClearManagedDict(PyObject *obj);
+
+#define TYPE_MAX_WATCHERS 8
+
+typedef int(*PyType_WatchCallback)(PyTypeObject *);
+PyAPI_FUNC(int) PyType_AddWatcher(PyType_WatchCallback callback);
+PyAPI_FUNC(int) PyType_ClearWatcher(int watcher_id);
+PyAPI_FUNC(int) PyType_Watch(int watcher_id, PyObject *type);
+PyAPI_FUNC(int) PyType_Unwatch(int watcher_id, PyObject *type);
+
+/* Attempt to assign a version tag to the given type.
+ *
+ * Returns 1 if the type already had a valid version tag or a new one was
+ * assigned, or 0 if a new tag could not be assigned.
+ */
+PyAPI_FUNC(int) PyUnstable_Type_AssignVersionTag(PyTypeObject *type);
diff --git a/contrib/tools/python3/src/Include/cpython/objimpl.h b/contrib/tools/python3/src/Include/cpython/objimpl.h
index d7c76eab5c..5a8cdd57c7 100644
--- a/contrib/tools/python3/src/Include/cpython/objimpl.h
+++ b/contrib/tools/python3/src/Include/cpython/objimpl.h
@@ -2,7 +2,9 @@
# error "this header file must not be included directly"
#endif
-#define _PyObject_SIZE(typeobj) ( (typeobj)->tp_basicsize )
+static inline size_t _PyObject_SIZE(PyTypeObject *type) {
+ return _Py_STATIC_CAST(size_t, type->tp_basicsize);
+}
/* _PyObject_VAR_SIZE returns the number of bytes (as size_t) allocated for a
vrbl-size object with nitems items, exclusive of gc overhead (if any). The
@@ -18,10 +20,11 @@
# error "_PyObject_VAR_SIZE requires SIZEOF_VOID_P be a power of 2"
#endif
-#define _PyObject_VAR_SIZE(typeobj, nitems) \
- _Py_SIZE_ROUND_UP((typeobj)->tp_basicsize + \
- (nitems)*(typeobj)->tp_itemsize, \
- SIZEOF_VOID_P)
+static inline size_t _PyObject_VAR_SIZE(PyTypeObject *type, Py_ssize_t nitems) {
+ size_t size = _Py_STATIC_CAST(size_t, type->tp_basicsize);
+ size += _Py_STATIC_CAST(size_t, nitems) * _Py_STATIC_CAST(size_t, type->tp_itemsize);
+ return _Py_SIZE_ROUND_UP(size, SIZEOF_VOID_P);
+}
/* This example code implements an object constructor with a custom
@@ -87,3 +90,6 @@ PyAPI_FUNC(int) PyObject_IS_GC(PyObject *obj);
PyAPI_FUNC(int) PyType_SUPPORTS_WEAKREFS(PyTypeObject *type);
PyAPI_FUNC(PyObject **) PyObject_GET_WEAKREFS_LISTPTR(PyObject *op);
+
+PyAPI_FUNC(PyObject *) PyUnstable_Object_GC_NewWithExtraData(PyTypeObject *,
+ size_t);
diff --git a/contrib/tools/python3/src/Include/cpython/odictobject.h b/contrib/tools/python3/src/Include/cpython/odictobject.h
index e070413017..3822d55486 100644
--- a/contrib/tools/python3/src/Include/cpython/odictobject.h
+++ b/contrib/tools/python3/src/Include/cpython/odictobject.h
@@ -18,8 +18,8 @@ PyAPI_DATA(PyTypeObject) PyODictKeys_Type;
PyAPI_DATA(PyTypeObject) PyODictItems_Type;
PyAPI_DATA(PyTypeObject) PyODictValues_Type;
-#define PyODict_Check(op) PyObject_TypeCheck(op, &PyODict_Type)
-#define PyODict_CheckExact(op) Py_IS_TYPE(op, &PyODict_Type)
+#define PyODict_Check(op) PyObject_TypeCheck((op), &PyODict_Type)
+#define PyODict_CheckExact(op) Py_IS_TYPE((op), &PyODict_Type)
#define PyODict_SIZE(op) PyDict_GET_SIZE((op))
PyAPI_FUNC(PyObject *) PyODict_New(void);
@@ -27,13 +27,13 @@ PyAPI_FUNC(int) PyODict_SetItem(PyObject *od, PyObject *key, PyObject *item);
PyAPI_FUNC(int) PyODict_DelItem(PyObject *od, PyObject *key);
/* wrappers around PyDict* functions */
-#define PyODict_GetItem(od, key) PyDict_GetItem(_PyObject_CAST(od), key)
+#define PyODict_GetItem(od, key) PyDict_GetItem(_PyObject_CAST(od), (key))
#define PyODict_GetItemWithError(od, key) \
- PyDict_GetItemWithError(_PyObject_CAST(od), key)
-#define PyODict_Contains(od, key) PyDict_Contains(_PyObject_CAST(od), key)
+ PyDict_GetItemWithError(_PyObject_CAST(od), (key))
+#define PyODict_Contains(od, key) PyDict_Contains(_PyObject_CAST(od), (key))
#define PyODict_Size(od) PyDict_Size(_PyObject_CAST(od))
#define PyODict_GetItemString(od, key) \
- PyDict_GetItemString(_PyObject_CAST(od), key)
+ PyDict_GetItemString(_PyObject_CAST(od), (key))
#endif
diff --git a/contrib/tools/python3/src/Include/cpython/picklebufobject.h b/contrib/tools/python3/src/Include/cpython/picklebufobject.h
index 0df2561dce..f3cbaeef91 100644
--- a/contrib/tools/python3/src/Include/cpython/picklebufobject.h
+++ b/contrib/tools/python3/src/Include/cpython/picklebufobject.h
@@ -12,7 +12,7 @@ extern "C" {
PyAPI_DATA(PyTypeObject) PyPickleBuffer_Type;
-#define PyPickleBuffer_Check(op) Py_IS_TYPE(op, &PyPickleBuffer_Type)
+#define PyPickleBuffer_Check(op) Py_IS_TYPE((op), &PyPickleBuffer_Type)
/* Create a PickleBuffer redirecting to the given buffer-enabled object */
PyAPI_FUNC(PyObject *) PyPickleBuffer_FromObject(PyObject *);
diff --git a/contrib/tools/python3/src/Include/cpython/pydebug.h b/contrib/tools/python3/src/Include/cpython/pydebug.h
index cab799f0b3..f6ebd99ed7 100644
--- a/contrib/tools/python3/src/Include/cpython/pydebug.h
+++ b/contrib/tools/python3/src/Include/cpython/pydebug.h
@@ -5,31 +5,31 @@
extern "C" {
#endif
-PyAPI_DATA(int) Py_DebugFlag;
-PyAPI_DATA(int) Py_VerboseFlag;
-PyAPI_DATA(int) Py_QuietFlag;
-PyAPI_DATA(int) Py_InteractiveFlag;
-PyAPI_DATA(int) Py_InspectFlag;
-PyAPI_DATA(int) Py_OptimizeFlag;
-PyAPI_DATA(int) Py_NoSiteFlag;
-PyAPI_DATA(int) Py_BytesWarningFlag;
-PyAPI_DATA(int) Py_FrozenFlag;
-PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
-PyAPI_DATA(int) Py_DontWriteBytecodeFlag;
-PyAPI_DATA(int) Py_NoUserSiteDirectory;
-PyAPI_DATA(int) Py_UnbufferedStdioFlag;
-PyAPI_DATA(int) Py_HashRandomizationFlag;
-PyAPI_DATA(int) Py_IsolatedFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_DebugFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_VerboseFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_QuietFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_InteractiveFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_InspectFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_OptimizeFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_NoSiteFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_BytesWarningFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_FrozenFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_IgnoreEnvironmentFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_DontWriteBytecodeFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_NoUserSiteDirectory;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_UnbufferedStdioFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_HashRandomizationFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_IsolatedFlag;
#ifdef MS_WINDOWS
-PyAPI_DATA(int) Py_LegacyWindowsFSEncodingFlag;
-PyAPI_DATA(int) Py_LegacyWindowsStdioFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_LegacyWindowsFSEncodingFlag;
+Py_DEPRECATED(3.12) PyAPI_DATA(int) Py_LegacyWindowsStdioFlag;
#endif
/* this is a wrapper around getenv() that pays attention to
Py_IgnoreEnvironmentFlag. It should be used for getting variables like
PYTHONPATH and PYTHONHOME from the environment */
-PyAPI_DATA(char*) Py_GETENV(const char *name);
+PyAPI_FUNC(char*) Py_GETENV(const char *name);
#ifdef __cplusplus
}
diff --git a/contrib/tools/python3/src/Include/cpython/pyerrors.h b/contrib/tools/python3/src/Include/cpython/pyerrors.h
index 47d80e3242..156665cbdb 100644
--- a/contrib/tools/python3/src/Include/cpython/pyerrors.h
+++ b/contrib/tools/python3/src/Include/cpython/pyerrors.h
@@ -37,6 +37,7 @@ typedef struct {
PyObject *msg;
PyObject *name;
PyObject *path;
+ PyObject *name_from;
} PyImportErrorObject;
typedef struct {
@@ -97,7 +98,8 @@ PyAPI_FUNC(void) _PyErr_GetExcInfo(PyThreadState *, PyObject **, PyObject **, Py
/* Context manipulation (PEP 3134) */
-PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
+Py_DEPRECATED(3.12) PyAPI_FUNC(void) _PyErr_ChainExceptions(PyObject *, PyObject *, PyObject *);
+PyAPI_FUNC(void) _PyErr_ChainExceptions1(PyObject *);
/* Like PyErr_Format(), but saves current exception as __context__ and
__cause__.
@@ -110,23 +112,13 @@ PyAPI_FUNC(PyObject *) _PyErr_FormatFromCause(
/* In exceptions.c */
-/* Helper that attempts to replace the current exception with one of the
- * same type but with a prefix added to the exception text. The resulting
- * exception description looks like:
- *
- * prefix (exc_type: original_exc_str)
- *
- * Only some exceptions can be safely replaced. If the function determines
- * it isn't safe to perform the replacement, it will leave the original
- * unmodified exception in place.
- *
- * Returns a borrowed reference to the new exception (if any), NULL if the
- * existing exception was left in place.
- */
-PyAPI_FUNC(PyObject *) _PyErr_TrySetFromCause(
- const char *prefix_format, /* ASCII-encoded string */
- ...
- );
+PyAPI_FUNC(int) _PyException_AddNote(
+ PyObject *exc,
+ PyObject *note);
+
+PyAPI_FUNC(PyObject*) PyUnstable_Exc_PrepReraiseStar(
+ PyObject *orig,
+ PyObject *excs);
/* In signalmodule.c */
@@ -176,4 +168,11 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
const char *format,
...);
-#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, message)
+extern PyObject *_PyErr_SetImportErrorWithNameFrom(
+ PyObject *,
+ PyObject *,
+ PyObject *,
+ PyObject *);
+
+
+#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, (message))
diff --git a/contrib/tools/python3/src/Include/cpython/pyframe.h b/contrib/tools/python3/src/Include/cpython/pyframe.h
index 1dc634ccee..0e2afff925 100644
--- a/contrib/tools/python3/src/Include/cpython/pyframe.h
+++ b/contrib/tools/python3/src/Include/cpython/pyframe.h
@@ -14,4 +14,22 @@ PyAPI_FUNC(PyObject *) PyFrame_GetBuiltins(PyFrameObject *frame);
PyAPI_FUNC(PyObject *) PyFrame_GetGenerator(PyFrameObject *frame);
PyAPI_FUNC(int) PyFrame_GetLasti(PyFrameObject *frame);
+PyAPI_FUNC(PyObject*) PyFrame_GetVar(PyFrameObject *frame, PyObject *name);
+PyAPI_FUNC(PyObject*) PyFrame_GetVarString(PyFrameObject *frame, const char *name);
+/* The following functions are for use by debuggers and other tools
+ * implementing custom frame evaluators with PEP 523. */
+
+struct _PyInterpreterFrame;
+
+/* Returns the code object of the frame (strong reference).
+ * Does not raise an exception. */
+PyAPI_FUNC(PyObject *) PyUnstable_InterpreterFrame_GetCode(struct _PyInterpreterFrame *frame);
+
+/* Returns a byte ofsset into the last executed instruction.
+ * Does not raise an exception. */
+PyAPI_FUNC(int) PyUnstable_InterpreterFrame_GetLasti(struct _PyInterpreterFrame *frame);
+
+/* Returns the currently executing line number, or -1 if there is no line number.
+ * Does not raise an exception. */
+PyAPI_FUNC(int) PyUnstable_InterpreterFrame_GetLine(struct _PyInterpreterFrame *frame);
diff --git a/contrib/tools/python3/src/Include/cpython/pylifecycle.h b/contrib/tools/python3/src/Include/cpython/pylifecycle.h
index bb5b07ef59..4daea33bf8 100644
--- a/contrib/tools/python3/src/Include/cpython/pylifecycle.h
+++ b/contrib/tools/python3/src/Include/cpython/pylifecycle.h
@@ -52,6 +52,7 @@ PyAPI_FUNC(const char *) _Py_gitidentifier(void);
PyAPI_FUNC(const char *) _Py_gitversion(void);
PyAPI_FUNC(int) _Py_IsFinalizing(void);
+PyAPI_FUNC(int) _Py_IsInterpreterFinalizing(PyInterpreterState *interp);
/* Random */
PyAPI_FUNC(int) _PyOS_URandom(void *buffer, Py_ssize_t size);
@@ -62,4 +63,49 @@ PyAPI_FUNC(int) _Py_CoerceLegacyLocale(int warn);
PyAPI_FUNC(int) _Py_LegacyLocaleDetected(int warn);
PyAPI_FUNC(char *) _Py_SetLocaleFromEnv(int category);
-PyAPI_FUNC(PyThreadState *) _Py_NewInterpreter(int isolated_subinterpreter);
+/* --- PyInterpreterConfig ------------------------------------ */
+
+#define PyInterpreterConfig_DEFAULT_GIL (0)
+#define PyInterpreterConfig_SHARED_GIL (1)
+#define PyInterpreterConfig_OWN_GIL (2)
+
+typedef struct {
+ // XXX "allow_object_sharing"? "own_objects"?
+ int use_main_obmalloc;
+ int allow_fork;
+ int allow_exec;
+ int allow_threads;
+ int allow_daemon_threads;
+ int check_multi_interp_extensions;
+ int gil;
+} PyInterpreterConfig;
+
+#define _PyInterpreterConfig_INIT \
+ { \
+ .use_main_obmalloc = 0, \
+ .allow_fork = 0, \
+ .allow_exec = 0, \
+ .allow_threads = 1, \
+ .allow_daemon_threads = 0, \
+ .check_multi_interp_extensions = 1, \
+ .gil = PyInterpreterConfig_OWN_GIL, \
+ }
+
+#define _PyInterpreterConfig_LEGACY_INIT \
+ { \
+ .use_main_obmalloc = 1, \
+ .allow_fork = 1, \
+ .allow_exec = 1, \
+ .allow_threads = 1, \
+ .allow_daemon_threads = 1, \
+ .check_multi_interp_extensions = 0, \
+ .gil = PyInterpreterConfig_SHARED_GIL, \
+ }
+
+PyAPI_FUNC(PyStatus) Py_NewInterpreterFromConfig(
+ PyThreadState **tstate_p,
+ const PyInterpreterConfig *config);
+
+typedef void (*atexit_datacallbackfunc)(void *);
+PyAPI_FUNC(int) _Py_AtExit(
+ PyInterpreterState *, atexit_datacallbackfunc, void *);
diff --git a/contrib/tools/python3/src/Include/cpython/pystate.h b/contrib/tools/python3/src/Include/cpython/pystate.h
index 2bd46067cb..628f2e0996 100644
--- a/contrib/tools/python3/src/Include/cpython/pystate.h
+++ b/contrib/tools/python3/src/Include/cpython/pystate.h
@@ -3,11 +3,46 @@
#endif
+/*
+Runtime Feature Flags
+
+Each flag indicate whether or not a specific runtime feature
+is available in a given context. For example, forking the process
+might not be allowed in the current interpreter (i.e. os.fork() would fail).
+*/
+
+/* Set if the interpreter share obmalloc runtime state
+ with the main interpreter. */
+#define Py_RTFLAGS_USE_MAIN_OBMALLOC (1UL << 5)
+
+/* Set if import should check a module for subinterpreter support. */
+#define Py_RTFLAGS_MULTI_INTERP_EXTENSIONS (1UL << 8)
+
+/* Set if threads are allowed. */
+#define Py_RTFLAGS_THREADS (1UL << 10)
+
+/* Set if daemon threads are allowed. */
+#define Py_RTFLAGS_DAEMON_THREADS (1UL << 11)
+
+/* Set if os.fork() is allowed. */
+#define Py_RTFLAGS_FORK (1UL << 15)
+
+/* Set if os.exec*() is allowed. */
+#define Py_RTFLAGS_EXEC (1UL << 16)
+
+
+PyAPI_FUNC(int) _PyInterpreterState_HasFeature(PyInterpreterState *interp,
+ unsigned long feature);
+
+
+/* private interpreter helpers */
+
PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *);
PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int);
PyAPI_FUNC(PyObject *) _PyInterpreterState_GetMainModule(PyInterpreterState *);
+
/* State unique per thread */
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
@@ -27,12 +62,6 @@ typedef int (*Py_tracefunc)(PyObject *, PyFrameObject *, int, PyObject *);
#define PyTrace_C_RETURN 6
#define PyTrace_OPCODE 7
-
-typedef struct {
- PyCodeObject *code; // The code object for the bounds. May be NULL.
- PyCodeAddressRange bounds; // Only valid if code != NULL.
-} PyTraceInfo;
-
// Internal structure: you should not use it directly, but use public functions
// like PyThreadState_EnterTracing() and PyThreadState_LeaveTracing().
typedef struct _PyCFrame {
@@ -46,7 +75,6 @@ typedef struct _PyCFrame {
* discipline and make sure that instances of this struct cannot
* accessed outside of their lifetime.
*/
- uint8_t use_tracing; // 0 or 255 (or'ed into opcode, hence 8-bit type)
/* Pointer to the currently executing frame (it can be NULL) */
struct _PyInterpreterFrame *current_frame;
struct _PyCFrame *previous;
@@ -79,6 +107,11 @@ typedef struct _stack_chunk {
PyObject * data[1]; /* Variable sized */
} _PyStackChunk;
+struct _py_trashcan {
+ int delete_nesting;
+ PyObject *delete_later;
+};
+
struct _ts {
/* See Python/ceval.c for comments explaining most fields */
@@ -86,24 +119,42 @@ struct _ts {
PyThreadState *next;
PyInterpreterState *interp;
- /* Has been initialized to a safe state.
+ struct {
+ /* Has been initialized to a safe state.
+
+ In order to be effective, this must be set to 0 during or right
+ after allocation. */
+ unsigned int initialized:1;
+
+ /* Has been bound to an OS thread. */
+ unsigned int bound:1;
+ /* Has been unbound from its OS thread. */
+ unsigned int unbound:1;
+ /* Has been bound aa current for the GILState API. */
+ unsigned int bound_gilstate:1;
+ /* Currently in use (maybe holds the GIL). */
+ unsigned int active:1;
- In order to be effective, this must be set to 0 during or right
- after allocation. */
- int _initialized;
+ /* various stages of finalization */
+ unsigned int finalizing:1;
+ unsigned int cleared:1;
+ unsigned int finalized:1;
- /* Was this thread state statically allocated? */
- int _static;
+ /* padding to align to 4 bytes */
+ unsigned int :24;
+ } _status;
- int recursion_remaining;
- int recursion_limit;
+ int py_recursion_remaining;
+ int py_recursion_limit;
+
+ int c_recursion_remaining;
int recursion_headroom; /* Allow 50 more calls to handle any errors. */
/* 'tracing' keeps track of the execution depth when tracing/profiling.
This is to prevent the actual trace/profile code from being recorded in
the trace/profile. */
int tracing;
- int tracing_what; /* The event currently being traced, if any. */
+ int what_event; /* The event currently being monitored, if any. */
/* Pointer to current _PyCFrame in the C stack frame of the currently,
* or most recently, executing _PyEval_EvalFrameDefault. */
@@ -115,9 +166,7 @@ struct _ts {
PyObject *c_traceobj;
/* The exception currently being raised */
- PyObject *curexc_type;
- PyObject *curexc_value;
- PyObject *curexc_traceback;
+ PyObject *current_exception;
/* Pointer to the top of the exception stack for the exceptions
* we may be currently handling. (See _PyErr_StackItem above.)
@@ -137,8 +186,7 @@ struct _ts {
*/
unsigned long native_thread_id;
- int trash_delete_nesting;
- PyObject *trash_delete_later;
+ struct _py_trashcan trash;
/* Called when a thread state is deleted normally, but not when it
* is destroyed after fork().
@@ -177,8 +225,6 @@ struct _ts {
/* Unique thread state id. */
uint64_t id;
- PyTraceInfo trace_info;
-
_PyStackChunk *datastack_chunk;
PyObject **datastack_top;
PyObject **datastack_limit;
@@ -202,12 +248,25 @@ struct _ts {
_PyCFrame root_cframe;
};
+/* WASI has limited call stack. Python's recursion limit depends on code
+ layout, optimization, and WASI runtime. Wasmtime can handle about 700
+ recursions, sometimes less. 500 is a more conservative limit. */
+#ifndef C_RECURSION_LIMIT
+# ifdef __wasi__
+# define C_RECURSION_LIMIT 500
+# else
+ // This value is duplicated in Lib/test/support/__init__.py
+# define C_RECURSION_LIMIT 1500
+# endif
+#endif
/* other API */
// Alias for backward compatibility with Python 3.8
#define _PyInterpreterState_Get PyInterpreterState_Get
+/* An alias for the internal _PyThreadState_New(),
+ kept for stable ABI compatibility. */
PyAPI_FUNC(PyThreadState *) _PyThreadState_Prealloc(PyInterpreterState *);
/* Similar to PyThreadState_Get(), but don't issue a fatal error
@@ -279,7 +338,10 @@ PyAPI_FUNC(const PyConfig*) _PyInterpreterState_GetConfig(PyInterpreterState *in
for example.
Python must be preinitialized to call this method.
- The caller must hold the GIL. */
+ The caller must hold the GIL.
+
+ Once done with the configuration, PyConfig_Clear() must be called to clear
+ it. */
PyAPI_FUNC(int) _PyInterpreterState_GetConfigCopy(
struct PyConfig *config);
@@ -313,6 +375,9 @@ PyAPI_FUNC(const PyConfig*) _Py_GetConfig(void);
// is necessary to pass safely between interpreters in the same process.
typedef struct _xid _PyCrossInterpreterData;
+typedef PyObject *(*xid_newobjectfunc)(_PyCrossInterpreterData *);
+typedef void (*xid_freefunc)(void *);
+
struct _xid {
// data is the cross-interpreter-safe derivation of a Python object
// (see _PyObject_GetCrossInterpreterData). It will be NULL if the
@@ -339,7 +404,7 @@ struct _xid {
// interpreter given the data. The resulting object (a new
// reference) will be equivalent to the original object. This field
// is required.
- PyObject *(*new_object)(_PyCrossInterpreterData *);
+ xid_newobjectfunc new_object;
// free is called when the data is released. If it is NULL then
// nothing will be done to free the data. For some types this is
// okay (e.g. bytes) and for those types this field should be set
@@ -349,18 +414,31 @@ struct _xid {
// leak. In that case, at the very least this field should be set
// to PyMem_RawFree (the default if not explicitly set to NULL).
// The call will happen with the original interpreter activated.
- void (*free)(void *);
+ xid_freefunc free;
};
+PyAPI_FUNC(void) _PyCrossInterpreterData_Init(
+ _PyCrossInterpreterData *data,
+ PyInterpreterState *interp, void *shared, PyObject *obj,
+ xid_newobjectfunc new_object);
+PyAPI_FUNC(int) _PyCrossInterpreterData_InitWithSize(
+ _PyCrossInterpreterData *,
+ PyInterpreterState *interp, const size_t, PyObject *,
+ xid_newobjectfunc);
+PyAPI_FUNC(void) _PyCrossInterpreterData_Clear(
+ PyInterpreterState *, _PyCrossInterpreterData *);
+
PyAPI_FUNC(int) _PyObject_GetCrossInterpreterData(PyObject *, _PyCrossInterpreterData *);
PyAPI_FUNC(PyObject *) _PyCrossInterpreterData_NewObject(_PyCrossInterpreterData *);
-PyAPI_FUNC(void) _PyCrossInterpreterData_Release(_PyCrossInterpreterData *);
+PyAPI_FUNC(int) _PyCrossInterpreterData_Release(_PyCrossInterpreterData *);
PyAPI_FUNC(int) _PyObject_CheckCrossInterpreterData(PyObject *);
/* cross-interpreter data registry */
-typedef int (*crossinterpdatafunc)(PyObject *, _PyCrossInterpreterData *);
+typedef int (*crossinterpdatafunc)(PyThreadState *tstate, PyObject *,
+ _PyCrossInterpreterData *);
PyAPI_FUNC(int) _PyCrossInterpreterData_RegisterClass(PyTypeObject *, crossinterpdatafunc);
+PyAPI_FUNC(int) _PyCrossInterpreterData_UnregisterClass(PyTypeObject *);
PyAPI_FUNC(crossinterpdatafunc) _PyCrossInterpreterData_Lookup(PyObject *);
diff --git a/contrib/tools/python3/src/Include/cpython/pythonrun.h b/contrib/tools/python3/src/Include/cpython/pythonrun.h
index 2e72d0820d..fb61765537 100644
--- a/contrib/tools/python3/src/Include/cpython/pythonrun.h
+++ b/contrib/tools/python3/src/Include/cpython/pythonrun.h
@@ -66,8 +66,8 @@ PyAPI_FUNC(PyObject *) Py_CompileStringObject(
PyCompilerFlags *flags,
int optimize);
-#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
-#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
+#define Py_CompileString(str, p, s) Py_CompileStringExFlags((str), (p), (s), NULL, -1)
+#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags((str), (p), (s), (f), -1)
PyAPI_FUNC(const char *) _Py_SourceAsString(
@@ -96,23 +96,23 @@ PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g,
PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags);
/* Use macros for a bunch of old variants */
-#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
-#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
+#define PyRun_String(str, s, g, l) PyRun_StringFlags((str), (s), (g), (l), NULL)
+#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags((fp), (name), 0, NULL)
#define PyRun_AnyFileEx(fp, name, closeit) \
- PyRun_AnyFileExFlags(fp, name, closeit, NULL)
+ PyRun_AnyFileExFlags((fp), (name), (closeit), NULL)
#define PyRun_AnyFileFlags(fp, name, flags) \
- PyRun_AnyFileExFlags(fp, name, 0, flags)
-#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
-#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
-#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
-#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
-#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
+ PyRun_AnyFileExFlags((fp), (name), 0, (flags))
+#define PyRun_SimpleString(s) PyRun_SimpleStringFlags((s), NULL)
+#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags((f), (p), 0, NULL)
+#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags((f), (p), (c), NULL)
+#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags((f), (p), NULL)
+#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags((f), (p), NULL)
#define PyRun_File(fp, p, s, g, l) \
- PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
+ PyRun_FileExFlags((fp), (p), (s), (g), (l), 0, NULL)
#define PyRun_FileEx(fp, p, s, g, l, c) \
- PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
+ PyRun_FileExFlags((fp), (p), (s), (g), (l), (c), NULL)
#define PyRun_FileFlags(fp, p, s, g, l, flags) \
- PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
+ PyRun_FileExFlags((fp), (p), (s), (g), (l), 0, (flags))
/* Stuff with no proper home (yet) */
diff --git a/contrib/tools/python3/src/Include/cpython/pytime.h b/contrib/tools/python3/src/Include/cpython/pytime.h
index 386e18a1a9..6891bd5c03 100644
--- a/contrib/tools/python3/src/Include/cpython/pytime.h
+++ b/contrib/tools/python3/src/Include/cpython/pytime.h
@@ -55,6 +55,10 @@ functions and constants
extern "C" {
#endif
+#ifdef __clang__
+struct timeval;
+#endif
+
/* _PyTime_t: Python timestamp with subsecond precision. It can be used to
store a duration, and so indirectly a date (related to another date, like
UNIX epoch). */
@@ -132,6 +136,10 @@ PyAPI_FUNC(_PyTime_t) _PyTime_FromSeconds(int seconds);
/* Create a timestamp from a number of nanoseconds. */
PyAPI_FUNC(_PyTime_t) _PyTime_FromNanoseconds(_PyTime_t ns);
+/* Create a timestamp from a number of microseconds.
+ * Clamp to [_PyTime_MIN; _PyTime_MAX] on overflow. */
+PyAPI_FUNC(_PyTime_t) _PyTime_FromMicrosecondsClamp(_PyTime_t us);
+
/* Create a timestamp from nanoseconds (Python int). */
PyAPI_FUNC(int) _PyTime_FromNanosecondsObject(_PyTime_t *t,
PyObject *obj);
diff --git a/contrib/tools/python3/src/Include/cpython/setobject.h b/contrib/tools/python3/src/Include/cpython/setobject.h
index b4443a678b..20fd63eaae 100644
--- a/contrib/tools/python3/src/Include/cpython/setobject.h
+++ b/contrib/tools/python3/src/Include/cpython/setobject.h
@@ -58,8 +58,13 @@ typedef struct {
PyObject *weakreflist; /* List of weak references */
} PySetObject;
-#define PySet_GET_SIZE(so) \
- (assert(PyAnySet_Check(so)), (((PySetObject *)(so))->used))
+#define _PySet_CAST(so) \
+ (assert(PyAnySet_Check(so)), _Py_CAST(PySetObject*, so))
+
+static inline Py_ssize_t PySet_GET_SIZE(PyObject *so) {
+ return _PySet_CAST(so)->used;
+}
+#define PySet_GET_SIZE(so) PySet_GET_SIZE(_PyObject_CAST(so))
PyAPI_DATA(PyObject *) _PySet_Dummy;
diff --git a/contrib/tools/python3/src/Include/cpython/tupleobject.h b/contrib/tools/python3/src/Include/cpython/tupleobject.h
index 3d9c1aff58..f6a1f076e0 100644
--- a/contrib/tools/python3/src/Include/cpython/tupleobject.h
+++ b/contrib/tools/python3/src/Include/cpython/tupleobject.h
@@ -23,11 +23,9 @@ static inline Py_ssize_t PyTuple_GET_SIZE(PyObject *op) {
PyTupleObject *tuple = _PyTuple_CAST(op);
return Py_SIZE(tuple);
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
-#endif
+#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))
-#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[index])
+#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])
/* Function *only* to be used to fill in brand new tuples */
static inline void
@@ -35,9 +33,7 @@ PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
PyTupleObject *tuple = _PyTuple_CAST(op);
tuple->ob_item[index] = value;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
#define PyTuple_SET_ITEM(op, index, value) \
- PyTuple_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value))
-#endif
+ PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);
diff --git a/contrib/tools/python3/src/Include/cpython/unicodeobject.h b/contrib/tools/python3/src/Include/cpython/unicodeobject.h
index 84307d1885..f177cd9e2a 100644
--- a/contrib/tools/python3/src/Include/cpython/unicodeobject.h
+++ b/contrib/tools/python3/src/Include/cpython/unicodeobject.h
@@ -11,63 +11,43 @@
/* --- Internal Unicode Operations ---------------------------------------- */
-#ifndef USE_UNICODE_WCHAR_CACHE
-# define USE_UNICODE_WCHAR_CACHE 1
-#endif /* USE_UNICODE_WCHAR_CACHE */
-
-/* Since splitting on whitespace is an important use case, and
- whitespace in most situations is solely ASCII whitespace, we
- optimize for the common case by using a quick look-up table
- _Py_ascii_whitespace (see below) with an inlined check.
-
- */
-#define Py_UNICODE_ISSPACE(ch) \
- ((Py_UCS4)(ch) < 128U ? _Py_ascii_whitespace[(ch)] : _PyUnicode_IsWhitespace(ch))
-
-#define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)
-#define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)
-#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
-#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)
-
-#define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch)
-#define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch)
-#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)
-
-#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
-#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
-#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
-#define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
+// Static inline functions to work with surrogates
+static inline int Py_UNICODE_IS_SURROGATE(Py_UCS4 ch) {
+ return (0xD800 <= ch && ch <= 0xDFFF);
+}
+static inline int Py_UNICODE_IS_HIGH_SURROGATE(Py_UCS4 ch) {
+ return (0xD800 <= ch && ch <= 0xDBFF);
+}
+static inline int Py_UNICODE_IS_LOW_SURROGATE(Py_UCS4 ch) {
+ return (0xDC00 <= ch && ch <= 0xDFFF);
+}
-#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
-#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
-#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)
+// Join two surrogate characters and return a single Py_UCS4 value.
+static inline Py_UCS4 Py_UNICODE_JOIN_SURROGATES(Py_UCS4 high, Py_UCS4 low) {
+ assert(Py_UNICODE_IS_HIGH_SURROGATE(high));
+ assert(Py_UNICODE_IS_LOW_SURROGATE(low));
+ return 0x10000 + (((high & 0x03FF) << 10) | (low & 0x03FF));
+}
-#define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch)
+// High surrogate = top 10 bits added to 0xD800.
+// The character must be in the range [U+10000; U+10ffff].
+static inline Py_UCS4 Py_UNICODE_HIGH_SURROGATE(Py_UCS4 ch) {
+ assert(0x10000 <= ch && ch <= 0x10ffff);
+ return (0xD800 - (0x10000 >> 10) + (ch >> 10));
+}
-#define Py_UNICODE_ISALNUM(ch) \
- (Py_UNICODE_ISALPHA(ch) || \
- Py_UNICODE_ISDECIMAL(ch) || \
- Py_UNICODE_ISDIGIT(ch) || \
- Py_UNICODE_ISNUMERIC(ch))
-
-/* macros to work with surrogates */
-#define Py_UNICODE_IS_SURROGATE(ch) (0xD800 <= (ch) && (ch) <= 0xDFFF)
-#define Py_UNICODE_IS_HIGH_SURROGATE(ch) (0xD800 <= (ch) && (ch) <= 0xDBFF)
-#define Py_UNICODE_IS_LOW_SURROGATE(ch) (0xDC00 <= (ch) && (ch) <= 0xDFFF)
-/* Join two surrogate characters and return a single Py_UCS4 value. */
-#define Py_UNICODE_JOIN_SURROGATES(high, low) \
- (((((Py_UCS4)(high) & 0x03FF) << 10) | \
- ((Py_UCS4)(low) & 0x03FF)) + 0x10000)
-/* high surrogate = top 10 bits added to D800 */
-#define Py_UNICODE_HIGH_SURROGATE(ch) (0xD800 - (0x10000 >> 10) + ((ch) >> 10))
-/* low surrogate = bottom 10 bits added to DC00 */
-#define Py_UNICODE_LOW_SURROGATE(ch) (0xDC00 + ((ch) & 0x3FF))
+// Low surrogate = bottom 10 bits added to 0xDC00.
+// The character must be in the range [U+10000; U+10ffff].
+static inline Py_UCS4 Py_UNICODE_LOW_SURROGATE(Py_UCS4 ch) {
+ assert(0x10000 <= ch && ch <= 0x10ffff);
+ return (0xDC00 + (ch & 0x3FF));
+}
/* --- Unicode Type ------------------------------------------------------- */
/* ASCII-only strings created through PyUnicode_New use the PyASCIIObject
structure. state.ascii and state.compact are set, and the data
- immediately follow the structure. utf8_length and wstr_length can be found
+ immediately follow the structure. utf8_length can be found
in the length field; the utf8 pointer is equal to the data pointer. */
typedef struct {
/* There are 4 forms of Unicode strings:
@@ -79,8 +59,7 @@ typedef struct {
* kind = PyUnicode_1BYTE_KIND
* compact = 1
* ascii = 1
- * ready = 1
- * (length is the length of the utf8 and wstr strings)
+ * (length is the length of the utf8)
* (data starts just after the structure)
* (since ASCII is decoded from UTF-8, the utf8 string are the data)
@@ -91,55 +70,27 @@ typedef struct {
* kind = PyUnicode_1BYTE_KIND, PyUnicode_2BYTE_KIND or
PyUnicode_4BYTE_KIND
* compact = 1
- * ready = 1
* ascii = 0
* utf8 is not shared with data
* utf8_length = 0 if utf8 is NULL
- * wstr is shared with data and wstr_length=length
- if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2
- or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_t)=4
- * wstr_length = 0 if wstr is NULL
* (data starts just after the structure)
- - legacy string, not ready:
-
- * structure = PyUnicodeObject
- * test: kind == PyUnicode_WCHAR_KIND
- * length = 0 (use wstr_length)
- * hash = -1
- * kind = PyUnicode_WCHAR_KIND
- * compact = 0
- * ascii = 0
- * ready = 0
- * interned = SSTATE_NOT_INTERNED
- * wstr is not NULL
- * data.any is NULL
- * utf8 is NULL
- * utf8_length = 0
-
- - legacy string, ready:
+ - legacy string:
* structure = PyUnicodeObject structure
- * test: !PyUnicode_IS_COMPACT(op) && kind != PyUnicode_WCHAR_KIND
+ * test: !PyUnicode_IS_COMPACT(op)
* kind = PyUnicode_1BYTE_KIND, PyUnicode_2BYTE_KIND or
PyUnicode_4BYTE_KIND
* compact = 0
- * ready = 1
* data.any is not NULL
* utf8 is shared and utf8_length = length with data.any if ascii = 1
* utf8_length = 0 if utf8 is NULL
- * wstr is shared with data.any and wstr_length = length
- if kind=PyUnicode_2BYTE_KIND and sizeof(wchar_t)=2
- or if kind=PyUnicode_4BYTE_KIND and sizeof(wchar_4)=4
- * wstr_length = 0 if wstr is NULL
Compact strings use only one memory block (structure + characters),
whereas legacy strings use one block for the structure and one block
for characters.
- Legacy strings are created by PyUnicode_FromUnicode() and
- PyUnicode_FromStringAndSize(NULL, size) functions. They become ready
- when PyUnicode_READY() is called.
+ Legacy strings are created by subclasses of Unicode.
See also _PyUnicode_CheckConsistency().
*/
@@ -147,22 +98,18 @@ typedef struct {
Py_ssize_t length; /* Number of code points in the string */
Py_hash_t hash; /* Hash value; -1 if not set */
struct {
- /*
- SSTATE_NOT_INTERNED (0)
- SSTATE_INTERNED_MORTAL (1)
- SSTATE_INTERNED_IMMORTAL (2)
-
- If interned != SSTATE_NOT_INTERNED, the two references from the
+ /* If interned is non-zero, the two references from the
dictionary to this object are *not* counted in ob_refcnt.
- */
+ The possible values here are:
+ 0: Not Interned
+ 1: Interned
+ 2: Interned and Immortal
+ 3: Interned, Immortal, and Static
+ This categorization allows the runtime to determine the right
+ cleanup mechanism at runtime shutdown. */
unsigned int interned:2;
/* Character size:
- - PyUnicode_WCHAR_KIND (0):
-
- * character type = wchar_t (16 or 32 bits, depending on the
- platform)
-
- PyUnicode_1BYTE_KIND (1):
* character type = Py_UCS1 (8 bits, unsigned)
@@ -193,16 +140,12 @@ typedef struct {
and the kind is PyUnicode_1BYTE_KIND. If ascii is set and compact is
set, use the PyASCIIObject structure. */
unsigned int ascii:1;
- /* The ready flag indicates whether the object layout is initialized
- completely. This means that this is either a compact object, or
- the data pointer is filled out. The bit is redundant, and helps
- to minimize the test in PyUnicode_IS_READY(). */
- unsigned int ready:1;
+ /* The object is statically allocated. */
+ unsigned int statically_allocated:1;
/* Padding to ensure that PyUnicode_DATA() is always aligned to
4 bytes (see issue #19537 on m68k). */
unsigned int :24;
} state;
- wchar_t *wstr; /* wchar_t representation (null-terminated) */
} PyASCIIObject;
/* Non-ASCII strings allocated through PyUnicode_New use the
@@ -213,13 +156,9 @@ typedef struct {
Py_ssize_t utf8_length; /* Number of bytes in utf8, excluding the
* terminating \0. */
char *utf8; /* UTF-8 representation (null-terminated) */
- Py_ssize_t wstr_length; /* Number of code points in wstr, possible
- * surrogates count as two code points. */
} PyCompactUnicodeObject;
-/* Strings allocated through PyUnicode_FromUnicode(NULL, len) use the
- PyUnicodeObject structure. The actual string data is initially in the wstr
- block, and copied into the data block using _PyUnicode_Ready. */
+/* Object format for Unicode subclasses. */
typedef struct {
PyCompactUnicodeObject _base;
union {
@@ -254,68 +193,56 @@ PyAPI_FUNC(int) _PyUnicode_CheckConsistency(
#define SSTATE_NOT_INTERNED 0
#define SSTATE_INTERNED_MORTAL 1
#define SSTATE_INTERNED_IMMORTAL 2
+#define SSTATE_INTERNED_IMMORTAL_STATIC 3
/* Use only if you know it's a string */
static inline unsigned int PyUnicode_CHECK_INTERNED(PyObject *op) {
return _PyASCIIObject_CAST(op)->state.interned;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
-#endif
+#define PyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
-/* Fast check to determine whether an object is ready. Equivalent to:
- PyUnicode_IS_COMPACT(op) || _PyUnicodeObject_CAST(op)->data.any */
-static inline unsigned int PyUnicode_IS_READY(PyObject *op) {
- return _PyASCIIObject_CAST(op)->state.ready;
+/* For backward compatibility */
+static inline unsigned int PyUnicode_IS_READY(PyObject* Py_UNUSED(op)) {
+ return 1;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_IS_READY(op) PyUnicode_IS_READY(_PyObject_CAST(op))
-#endif
+#define PyUnicode_IS_READY(op) PyUnicode_IS_READY(_PyObject_CAST(op))
/* Return true if the string contains only ASCII characters, or 0 if not. The
string may be compact (PyUnicode_IS_COMPACT_ASCII) or not, but must be
ready. */
static inline unsigned int PyUnicode_IS_ASCII(PyObject *op) {
- assert(PyUnicode_IS_READY(op));
return _PyASCIIObject_CAST(op)->state.ascii;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_IS_ASCII(op) PyUnicode_IS_ASCII(_PyObject_CAST(op))
-#endif
+#define PyUnicode_IS_ASCII(op) PyUnicode_IS_ASCII(_PyObject_CAST(op))
/* Return true if the string is compact or 0 if not.
No type checks or Ready calls are performed. */
static inline unsigned int PyUnicode_IS_COMPACT(PyObject *op) {
return _PyASCIIObject_CAST(op)->state.compact;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_IS_COMPACT(op) PyUnicode_IS_COMPACT(_PyObject_CAST(op))
-#endif
+#define PyUnicode_IS_COMPACT(op) PyUnicode_IS_COMPACT(_PyObject_CAST(op))
/* Return true if the string is a compact ASCII string (use PyASCIIObject
structure), or 0 if not. No type checks or Ready calls are performed. */
static inline int PyUnicode_IS_COMPACT_ASCII(PyObject *op) {
return (_PyASCIIObject_CAST(op)->state.ascii && PyUnicode_IS_COMPACT(op));
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_IS_COMPACT_ASCII(op) PyUnicode_IS_COMPACT_ASCII(_PyObject_CAST(op))
-#endif
+#define PyUnicode_IS_COMPACT_ASCII(op) PyUnicode_IS_COMPACT_ASCII(_PyObject_CAST(op))
enum PyUnicode_Kind {
-/* String contains only wstr byte characters. This is only possible
- when the string was created with a legacy API and _PyUnicode_Ready()
- has not been called yet. */
- PyUnicode_WCHAR_KIND = 0,
/* Return values of the PyUnicode_KIND() function: */
PyUnicode_1BYTE_KIND = 1,
PyUnicode_2BYTE_KIND = 2,
PyUnicode_4BYTE_KIND = 4
};
-/* Return one of the PyUnicode_*_KIND values defined above. */
-#define PyUnicode_KIND(op) \
- (assert(PyUnicode_IS_READY(op)), \
- _PyASCIIObject_CAST(op)->state.kind)
+// PyUnicode_KIND(): Return one of the PyUnicode_*_KIND values defined above.
+//
+// gh-89653: Converting this macro to a static inline function would introduce
+// new compiler warnings on "kind < PyUnicode_KIND(str)" (compare signed and
+// unsigned numbers) where kind type is an int or on
+// "unsigned int kind = PyUnicode_KIND(str)" (cast signed to unsigned).
+#define PyUnicode_KIND(op) _Py_RVALUE(_PyASCIIObject_CAST(op)->state.kind)
/* Return a void pointer to the raw unicode buffer. */
static inline void* _PyUnicode_COMPACT_DATA(PyObject *op) {
@@ -339,9 +266,7 @@ static inline void* PyUnicode_DATA(PyObject *op) {
}
return _PyUnicode_NONCOMPACT_DATA(op);
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_DATA(op) PyUnicode_DATA(_PyObject_CAST(op))
-#endif
+#define PyUnicode_DATA(op) PyUnicode_DATA(_PyObject_CAST(op))
/* Return pointers to the canonical representation cast to unsigned char,
Py_UCS2, or Py_UCS4 for direct character access.
@@ -352,16 +277,11 @@ static inline void* PyUnicode_DATA(PyObject *op) {
#define PyUnicode_2BYTE_DATA(op) _Py_STATIC_CAST(Py_UCS2*, PyUnicode_DATA(op))
#define PyUnicode_4BYTE_DATA(op) _Py_STATIC_CAST(Py_UCS4*, PyUnicode_DATA(op))
-/* Returns the length of the unicode string. The caller has to make sure that
- the string has it's canonical representation set before calling
- this function. Call PyUnicode_(FAST_)Ready to ensure that. */
+/* Returns the length of the unicode string. */
static inline Py_ssize_t PyUnicode_GET_LENGTH(PyObject *op) {
- assert(PyUnicode_IS_READY(op));
return _PyASCIIObject_CAST(op)->length;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
-#endif
+#define PyUnicode_GET_LENGTH(op) PyUnicode_GET_LENGTH(_PyObject_CAST(op))
/* Write into the canonical representation, this function does not do any sanity
checks and is intended for usage in loops. The caller should cache the
@@ -371,6 +291,7 @@ static inline Py_ssize_t PyUnicode_GET_LENGTH(PyObject *op) {
static inline void PyUnicode_WRITE(int kind, void *data,
Py_ssize_t index, Py_UCS4 value)
{
+ assert(index >= 0);
if (kind == PyUnicode_1BYTE_KIND) {
assert(value <= 0xffU);
_Py_STATIC_CAST(Py_UCS1*, data)[index] = _Py_STATIC_CAST(Py_UCS1, value);
@@ -385,17 +306,16 @@ static inline void PyUnicode_WRITE(int kind, void *data,
_Py_STATIC_CAST(Py_UCS4*, data)[index] = value;
}
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
#define PyUnicode_WRITE(kind, data, index, value) \
PyUnicode_WRITE(_Py_STATIC_CAST(int, kind), _Py_CAST(void*, data), \
(index), _Py_STATIC_CAST(Py_UCS4, value))
-#endif
/* Read a code point from the string's canonical representation. No checks
or ready calls are performed. */
static inline Py_UCS4 PyUnicode_READ(int kind,
const void *data, Py_ssize_t index)
{
+ assert(index >= 0);
if (kind == PyUnicode_1BYTE_KIND) {
return _Py_STATIC_CAST(const Py_UCS1*, data)[index];
}
@@ -405,12 +325,10 @@ static inline Py_UCS4 PyUnicode_READ(int kind,
assert(kind == PyUnicode_4BYTE_KIND);
return _Py_STATIC_CAST(const Py_UCS4*, data)[index];
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
#define PyUnicode_READ(kind, data, index) \
PyUnicode_READ(_Py_STATIC_CAST(int, kind), \
_Py_STATIC_CAST(const void*, data), \
(index))
-#endif
/* PyUnicode_READ_CHAR() is less efficient than PyUnicode_READ() because it
calls PyUnicode_KIND() and might call it twice. For single reads, use
@@ -419,7 +337,11 @@ static inline Py_UCS4 PyUnicode_READ(int kind,
static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
{
int kind;
- assert(PyUnicode_IS_READY(unicode));
+
+ assert(index >= 0);
+ // Tolerate reading the NUL character at str[len(str)]
+ assert(index <= PyUnicode_GET_LENGTH(unicode));
+
kind = PyUnicode_KIND(unicode);
if (kind == PyUnicode_1BYTE_KIND) {
return PyUnicode_1BYTE_DATA(unicode)[index];
@@ -430,10 +352,8 @@ static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
assert(kind == PyUnicode_4BYTE_KIND);
return PyUnicode_4BYTE_DATA(unicode)[index];
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_READ_CHAR(unicode, index) \
- PyUnicode_READ_CHAR(_PyObject_CAST(unicode), (index))
-#endif
+#define PyUnicode_READ_CHAR(unicode, index) \
+ PyUnicode_READ_CHAR(_PyObject_CAST(unicode), (index))
/* Return a maximum character value which is suitable for creating another
string based on op. This is always an approximation but more efficient
@@ -442,7 +362,6 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
{
int kind;
- assert(PyUnicode_IS_READY(op));
if (PyUnicode_IS_ASCII(op)) {
return 0x7fU;
}
@@ -457,10 +376,8 @@ static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
assert(kind == PyUnicode_4BYTE_KIND);
return 0x10ffffU;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_MAX_CHAR_VALUE(op) \
- PyUnicode_MAX_CHAR_VALUE(_PyObject_CAST(op))
-#endif
+#define PyUnicode_MAX_CHAR_VALUE(op) \
+ PyUnicode_MAX_CHAR_VALUE(_PyObject_CAST(op))
/* === Public API ========================================================= */
@@ -474,31 +391,12 @@ PyAPI_FUNC(PyObject*) PyUnicode_New(
Py_UCS4 maxchar /* maximum code point value in the string */
);
-/* Initializes the canonical string representation from the deprecated
- wstr/Py_UNICODE representation. This function is used to convert Unicode
- objects which were created using the old API to the new flexible format
- introduced with PEP 393.
-
- Don't call this function directly, use the public PyUnicode_READY() function
- instead. */
-PyAPI_FUNC(int) _PyUnicode_Ready(
- PyObject *unicode /* Unicode object */
- );
-
-/* PyUnicode_READY() does less work than _PyUnicode_Ready() in the best
- case. If the canonical representation is not yet set, it will still call
- _PyUnicode_Ready().
- Returns 0 on success and -1 on errors. */
-static inline int PyUnicode_READY(PyObject *op)
+/* For backward compatibility */
+static inline int PyUnicode_READY(PyObject* Py_UNUSED(op))
{
- if (PyUnicode_IS_READY(op)) {
- return 0;
- }
- return _PyUnicode_Ready(op);
+ return 0;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_READY(op) PyUnicode_READY(_PyObject_CAST(op))
-#endif
+#define PyUnicode_READY(op) PyUnicode_READY(_PyObject_CAST(op))
/* Get a copy of a Unicode string. */
PyAPI_FUNC(PyObject*) _PyUnicode_Copy(
@@ -586,139 +484,12 @@ PyAPI_FUNC(Py_UCS4) _PyUnicode_FindMaxChar (
Py_ssize_t start,
Py_ssize_t end);
-/* --- Legacy deprecated API ---------------------------------------------- */
-
-/* Create a Unicode Object from the Py_UNICODE buffer u of the given
- size.
-
- u may be NULL which causes the contents to be undefined. It is the
- user's responsibility to fill in the needed data afterwards. Note
- that modifying the Unicode object contents after construction is
- only allowed if u was set to NULL.
-
- The buffer is copied into the new object. */
-Py_DEPRECATED(3.3) PyAPI_FUNC(PyObject*) PyUnicode_FromUnicode(
- const Py_UNICODE *u, /* Unicode buffer */
- Py_ssize_t size /* size of buffer */
- );
-
-/* Return a read-only pointer to the Unicode object's internal
- Py_UNICODE buffer.
- If the wchar_t/Py_UNICODE representation is not yet available, this
- function will calculate it. */
-Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicode(
- PyObject *unicode /* Unicode object */
- );
-
-/* Similar to PyUnicode_AsUnicode(), but raises a ValueError if the string
- contains null characters. */
-PyAPI_FUNC(const Py_UNICODE *) _PyUnicode_AsUnicode(
- PyObject *unicode /* Unicode object */
- );
-
-/* Return a read-only pointer to the Unicode object's internal
- Py_UNICODE buffer and save the length at size.
- If the wchar_t/Py_UNICODE representation is not yet available, this
- function will calculate it. */
-
-Py_DEPRECATED(3.3) PyAPI_FUNC(Py_UNICODE *) PyUnicode_AsUnicodeAndSize(
- PyObject *unicode, /* Unicode object */
- Py_ssize_t *size /* location where to save the length */
- );
-
-
-/* Fast access macros */
-
-Py_DEPRECATED(3.3)
-static inline Py_ssize_t PyUnicode_WSTR_LENGTH(PyObject *op)
-{
- if (PyUnicode_IS_COMPACT_ASCII(op)) {
- return _PyASCIIObject_CAST(op)->length;
- }
- else {
- return _PyCompactUnicodeObject_CAST(op)->wstr_length;
- }
-}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_WSTR_LENGTH(op) PyUnicode_WSTR_LENGTH(_PyObject_CAST(op))
-#endif
-
-/* Returns the deprecated Py_UNICODE representation's size in code units
- (this includes surrogate pairs as 2 units).
- If the Py_UNICODE representation is not available, it will be computed
- on request. Use PyUnicode_GET_LENGTH() for the length in code points. */
-
-Py_DEPRECATED(3.3)
-static inline Py_ssize_t PyUnicode_GET_SIZE(PyObject *op)
-{
- _Py_COMP_DIAG_PUSH
- _Py_COMP_DIAG_IGNORE_DEPR_DECLS
- if (_PyASCIIObject_CAST(op)->wstr == _Py_NULL) {
- (void)PyUnicode_AsUnicode(op);
- assert(_PyASCIIObject_CAST(op)->wstr != _Py_NULL);
- }
- return PyUnicode_WSTR_LENGTH(op);
- _Py_COMP_DIAG_POP
-}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_GET_SIZE(op) PyUnicode_GET_SIZE(_PyObject_CAST(op))
-#endif
-
-Py_DEPRECATED(3.3)
-static inline Py_ssize_t PyUnicode_GET_DATA_SIZE(PyObject *op)
-{
- _Py_COMP_DIAG_PUSH
- _Py_COMP_DIAG_IGNORE_DEPR_DECLS
- return PyUnicode_GET_SIZE(op) * Py_UNICODE_SIZE;
- _Py_COMP_DIAG_POP
-}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_GET_DATA_SIZE(op) PyUnicode_GET_DATA_SIZE(_PyObject_CAST(op))
-#endif
-
-/* Alias for PyUnicode_AsUnicode(). This will create a wchar_t/Py_UNICODE
- representation on demand. Using this macro is very inefficient now,
- try to port your code to use the new PyUnicode_*BYTE_DATA() macros or
- use PyUnicode_WRITE() and PyUnicode_READ(). */
-
-Py_DEPRECATED(3.3)
-static inline Py_UNICODE* PyUnicode_AS_UNICODE(PyObject *op)
-{
- wchar_t *wstr = _PyASCIIObject_CAST(op)->wstr;
- if (wstr != _Py_NULL) {
- return wstr;
- }
-
- _Py_COMP_DIAG_PUSH
- _Py_COMP_DIAG_IGNORE_DEPR_DECLS
- return PyUnicode_AsUnicode(op);
- _Py_COMP_DIAG_POP
-}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_AS_UNICODE(op) PyUnicode_AS_UNICODE(_PyObject_CAST(op))
-#endif
-
-Py_DEPRECATED(3.3)
-static inline const char* PyUnicode_AS_DATA(PyObject *op)
-{
- _Py_COMP_DIAG_PUSH
- _Py_COMP_DIAG_IGNORE_DEPR_DECLS
- Py_UNICODE *data = PyUnicode_AS_UNICODE(op);
- // In C++, casting directly PyUnicode* to const char* is not valid
- return _Py_STATIC_CAST(const char*, _Py_STATIC_CAST(const void*, data));
- _Py_COMP_DIAG_POP
-}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyUnicode_AS_DATA(op) PyUnicode_AS_DATA(_PyObject_CAST(op))
-#endif
-
-
/* --- _PyUnicodeWriter API ----------------------------------------------- */
typedef struct {
PyObject *buffer;
void *data;
- enum PyUnicode_Kind kind;
+ int kind;
Py_UCS4 maxchar;
Py_ssize_t size;
Py_ssize_t pos;
@@ -769,8 +540,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
Return 0 on success, raise an exception and return -1 on error. */
#define _PyUnicodeWriter_PrepareKind(WRITER, KIND) \
- (assert((KIND) != PyUnicode_WCHAR_KIND), \
- (KIND) <= (WRITER)->kind \
+ ((KIND) <= (WRITER)->kind \
? 0 \
: _PyUnicodeWriter_PrepareKindInternal((WRITER), (KIND)))
@@ -778,7 +548,7 @@ _PyUnicodeWriter_PrepareInternal(_PyUnicodeWriter *writer,
macro instead. */
PyAPI_FUNC(int)
_PyUnicodeWriter_PrepareKindInternal(_PyUnicodeWriter *writer,
- enum PyUnicode_Kind kind);
+ int kind);
/* Append a Unicode character.
Return 0 on success, raise an exception and return -1 on error. */
@@ -1024,10 +794,6 @@ PyAPI_FUNC(Py_ssize_t) _PyUnicode_InsertThousandsGrouping(
/* === Characters Type APIs =============================================== */
-/* Helper array used by Py_UNICODE_ISSPACE(). */
-
-PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[];
-
/* These should not be used directly. Use the Py_UNICODE_IS* and
Py_UNICODE_TO* macros instead.
@@ -1135,6 +901,50 @@ PyAPI_FUNC(int) _PyUnicode_IsAlpha(
Py_UCS4 ch /* Unicode character */
);
+// Helper array used by Py_UNICODE_ISSPACE().
+PyAPI_DATA(const unsigned char) _Py_ascii_whitespace[];
+
+// Since splitting on whitespace is an important use case, and
+// whitespace in most situations is solely ASCII whitespace, we
+// optimize for the common case by using a quick look-up table
+// _Py_ascii_whitespace (see below) with an inlined check.
+static inline int Py_UNICODE_ISSPACE(Py_UCS4 ch) {
+ if (ch < 128) {
+ return _Py_ascii_whitespace[ch];
+ }
+ return _PyUnicode_IsWhitespace(ch);
+}
+
+#define Py_UNICODE_ISLOWER(ch) _PyUnicode_IsLowercase(ch)
+#define Py_UNICODE_ISUPPER(ch) _PyUnicode_IsUppercase(ch)
+#define Py_UNICODE_ISTITLE(ch) _PyUnicode_IsTitlecase(ch)
+#define Py_UNICODE_ISLINEBREAK(ch) _PyUnicode_IsLinebreak(ch)
+
+#define Py_UNICODE_TOLOWER(ch) _PyUnicode_ToLowercase(ch)
+#define Py_UNICODE_TOUPPER(ch) _PyUnicode_ToUppercase(ch)
+#define Py_UNICODE_TOTITLE(ch) _PyUnicode_ToTitlecase(ch)
+
+#define Py_UNICODE_ISDECIMAL(ch) _PyUnicode_IsDecimalDigit(ch)
+#define Py_UNICODE_ISDIGIT(ch) _PyUnicode_IsDigit(ch)
+#define Py_UNICODE_ISNUMERIC(ch) _PyUnicode_IsNumeric(ch)
+#define Py_UNICODE_ISPRINTABLE(ch) _PyUnicode_IsPrintable(ch)
+
+#define Py_UNICODE_TODECIMAL(ch) _PyUnicode_ToDecimalDigit(ch)
+#define Py_UNICODE_TODIGIT(ch) _PyUnicode_ToDigit(ch)
+#define Py_UNICODE_TONUMERIC(ch) _PyUnicode_ToNumeric(ch)
+
+#define Py_UNICODE_ISALPHA(ch) _PyUnicode_IsAlpha(ch)
+
+static inline int Py_UNICODE_ISALNUM(Py_UCS4 ch) {
+ return (Py_UNICODE_ISALPHA(ch)
+ || Py_UNICODE_ISDECIMAL(ch)
+ || Py_UNICODE_ISDIGIT(ch)
+ || Py_UNICODE_ISNUMERIC(ch));
+}
+
+
+/* === Misc functions ===================================================== */
+
PyAPI_FUNC(PyObject*) _PyUnicode_FormatLong(PyObject *, int, int, int);
/* Return an interned Unicode object for an Identifier; may fail if there is no memory.*/
@@ -1144,7 +954,7 @@ PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
and where the hash values are equal (i.e. a very probable match) */
PyAPI_FUNC(int) _PyUnicode_EQ(PyObject *, PyObject *);
-/* Equality check. Returns -1 on failure. */
+/* Equality check. */
PyAPI_FUNC(int) _PyUnicode_Equal(PyObject *, PyObject *);
PyAPI_FUNC(int) _PyUnicode_WideCharString_Converter(PyObject *, void *);
diff --git a/contrib/tools/python3/src/Include/cpython/warnings.h b/contrib/tools/python3/src/Include/cpython/warnings.h
index 2ef8e3ce94..4e3eb88e8f 100644
--- a/contrib/tools/python3/src/Include/cpython/warnings.h
+++ b/contrib/tools/python3/src/Include/cpython/warnings.h
@@ -17,4 +17,4 @@ PyAPI_FUNC(int) PyErr_WarnExplicitFormat(
const char *format, ...);
// DEPRECATED: Use PyErr_WarnEx() instead.
-#define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1)
+#define PyErr_Warn(category, msg) PyErr_WarnEx((category), (msg), 1)
diff --git a/contrib/tools/python3/src/Include/cpython/weakrefobject.h b/contrib/tools/python3/src/Include/cpython/weakrefobject.h
index 26b364f41d..fd79fdc2dc 100644
--- a/contrib/tools/python3/src/Include/cpython/weakrefobject.h
+++ b/contrib/tools/python3/src/Include/cpython/weakrefobject.h
@@ -53,6 +53,4 @@ static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj) {
}
return Py_None;
}
-#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
-# define PyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref))
-#endif
+#define PyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref))