diff --git a/Include/object.h b/Include/object.h index a9d434b5108068..fd69df7135df58 100644 --- a/Include/object.h +++ b/Include/object.h @@ -183,11 +183,11 @@ typedef struct{ } PyType_Slot; typedef struct{ - const char* name; - int basicsize; - int itemsize; - unsigned int flags; - PyType_Slot *slots; /* terminated by slot==0. */ + const char* ts_name; + int ts_basicsize; + int ts_itemsize; + unsigned int ts_flags; + PyType_Slot *ts_slots; /* terminated by slot==0. */ } PyType_Spec; PyAPI_FUNC(PyObject*) PyType_FromSpec(PyType_Spec*); diff --git a/Misc/NEWS.d/next/C API/2019-09-02-14-46-19.bpo-38007.01cujD.rst b/Misc/NEWS.d/next/C API/2019-09-02-14-46-19.bpo-38007.01cujD.rst new file mode 100644 index 00000000000000..cff8af600cf498 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2019-09-02-14-46-19.bpo-38007.01cujD.rst @@ -0,0 +1 @@ +Compilation bug fixed: CPython and Qt headers could not be used together because PyType_Spec struct "slots" member name conflicted with Qt's "slots" macro. This change keeps binary compatibility, but client code should follow changes in PyType_Spec struct member names, if recompiled. diff --git a/Objects/structseq.c b/Objects/structseq.c index 2c25e1646a2a67..e995b355fe9238 100644 --- a/Objects/structseq.c +++ b/Objects/structseq.c @@ -468,11 +468,11 @@ PyStructSequence_NewType(PyStructSequence_Desc *desc) /* Initialize Spec */ /* The name in this PyType_Spec is statically allocated so it is */ /* expected that it'll outlive the PyType_Spec */ - spec.name = desc->name; - spec.basicsize = sizeof(PyStructSequence) - sizeof(PyObject *); - spec.itemsize = sizeof(PyObject *); - spec.flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC; - spec.slots = slots; + spec.ts_name = desc->name; + spec.ts_basicsize = sizeof(PyStructSequence) - sizeof(PyObject *); + spec.ts_itemsize = sizeof(PyObject *); + spec.ts_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC; + spec.ts_slots = slots; bases = PyTuple_Pack(1, &PyTuple_Type); if (bases == NULL) { diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 1d8216d2988728..46aaec92875cbb 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -2857,7 +2857,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) char *s, *res_start; nmembers = 0; - for (slot = spec->slots; slot->slot; slot++) { + for (slot = spec->ts_slots; slot->slot; slot++) { if (slot->slot == Py_tp_members) { nmembers = 0; for (memb = slot->pfunc; memb->name != NULL; memb++) { @@ -2871,34 +2871,34 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) return NULL; res_start = (char*)res; - if (spec->name == NULL) { + if (spec->ts_name == NULL) { PyErr_SetString(PyExc_SystemError, "Type spec does not define the name field."); goto fail; } /* Set the type name and qualname */ - s = strrchr(spec->name, '.'); + s = strrchr(spec->ts_name, '.'); if (s == NULL) - s = (char*)spec->name; + s = (char*)spec->ts_name; else s++; type = &res->ht_type; /* The flags must be initialized early, before the GC traverses us */ - type->tp_flags = spec->flags | Py_TPFLAGS_HEAPTYPE; + type->tp_flags = spec->ts_flags | Py_TPFLAGS_HEAPTYPE; res->ht_name = PyUnicode_FromString(s); if (!res->ht_name) goto fail; res->ht_qualname = res->ht_name; Py_INCREF(res->ht_qualname); - type->tp_name = spec->name; + type->tp_name = spec->ts_name; /* Adjust for empty tuple bases */ if (!bases) { base = &PyBaseObject_Type; /* See whether Py_tp_base(s) was specified */ - for (slot = spec->slots; slot->slot; slot++) { + for (slot = spec->ts_slots; slot->slot; slot++) { if (slot->slot == Py_tp_base) base = slot->pfunc; else if (slot->slot == Py_tp_bases) { @@ -2938,10 +2938,10 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) Py_INCREF(base); type->tp_base = base; - type->tp_basicsize = spec->basicsize; - type->tp_itemsize = spec->itemsize; + type->tp_basicsize = spec->ts_basicsize; + type->tp_itemsize = spec->ts_itemsize; - for (slot = spec->slots; slot->slot; slot++) { + for (slot = spec->ts_slots; slot->slot; slot++) { if (slot->slot < 0 || (size_t)slot->slot >= Py_ARRAY_LENGTH(slotoffsets)) { PyErr_SetString(PyExc_RuntimeError, "invalid slot offset"); @@ -2991,11 +2991,11 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) } /* Set type.__module__ */ - s = strrchr(spec->name, '.'); + s = strrchr(spec->ts_name, '.'); if (s != NULL) { int err; modname = PyUnicode_FromStringAndSize( - spec->name, (Py_ssize_t)(s - spec->name)); + spec->ts_name, (Py_ssize_t)(s - spec->ts_name)); if (modname == NULL) { goto fail; } @@ -3006,7 +3006,7 @@ PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases) } else { if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, "builtin type %.200s has no __module__ attribute", - spec->name)) + spec->ts_name)) goto fail; }