8000 gh-92781: Avoid mixing declarations and code in C API (#92783) (#92813) · python/cpython@a3d2ce9 · GitHub
[go: up one dir, main page]

Skip to content

Commit a3d2ce9

Browse files
authored
gh-92781: Avoid mixing declarations and code in C API (#92783) (#92813)
Avoid mixing declarations and code in the C API to fix the compiler warning: "ISO C90 forbids mixed declarations and code" [-Werror=declaration-after-statement]. (cherry picked from commit 90e7230)
1 parent 5f24acd commit a3d2ce9

File tree

4 files changed

+16
-9
lines changed

4 files changed

+16
-9
lines changed

Include/cpython/abstract.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ static inline PyObject *
111111
PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg)
112112
{
113113
PyObject *args[2] = {self, arg};
114-
115-
assert(arg != NULL);
116114
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
115+
assert(arg != NULL);
117116
return PyObject_VectorcallMethod(name, args, nargsf, _Py_NULL);
118117
}
119118

@@ -160,9 +159,8 @@ static inline PyObject *
160159
_PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg)
161160
{
162161
PyObject *args[2] = {self, arg};
163-
164-
assert(arg != NULL);
165162
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
163+
assert(arg != NULL);
166164
return _PyObject_VectorcallMethodId(name, args, nargsf, _Py_NULL);
167165
}
168166

Include/cpython/unicodeobject.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,9 @@ static inline void* _PyUnicode_COMPACT_DATA(PyObject *op) {
326326
}
327327

328328
static inline void* _PyUnicode_NONCOMPACT_DATA(PyObject *op) {
329+
void *data;
329330
assert(!PyUnicode_IS_COMPACT(op));
330-
void *data = _PyUnicodeObject_CAST(op)->data.any;
331+
data = _PyUnicodeObject_CAST(op)->data.any;
331332
assert(data != NULL);
332333
return data;
333334
}
@@ -416,8 +417,9 @@ static inline Py_UCS4 PyUnicode_READ(int kind,
416417
cache kind and use PyUnicode_READ instead. */
417418
static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
418419
{
420+
int kind;
419421
assert(PyUnicode_IS_READY(unicode));
420-
int kind = PyUnicode_KIND(unicode);
422+
kind = PyUnicode_KIND(unicode);
421423
if (kind == PyUnicode_1BYTE_KIND) {
422424
return PyUnicode_1BYTE_DATA(unicode)[index];
423425
}
@@ -437,12 +439,14 @@ static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
437439
than iterating over the string. */
438440
static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
439441
{
442+
int kind;
443+
440444
assert(PyUnicode_IS_READY(op));
441445
if (PyUnicode_IS_ASCII(op)) {
442446
return 0x7fU;
443447
}
444448

445-
int kind = PyUnicode_KIND(op);
449+
kind = PyUnicode_KIND(op);
446450
if (kind == PyUnicode_1BYTE_KIND) {
447451
return 0xffU;
448452
}

Include/cpython/weakrefobject.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ PyAPI_FUNC(Py_ssize_t) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
3737
PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
3838

3939
static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj) {
40+
PyWeakReference *ref;
41+
PyObject *obj;
4042
assert(PyWeakref_Check(ref_obj));
41-
PyWeakReference *ref = _Py_CAST(PyWeakReference*, ref_obj);
42-
PyObject *obj = ref->wr_object;
43+
ref = _Py_CAST(PyWeakReference*, ref_obj);
44+
obj = ref->wr_object;
4345
// Explanation for the Py_REFCNT() check: when a weakref's target is part
4446
// of a long chain of deallocations which triggers the trashcan mechanism,
4547
// clearing the weakrefs can be delayed long after the target's refcount
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Avoid mixing declarations and code in the C API to fix the compiler warning:
2+
"ISO C90 forbids mixed declarations and code"
3+
[-Werror=declaration-after-statement]. Patch by Victor Stinner.

0 commit comments

Comments
 (0)
0