GeezerVison is showing github.com — gh-91768: C API no longer use "const PyObject*" type (#91769) · python/cpython@eaa85cb
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: Doc/c-api/structures.rst +12-7Lines changed: 12 additions & 7 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -62,38 +62,38 @@ the definition of all other Python objects. | 62 | 62 | See documentation of :c:type:`PyVarObject` above. | 63 | 63 |
| 64 | 64 |
| 65 | | -.. c:function:: int Py_Is(const PyObject *x, const PyObject *y) | | 65 | +.. c:function:: int Py_Is(PyObject *x, PyObject *y) | 66 | 66 |
| 67 | 67 | Test if the *x* object is the *y* object, the same as ``x is y`` in Python. | 68 | 68 |
| 69 | 69 | .. versionadded:: 3.10 | 70 | 70 |
| 71 | 71 |
| 72 | | -.. c:function:: int Py_IsNone(const PyObject *x) | | 72 | +.. c:function:: int Py_IsNone(PyObject *x) | 73 | 73 |
| 74 | 74 | Test if an object is the ``None`` singleton, | 75 | 75 | the same as ``x is None`` in Python. | 76 | 76 |
| 77 | 77 | .. versionadded:: 3.10 | 78 | 78 |
| 79 | 79 |
| 80 | | -.. c:function:: int Py_IsTrue(const PyObject *x) | | 80 | +.. c:function:: int Py_IsTrue(PyObject *x) | 81 | 81 |
| 82 | 82 | Test if an object is the ``True`` singleton, | 83 | 83 | the same as ``x is True`` in Python. | 84 | 84 |
| 85 | 85 | .. versionadded:: 3.10 | 86 | 86 |
| 87 | 87 |
| 88 | | -.. c:function:: int Py_IsFalse(const PyObject *x) | | 88 | +.. c:function:: int Py_IsFalse(PyObject *x) | 89 | 89 |
| 90 | 90 | Test if an object is the ``False`` singleton, | 91 | 91 | the same as ``x is False`` in Python. | 92 | 92 |
| 93 | 93 | .. versionadded:: 3.10 | 94 | 94 |
| 95 | 95 |
| 96 | | -.. c:function:: PyTypeObject* Py_TYPE(const PyObject *o) | | 96 | +.. c:function:: PyTypeObject* Py_TYPE(PyObject *o) | 97 | 97 |
| 98 | 98 | Get the type of the Python object *o*. | 99 | 99 |
| @@ -103,6 +103,7 @@ the definition of all other Python objects. | 103 | 103 |
| 104 | 104 | .. versionchanged:: 3.11 | 105 | 105 | :c:func:`Py_TYPE()` is changed to an inline static function. | | 106 | + The parameter type is no longer :c:type:`const PyObject*`. | 106 | 107 |
| 107 | 108 |
| 108 | 109 | .. c:function:: int Py_IS_TYPE(PyObject *o, PyTypeObject *type) | @@ -120,12 +121,15 @@ the definition of all other Python objects. | 120 | 121 | .. versionadded:: 3.9 | 121 | 122 |
| 122 | 123 |
| 123 | | -.. c:function:: Py_ssize_t Py_REFCNT(const PyObject *o) | | 124 | +.. c:function:: Py_ssize_t Py_REFCNT(PyObject *o) | 124 | 125 |
| 125 | 126 | Get the reference count of the Python object *o*. | 126 | 127 |
| 127 | 128 | Use the :c:func:`Py_SET_REFCNT()` function to set an object reference count. | 128 | 129 |
| | 130 | + .. versionchanged:: 3.11 | | 131 | + The parameter type is no longer :c:type:`const PyObject*`. | | 132 | +
| 129 | 133 | .. versionchanged:: 3.10 | 130 | 134 | :c:func:`Py_REFCNT()` is changed to the inline static function. | 131 | 135 |
| @@ -137,14 +141,15 @@ the definition of all other Python objects. | 137 | 141 | .. versionadded:: 3.9 | 138 | 142 |
| 139 | 143 |
| 140 | | -.. c:function:: Py_ssize_t Py_SIZE(const PyVarObject *o) | | 144 | +.. c:function:: Py_ssize_t Py_SIZE(PyVarObject *o) | 141 | 145 |
| 142 | 146 | Get the size of the Python object *o*. | 143 | 147 |
| 144 | 148 | Use the :c:func:`Py_SET_SIZE` function to set an object size. | 145 | 149 |
| 146 | 150 | .. versionchanged:: 3.11 | 147 | 151 | :c:func:`Py_SIZE()` is changed to an inline static function. | | 152 | + The parameter type is no longer :c:type:`const PyVarObject*`. | 148 | 153 |
| 149 | 154 |
| 150 | 155 | .. c:function:: void Py_SET_SIZE(PyVarObject *o, Py_ssize_t size) | |
Collapse file Copy file name to clipboardExpand all lines: Include/internal/pycore_strhex.h +2-2Lines changed: 2 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -22,12 +22,12 @@ PyAPI_FUNC(PyObject*) _Py_strhex_bytes( | 22 | 22 | PyAPI_FUNC(PyObject*) _Py_strhex_with_sep( | 23 | 23 | const char* argbuf, | 24 | 24 | const Py_ssize_t arglen, | 25 | | - const PyObject* sep, | | 25 | + PyObject* sep, | 26 | 26 | const int bytes_per_group); | 27 | 27 | PyAPI_FUNC(PyObject*) _Py_strhex_bytes_with_sep( | 28 | 28 | const char* argbuf, | 29 | 29 | const Py_ssize_t arglen, | 30 | | - const PyObject* sep, | | 30 | + PyObject* sep, | 31 | 31 | const int bytes_per_group); | 32 | 32 |
| 33 | 33 | #ifdef __cplusplus | |
Collapse file Copy file name to clipboardExpand all lines: Include/object.h +9-13Lines changed: 9 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -105,7 +105,6 @@ struct _object { | 105 | 105 |
| 106 | 106 | /* Cast argument to PyObject* type. */ | 107 | 107 | #define _PyObject_CAST(op) ((PyObject*)(op)) | 108 | | -#define _PyObject_CAST_CONST(op) ((const PyObject*)(op)) | 109 | 108 |
| 110 | 109 | typedef struct { | 111 | 110 | PyObject ob_base; | @@ -114,39 +113,36 @@ typedef struct { | 114 | 113 |
| 115 | 114 | /* Cast argument to PyVarObject* type. */ | 116 | 115 | #define _PyVarObject_CAST(op) ((PyVarObject*)(op)) | 117 | | -#define _PyVarObject_CAST_CONST(op) ((const PyVarObject*)(op)) | 118 | 116 |
| 119 | 117 |
| 120 | 118 | // Test if the 'x' object is the 'y' object, the same as "x is y" in Python. | 121 | 119 | PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y); | 122 | 120 | #define Py_Is(x, y) ((x) == (y)) | 123 | 121 |
| 124 | 122 |
| 125 | | -static inline Py_ssize_t Py_REFCNT(const PyObject *ob) { | | 123 | +static inline Py_ssize_t Py_REFCNT(PyObject *ob) { | 126 | 124 | return ob->ob_refcnt; | 127 | 125 | } | 128 | | -#define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST_CONST(ob)) | | 126 | +#define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob)) | 129 | 127 |
| 130 | 128 |
| 131 | 129 | // bpo-39573: The Py_SET_TYPE() function must be used to set an object type. | 132 | | -static inline PyTypeObject* Py_TYPE(const PyObject *ob) { | | 130 | +static inline PyTypeObject* Py_TYPE(PyObject *ob) { | 133 | 131 | return ob->ob_type; | 134 | 132 | } | 135 | | -#define Py_TYPE(ob) Py_TYPE(_PyObject_CAST_CONST(ob)) | | 133 | +#define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob)) | 136 | 134 |
| 137 | 135 | // bpo-39573: The Py_SET_SIZE() function must be used to set an object size. | 138 | | -static inline Py_ssize_t Py_SIZE(const PyVarObject *ob) { | | 136 | +static inline Py_ssize_t Py_SIZE(PyVarObject *ob) { | 139 | 137 | return ob->ob_size; | 140 | 138 | } | 141 | | -#define Py_SIZE(ob) Py_SIZE(_PyVarObject_CAST_CONST(ob)) | | 139 | +#define Py_SIZE(ob) Py_SIZE(_PyVarObject_CAST(ob)) | 142 | 140 |
| 143 | 141 |
| 144 | | -static inline int Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) { | 145 | | - // bpo-44378: Don't use Py_TYPE() since Py_TYPE() requires a non-const | 146 | | - // object. | 147 | | - return ob->ob_type == type; | | 142 | +static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) { | | 143 | + return Py_TYPE(ob) == type; | 148 | 144 | } | 149 | | -#define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST_CONST(ob), type) | | 145 | +#define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), type) | 150 | 146 |
| 151 | 147 |
| 152 | 148 | static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { | |
Collapse file Copy file name to clipboard +3Lines changed: 3 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
| | 1 | +:c:func:`Py_REFCNT`, :c:func:`Py_TYPE`, :c:func:`Py_SIZE` and | | 2 | +:c:func:`Py_IS_TYPE` functions argument type is now ``PyObject*``, rather | | 3 | +than ``const PyObject*``. Patch by Victor Stinner. |
Collapse file Copy file name to clipboardExpand all lines: Python/pystrhex.c +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | #include <stdlib.h> // abs() | 6 | 6 |
| 7 | 7 | static PyObject *_Py_strhex_impl(const char* argbuf, const Py_ssize_t arglen, | 8 | | - const PyObject* sep, int bytes_per_sep_group, | | 8 | + PyObject* sep, int bytes_per_sep_group, | 9 | 9 | const int return_bytes) | 10 | 10 | { | 11 | 11 | assert(arglen >= 0); | @@ -152,21 +152,23 @@ PyObject * _Py_strhex(const char* argbuf, const Py_ssize_t arglen) | 152 | 152 |
| 153 | 153 | /* Same as above but returns a bytes() instead of str() to avoid the | 154 | 154 | * need to decode the str() when bytes are needed. */ | 155 | | -PyObject * _Py_strhex_bytes(const char* argbuf, const Py_ssize_t arglen) | | 155 | +PyObject* _Py_strhex_bytes(const char* argbuf, const Py_ssize_t arglen) | 156 | 156 | { | 157 | 157 | return _Py_strhex_impl(argbuf, arglen, NULL, 0, 1); | 158 | 158 | } | 159 | 159 |
| 160 | 160 | /* These variants include support for a separator between every N bytes: */ | 161 | 161 |
| 162 | | -PyObject * _Py_strhex_with_sep(const char* argbuf, const Py_ssize_t arglen, const PyObject* sep, const int bytes_per_group) | | 162 | +PyObject* _Py_strhex_with_sep(const char* argbuf, const Py_ssize_t arglen, | | 163 | + PyObject* sep, const int bytes_per_group) | 163 | 164 | { | 164 | 165 | return _Py_strhex_impl(argbuf, arglen, sep, bytes_per_group, 0); | 165 | 166 | } | 166 | 167 |
| 167 | 168 | /* Same as above but returns a bytes() instead of str() to avoid the | 168 | 169 | * need to decode the str() when bytes are needed. */ | 169 | | -PyObject * _Py_strhex_bytes_with_sep(const char* argbuf, const Py_ssize_t arglen, const PyObject* sep, const int bytes_per_group) | | 170 | +PyObject* _Py_strhex_bytes_with_sep(const char* argbuf, const Py_ssize_t arglen, | | 171 | + PyObject* sep, const int bytes_per_group) | 170 | 172 | { | 171 | 173 | return _Py_strhex_impl(argbuf, arglen, sep, bytes_per_group, 1); | 172 | 174 | } |
|