Skip to content
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

gh-87347: Add parenthesis around macro arguments #93915

Merged
merged 6 commits into from
Jun 20, 2022
Merged
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/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ extern "C" {
-1 on failure.

This is the equivalent of the Python statement: del o.attr_name. */
#define PyObject_DelAttrString(O,A) PyObject_SetAttrString((O),(A), NULL)
#define PyObject_DelAttrString(O, A) PyObject_SetAttrString((O), (A), NULL)


/* Implemented as a macro:
Expand All @@ -98,7 +98,7 @@ extern "C" {
Delete attribute named attr_name, for object o. Returns -1
on failure. This is the equivalent of the Python
statement: del o.attr_name. */
#define PyObject_DelAttr(O,A) PyObject_SetAttr((O),(A), NULL)
#define PyObject_DelAttr(O, A) PyObject_SetAttr((O), (A), NULL)


/* Implemented elsewhere:
Expand Down Expand Up @@ -722,7 +722,7 @@ PyAPI_FUNC(PyObject *) PySequence_Fast(PyObject *o, const char* m);
/* Return the 'i'-th element of the sequence 'o', assuming that o was returned
by PySequence_Fast, and that i is within bounds. */
#define PySequence_Fast_GET_ITEM(o, i)\
(PyList_Check(o) ? PyList_GET_ITEM(o, i) : PyTuple_GET_ITEM(o, i))
(PyList_Check(o) ? PyList_GET_ITEM((o), (i)) : PyTuple_GET_ITEM((o), (i)))

/* Return a pointer to the underlying item array for
an object returned by PySequence_Fast */
Expand Down Expand Up @@ -802,7 +802,7 @@ PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
failure.

This is equivalent to the Python statement: del o[key]. */
#define PyMapping_DelItemString(O,K) PyObject_DelItemString((O),(K))
#define PyMapping_DelItemString(O, K) PyObject_DelItemString((O), (K))

/* Implemented as a macro:

Expand All @@ -812,7 +812,7 @@ PyAPI_FUNC(Py_ssize_t) PyMapping_Length(PyObject *o);
Returns -1 on failure.

This is equivalent to the Python statement: del o[key]. */
#define PyMapping_DelItem(O,K) PyObject_DelItem((O),(K))
#define PyMapping_DelItem(O, K) PyObject_DelItem((O), (K))

/* On success, return 1 if the mapping object 'o' has the key 'key',
and 0 otherwise.
Expand Down
2 changes: 1 addition & 1 deletion Include/ceval.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallObjectWithKeywords(

/* Deprecated since PyEval_CallObjectWithKeywords is deprecated */
#define PyEval_CallObject(callable, arg) \
PyEval_CallObjectWithKeywords(callable, arg, _PyObject_CAST(_Py_NULL))
PyEval_CallObjectWithKeywords((callable), (arg), _PyObject_CAST(_Py_NULL))

Py_DEPRECATED(3.9) PyAPI_FUNC(PyObject *) PyEval_CallFunction(
PyObject *callable, const char *format, ...);
Expand Down
2 changes: 1 addition & 1 deletion Include/cpython/abstract.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ PyAPI_FUNC(Py_ssize_t) PyObject_LengthHint(PyObject *o, Py_ssize_t);
/* Assume tp_as_sequence and sq_item exist and that 'i' does not
need to be corrected for a negative index. */
#define PySequence_ITEM(o, i)\
( Py_TYPE(o)->tp_as_sequence->sq_item(o, i) )
( Py_TYPE(o)->tp_as_sequence->sq_item((o), (i)) )

#define PY_ITERSEARCH_COUNT 1
#define PY_ITERSEARCH_INDEX 2
Expand Down
6 changes: 3 additions & 3 deletions Include/cpython/classobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ PyAPI_FUNC(PyObject *) PyMethod_Self(PyObject *);
/* Macros for direct access to these values. Type checks are *not*
done, so use with care. */
#define PyMethod_GET_FUNCTION(meth) \
(((PyMethodObject *)meth) -> im_func)
(((PyMethodObject *)(meth)) -> im_func)
#define PyMethod_GET_SELF(meth) \
(((PyMethodObject *)meth) -> im_self)
(((PyMethodObject *)(meth)) -> im_self)

typedef struct {
PyObject_HEAD
Expand All @@ -48,7 +48,7 @@ PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
/* Macros for direct access to these values. Type checks are *not*
done, so use with care. */
#define PyInstanceMethod_GET_FUNCTION(meth) \
(((PyInstanceMethodObject *)meth) -> func)
(((PyInstanceMethodObject *)(meth)) -> func)

#ifdef __cplusplus
}
Expand Down
3 changes: 2 additions & 1 deletion Include/cpython/code.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ typedef uint16_t _Py_CODEUNIT;
#endif

// Use "unsigned char" instead of "uint8_t" here to avoid illegal aliasing:
#define _Py_SET_OPCODE(word, opcode) (((unsigned char *)&(word))[0] = (opcode))
#define _Py_SET_OPCODE(word, opcode) \
do { ((unsigned char *)&(word))[0] = (opcode); } while (0)

// To avoid repeating ourselves in deepfreeze.py, all PyCodeObject members are
// defined in this macro:
Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/listobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ static inline Py_ssize_t PyList_GET_SIZE(PyObject *op) {
}
#define PyList_GET_SIZE(op) PyList_GET_SIZE(_PyObject_CAST(op))

#define PyList_GET_ITEM(op, index) (_PyList_CAST(op)->ob_item[index])
#define PyList_GET_ITEM(op, index) (_PyList_CAST(op)->ob_item[(index)])

static inline void
PyList_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
PyListObject *list = _PyList_CAST(op);
list->ob_item[index] = value;
}
#define PyList_SET_ITEM(op, index, value) \
PyList_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value))
PyList_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))
4 changes: 2 additions & 2 deletions Include/cpython/modsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
#define _PyArg_NoPositional(funcname, args) \
((args) == NULL || _PyArg_NoPositional((funcname), (args)))

#define _Py_ANY_VARARGS(n) (n == PY_SSIZE_T_MAX)
#define _Py_ANY_VARARGS(n) ((n) == PY_SSIZE_T_MAX)

PyAPI_FUNC(void) _PyArg_BadArgument(const char *, const char *, const char *, PyObject *);
PyAPI_FUNC(int) _PyArg_CheckPositional(const char *, Py_ssize_t,
Expand Down Expand Up @@ -100,7 +100,7 @@ PyAPI_FUNC(PyObject * const *) _PyArg_UnpackKeywordsWithVararg(

#define _PyArg_UnpackKeywords(args, nargs, kwargs, kwnames, parser, minpos, maxpos, minkw, buf) \
(((minkw) == 0 && (kwargs) == NULL && (kwnames) == NULL && \
(minpos) <= (nargs) && (nargs) <= (maxpos) && args != NULL) ? (args) : \
(minpos) <= (nargs) && (nargs) <= (maxpos) && (args) != NULL) ? (args) : \
_PyArg_UnpackKeywords((args), (nargs), (kwargs), (kwnames), (parser), \
(minpos), (maxpos), (minkw), (buf)))

Expand Down
12 changes: 6 additions & 6 deletions Include/cpython/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef struct _Py_Identifier {
// For now we are keeping _Py_IDENTIFIER for continued use
// in non-builtin extensions (and naughty PyPI modules).

#define _Py_static_string_init(value) { .string = value, .index = -1 }
#define _Py_static_string_init(value) { .string = (value), .index = -1 }
#define _Py_static_string(varname, value) static _Py_Identifier varname = _Py_static_string_init(value)
#define _Py_IDENTIFIER(varname) _Py_static_string(PyId_##varname, #varname)

Expand Down Expand Up @@ -385,9 +385,9 @@ _PyObject_DebugTypeStats(FILE *out);
#endif

#define _PyObject_ASSERT_WITH_MSG(obj, expr, msg) \
_PyObject_ASSERT_FROM(obj, expr, msg, __FILE__, __LINE__, __func__)
_PyObject_ASSERT_FROM((obj), expr, (msg), __FILE__, __LINE__, __func__)
#define _PyObject_ASSERT(obj, expr) \
_PyObject_ASSERT_WITH_MSG(obj, expr, NULL)
_PyObject_ASSERT_WITH_MSG((obj), expr, NULL)

#define _PyObject_ASSERT_FAILED_MSG(obj, msg) \
_PyObject_AssertFailed((obj), NULL, (msg), __FILE__, __LINE__, __func__)
Expand Down Expand Up @@ -493,8 +493,8 @@ PyAPI_FUNC(int) _PyTrash_cond(PyObject *op, destructor dealloc);
} while (0);

#define Py_TRASHCAN_BEGIN(op, dealloc) \
Py_TRASHCAN_BEGIN_CONDITION(op, \
_PyTrash_cond(_PyObject_CAST(op), (destructor)dealloc))
Py_TRASHCAN_BEGIN_CONDITION((op), \
_PyTrash_cond(_PyObject_CAST(op), (destructor)(dealloc)))

/* The following two macros, Py_TRASHCAN_SAFE_BEGIN and
* Py_TRASHCAN_SAFE_END, are deprecated since version 3.11 and
Expand All @@ -505,7 +505,7 @@ Py_DEPRECATED(3.11) typedef int UsingDeprecatedTrashcanMacro;
#define Py_TRASHCAN_SAFE_BEGIN(op) \
do { \
UsingDeprecatedTrashcanMacro cond=1; \
Py_TRASHCAN_BEGIN_CONDITION(op, cond);
Py_TRASHCAN_BEGIN_CONDITION((op), cond);
#define Py_TRASHCAN_SAFE_END(op) \
Py_TRASHCAN_END; \
} while(0);
8 changes: 4 additions & 4 deletions Include/cpython/odictobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ PyAPI_FUNC(int) PyODict_SetItem(PyObject *od, PyObject *key, PyObject *item);
PyAPI_FUNC(int) PyODict_DelItem(PyObject *od, PyObject *key);

/* wrappers around PyDict* functions */
#define PyODict_GetItem(od, key) PyDict_GetItem(_PyObject_CAST(od), key)
#define PyODict_GetItem(od, key) PyDict_GetItem(_PyObject_CAST(od), (key))
#define PyODict_GetItemWithError(od, key) \
PyDict_GetItemWithError(_PyObject_CAST(od), key)
#define PyODict_Contains(od, key) PyDict_Contains(_PyObject_CAST(od), key)
PyDict_GetItemWithError(_PyObject_CAST(od), (key))
#define PyODict_Contains(od, key) PyDict_Contains(_PyObject_CAST(od), (key))
#define PyODict_Size(od) PyDict_Size(_PyObject_CAST(od))
#define PyODict_GetItemString(od, key) \
PyDict_GetItemString(_PyObject_CAST(od), key)
PyDict_GetItemString(_PyObject_CAST(od), (key))

#endif

Expand Down
2 changes: 1 addition & 1 deletion Include/cpython/pyerrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,4 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalErrorFormat(
const char *format,
...);

#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, message)
#define Py_FatalError(message) _Py_FatalErrorFunc(__func__, (message))
28 changes: 14 additions & 14 deletions Include/cpython/pythonrun.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ PyAPI_FUNC(PyObject *) Py_CompileStringObject(
PyCompilerFlags *flags,
int optimize);

#define Py_CompileString(str, p, s) Py_CompileStringExFlags(str, p, s, NULL, -1)
#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags(str, p, s, f, -1)
#define Py_CompileString(str, p, s) Py_CompileStringExFlags((str), (p), (s), NULL, -1)
#define Py_CompileStringFlags(str, p, s, f) Py_CompileStringExFlags((str), (p), (s), (f), -1)


PyAPI_FUNC(const char *) _Py_SourceAsString(
Expand Down Expand Up @@ -96,23 +96,23 @@ PyAPI_FUNC(PyObject *) PyRun_FileEx(FILE *fp, const char *p, int s, PyObject *g,
PyAPI_FUNC(PyObject *) PyRun_FileFlags(FILE *fp, const char *p, int s, PyObject *g, PyObject *l, PyCompilerFlags *flags);

/* Use macros for a bunch of old variants */
#define PyRun_String(str, s, g, l) PyRun_StringFlags(str, s, g, l, NULL)
#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags(fp, name, 0, NULL)
#define PyRun_String(str, s, g, l) PyRun_StringFlags((str), (s), (g), (l), NULL)
#define PyRun_AnyFile(fp, name) PyRun_AnyFileExFlags((fp), (name), 0, NULL)
#define PyRun_AnyFileEx(fp, name, closeit) \
PyRun_AnyFileExFlags(fp, name, closeit, NULL)
PyRun_AnyFileExFlags((fp), (name), (closeit), NULL)
#define PyRun_AnyFileFlags(fp, name, flags) \
PyRun_AnyFileExFlags(fp, name, 0, flags)
#define PyRun_SimpleString(s) PyRun_SimpleStringFlags(s, NULL)
#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags(f, p, 0, NULL)
#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags(f, p, c, NULL)
#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags(f, p, NULL)
#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags(f, p, NULL)
PyRun_AnyFileExFlags((fp), (name), 0, (flags))
#define PyRun_SimpleString(s) PyRun_SimpleStringFlags((s), NULL)
#define PyRun_SimpleFile(f, p) PyRun_SimpleFileExFlags((f), (p), 0, NULL)
#define PyRun_SimpleFileEx(f, p, c) PyRun_SimpleFileExFlags((f), (p), (c), NULL)
#define PyRun_InteractiveOne(f, p) PyRun_InteractiveOneFlags((f), (p), NULL)
#define PyRun_InteractiveLoop(f, p) PyRun_InteractiveLoopFlags((f), (p), NULL)
#define PyRun_File(fp, p, s, g, l) \
PyRun_FileExFlags(fp, p, s, g, l, 0, NULL)
PyRun_FileExFlags((fp), (p), (s), (g), (l), 0, NULL)
#define PyRun_FileEx(fp, p, s, g, l, c) \
PyRun_FileExFlags(fp, p, s, g, l, c, NULL)
PyRun_FileExFlags((fp), (p), (s), (g), (l), (c), NULL)
#define PyRun_FileFlags(fp, p, s, g, l, flags) \
PyRun_FileExFlags(fp, p, s, g, l, 0, flags)
PyRun_FileExFlags((fp), (p), (s), (g), (l), 0, (flags))


/* Stuff with no proper home (yet) */
Expand Down
4 changes: 2 additions & 2 deletions Include/cpython/tupleobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static inline Py_ssize_t PyTuple_GET_SIZE(PyObject *op) {
}
#define PyTuple_GET_SIZE(op) PyTuple_GET_SIZE(_PyObject_CAST(op))

#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[index])
#define PyTuple_GET_ITEM(op, index) (_PyTuple_CAST(op)->ob_item[(index)])

/* Function *only* to be used to fill in brand new tuples */
static inline void
Expand All @@ -34,6 +34,6 @@ PyTuple_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
tuple->ob_item[index] = value;
}
#define PyTuple_SET_ITEM(op, index, value) \
PyTuple_SET_ITEM(_PyObject_CAST(op), index, _PyObject_CAST(value))
PyTuple_SET_ITEM(_PyObject_CAST(op), (index), _PyObject_CAST(value))

PyAPI_FUNC(void) _PyTuple_DebugMallocStats(FILE *out);
2 changes: 1 addition & 1 deletion Include/cpython/warnings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ PyAPI_FUNC(int) PyErr_WarnExplicitFormat(
const char *format, ...);

// DEPRECATED: Use PyErr_WarnEx() instead.
#define PyErr_Warn(category, msg) PyErr_WarnEx(category, msg, 1)
#define PyErr_Warn(category, msg) PyErr_WarnEx((category), (msg), 1)
Loading