aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Include/cpython/object.h
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/object.h
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/object.h')
-rw-r--r--contrib/tools/python3/src/Include/cpython/object.h144
1 files changed, 104 insertions, 40 deletions
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);