summaryrefslogtreecommitdiff
path: root/Include
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-04-21 22:07:19 +0200
committerGitHub <noreply@github.com>2022-04-21 22:07:19 +0200
commiteaa85cb22fa2d9e7cd31c2eac29a56cd3a8f2f65 (patch)
treeaf608caa1e93136eb244a107ba069714ec035b89 /Include
parent128d6241176a879ea9b6e34ea67f1d113d22a1b8 (diff)
downloadcpython-git-eaa85cb22fa2d9e7cd31c2eac29a56cd3a8f2f65.tar.gz
gh-91768: C API no longer use "const PyObject*" type (#91769)
Py_REFCNT(), Py_TYPE(), Py_SIZE() and Py_IS_TYPE() functions argument type is now "PyObject*", rather than "const PyObject*". * Replace also "const PyObject*" with "PyObject*" in functions: * _Py_strhex_impl() * _Py_strhex_with_sep() * _Py_strhex_bytes_with_sep() * Remove _PyObject_CAST_CONST() and _PyVarObject_CAST_CONST() macros. * Py_IS_TYPE() can now use Py_TYPE() in its implementation.
Diffstat (limited to 'Include')
-rw-r--r--Include/internal/pycore_strhex.h4
-rw-r--r--Include/object.h22
2 files changed, 11 insertions, 15 deletions
diff --git a/Include/internal/pycore_strhex.h b/Include/internal/pycore_strhex.h
index 1633671da0..f427b4d695 100644
--- a/Include/internal/pycore_strhex.h
+++ b/Include/internal/pycore_strhex.h
@@ -22,12 +22,12 @@ PyAPI_FUNC(PyObject*) _Py_strhex_bytes(
PyAPI_FUNC(PyObject*) _Py_strhex_with_sep(
const char* argbuf,
const Py_ssize_t arglen,
- const PyObject* sep,
+ PyObject* sep,
const int bytes_per_group);
PyAPI_FUNC(PyObject*) _Py_strhex_bytes_with_sep(
const char* argbuf,
const Py_ssize_t arglen,
- const PyObject* sep,
+ PyObject* sep,
const int bytes_per_group);
#ifdef __cplusplus
diff --git a/Include/object.h b/Include/object.h
index 0b4b55ea1d..8a45ddbf60 100644
--- a/Include/object.h
+++ b/Include/object.h
@@ -105,7 +105,6 @@ struct _object {
/* Cast argument to PyObject* type. */
#define _PyObject_CAST(op) ((PyObject*)(op))
-#define _PyObject_CAST_CONST(op) ((const PyObject*)(op))
typedef struct {
PyObject ob_base;
@@ -114,7 +113,6 @@ typedef struct {
/* Cast argument to PyVarObject* type. */
#define _PyVarObject_CAST(op) ((PyVarObject*)(op))
-#define _PyVarObject_CAST_CONST(op) ((const PyVarObject*)(op))
// Test if the 'x' object is the 'y' object, the same as "x is y" in Python.
@@ -122,31 +120,29 @@ PyAPI_FUNC(int) Py_Is(PyObject *x, PyObject *y);
#define Py_Is(x, y) ((x) == (y))
-static inline Py_ssize_t Py_REFCNT(const PyObject *ob) {
+static inline Py_ssize_t Py_REFCNT(PyObject *ob) {
return ob->ob_refcnt;
}
-#define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST_CONST(ob))
+#define Py_REFCNT(ob) Py_REFCNT(_PyObject_CAST(ob))
// bpo-39573: The Py_SET_TYPE() function must be used to set an object type.
-static inline PyTypeObject* Py_TYPE(const PyObject *ob) {
+static inline PyTypeObject* Py_TYPE(PyObject *ob) {
return ob->ob_type;
}
-#define Py_TYPE(ob) Py_TYPE(_PyObject_CAST_CONST(ob))
+#define Py_TYPE(ob) Py_TYPE(_PyObject_CAST(ob))
// bpo-39573: The Py_SET_SIZE() function must be used to set an object size.
-static inline Py_ssize_t Py_SIZE(const PyVarObject *ob) {
+static inline Py_ssize_t Py_SIZE(PyVarObject *ob) {
return ob->ob_size;
}
-#define Py_SIZE(ob) Py_SIZE(_PyVarObject_CAST_CONST(ob))
+#define Py_SIZE(ob) Py_SIZE(_PyVarObject_CAST(ob))
-static inline int Py_IS_TYPE(const PyObject *ob, const PyTypeObject *type) {
- // bpo-44378: Don't use Py_TYPE() since Py_TYPE() requires a non-const
- // object.
- return ob->ob_type == type;
+static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) {
+ return Py_TYPE(ob) == type;
}
-#define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST_CONST(ob), type)
+#define Py_IS_TYPE(ob, type) Py_IS_TYPE(_PyObject_CAST(ob), type)
static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) {