mirror of
https://github.com/python/cpython.git
synced 2024-11-27 03:45:08 +08:00
gh-83754: Use the Py_TYPE() macro (#120599)
Don't access directly PyObject.ob_type, but use the Py_TYPE() macro instead.
This commit is contained in:
parent
3df2022931
commit
c2d5df5787
@ -120,7 +120,7 @@ PyAPI_FUNC(PyLongObject*) _PyLong_FromDigits(
|
||||
|
||||
static inline int
|
||||
_PyLong_IsCompact(const PyLongObject* op) {
|
||||
assert(PyType_HasFeature((op)->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS));
|
||||
assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
|
||||
return op->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS);
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ static inline Py_ssize_t
|
||||
_PyLong_CompactValue(const PyLongObject *op)
|
||||
{
|
||||
Py_ssize_t sign;
|
||||
assert(PyType_HasFeature((op)->ob_base.ob_type, Py_TPFLAGS_LONG_SUBCLASS));
|
||||
assert(PyType_HasFeature(Py_TYPE(op), Py_TPFLAGS_LONG_SUBCLASS));
|
||||
assert(PyUnstable_Long_IsCompact(op));
|
||||
sign = 1 - (op->long_value.lv_tag & _PyLong_SIGN_MASK);
|
||||
return sign * (Py_ssize_t)op->long_value.ob_digit[0];
|
||||
|
@ -261,8 +261,8 @@ PyAPI_DATA(PyTypeObject) PyBool_Type;
|
||||
|
||||
// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
|
||||
static inline Py_ssize_t Py_SIZE(PyObject *ob) {
|
||||
assert(ob->ob_type != &PyLong_Type);
|
||||
assert(ob->ob_type != &PyBool_Type);
|
||||
assert(Py_TYPE(ob) != &PyLong_Type);
|
||||
assert(Py_TYPE(ob) != &PyBool_Type);
|
||||
return _PyVarObject_CAST(ob)->ob_size;
|
||||
}
|
||||
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
|
||||
@ -289,8 +289,8 @@ static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
|
||||
#endif
|
||||
|
||||
static inline void Py_SET_SIZE(PyVarObject *ob, Py_ssize_t size) {
|
||||
assert(ob->ob_base.ob_type != &PyLong_Type);
|
||||
assert(ob->ob_base.ob_type != &PyBool_Type);
|
||||
assert(Py_TYPE(_PyObject_CAST(ob)) != &PyLong_Type);
|
||||
assert(Py_TYPE(_PyObject_CAST(ob)) != &PyBool_Type);
|
||||
#ifdef Py_GIL_DISABLED
|
||||
_Py_atomic_store_ssize_relaxed(&ob->ob_size, size);
|
||||
#else
|
||||
|
@ -3090,7 +3090,7 @@ static PyDateTime_Delta *
|
||||
look_up_delta(int days, int seconds, int microseconds, PyTypeObject *type)
|
||||
{
|
||||
if (days == 0 && seconds == 0 && microseconds == 0
|
||||
&& type == zero_delta.ob_base.ob_type)
|
||||
&& type == Py_TYPE(&zero_delta))
|
||||
{
|
||||
return &zero_delta;
|
||||
}
|
||||
|
@ -2389,7 +2389,7 @@ PyObject *
|
||||
_PyDict_GetItemWithError(PyObject *dp, PyObject *kv)
|
||||
{
|
||||
assert(PyUnicode_CheckExact(kv));
|
||||
Py_hash_t hash = kv->ob_type->tp_hash(kv);
|
||||
Py_hash_t hash = Py_TYPE(kv)->tp_hash(kv);
|
||||
if (hash == -1) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -2083,7 +2083,7 @@ PyVarObject *
|
||||
_PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
|
||||
{
|
||||
const size_t basicsize = _PyObject_VAR_SIZE(Py_TYPE(op), nitems);
|
||||
const size_t presize = _PyType_PreHeaderSize(((PyObject *)op)->ob_type);
|
||||
const size_t presize = _PyType_PreHeaderSize(Py_TYPE(op));
|
||||
_PyObject_ASSERT((PyObject *)op, !_PyObject_GC_IS_TRACKED(op));
|
||||
if (basicsize > (size_t)PY_SSIZE_T_MAX - presize) {
|
||||
return (PyVarObject *)PyErr_NoMemory();
|
||||
@ -2101,7 +2101,7 @@ _PyObject_GC_Resize(PyVarObject *op, Py_ssize_t nitems)
|
||||
void
|
||||
PyObject_GC_Del(void *op)
|
||||
{
|
||||
size_t presize = _PyType_PreHeaderSize(((PyObject *)op)->ob_type);
|
||||
size_t presize = _PyType_PreHeaderSize(Py_TYPE(op));
|
||||
PyGC_Head *g = AS_GC(op);
|
||||
if (_PyObject_GC_IS_TRACKED(op)) {
|
||||
gc_list_remove(g);
|
||||
@ -2109,7 +2109,7 @@ PyObject_GC_Del(void *op)
|
||||
PyObject *exc = PyErr_GetRaisedException();
|
||||
if (PyErr_WarnExplicitFormat(PyExc_ResourceWarning, "gc", 0,
|
||||
"gc", NULL, "Object of type %s is not untracked before destruction",
|
||||
((PyObject*)op)->ob_type->tp_name)) {
|
||||
Py_TYPE(op)->tp_name)) {
|
||||
PyErr_WriteUnraisable(NULL);
|
||||
}
|
||||
PyErr_SetRaisedException(exc);
|
||||
|
@ -637,7 +637,7 @@ specialize_module_load_attr(
|
||||
) {
|
||||
_PyAttrCache *cache = (_PyAttrCache *)(instr + 1);
|
||||
PyModuleObject *m = (PyModuleObject *)owner;
|
||||
assert((owner->ob_type->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0);
|
||||
assert((Py_TYPE(owner)->tp_flags & Py_TPFLAGS_MANAGED_DICT) == 0);
|
||||
PyDictObject *dict = (PyDictObject *)m->md_dict;
|
||||
if (dict == NULL) {
|
||||
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_NO_DICT);
|
||||
|
Loading…
Reference in New Issue
Block a user