Skip to content

Commit 2db046d

Browse files
committed
Issue #6151: Make PyDescr_COMMON conform to standard C.
1 parent cf76e1a commit 2db046d

4 files changed

Lines changed: 31 additions & 23 deletions

File tree

Include/descrobject.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,17 @@ struct wrapperbase {
3737

3838
/* Various kinds of descriptor objects */
3939

40-
#define PyDescr_COMMON \
41-
PyObject_HEAD \
42-
PyTypeObject *d_type; \
43-
PyObject *d_name
44-
4540
typedef struct {
46-
PyDescr_COMMON;
41+
PyObject_HEAD
42+
PyTypeObject *d_type;
43+
PyObject *d_name;
4744
} PyDescrObject;
4845

46+
#define PyDescr_COMMON PyDescrObject d_common
47+
48+
#define PyDescr_TYPE(x) (((PyDescrObject *)(x))->d_type)
49+
#define PyDescr_NAME(x) (((PyDescrObject *)(x))->d_name)
50+
4951
typedef struct {
5052
PyDescr_COMMON;
5153
PyMethodDef *d_method;

Misc/NEWS

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ Core and Builtins
3636
C-API
3737
-----
3838

39-
- Issue #6405: Remove duplicatet type declarations in descrobject.h.
39+
- Issue #6151: Made PyDescr_COMMON conform to standard C (like PyObject_HEAD
40+
in PEP 3123). The PyDescr_TYPE and PyDescr_NAME macros should be
41+
should used for accessing the d_type and d_name members of structures
42+
using PyDescr_COMMON.
43+
44+
- Issue #6405: Remove duplicate type declarations in descrobject.h.
4045

4146
- The code flags for old __future__ features are now available again.
4247

@@ -49,6 +54,7 @@ C-API
4954
- Issue #1419652: Change the first argument to PyImport_AppendInittab() to
5055
``const char *`` as the string is stored beyond the call.
5156

57+
5258
Library
5359
-------
5460

Objects/descrobject.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
9292
"descriptor '%V' for type '%s' "
9393
"needs either an object or a type",
9494
descr_name((PyDescrObject *)descr), "?",
95-
descr->d_type->tp_name);
95+
PyDescr_TYPE(descr)->tp_name);
9696
return NULL;
9797
}
9898
}
@@ -101,16 +101,16 @@ classmethod_get(PyMethodDescrObject *descr, PyObject *obj, PyObject *type)
101101
"descriptor '%V' for type '%s' "
102102
"needs a type, not a '%s' as arg 2",
103103
descr_name((PyDescrObject *)descr), "?",
104-
descr->d_type->tp_name,
104+
PyDescr_TYPE(descr)->tp_name,
105105
type->ob_type->tp_name);
106106
return NULL;
107107
}
108-
if (!PyType_IsSubtype((PyTypeObject *)type, descr->d_type)) {
108+
if (!PyType_IsSubtype((PyTypeObject *)type, PyDescr_TYPE(descr))) {
109109
PyErr_Format(PyExc_TypeError,
110110
"descriptor '%V' for type '%s' "
111111
"doesn't apply to type '%s'",
112112
descr_name((PyDescrObject *)descr), "?",
113-
descr->d_type->tp_name,
113+
PyDescr_TYPE(descr)->tp_name,
114114
((PyTypeObject *)type)->tp_name);
115115
return NULL;
116116
}
@@ -149,7 +149,7 @@ getset_get(PyGetSetDescrObject *descr, PyObject *obj, PyObject *type)
149149
PyErr_Format(PyExc_AttributeError,
150150
"attribute '%V' of '%.100s' objects is not readable",
151151
descr_name((PyDescrObject *)descr), "?",
152-
descr->d_type->tp_name);
152+
PyDescr_TYPE(descr)->tp_name);
153153
return NULL;
154154
}
155155

@@ -204,7 +204,7 @@ getset_set(PyGetSetDescrObject *descr, PyObject *obj, PyObject *value)
204204
PyErr_Format(PyExc_AttributeError,
205205
"attribute '%V' of '%.100s' objects is not writable",
206206
descr_name((PyDescrObject *)descr), "?",
207-
descr->d_type->tp_name);
207+
PyDescr_TYPE(descr)->tp_name);
208208
return -1;
209209
}
210210

