diff options
author | Mark Shannon <mark@hotpy.org> | 2023-03-22 14:49:51 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-22 14:49:51 (GMT) |
commit | 7559f5fda94ab568a1a910b17683ed81dc3426fb (patch) | |
tree | a050bbc075372c6246fe3386560596f2283ae8bb /Include/object.h | |
parent | 713df2c53489ce8012d0ede10b70950e6b0d8372 (diff) | |
download | cpython-7559f5fda94ab568a1a910b17683ed81dc3426fb.zip cpython-7559f5fda94ab568a1a910b17683ed81dc3426fb.tar.gz cpython-7559f5fda94ab568a1a910b17683ed81dc3426fb.tar.bz2 |
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().
Diffstat (limited to 'Include/object.h')
-rw-r--r-- | Include/object.h | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Include/object.h b/Include/object.h index fc57735..2943a60 100644 --- a/Include/object.h +++ b/Include/object.h @@ -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 |