Skip to content

bpo-38007: Added ts_ prefix to PyType_Spec struct members #15644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 5 additions & 5 deletions Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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*);
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
10 changes: 5 additions & 5 deletions Objects/structseq.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 13 additions & 13 deletions Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}

Expand Down