mirror of
https://github.com/python/cpython.git
synced 2025-09-27 18:59:43 +00:00
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 90e7230073
)
This commit is contained in:
parent
5f24acdca0
commit
a3d2ce95d1
4 changed files with 16 additions and 9 deletions
|
@ -111,9 +111,8 @@ static inline PyObject *
|
||||||
PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg)
|
PyObject_CallMethodOneArg(PyObject *self, PyObject *name, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyObject *args[2] = {self, arg};
|
PyObject *args[2] = {self, arg};
|
||||||
|
|
||||||
assert(arg != NULL);
|
|
||||||
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||||
|
assert(arg != NULL);
|
||||||
return PyObject_VectorcallMethod(name, args, nargsf, _Py_NULL);
|
return PyObject_VectorcallMethod(name, args, nargsf, _Py_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,9 +159,8 @@ static inline PyObject *
|
||||||
_PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg)
|
_PyObject_CallMethodIdOneArg(PyObject *self, _Py_Identifier *name, PyObject *arg)
|
||||||
{
|
{
|
||||||
PyObject *args[2] = {self, arg};
|
PyObject *args[2] = {self, arg};
|
||||||
|
|
||||||
assert(arg != NULL);
|
|
||||||
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
size_t nargsf = 2 | PY_VECTORCALL_ARGUMENTS_OFFSET;
|
||||||
|
assert(arg != NULL);
|
||||||
return _PyObject_VectorcallMethodId(name, args, nargsf, _Py_NULL);
|
return _PyObject_VectorcallMethodId(name, args, nargsf, _Py_NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -326,8 +326,9 @@ static inline void* _PyUnicode_COMPACT_DATA(PyObject *op) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void* _PyUnicode_NONCOMPACT_DATA(PyObject *op) {
|
static inline void* _PyUnicode_NONCOMPACT_DATA(PyObject *op) {
|
||||||
|
void *data;
|
||||||
assert(!PyUnicode_IS_COMPACT(op));
|
assert(!PyUnicode_IS_COMPACT(op));
|
||||||
void *data = _PyUnicodeObject_CAST(op)->data.any;
|
data = _PyUnicodeObject_CAST(op)->data.any;
|
||||||
assert(data != NULL);
|
assert(data != NULL);
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -416,8 +417,9 @@ static inline Py_UCS4 PyUnicode_READ(int kind,
|
||||||
cache kind and use PyUnicode_READ instead. */
|
cache kind and use PyUnicode_READ instead. */
|
||||||
static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
|
static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
|
||||||
{
|
{
|
||||||
|
int kind;
|
||||||
assert(PyUnicode_IS_READY(unicode));
|
assert(PyUnicode_IS_READY(unicode));
|
||||||
int kind = PyUnicode_KIND(unicode);
|
kind = PyUnicode_KIND(unicode);
|
||||||
if (kind == PyUnicode_1BYTE_KIND) {
|
if (kind == PyUnicode_1BYTE_KIND) {
|
||||||
return PyUnicode_1BYTE_DATA(unicode)[index];
|
return PyUnicode_1BYTE_DATA(unicode)[index];
|
||||||
}
|
}
|
||||||
|
@ -437,12 +439,14 @@ static inline Py_UCS4 PyUnicode_READ_CHAR(PyObject *unicode, Py_ssize_t index)
|
||||||
than iterating over the string. */
|
than iterating over the string. */
|
||||||
static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
|
static inline Py_UCS4 PyUnicode_MAX_CHAR_VALUE(PyObject *op)
|
||||||
{
|
{
|
||||||
|
int kind;
|
||||||
|
|
||||||
assert(PyUnicode_IS_READY(op));
|
assert(PyUnicode_IS_READY(op));
|
||||||
if (PyUnicode_IS_ASCII(op)) {
|
if (PyUnicode_IS_ASCII(op)) {
|
||||||
return 0x7fU;
|
return 0x7fU;
|
||||||
}
|
}
|
||||||
|
|
||||||
int kind = PyUnicode_KIND(op);
|
kind = PyUnicode_KIND(op);
|
||||||
if (kind == PyUnicode_1BYTE_KIND) {
|
if (kind == PyUnicode_1BYTE_KIND) {
|
||||||
return 0xffU;
|
return 0xffU;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,9 +37,11 @@ PyAPI_FUNC(Py_ssize_t) _PyWeakref_GetWeakrefCount(PyWeakReference *head);
|
||||||
PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
|
PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
|
||||||
|
|
||||||
static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj) {
|
static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj) {
|
||||||
|
PyWeakReference *ref;
|
||||||
|
PyObject *obj;
|
||||||
assert(PyWeakref_Check(ref_obj));
|
assert(PyWeakref_Check(ref_obj));
|
||||||
PyWeakReference *ref = _Py_CAST(PyWeakReference*, ref_obj);
|
ref = _Py_CAST(PyWeakReference*, ref_obj);
|
||||||
PyObject *obj = ref->wr_object;
|
obj = ref->wr_object;
|
||||||
// Explanation for the Py_REFCNT() check: when a weakref's target is part
|
// Explanation for the Py_REFCNT() check: when a weakref's target is part
|
||||||
// of a long chain of deallocations which triggers the trashcan mechanism,
|
// of a long chain of deallocations which triggers the trashcan mechanism,
|
||||||
// clearing the weakrefs can be delayed long after the target's refcount
|
// clearing the weakrefs can be delayed long after the target's refcount
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
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]. Patch by Victor Stinner.
|
Loading…
Add table
Add a link
Reference in a new issue