@@ -222,17 +222,17 @@ methoddescr_call(PyMethodDescrObject *descr, PyObject *args, PyObject *kwds)
222222
"descriptor '%V' of '%.100s' "
223223
"object needs an argument",
224224
descr_name((PyDescrObject *)descr), "?",
225-
descr->d_type->tp_name);
225+
PyDescr_TYPE(descr)->tp_name);
226226
return NULL;
227227
}
228228
self = PyTuple_GET_ITEM(args, 0);
229-
if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) {
229+
if (!PyObject_IsInstance(self, (PyObject *)PyDescr_TYPE(descr))) {
230230
PyErr_Format(PyExc_TypeError,
231231
"descriptor '%V' "
232232
"requires a '%.100s' object "
233233
"but received a '%.100s'",
234234
descr_name((PyDescrObject *)descr), "?",
235-
descr->d_type->tp_name,
235+
PyDescr_TYPE(descr)->tp_name,
236236
self->ob_type->tp_name);
237237
return NULL;
238238
}
@@ -257,7 +257,7 @@ classmethoddescr_call(PyMethodDescrObject *descr, PyObject *args,
257257
{
258258
PyObject *func, *result;
259259

260-
func = PyCFunction_New(descr->d_method, (PyObject *)descr->d_type);
260+
func = PyCFunction_New(descr->d_method, (PyObject *)PyDescr_TYPE(descr));
261261
if (func == NULL)
262262
return NULL;
263263

@@ -280,17 +280,17 @@ wrapperdescr_call(PyWrapperDescrObject *descr, PyObject *args, PyObject *kwds)
280280
"descriptor '%V' of '%.100s' "
281281
"object needs an argument",
282282
descr_name((PyDescrObject *)descr), "?",
283-
descr->d_type->tp_name);
283+
PyDescr_TYPE(descr)->tp_name);
284284
return NULL;
285285
}
286286
self = PyTuple_GET_ITEM(args, 0);
287-
if (!PyObject_IsInstance(self, (PyObject *)(descr->d_type))) {
287+
if (!PyObject_IsInstance(self, (PyObject *)PyDescr_TYPE(descr))) {
288288
PyErr_Format(PyExc_TypeError,
289289
"descriptor '%V' "
290290
"requires a '%.100s' object "
291291
"but received a '%.100s'",
292292
descr_name((PyDescrObject *)descr), "?",
293-
descr->d_type->tp_name,
293+
PyDescr_TYPE(descr)->tp_name,
294294
self->ob_type->tp_name);
295295
return NULL;
296296
}
@@ -949,7 +949,7 @@ static PyMemberDef wrapper_members[] = {
949949
static PyObject *
950950
wrapper_objclass(wrapperobject *wp)
951951
{
952-
PyObject *c = (PyObject *)wp->descr->d_type;
952+
PyObject *c = (PyObject *)PyDescr_TYPE(wp->descr);
953953

954954
Py_INCREF(c);
955955
return c;
@@ -1059,7 +1059,7 @@ PyWrapper_New(PyObject *d, PyObject *self)
10591059

10601060
assert(PyObject_TypeCheck(d, &PyWrapperDescr_Type));
10611061
descr = (PyWrapperDescrObject *)d;
1062-
assert(PyObject_IsInstance(self, (PyObject *)(descr->d_type)));
1062+
assert(PyObject_IsInstance(self, (PyObject *)PyDescr_TYPE(descr)));
10631063

10641064
wp = PyObject_GC_New(wrapperobject, &wrappertype);
10651065
if (wp != NULL) {

Objects/typeobject.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5648,7 +5648,7 @@ update_one_slot(PyTypeObject *type, slotdef *p)
56485648
generic = p->function;
56495649
d = (PyWrapperDescrObject *)descr;
56505650
if (d->d_base->wrapper == p->wrapper &&
5651-
PyType_IsSubtype(type, d->d_type))
5651+
PyType_IsSubtype(type, PyDescr_TYPE(d)))
56525652
{
56535653
if (specific == NULL ||
56545654
specific == d->d_wrapped)

0 commit comments

Comments
 (0)