mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
GH-101291: Rearrange the size bits in PyLongObject (GH-102464)
* Eliminate all remaining uses of Py_SIZE and Py_SET_SIZE on PyLongObject, adding asserts. * Change layout of size/sign bits in longobject to support future addition of immortal ints and tagged medium ints. * Add functions to hide some internals of long object, and for setting sign and digit count. * Replace uses of IS_MEDIUM_VALUE macro with _PyLong_IsCompact().
This commit is contained in:
parent
713df2c534
commit
7559f5fda9
25 changed files with 982 additions and 898 deletions
|
@ -138,8 +138,13 @@ static inline PyTypeObject* Py_TYPE(PyObject *ob) {
|
|||
# define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
|
||||
#endif
|
||||
|
||||
PyAPI_DATA(PyTypeObject) PyLong_Type;
|
||||
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);
|
||||
PyVarObject *var_ob = _PyVarObject_CAST(ob);
|
||||
return var_ob->ob_size;
|
||||
}
|
||||
|
@ -171,8 +176,9 @@ static inline void Py_SET_TYPE(PyObject *ob, PyTypeObject *type) {
|
|||
# define Py_SET_TYPE(ob, type) Py_SET_TYPE(_PyObject_CAST(ob), 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);
|
||||
ob->ob_size = size;
|
||||
}
|
||||
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue