Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use a macro and remove redundant casts for superobject casts
  • Loading branch information
picnixz committed Feb 6, 2025
commit 8caec09f422d4f6b661fa5b6afb532b96ef8da3f
16 changes: 9 additions & 7 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -11499,6 +11499,8 @@ typedef struct {
PyTypeObject *obj_type;
} superobject;

#define superobject_CAST(op) ((superobject *)(op))

static PyMemberDef super_members[] = {
{"__thisclass__", _Py_T_OBJECT, offsetof(superobject, type), Py_READONLY,
"the class invoking super()"},
Expand All @@ -11512,7 +11514,7 @@ static PyMemberDef super_members[] = {
static void
super_dealloc(PyObject *self)
{
superobject *su = (superobject *)self;
superobject *su = superobject_CAST(self);

_PyObject_GC_UNTRACK(self);
Py_XDECREF(su->obj);
Expand All @@ -11524,7 +11526,7 @@ super_dealloc(PyObject *self)
static PyObject *
super_repr(PyObject *self)
{
superobject *su = (superobject *)self;
superobject *su = superobject_CAST(self);

if (su->obj_type)
return PyUnicode_FromFormat(
Expand Down Expand Up @@ -11646,7 +11648,7 @@ do_super_lookup(superobject *su, PyTypeObject *su_type, PyObject *su_obj,
static PyObject *
super_getattro(PyObject *self, PyObject *name)
{
superobject *su = (superobject *)self;
superobject *su = superobject_CAST(self);

/* We want __class__ to return the class of the super object
(i.e. super, or a subclass), not the class of su->obj. */
Expand Down Expand Up @@ -11739,7 +11741,7 @@ _PySuper_Lookup(PyTypeObject *su_type, PyObject *su_obj, PyObject *name, int *me
static PyObject *
super_descr_get(PyObject *self, PyObject *obj, PyObject *type)
{
superobject *su = (superobject *)self;
superobject *su = superobject_CAST(self);
superobject *newobj;

if (obj == NULL || obj == Py_None || su->obj != NULL) {
Expand Down Expand Up @@ -11871,7 +11873,7 @@ super_init(PyObject *self, PyObject *args, PyObject *kwds)

static inline int
super_init_impl(PyObject *self, PyTypeObject *type, PyObject *obj) {
superobject *su = (superobject *)self;
superobject *su = superobject_CAST(self);
PyTypeObject *obj_type = NULL;
if (type == NULL) {
/* Call super(), without args -- fill in from __class__
Expand Down Expand Up @@ -11930,7 +11932,7 @@ PyDoc_STRVAR(super_doc,
static int
super_traverse(PyObject *self, visitproc visit, void *arg)
{
superobject *su = (superobject *)self;
superobject *su = superobject_CAST(self);

Py_VISIT(su->obj);
Py_VISIT(su->type);
Expand Down Expand Up @@ -12022,5 +12024,5 @@ PyTypeObject PySuper_Type = {
PyType_GenericAlloc, /* tp_alloc */
PyType_GenericNew, /* tp_new */
PyObject_GC_Del, /* tp_free */
.tp_vectorcall = (vectorcallfunc)super_vectorcall,
.tp_vectorcall = super_vectorcall,
};