Skip to content

Commit 917096a

Browse files
committed
[CPyCppyy] Avoid compiler warnings with Python 3.15
This avoids compiler warnings about missing field initializers because of a new data member in Python 3.15. Also, refactor the code a bit, so that next time a new member is added, we just have to change the code in one place.
1 parent 8519c46 commit 917096a

11 files changed

Lines changed: 45 additions & 90 deletions

bindings/pyroot/cppyy/CPyCppyy/src/CPPDataMember.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,7 @@ PyTypeObject CPPDataMember_Type = {
307307
#if PY_VERSION_HEX >= 0x03080000
308308
, 0 // tp_vectorcall
309309
#endif
310-
#if PY_VERSION_HEX >= 0x030c0000
311-
, 0 // tp_watched
312-
#endif
313-
#if PY_VERSION_HEX >= 0x030d0000
314-
, 0 // tp_versions_used
315-
#endif
310+
CPYCPPYY_PYTYPE_TAIL
316311
};
317312

318313
} // namespace CPyCppyy

bindings/pyroot/cppyy/CPyCppyy/src/CPPExcInstance.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,12 +285,7 @@ PyTypeObject CPPExcInstance_Type = {
285285
#if PY_VERSION_HEX >= 0x03080000
286286
, 0 // tp_vectorcall
287287
#endif
288-
#if PY_VERSION_HEX >= 0x030c0000
289-
, 0 // tp_watched
290-
#endif
291-
#if PY_VERSION_HEX >= 0x030d0000
292-
, 0 // tp_versions_used
293-
#endif
288+
CPYCPPYY_PYTYPE_TAIL
294289
};
295290

296291
} // namespace CPyCppyy

bindings/pyroot/cppyy/CPyCppyy/src/CPPInstance.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,12 +1125,7 @@ PyTypeObject CPPInstance_Type = {
11251125
#if PY_VERSION_HEX >= 0x03080000
11261126
, 0 // tp_vectorcall
11271127
#endif
1128-
#if PY_VERSION_HEX >= 0x030c0000
1129-
, 0 // tp_watched
1130-
#endif
1131-
#if PY_VERSION_HEX >= 0x030d0000
1132-
, 0 // tp_versions_used
1133-
#endif
1128+
CPYCPPYY_PYTYPE_TAIL
11341129
};
11351130

11361131
} // namespace CPyCppyy

bindings/pyroot/cppyy/CPyCppyy/src/CPPOverload.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,12 +1092,7 @@ PyTypeObject CPPOverload_Type = {
10921092
#if PY_VERSION_HEX >= 0x03080000
10931093
, 0 // tp_vectorcall
10941094
#endif
1095-
#if PY_VERSION_HEX >= 0x030c0000
1096-
, 0 // tp_watched
1097-
#endif
1098-
#if PY_VERSION_HEX >= 0x030d0000
1099-
, 0 // tp_versions_used
1100-
#endif
1095+
CPYCPPYY_PYTYPE_TAIL
11011096
};
11021097

11031098
} // namespace CPyCppyy

bindings/pyroot/cppyy/CPyCppyy/src/CPPScope.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -705,12 +705,7 @@ PyTypeObject CPPScope_Type = {
705705
#if PY_VERSION_HEX >= 0x03080000
706706
, 0 // tp_vectorcall
707707
#endif
708-
#if PY_VERSION_HEX >= 0x030c0000
709-
, 0 // tp_watched
710-
#endif
711-
#if PY_VERSION_HEX >= 0x030d0000
712-
, 0 // tp_versions_used
713-
#endif
708+
CPYCPPYY_PYTYPE_TAIL
714709
};
715710

716711
} // namespace CPyCppyy

