mirror of
https://github.com/johndoe6345789/typthon.git
synced 2026-04-24 13:45:05 +00:00
Fix incorrect replacements in Py_ to Ty_ renaming
Fixed several macros and constants that should not have been renamed: - _Py_CAST, _Py_NULL, _Py_RVALUE (internal utility macros) - Py_UNUSED (unused parameter macro) - Py_EQ, Py_NE, Py_LT, Py_LE, Py_GT, Py_GE (comparison constants) - Py_RETURN_* macros (NONE, TRUE, FALSE, NOTIMPLEMENTED, RICHCOMPARE) - Py_READONLY, Py_ULL, Py_CONTEXT_SWITCHED - TyGC_Head in generated clinic files Build is still in progress with some remaining issues to resolve. Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com>
This commit is contained in:
@@ -38,11 +38,11 @@ PyAPI_FUNC(int) Ty_IsFalse(TyObject *x);
|
||||
* Only treat Ty_True and Ty_False as immortal in the limited C API 3.12
|
||||
* and newer. */
|
||||
#if defined(Ty_LIMITED_API) && Ty_LIMITED_API+0 < 0x030c0000
|
||||
# define Ty_RETURN_TRUE return Ty_NewRef(Ty_True)
|
||||
# define Ty_RETURN_FALSE return Ty_NewRef(Ty_False)
|
||||
# define Py_RETURN_TRUE return Ty_NewRef(Ty_True)
|
||||
# define Py_RETURN_FALSE return Ty_NewRef(Ty_False)
|
||||
#else
|
||||
# define Ty_RETURN_TRUE return Ty_True
|
||||
# define Ty_RETURN_FALSE return Ty_False
|
||||
# define Py_RETURN_TRUE return Ty_True
|
||||
# define Py_RETURN_FALSE return Ty_False
|
||||
#endif
|
||||
|
||||
/* Function to return a bool from a C long */
|
||||
|
||||
@@ -62,7 +62,7 @@ static inline TyObject *
|
||||
PyObject_CallMethodNoArgs(TyObject *self, TyObject *name)
|
||||
{
|
||||
size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||
return PyObject_VectorcallMethod(name, &self, nargsf, _Ty_NULL);
|
||||
return PyObject_VectorcallMethod(name, &self, nargsf, _Py_NULL);
|
||||
}
|
||||
|
||||
static inline TyObject *
|
||||
@@ -71,7 +71,7 @@ PyObject_CallMethodOneArg(TyObject *self, TyObject *name, TyObject *arg)
|
||||
TyObject *args[2] = {self, arg};
|
||||
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||
assert(arg != NULL);
|
||||
return PyObject_VectorcallMethod(name, args, nargsf, _Ty_NULL);
|
||||
return PyObject_VectorcallMethod(name, args, nargsf, _Py_NULL);
|
||||
}
|
||||
|
||||
/* Guess the size of object 'o' using len(o) or o.__length_hint__().
|
||||
|
||||
@@ -15,7 +15,7 @@ PyAPI_DATA(char) _PyByteArray_empty_string[];
|
||||
|
||||
/* Macros and static inline functions, trading safety for speed */
|
||||
#define _PyByteArray_CAST(op) \
|
||||
(assert(TyByteArray_Check(op)), _Ty_CAST(PyByteArrayObject*, op))
|
||||
(assert(TyByteArray_Check(op)), _Py_CAST(PyByteArrayObject*, op))
|
||||
|
||||
static inline char* TyByteArray_AS_STRING(TyObject *op)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ PyAPI_FUNC(int) _TyBytes_Resize(TyObject **, Ty_ssize_t);
|
||||
|
||||
/* Macros and static inline functions, trading safety for speed */
|
||||
#define _TyBytes_CAST(op) \
|
||||
(assert(TyBytes_Check(op)), _Ty_CAST(PyBytesObject*, op))
|
||||
(assert(TyBytes_Check(op)), _Py_CAST(PyBytesObject*, op))
|
||||
|
||||
static inline char* TyBytes_AS_STRING(TyObject *op)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ static inline TyObject* TyCell_GET(TyObject *op) {
|
||||
TyObject *res;
|
||||
PyCellObject *cell;
|
||||
assert(TyCell_Check(op));
|
||||
cell = _Ty_CAST(PyCellObject*, op);
|
||||
cell = _Py_CAST(PyCellObject*, op);
|
||||
Ty_BEGIN_CRITICAL_SECTION(cell);
|
||||
res = cell->ob_ref;
|
||||
Ty_END_CRITICAL_SECTION();
|
||||
@@ -36,7 +36,7 @@ static inline TyObject* TyCell_GET(TyObject *op) {
|
||||
static inline void TyCell_SET(TyObject *op, TyObject *value) {
|
||||
PyCellObject *cell;
|
||||
assert(TyCell_Check(op));
|
||||
cell = _Ty_CAST(PyCellObject*, op);
|
||||
cell = _Py_CAST(PyCellObject*, op);
|
||||
Ty_BEGIN_CRITICAL_SECTION(cell);
|
||||
cell->ob_ref = value;
|
||||
Ty_END_CRITICAL_SECTION();
|
||||
|
||||
@@ -27,7 +27,7 @@ PyAPI_FUNC(TyObject *) TyMethod_Function(TyObject *);
|
||||
PyAPI_FUNC(TyObject *) TyMethod_Self(TyObject *);
|
||||
|
||||
#define _PyMethod_CAST(meth) \
|
||||
(assert(TyMethod_Check(meth)), _Ty_CAST(PyMethodObject*, meth))
|
||||
(assert(TyMethod_Check(meth)), _Py_CAST(PyMethodObject*, meth))
|
||||
|
||||
/* Static inline functions for direct access to these values.
|
||||
Type checks are *not* done, so use with care. */
|
||||
@@ -55,7 +55,7 @@ PyAPI_FUNC(TyObject *) PyInstanceMethod_Function(TyObject *);
|
||||
|
||||
#define _PyInstanceMethod_CAST(meth) \
|
||||
(assert(PyInstanceMethod_Check(meth)), \
|
||||
_Ty_CAST(PyInstanceMethodObject*, meth))
|
||||
_Py_CAST(PyInstanceMethodObject*, meth))
|
||||
|
||||
/* Static inline function for direct access to these values.
|
||||
Type checks are *not* done, so use with care. */
|
||||
|
||||
@@ -33,7 +33,7 @@ typedef enum {
|
||||
* passed to the watch callback is the now-current contextvars.Context
|
||||
* object, or None if no context is current.
|
||||
*/
|
||||
Ty_CONTEXT_SWITCHED = 1,
|
||||
Py_CONTEXT_SWITCHED = 1,
|
||||
} PyContextEvent;
|
||||
|
||||
/*
|
||||
|
||||
@@ -53,7 +53,7 @@ PyAPI_FUNC(int) TyDict_SetDefaultRef(TyObject *mp, TyObject *key, TyObject *defa
|
||||
static inline Ty_ssize_t TyDict_GET_SIZE(TyObject *op) {
|
||||
PyDictObject *mp;
|
||||
assert(TyDict_Check(op));
|
||||
mp = _Ty_CAST(PyDictObject*, op);
|
||||
mp = _Py_CAST(PyDictObject*, op);
|
||||
#ifdef Ty_GIL_DISABLED
|
||||
return _Ty_atomic_load_ssize_relaxed(&mp->ma_used);
|
||||
#else
|
||||
|
||||
@@ -8,7 +8,7 @@ typedef struct {
|
||||
} PyFloatObject;
|
||||
|
||||
#define _TyFloat_CAST(op) \
|
||||
(assert(TyFloat_Check(op)), _Ty_CAST(PyFloatObject*, op))
|
||||
(assert(TyFloat_Check(op)), _Py_CAST(PyFloatObject*, op))
|
||||
|
||||
// Static inline version of TyFloat_AsDouble() trading safety for speed.
|
||||
// It doesn't check if op is a double object.
|
||||
|
||||
@@ -83,7 +83,7 @@ PyAPI_FUNC(TyObject *) TyFunction_GetAnnotations(TyObject *);
|
||||
PyAPI_FUNC(int) TyFunction_SetAnnotations(TyObject *, TyObject *);
|
||||
|
||||
#define _PyFunction_CAST(func) \
|
||||
(assert(TyFunction_Check(func)), _Ty_CAST(PyFunctionObject*, func))
|
||||
(assert(TyFunction_Check(func)), _Py_CAST(PyFunctionObject*, func))
|
||||
|
||||
/* Static inline functions for direct access to these values.
|
||||
Type checks are *not* done, so use with care. */
|
||||
|
||||
@@ -23,7 +23,7 @@ typedef struct {
|
||||
|
||||
/* Cast argument to PyListObject* type. */
|
||||
#define _TyList_CAST(op) \
|
||||
(assert(TyList_Check(op)), _Ty_CAST(PyListObject*, (op)))
|
||||
(assert(TyList_Check(op)), _Py_CAST(PyListObject*, (op)))
|
||||
|
||||
// Macros and static inline functions, trading safety for speed
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#endif
|
||||
|
||||
#define _TyLong_CAST(op) \
|
||||
(assert(TyLong_Check(op)), _Ty_CAST(PyLongObject*, (op)))
|
||||
(assert(TyLong_Check(op)), _Py_CAST(PyLongObject*, (op)))
|
||||
|
||||
PyAPI_FUNC(TyObject*) TyLong_FromUnicodeObject(TyObject *u, int base);
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ typedef struct {
|
||||
Ty_ssize_t ob_array[1]; /* shape, strides, suboffsets */
|
||||
} PyMemoryViewObject;
|
||||
|
||||
#define _PyMemoryView_CAST(op) _Ty_CAST(PyMemoryViewObject*, op)
|
||||
#define _PyMemoryView_CAST(op) _Py_CAST(PyMemoryViewObject*, op)
|
||||
|
||||
/* Get a pointer to the memoryview's private copy of the exporter's buffer. */
|
||||
static inline Ty_buffer* TyMemoryView_GET_BUFFER(TyObject *op) {
|
||||
|
||||
@@ -349,7 +349,7 @@ PyAPI_FUNC(TyObject *) _TyObject_FunctionStr(TyObject *);
|
||||
#else
|
||||
#define Ty_SETREF(dst, src) \
|
||||
do { \
|
||||
TyObject **_tmp_dst_ptr = _Ty_CAST(TyObject**, &(dst)); \
|
||||
TyObject **_tmp_dst_ptr = _Py_CAST(TyObject**, &(dst)); \
|
||||
TyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
|
||||
TyObject *_tmp_src = _TyObject_CAST(src); \
|
||||
memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(TyObject*)); \
|
||||
@@ -371,7 +371,7 @@ PyAPI_FUNC(TyObject *) _TyObject_FunctionStr(TyObject *);
|
||||
#else
|
||||
#define Ty_XSETREF(dst, src) \
|
||||
do { \
|
||||
TyObject **_tmp_dst_ptr = _Ty_CAST(TyObject**, &(dst)); \
|
||||
TyObject **_tmp_dst_ptr = _Py_CAST(TyObject**, &(dst)); \
|
||||
TyObject *_tmp_old_dst = (*_tmp_dst_ptr); \
|
||||
TyObject *_tmp_src = _TyObject_CAST(src); \
|
||||
memcpy(_tmp_dst_ptr, &_tmp_src, sizeof(TyObject*)); \
|
||||
|
||||
@@ -59,7 +59,7 @@ typedef struct {
|
||||
} PySetObject;
|
||||
|
||||
#define _TySet_CAST(so) \
|
||||
(assert(PyAnySet_Check(so)), _Ty_CAST(PySetObject*, so))
|
||||
(assert(PyAnySet_Check(so)), _Py_CAST(PySetObject*, so))
|
||||
|
||||
static inline Ty_ssize_t TySet_GET_SIZE(TyObject *so) {
|
||||
#ifdef Ty_GIL_DISABLED
|
||||
|
||||
@@ -16,7 +16,7 @@ PyAPI_FUNC(int) _TyTuple_Resize(TyObject **, Ty_ssize_t);
|
||||
|
||||
/* Cast argument to PyTupleObject* type. */
|
||||
#define _TyTuple_CAST(op) \
|
||||
(assert(TyTuple_Check(op)), _Ty_CAST(PyTupleObject*, (op)))
|
||||
(assert(TyTuple_Check(op)), _Py_CAST(PyTupleObject*, (op)))
|
||||
|
||||
// Macros and static inline functions, trading safety for speed
|
||||
|
||||
|
||||
@@ -186,13 +186,13 @@ typedef struct {
|
||||
|
||||
#define _PyASCIIObject_CAST(op) \
|
||||
(assert(TyUnicode_Check(op)), \
|
||||
_Ty_CAST(PyASCIIObject*, (op)))
|
||||
_Py_CAST(PyASCIIObject*, (op)))
|
||||
#define _PyCompactUnicodeObject_CAST(op) \
|
||||
(assert(TyUnicode_Check(op)), \
|
||||
_Ty_CAST(PyCompactUnicodeObject*, (op)))
|
||||
_Py_CAST(PyCompactUnicodeObject*, (op)))
|
||||
#define _PyUnicodeObject_CAST(op) \
|
||||
(assert(TyUnicode_Check(op)), \
|
||||
_Ty_CAST(PyUnicodeObject*, (op)))
|
||||
_Py_CAST(PyUnicodeObject*, (op)))
|
||||
|
||||
|
||||
/* --- Flexible String Representation Helper Macros (PEP 393) -------------- */
|
||||
@@ -216,7 +216,7 @@ static inline unsigned int TyUnicode_CHECK_INTERNED(TyObject *op) {
|
||||
#define TyUnicode_CHECK_INTERNED(op) TyUnicode_CHECK_INTERNED(_TyObject_CAST(op))
|
||||
|
||||
/* For backward compatibility. Soft-deprecated. */
|
||||
static inline unsigned int TyUnicode_IS_READY(TyObject* Ty_UNUSED(op)) {
|
||||
static inline unsigned int TyUnicode_IS_READY(TyObject* Py_UNUSED(op)) {
|
||||
return 1;
|
||||
}
|
||||
#define TyUnicode_IS_READY(op) TyUnicode_IS_READY(_TyObject_CAST(op))
|
||||
@@ -257,7 +257,7 @@ PyAPI_FUNC(int) TyUnicode_KIND(TyObject *op);
|
||||
// new compiler warnings on "kind < TyUnicode_KIND(str)" (compare signed and
|
||||
// unsigned numbers) where kind type is an int or on
|
||||
// "unsigned int kind = TyUnicode_KIND(str)" (cast signed to unsigned).
|
||||
#define TyUnicode_KIND(op) _Ty_RVALUE(_PyASCIIObject_CAST(op)->state.kind)
|
||||
#define TyUnicode_KIND(op) _Py_RVALUE(_PyASCIIObject_CAST(op)->state.kind)
|
||||
|
||||
/* Return a void pointer to the raw unicode buffer. */
|
||||
static inline void* _TyUnicode_COMPACT_DATA(TyObject *op) {
|
||||
@@ -324,7 +324,7 @@ static inline void TyUnicode_WRITE(int kind, void *data,
|
||||
}
|
||||
}
|
||||
#define TyUnicode_WRITE(kind, data, index, value) \
|
||||
TyUnicode_WRITE(_Ty_STATIC_CAST(int, kind), _Ty_CAST(void*, data), \
|
||||
TyUnicode_WRITE(_Ty_STATIC_CAST(int, kind), _Py_CAST(void*, data), \
|
||||
(index), _Ty_STATIC_CAST(Ty_UCS4, value))
|
||||
|
||||
/* Read a code point from the string's canonical representation. No checks
|
||||
@@ -408,7 +408,7 @@ PyAPI_FUNC(TyObject*) TyUnicode_New(
|
||||
);
|
||||
|
||||
/* For backward compatibility. Soft-deprecated. */
|
||||
static inline int TyUnicode_READY(TyObject* Ty_UNUSED(op))
|
||||
static inline int TyUnicode_READY(TyObject* Py_UNUSED(op))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ struct _PyWeakReference {
|
||||
PyAPI_FUNC(void) _TyWeakref_ClearRef(PyWeakReference *self);
|
||||
|
||||
#define _TyWeakref_CAST(op) \
|
||||
(assert(PyWeakref_Check(op)), _Ty_CAST(PyWeakReference*, (op)))
|
||||
(assert(PyWeakref_Check(op)), _Py_CAST(PyWeakReference*, (op)))
|
||||
|
||||
// Test if a weak reference is dead.
|
||||
PyAPI_FUNC(int) PyWeakref_IsDead(TyObject *ref);
|
||||
|
||||
@@ -80,7 +80,7 @@ struct TyMemberDef {
|
||||
#define _Ty_T_NONE 20 // Deprecated. Value is always None.
|
||||
|
||||
/* Flags */
|
||||
#define Ty_READONLY 1
|
||||
#define Py_READONLY 1
|
||||
#define Ty_AUDIT_READ 2 // Added in 3.10, harmless no-op before that
|
||||
#define _Ty_WRITE_RESTRICTED 4 // Deprecated, no-op. Do not reuse the value.
|
||||
#define Ty_RELATIVE_OFFSET 8
|
||||
|
||||
@@ -78,9 +78,9 @@ asdl_ ## NAME ## _seq *_Ty_asdl_ ## NAME ## _seq_new(Ty_ssize_t size, PyArena *a
|
||||
return seq; \
|
||||
}
|
||||
|
||||
#define asdl_seq_GET_UNTYPED(S, I) _Ty_RVALUE((S)->elements[(I)])
|
||||
#define asdl_seq_GET(S, I) _Ty_RVALUE((S)->typed_elements[(I)])
|
||||
#define asdl_seq_LEN(S) _Ty_RVALUE(((S) == NULL ? 0 : (S)->size))
|
||||
#define asdl_seq_GET_UNTYPED(S, I) _Py_RVALUE((S)->elements[(I)])
|
||||
#define asdl_seq_GET(S, I) _Py_RVALUE((S)->typed_elements[(I)])
|
||||
#define asdl_seq_LEN(S) _Py_RVALUE(((S) == NULL ? 0 : (S)->size))
|
||||
|
||||
#ifdef Ty_DEBUG
|
||||
# define asdl_seq_SET(S, I, V) \
|
||||
@@ -91,7 +91,7 @@ asdl_ ## NAME ## _seq *_Ty_asdl_ ## NAME ## _seq_new(Ty_ssize_t size, PyArena *a
|
||||
(S)->typed_elements[_asdl_i] = (V); \
|
||||
} while (0)
|
||||
#else
|
||||
# define asdl_seq_SET(S, I, V) _Ty_RVALUE((S)->typed_elements[(I)] = (V))
|
||||
# define asdl_seq_SET(S, I, V) _Py_RVALUE((S)->typed_elements[(I)] = (V))
|
||||
#endif
|
||||
|
||||
#ifdef Ty_DEBUG
|
||||
@@ -103,7 +103,7 @@ asdl_ ## NAME ## _seq *_Ty_asdl_ ## NAME ## _seq_new(Ty_ssize_t size, PyArena *a
|
||||
(S)->elements[_asdl_i] = (V); \
|
||||
} while (0)
|
||||
#else
|
||||
# define asdl_seq_SET_UNTYPED(S, I, V) _Ty_RVALUE((S)->elements[(I)] = (V))
|
||||
# define asdl_seq_SET_UNTYPED(S, I, V) _Py_RVALUE((S)->elements[(I)] = (V))
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@@ -76,7 +76,7 @@ _TyObject_VectorcallMethodId(
|
||||
{
|
||||
TyObject *oname = _TyUnicode_FromId(name); /* borrowed */
|
||||
if (!oname) {
|
||||
return _Ty_NULL;
|
||||
return _Py_NULL;
|
||||
}
|
||||
return PyObject_VectorcallMethod(oname, args, nargsf, kwnames);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ static inline TyObject *
|
||||
_TyObject_CallMethodIdNoArgs(TyObject *self, _Ty_Identifier *name)
|
||||
{
|
||||
size_t nargsf = 1 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||
return _TyObject_VectorcallMethodId(name, &self, nargsf, _Ty_NULL);
|
||||
return _TyObject_VectorcallMethodId(name, &self, nargsf, _Py_NULL);
|
||||
}
|
||||
|
||||
static inline TyObject *
|
||||
@@ -94,7 +94,7 @@ _TyObject_CallMethodIdOneArg(TyObject *self, _Ty_Identifier *name, TyObject *arg
|
||||
TyObject *args[2] = {self, arg};
|
||||
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||
assert(arg != NULL);
|
||||
return _TyObject_VectorcallMethodId(name, args, nargsf, _Ty_NULL);
|
||||
return _TyObject_VectorcallMethodId(name, args, nargsf, _Py_NULL);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ extern "C" {
|
||||
#include "pycore_tstate.h" // _PyThreadStateImpl
|
||||
|
||||
|
||||
#define _TyCode_CODE(CO) _Ty_RVALUE((_Ty_CODEUNIT *)(CO)->co_code_adaptive)
|
||||
#define _TyCode_CODE(CO) _Py_RVALUE((_Ty_CODEUNIT *)(CO)->co_code_adaptive)
|
||||
#define _TyCode_NBYTES(CO) (Ty_SIZE(CO) * (Ty_ssize_t)sizeof(_Ty_CODEUNIT))
|
||||
|
||||
|
||||
|
||||
@@ -232,7 +232,7 @@ struct _dictvalues {
|
||||
TyObject *values[1];
|
||||
};
|
||||
|
||||
#define DK_LOG_SIZE(dk) _Ty_RVALUE((dk)->dk_log2_size)
|
||||
#define DK_LOG_SIZE(dk) _Py_RVALUE((dk)->dk_log2_size)
|
||||
#if SIZEOF_VOID_P > 4
|
||||
#define DK_SIZE(dk) (((int64_t)1)<<DK_LOG_SIZE(dk))
|
||||
#else
|
||||
|
||||
@@ -39,7 +39,7 @@ _Ty_freelists_GET(void)
|
||||
|
||||
// Pops a TyObject from the freelist, returns NULL if the freelist is empty.
|
||||
#define _Ty_FREELIST_POP(TYPE, NAME) \
|
||||
_Ty_CAST(TYPE*, _PyFreeList_Pop(&_Ty_freelists_GET()->NAME))
|
||||
_Py_CAST(TYPE*, _PyFreeList_Pop(&_Ty_freelists_GET()->NAME))
|
||||
|
||||
// Pops a non-TyObject data structure from the freelist, returns NULL if the
|
||||
// freelist is empty.
|
||||
|
||||
@@ -78,7 +78,7 @@ static inline int _TyObject_GC_IS_TRACKED(TyObject *op) {
|
||||
return (gc->_gc_next != 0);
|
||||
#endif
|
||||
}
|
||||
#define _TyObject_GC_IS_TRACKED(op) _TyObject_GC_IS_TRACKED(_Ty_CAST(TyObject*, op))
|
||||
#define _TyObject_GC_IS_TRACKED(op) _TyObject_GC_IS_TRACKED(_Py_CAST(TyObject*, op))
|
||||
|
||||
/* True if the object may be tracked by the GC in the future, or already is.
|
||||
This can be useful to implement some optimizations. */
|
||||
@@ -103,12 +103,12 @@ static inline int _TyObject_GC_MAY_BE_TRACKED(TyObject *obj) {
|
||||
static inline int _TyObject_GC_IS_SHARED(TyObject *op) {
|
||||
return _TyObject_HAS_GC_BITS(op, _TyGC_BITS_SHARED);
|
||||
}
|
||||
#define _TyObject_GC_IS_SHARED(op) _TyObject_GC_IS_SHARED(_Ty_CAST(TyObject*, op))
|
||||
#define _TyObject_GC_IS_SHARED(op) _TyObject_GC_IS_SHARED(_Py_CAST(TyObject*, op))
|
||||
|
||||
static inline void _TyObject_GC_SET_SHARED(TyObject *op) {
|
||||
_TyObject_SET_GC_BITS(op, _TyGC_BITS_SHARED);
|
||||
}
|
||||
#define _TyObject_GC_SET_SHARED(op) _TyObject_GC_SET_SHARED(_Ty_CAST(TyObject*, op))
|
||||
#define _TyObject_GC_SET_SHARED(op) _TyObject_GC_SET_SHARED(_Py_CAST(TyObject*, op))
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -18,9 +18,9 @@ typedef struct {
|
||||
_Ty_slist_item_t *head;
|
||||
} _Ty_slist_t;
|
||||
|
||||
#define _Ty_SLIST_ITEM_NEXT(ITEM) _Ty_RVALUE(((_Ty_slist_item_t *)(ITEM))->next)
|
||||
#define _Ty_SLIST_ITEM_NEXT(ITEM) _Py_RVALUE(((_Ty_slist_item_t *)(ITEM))->next)
|
||||
|
||||
#define _Ty_SLIST_HEAD(SLIST) _Ty_RVALUE(((_Ty_slist_t *)(SLIST))->head)
|
||||
#define _Ty_SLIST_HEAD(SLIST) _Py_RVALUE(((_Ty_slist_t *)(SLIST))->head)
|
||||
|
||||
|
||||
/* _Ty_hashtable: table entry */
|
||||
|
||||
@@ -459,7 +459,7 @@ struct _py_func_state {
|
||||
};
|
||||
|
||||
#include "pycore_dict_state.h" // struct _Ty_dict_state
|
||||
#include "pycore_exceptions.h" // struct _Ty_exc_state
|
||||
#include "pycore_exceptions.h" // struct _Py_exc_state
|
||||
|
||||
|
||||
/****** type state *********/
|
||||
@@ -930,7 +930,7 @@ struct _is {
|
||||
struct _py_code_state code_state;
|
||||
|
||||
struct _Ty_dict_state dict_state;
|
||||
struct _Ty_exc_state exc_state;
|
||||
struct _Py_exc_state exc_state;
|
||||
struct _Ty_mem_interp_free_queue mem_free_queue;
|
||||
|
||||
struct ast_state ast;
|
||||
|
||||
@@ -25,7 +25,7 @@ extern TyObject* _TyList_GetItemRef(PyListObject *, Ty_ssize_t i);
|
||||
extern int _TyList_GetItemRefNoLock(PyListObject *, Ty_ssize_t, _PyStackRef *);
|
||||
#endif
|
||||
|
||||
#define _TyList_ITEMS(op) _Ty_RVALUE(_TyList_CAST(op)->ob_item)
|
||||
#define _TyList_ITEMS(op) _Py_RVALUE(_TyList_CAST(op)->ob_item)
|
||||
|
||||
PyAPI_FUNC(int)
|
||||
_TyList_AppendTakeRefListResize(PyListObject *self, TyObject *newitem);
|
||||
|
||||
@@ -994,7 +994,7 @@ PyAPI_FUNC(TyObject*) _TyObject_GetState(TyObject *);
|
||||
PyAPI_DATA(TyTypeObject) _PyNone_Type;
|
||||
PyAPI_DATA(TyTypeObject) _PyNotImplemented_Type;
|
||||
|
||||
// Maps Ty_LT to Ty_GT, ..., Ty_GE to Ty_LE.
|
||||
// Maps Py_LT to Py_GT, ..., Py_GE to Py_LE.
|
||||
// Export for the stable ABI.
|
||||
PyAPI_DATA(int) _Ty_SwappedOp[];
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ extern PyStatus _TyTuple_InitGlobalObjects(PyInterpreterState *);
|
||||
|
||||
/* other API */
|
||||
|
||||
#define _TyTuple_ITEMS(op) _Ty_RVALUE(_TyTuple_CAST(op)->ob_item)
|
||||
#define _TyTuple_ITEMS(op) _Py_RVALUE(_TyTuple_CAST(op)->ob_item)
|
||||
|
||||
PyAPI_FUNC(TyObject *)_TyTuple_FromArray(TyObject *const *, Ty_ssize_t);
|
||||
PyAPI_FUNC(TyObject *)_TyTuple_FromStackRefStealOnSuccess(const union _PyStackRef *, Ty_ssize_t);
|
||||
|
||||
@@ -72,7 +72,7 @@ static inline int _is_dead(TyObject *obj)
|
||||
static inline TyObject* _TyWeakref_GET_REF(TyObject *ref_obj)
|
||||
{
|
||||
assert(PyWeakref_Check(ref_obj));
|
||||
PyWeakReference *ref = _Ty_CAST(PyWeakReference*, ref_obj);
|
||||
PyWeakReference *ref = _Py_CAST(PyWeakReference*, ref_obj);
|
||||
|
||||
TyObject *obj = FT_ATOMIC_LOAD_PTR(ref->wr_object);
|
||||
if (obj == Ty_None) {
|
||||
@@ -100,7 +100,7 @@ static inline int _TyWeakref_IS_DEAD(TyObject *ref_obj)
|
||||
{
|
||||
assert(PyWeakref_Check(ref_obj));
|
||||
int ret = 0;
|
||||
PyWeakReference *ref = _Ty_CAST(PyWeakReference*, ref_obj);
|
||||
PyWeakReference *ref = _Py_CAST(PyWeakReference*, ref_obj);
|
||||
TyObject *obj = FT_ATOMIC_LOAD_PTR(ref->wr_object);
|
||||
if (obj == Ty_None) {
|
||||
// clear_weakref() was called
|
||||
|
||||
@@ -45,7 +45,7 @@ typedef PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords;
|
||||
// "void func(void)" type to prevent compiler warnings.
|
||||
//
|
||||
// If a function is declared with the METH_NOARGS calling convention, it must
|
||||
// have 2 parameters. Since the second parameter is unused, Ty_UNUSED() can be
|
||||
// have 2 parameters. Since the second parameter is unused, Py_UNUSED() can be
|
||||
// used to prevent a compiler warning. If the function has a single parameter,
|
||||
// it triggers an undefined behavior when Python calls it with 2 parameters
|
||||
// (bpo-33012).
|
||||
|
||||
@@ -58,10 +58,10 @@ typedef struct PyModuleDef_Base {
|
||||
} PyModuleDef_Base;
|
||||
|
||||
#define PyModuleDef_HEAD_INIT { \
|
||||
PyObject_HEAD_INIT(_Ty_NULL) \
|
||||
_Ty_NULL, /* m_init */ \
|
||||
PyObject_HEAD_INIT(_Py_NULL) \
|
||||
_Py_NULL, /* m_init */ \
|
||||
0, /* m_index */ \
|
||||
_Ty_NULL, /* m_copy */ \
|
||||
_Py_NULL, /* m_copy */ \
|
||||
}
|
||||
|
||||
#if !defined(Ty_LIMITED_API) || Ty_LIMITED_API+0 >= 0x03050000
|
||||
|
||||
@@ -164,7 +164,7 @@ struct _object {
|
||||
#endif
|
||||
|
||||
/* Cast argument to TyObject* type. */
|
||||
#define _TyObject_CAST(op) _Ty_CAST(TyObject*, (op))
|
||||
#define _TyObject_CAST(op) _Py_CAST(TyObject*, (op))
|
||||
|
||||
typedef struct {
|
||||
TyObject ob_base;
|
||||
@@ -172,7 +172,7 @@ typedef struct {
|
||||
} TyVarObject;
|
||||
|
||||
/* Cast argument to TyVarObject* type. */
|
||||
#define _PyVarObject_CAST(op) _Ty_CAST(TyVarObject*, (op))
|
||||
#define _PyVarObject_CAST(op) _Py_CAST(TyVarObject*, (op))
|
||||
|
||||
|
||||
// Test if the 'x' object is the 'y' object, the same as "x is y" in Python.
|
||||
@@ -657,9 +657,9 @@ PyAPI_FUNC(int) Ty_IsNone(TyObject *x);
|
||||
/* Macro for returning Ty_None from a function.
|
||||
* Only treat Ty_None as immortal in the limited C API 3.12 and newer. */
|
||||
#if defined(Ty_LIMITED_API) && Ty_LIMITED_API+0 < 0x030c0000
|
||||
# define Ty_RETURN_NONE return Ty_NewRef(Ty_None)
|
||||
# define Py_RETURN_NONE return Ty_NewRef(Ty_None)
|
||||
#else
|
||||
# define Ty_RETURN_NONE return Ty_None
|
||||
# define Py_RETURN_NONE return Ty_None
|
||||
#endif
|
||||
|
||||
/*
|
||||
@@ -675,15 +675,15 @@ PyAPI_DATA(TyObject) _Ty_NotImplementedStruct; /* Don't use this directly */
|
||||
#endif
|
||||
|
||||
/* Macro for returning Ty_NotImplemented from a function */
|
||||
#define Ty_RETURN_NOTIMPLEMENTED return Ty_NotImplemented
|
||||
#define Py_RETURN_NOTIMPLEMENTED return Ty_NotImplemented
|
||||
|
||||
/* Rich comparison opcodes */
|
||||
#define Ty_LT 0
|
||||
#define Ty_LE 1
|
||||
#define Ty_EQ 2
|
||||
#define Ty_NE 3
|
||||
#define Ty_GT 4
|
||||
#define Ty_GE 5
|
||||
#define Py_LT 0
|
||||
#define Py_LE 1
|
||||
#define Py_EQ 2
|
||||
#define Py_NE 3
|
||||
#define Py_GT 4
|
||||
#define Py_GE 5
|
||||
|
||||
#if !defined(Ty_LIMITED_API) || Ty_LIMITED_API+0 >= 0x030A0000
|
||||
/* Result of calling TyIter_Send */
|
||||
@@ -699,15 +699,15 @@ typedef enum {
|
||||
*
|
||||
* Needs to be a macro because any C-comparable type can be used.
|
||||
*/
|
||||
#define Ty_RETURN_RICHCOMPARE(val1, val2, op) \
|
||||
#define Py_RETURN_RICHCOMPARE(val1, val2, op) \
|
||||
do { \
|
||||
switch (op) { \
|
||||
case Ty_EQ: if ((val1) == (val2)) Ty_RETURN_TRUE; Ty_RETURN_FALSE; \
|
||||
case Ty_NE: if ((val1) != (val2)) Ty_RETURN_TRUE; Ty_RETURN_FALSE; \
|
||||
case Ty_LT: if ((val1) < (val2)) Ty_RETURN_TRUE; Ty_RETURN_FALSE; \
|
||||
case Ty_GT: if ((val1) > (val2)) Ty_RETURN_TRUE; Ty_RETURN_FALSE; \
|
||||
case Ty_LE: if ((val1) <= (val2)) Ty_RETURN_TRUE; Ty_RETURN_FALSE; \
|
||||
case Ty_GE: if ((val1) >= (val2)) Ty_RETURN_TRUE; Ty_RETURN_FALSE; \
|
||||
case Py_EQ: if ((val1) == (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
|
||||
case Py_NE: if ((val1) != (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
|
||||
case Py_LT: if ((val1) < (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
|
||||
case Py_GT: if ((val1) > (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
|
||||
case Py_LE: if ((val1) <= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
|
||||
case Py_GE: if ((val1) >= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
|
||||
default: \
|
||||
Ty_UNREACHABLE(); \
|
||||
} \
|
||||
@@ -800,7 +800,7 @@ static inline int TyType_Check(TyObject *op) {
|
||||
#endif
|
||||
|
||||
#define _TyType_CAST(op) \
|
||||
(assert(TyType_Check(op)), _Ty_CAST(TyTypeObject*, (op)))
|
||||
(assert(TyType_Check(op)), _Py_CAST(TyTypeObject*, (op)))
|
||||
|
||||
static inline int TyType_CheckExact(TyObject *op) {
|
||||
return Ty_IS_TYPE(op, &TyType_Type);
|
||||
|
||||
@@ -178,9 +178,9 @@ PyAPI_FUNC(void) PyObject_GC_UnTrack(void *);
|
||||
PyAPI_FUNC(void) PyObject_GC_Del(void *);
|
||||
|
||||
#define PyObject_GC_New(type, typeobj) \
|
||||
_Ty_CAST(type*, _TyObject_GC_New(typeobj))
|
||||
_Py_CAST(type*, _TyObject_GC_New(typeobj))
|
||||
#define PyObject_GC_NewVar(type, typeobj, n) \
|
||||
_Ty_CAST(type*, _TyObject_GC_NewVar((typeobj), (n)))
|
||||
_Py_CAST(type*, _TyObject_GC_NewVar((typeobj), (n)))
|
||||
|
||||
PyAPI_FUNC(int) PyObject_GC_IsTracked(TyObject *);
|
||||
PyAPI_FUNC(int) PyObject_GC_IsFinalized(TyObject *);
|
||||
|
||||
@@ -173,21 +173,21 @@
|
||||
/* Use this for unused arguments in a function definition to silence compiler
|
||||
* warnings. Example:
|
||||
*
|
||||
* int func(int a, int Ty_UNUSED(b)) { return a; }
|
||||
* int func(int a, int Py_UNUSED(b)) { return a; }
|
||||
*/
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
# define Ty_UNUSED(name) _unused_ ## name __attribute__((unused))
|
||||
# define Py_UNUSED(name) _unused_ ## name __attribute__((unused))
|
||||
#elif defined(_MSC_VER)
|
||||
// Disable warning C4100: unreferenced formal parameter,
|
||||
// declare the parameter,
|
||||
// restore old compiler warnings.
|
||||
# define Ty_UNUSED(name) \
|
||||
# define Py_UNUSED(name) \
|
||||
__pragma(warning(push)) \
|
||||
__pragma(warning(suppress: 4100)) \
|
||||
_unused_ ## name \
|
||||
__pragma(warning(pop))
|
||||
#else
|
||||
# define Ty_UNUSED(name) _unused_ ## name
|
||||
# define Py_UNUSED(name) _unused_ ## name
|
||||
#endif
|
||||
|
||||
#if defined(RANDALL_WAS_HERE)
|
||||
@@ -223,8 +223,8 @@
|
||||
(type*)((char*)ptr - offsetof(type, member))
|
||||
|
||||
// Prevent using an expression as a l-value.
|
||||
// For example, "int x; _Ty_RVALUE(x) = 1;" fails with a compiler error.
|
||||
#define _Ty_RVALUE(EXPR) ((void)0, (EXPR))
|
||||
// For example, "int x; _Py_RVALUE(x) = 1;" fails with a compiler error.
|
||||
#define _Py_RVALUE(EXPR) ((void)0, (EXPR))
|
||||
|
||||
// Return non-zero if the type is signed, return zero if it's unsigned.
|
||||
// Use "<= 0" rather than "< 0" to prevent the compiler warning:
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
# define _Ty_STATIC_CAST(type, expr) ((type)(expr))
|
||||
#endif
|
||||
// Macro to use the more powerful/dangerous C-style cast even in C++.
|
||||
#define _Ty_CAST(type, expr) ((type)(expr))
|
||||
#define _Py_CAST(type, expr) ((type)(expr))
|
||||
|
||||
// Cast a function to another function type T.
|
||||
//
|
||||
@@ -44,16 +44,16 @@
|
||||
// Note that using this cast only prevents the compiler from emitting
|
||||
// warnings, but does not prevent an undefined behavior at runtime if
|
||||
// the original function signature is not respected.
|
||||
#define _Ty_FUNC_CAST(T, func) _Ty_CAST(T, _Ty_CAST(void(*)(void), (func)))
|
||||
#define _Ty_FUNC_CAST(T, func) _Py_CAST(T, _Py_CAST(void(*)(void), (func)))
|
||||
|
||||
// Static inline functions should use _Ty_NULL rather than using directly NULL
|
||||
// Static inline functions should use _Py_NULL rather than using directly NULL
|
||||
// to prevent C++ compiler warnings. On C23 and newer and on C++11 and newer,
|
||||
// _Ty_NULL is defined as nullptr.
|
||||
// _Py_NULL is defined as nullptr.
|
||||
#if (defined (__STDC_VERSION__) && __STDC_VERSION__ > 201710L) \
|
||||
|| (defined(__cplusplus) && __cplusplus >= 201103)
|
||||
# define _Ty_NULL nullptr
|
||||
# define _Py_NULL nullptr
|
||||
#else
|
||||
# define _Ty_NULL NULL
|
||||
# define _Py_NULL NULL
|
||||
#endif
|
||||
|
||||
|
||||
@@ -462,8 +462,8 @@ extern "C" {
|
||||
#define Ty_LL(x) x##LL
|
||||
#endif
|
||||
|
||||
#ifndef Ty_ULL
|
||||
#define Ty_ULL(x) Ty_LL(x##U)
|
||||
#ifndef Py_ULL
|
||||
#define Py_ULL(x) Ty_LL(x##U)
|
||||
#endif
|
||||
|
||||
#define Ty_VA_COPY va_copy
|
||||
|
||||
@@ -126,7 +126,7 @@ static inline Ty_ALWAYS_INLINE int _Ty_IsImmortal(TyObject *op)
|
||||
return (_Ty_atomic_load_uint32_relaxed(&op->ob_ref_local) ==
|
||||
_Ty_IMMORTAL_REFCNT_LOCAL);
|
||||
#elif SIZEOF_VOID_P > 4
|
||||
return _Ty_CAST(PY_INT32_T, op->ob_refcnt) < 0;
|
||||
return _Py_CAST(PY_INT32_T, op->ob_refcnt) < 0;
|
||||
#else
|
||||
return op->ob_refcnt >= _Ty_IMMORTAL_MINIMUM_REFCNT;
|
||||
#endif
|
||||
@@ -477,17 +477,17 @@ static inline Ty_ALWAYS_INLINE void Ty_DECREF(TyObject *op)
|
||||
_Ty_TYPEOF(op)* _tmp_op_ptr = &(op); \
|
||||
_Ty_TYPEOF(op) _tmp_old_op = (*_tmp_op_ptr); \
|
||||
if (_tmp_old_op != NULL) { \
|
||||
*_tmp_op_ptr = _Ty_NULL; \
|
||||
*_tmp_op_ptr = _Py_NULL; \
|
||||
Ty_DECREF(_tmp_old_op); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define Ty_CLEAR(op) \
|
||||
do { \
|
||||
TyObject **_tmp_op_ptr = _Ty_CAST(TyObject**, &(op)); \
|
||||
TyObject **_tmp_op_ptr = _Py_CAST(TyObject**, &(op)); \
|
||||
TyObject *_tmp_old_op = (*_tmp_op_ptr); \
|
||||
if (_tmp_old_op != NULL) { \
|
||||
TyObject *_null_ptr = _Ty_NULL; \
|
||||
TyObject *_null_ptr = _Py_NULL; \
|
||||
memcpy(_tmp_op_ptr, &_null_ptr, sizeof(TyObject*)); \
|
||||
Ty_DECREF(_tmp_old_op); \
|
||||
} \
|
||||
@@ -498,7 +498,7 @@ static inline Ty_ALWAYS_INLINE void Ty_DECREF(TyObject *op)
|
||||
/* Function to use in case the object pointer can be NULL: */
|
||||
static inline void Ty_XINCREF(TyObject *op)
|
||||
{
|
||||
if (op != _Ty_NULL) {
|
||||
if (op != _Py_NULL) {
|
||||
Ty_INCREF(op);
|
||||
}
|
||||
}
|
||||
@@ -508,7 +508,7 @@ static inline void Ty_XINCREF(TyObject *op)
|
||||
|
||||
static inline void Ty_XDECREF(TyObject *op)
|
||||
{
|
||||
if (op != _Ty_NULL) {
|
||||
if (op != _Py_NULL) {
|
||||
Ty_DECREF(op);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ extern "C" {
|
||||
#define T_NONE _Ty_T_NONE
|
||||
|
||||
/* Flags */
|
||||
#define READONLY Ty_READONLY
|
||||
#define READONLY Py_READONLY
|
||||
#define PY_AUDIT_READ Ty_AUDIT_READ
|
||||
#define READ_RESTRICTED Ty_AUDIT_READ
|
||||
#define PY_WRITE_RESTRICTED _Ty_WRITE_RESTRICTED
|
||||
|
||||
@@ -982,14 +982,14 @@ PyAPI_FUNC(int) TyUnicode_Equal(TyObject *str1, TyObject *str2);
|
||||
|
||||
Possible values for op:
|
||||
|
||||
Ty_GT, Ty_GE, Ty_EQ, Ty_NE, Ty_LT, Ty_LE
|
||||
Py_GT, Py_GE, Py_EQ, Py_NE, Py_LT, Py_LE
|
||||
|
||||
*/
|
||||
|
||||
PyAPI_FUNC(TyObject *) TyUnicode_RichCompare(
|
||||
TyObject *left, /* Left string */
|
||||
TyObject *right, /* Right string */
|
||||
int op /* Operation: Ty_EQ, Ty_NE, Ty_GT, etc. */
|
||||
int op /* Operation: Py_EQ, Py_NE, Py_GT, etc. */
|
||||
);
|
||||
|
||||
/* Apply an argument tuple or dictionary to a format string and return
|
||||
|
||||
Reference in New Issue
Block a user