Skip to content

Commit 9689f80

Browse files
encukouvstinner
authored andcommitted
bpo-37191: Avoid declaration-after-statement in header included from Python.h (GH-13887)
1 parent 5effd10 commit 9689f80

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

Include/cpython/abstract.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,14 @@ static inline vectorcallfunc
8181
_PyVectorcall_Function(PyObject *callable)
8282
{
8383
PyTypeObject *tp = Py_TYPE(callable);
84+
Py_ssize_t offset = tp->tp_vectorcall_offset;
85+
vectorcallfunc *ptr;
8486
if (!PyType_HasFeature(tp, _Py_TPFLAGS_HAVE_VECTORCALL)) {
8587
return NULL;
8688
}
8789
assert(PyCallable_Check(callable));
88-
Py_ssize_t offset = tp->tp_vectorcall_offset;
8990
assert(offset > 0);
90-
vectorcallfunc *ptr = (vectorcallfunc *)(((char *)callable) + offset);
91+
ptr = (vectorcallfunc*)(((char *)callable) + offset);
9192
return *ptr;
9293
}
9394

@@ -114,14 +115,16 @@ static inline PyObject *
114115
_PyObject_Vectorcall(PyObject *callable, PyObject *const *args,
115116
size_t nargsf, PyObject *kwnames)
116117
{
118+
PyObject *res;
119+
vectorcallfunc func;
117120
assert(kwnames == NULL || PyTuple_Check(kwnames));
118121
assert(args != NULL || PyVectorcall_NARGS(nargsf) == 0);
119-
vectorcallfunc func = _PyVectorcall_Function(callable);
122+
func = _PyVectorcall_Function(callable);
120123
if (func == NULL) {
121124
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
122125
return _PyObject_MakeTpCall(callable, args, nargs, kwnames);
123126
}
124-
PyObject *res = func(callable, args, nargsf, kwnames);
127+
res = func(callable, args, nargsf, kwnames);
125128
return _Py_CheckFunctionResult(callable, res, NULL);
126129
}
127130

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Python.h does not need compiler support for intermingled declarations (GCC's
2+
``-Wdeclaration-after-statement``), which were added in 3.8.0 Beta 1. Note
3+
that in Python 3.9, intermingled declarations will be needed again.

0 commit comments

Comments
 (0)