bindings/pyroot/cppyy/CPyCppyy/src/CPyCppyy.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,34 @@ static inline PyObject* PyObject_CallMethodOneArg(PyObject* obj, PyObject* name,
385385
// export macros for our own API
386386
#include "CPyCppyy/CommonDefs.h"
387387

388+
// --- reusable PyTypeObject initializer tail -------------------------------
389+
// Members appended to PyTypeObject in newer CPython releases. Every CPyCppyy
390+
// type leaves all of these zero/null-initialized, so they share one tail.
391+
// To support a future Python version, add one block below and one line to
392+
// CPYCPPYY_PYTYPE_TAIL.
393+
394+
#if PY_VERSION_HEX >= 0x030c0000
395+
#define CPYCPPYY_TP_WATCHED , 0 /* tp_watched (>= 3.12) */
396+
#else
397+
#define CPYCPPYY_TP_WATCHED
398+
#endif
399+
400+
#if PY_VERSION_HEX >= 0x030d0000
401+
#define CPYCPPYY_TP_VERSIONS_USED , 0 /* tp_versions_used(>= 3.13) */
402+
#else
403+
#define CPYCPPYY_TP_VERSIONS_USED
404+
#endif
405+
406+
#if PY_VERSION_HEX >= 0x030f0000
407+
#define CPYCPPYY_TP_ITERITEM , nullptr /* _tp_iteritem (>= 3.15) */
408+
#else
409+
#define CPYCPPYY_TP_ITERITEM
410+
#endif
411+
412+
#define CPYCPPYY_PYTYPE_TAIL \
413+
CPYCPPYY_TP_WATCHED \
414+
CPYCPPYY_TP_VERSIONS_USED \
415+
CPYCPPYY_TP_ITERITEM
416+
// --------------------------------------------------------------------------
417+
388418
#endif // !CPYCPPYY_CPYCPPYY_H

bindings/pyroot/cppyy/CPyCppyy/src/CPyCppyyModule.cxx

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,7 @@ static PyTypeObject PyNullPtr_t_Type = {
171171
#if PY_VERSION_HEX >= 0x03080000
172172
, 0 // tp_vectorcall
173173
#endif
174-
#if PY_VERSION_HEX >= 0x030c0000
175-
, 0 // tp_watched
176-
#endif
177-
#if PY_VERSION_HEX >= 0x030d0000
178-
, 0 // tp_versions_used
179-
#endif
174+
CPYCPPYY_PYTYPE_TAIL
180175
};
181176

182177

@@ -218,12 +213,7 @@ static PyTypeObject PyDefault_t_Type = {
218213
#if PY_VERSION_HEX >= 0x03080000
219214
, 0 // tp_vectorcall
220215
#endif
221-
#if PY_VERSION_HEX >= 0x030c0000
222-
, 0 // tp_watched
223-
#endif
224-
#if PY_VERSION_HEX >= 0x030d0000
225-
, 0 // tp_versions_used
226-
#endif
216+
CPYCPPYY_PYTYPE_TAIL
227217
};
228218

229219
namespace {

bindings/pyroot/cppyy/CPyCppyy/src/CustomPyTypes.cxx

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,7 @@ PyTypeObject TypedefPointerToClass_Type = {
167167
#if PY_VERSION_HEX >= 0x03080000
168168
, 0 // tp_vectorcall
169169
#endif
170-
#if PY_VERSION_HEX >= 0x030c0000
171-
, 0 // tp_watched
172-
#endif
173-
#if PY_VERSION_HEX >= 0x030d0000
174-
, 0 // tp_versions_used
175-
#endif
170+
CPYCPPYY_PYTYPE_TAIL
176171
};
177172

178173
//= instancemethod object with a more efficient call function ================
@@ -341,12 +336,7 @@ PyTypeObject CustomInstanceMethod_Type = {
341336
#if PY_VERSION_HEX >= 0x03080000
342337
, 0 // tp_vectorcall
343338
#endif
344-
#if PY_VERSION_HEX >= 0x030c0000
345-
, 0 // tp_watched
346-
#endif
347-
#if PY_VERSION_HEX >= 0x030d0000
348-
, 0 // tp_versions_used
349-
#endif
339+
CPYCPPYY_PYTYPE_TAIL
350340
};
351341

352342

@@ -401,12 +391,7 @@ PyTypeObject IndexIter_Type = {
401391
#if PY_VERSION_HEX >= 0x03080000
402392
, 0 // tp_vectorcall
403393
#endif
404-
#if PY_VERSION_HEX >= 0x030c0000
405-
, 0 // tp_watched
406-
#endif
407-
#if PY_VERSION_HEX >= 0x030d0000
408-
, 0 // tp_versions_used
409-
#endif
394+
CPYCPPYY_PYTYPE_TAIL
410395
};
411396

412397

@@ -472,12 +457,7 @@ PyTypeObject VectorIter_Type = {
472457
#if PY_VERSION_HEX >= 0x03080000
473458
, 0 // tp_vectorcall
474459
#endif
475-
#if PY_VERSION_HEX >= 0x030c0000
476-
, 0 // tp_watched
477-
#endif
478-
#if PY_VERSION_HEX >= 0x030d0000
479-
, 0 // tp_versions_used
480-
#endif
460+
CPYCPPYY_PYTYPE_TAIL
481461
};
482462

483463
} // namespace CPyCppyy

bindings/pyroot/cppyy/CPyCppyy/src/LowLevelViews.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -980,12 +980,7 @@ PyTypeObject LowLevelView_Type = {
980980
#if PY_VERSION_HEX >= 0x03080000
981981
, 0 // tp_vectorcall
982982
#endif
983-
#if PY_VERSION_HEX >= 0x030c0000
984-
, 0 // tp_watched
985-
#endif
986-
#if PY_VERSION_HEX >= 0x030d0000
987-
, 0 // tp_versions_used
988-
#endif
983+
CPYCPPYY_PYTYPE_TAIL
989984
};
990985

991986
} // namespace CPyCppyy

bindings/pyroot/cppyy/CPyCppyy/src/TemplateProxy.cxx

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -978,12 +978,7 @@ PyTypeObject TemplateProxy_Type = {
978978
#if PY_VERSION_HEX >= 0x03080000
979979
, 0 // tp_vectorcall
980980
#endif
981-
#if PY_VERSION_HEX >= 0x030c0000
982-
, 0 // tp_watched
983-
#endif
984-
#if PY_VERSION_HEX >= 0x030d0000
985-
, 0 // tp_versions_used
986-
#endif
981+
CPYCPPYY_PYTYPE_TAIL
987982
};
988983

989984
} // namespace CPyCppyy

0 commit comments

Comments
 (0)