summaryrefslogtreecommitdiffstats
path: root/Include/internal
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-06-20 14:04:52 (GMT)
committerGitHub <noreply@github.com>2022-06-20 14:04:52 (GMT)
commit7ad6f74fcf9db1ccfeaf0986064870d8d3887300 (patch)
tree2b140e0e4fdb3b58379887bab6ff68ade5c67c60 /Include/internal
parent61f24e7885bed096b5d7f75aff13c1001994b35a (diff)
downloadcpython-7ad6f74fcf9db1ccfeaf0986064870d8d3887300.zip
cpython-7ad6f74fcf9db1ccfeaf0986064870d8d3887300.tar.gz
cpython-7ad6f74fcf9db1ccfeaf0986064870d8d3887300.tar.bz2
gh-87347: Add parenthesis around macro arguments (#93915)
Add unit test on Py_MEMBER_SIZE() and some other macros.
Diffstat (limited to 'Include/internal')
-rw-r--r--Include/internal/pycore_asdl.h4
-rw-r--r--Include/internal/pycore_code.h10
-rw-r--r--Include/internal/pycore_dict.h6
-rw-r--r--Include/internal/pycore_hashtable.h4
-rw-r--r--Include/internal/pycore_initconfig.h8
-rw-r--r--Include/internal/pycore_object.h9
-rw-r--r--Include/internal/pycore_pystate.h2
-rw-r--r--Include/internal/pycore_runtime_init.h16
8 files changed, 31 insertions, 28 deletions
diff --git a/Include/internal/pycore_asdl.h b/Include/internal/pycore_asdl.h
index 5b01c7a..afeada8 100644
--- a/Include/internal/pycore_asdl.h
+++ b/Include/internal/pycore_asdl.h
@@ -91,7 +91,7 @@ asdl_ ## NAME ## _seq *_Py_asdl_ ## NAME ## _seq_new(Py_ssize_t size, PyArena *a
(S)->typed_elements[_asdl_i] = (V); \
} while (0)
#else
-# define asdl_seq_SET(S, I, V) _Py_RVALUE((S)->typed_elements[I] = (V))
+# define asdl_seq_SET(S, I, V) _Py_RVALUE((S)->typed_elements[(I)] = (V))
#endif
#ifdef Py_DEBUG
@@ -103,7 +103,7 @@ asdl_ ## NAME ## _seq *_Py_asdl_ ## NAME ## _seq_new(Py_ssize_t size, PyArena *a
(S)->elements[_asdl_i] = (V); \
} while (0)
#else
-# define asdl_seq_SET_UNTYPED(S, I, V) _Py_RVALUE((S)->elements[I] = (V))
+# define asdl_seq_SET_UNTYPED(S, I, V) _Py_RVALUE((S)->elements[(I)] = (V))
#endif
#ifdef __cplusplus
diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h
index bb82d9f..7e21c5a 100644
--- a/Include/internal/pycore_code.h
+++ b/Include/internal/pycore_code.h
@@ -252,16 +252,16 @@ extern int _PyStaticCode_InternStrings(PyCodeObject *co);
#ifdef Py_STATS
-#define STAT_INC(opname, name) _py_stats.opcode_stats[opname].specialization.name++
-#define STAT_DEC(opname, name) _py_stats.opcode_stats[opname].specialization.name--
-#define OPCODE_EXE_INC(opname) _py_stats.opcode_stats[opname].execution_count++
+#define STAT_INC(opname, name) _py_stats.opcode_stats[(opname)].specialization.name++
+#define STAT_DEC(opname, name) _py_stats.opcode_stats[(opname)].specialization.name--
+#define OPCODE_EXE_INC(opname) _py_stats.opcode_stats[(opname)].execution_count++
#define CALL_STAT_INC(name) _py_stats.call_stats.name++
#define OBJECT_STAT_INC(name) _py_stats.object_stats.name++
#define OBJECT_STAT_INC_COND(name, cond) \
do { if (cond) _py_stats.object_stats.name++; } while (0)
-#define EVAL_CALL_STAT_INC(name) _py_stats.call_stats.eval_calls[name]++
+#define EVAL_CALL_STAT_INC(name) _py_stats.call_stats.eval_calls[(name)]++
#define EVAL_CALL_STAT_INC_IF_FUNCTION(name, callable) \
- do { if (PyFunction_Check(callable)) _py_stats.call_stats.eval_calls[name]++; } while (0)
+ do { if (PyFunction_Check(callable)) _py_stats.call_stats.eval_calls[(name)]++; } while (0)
// Used by the _opcode extension which is built as a shared library
PyAPI_FUNC(PyObject*) _Py_GetSpecializationStats(void);
diff --git a/Include/internal/pycore_dict.h b/Include/internal/pycore_dict.h
index 24d2a71..c831c4c 100644
--- a/Include/internal/pycore_dict.h
+++ b/Include/internal/pycore_dict.h
@@ -154,9 +154,11 @@ struct _dictvalues {
2 : sizeof(int32_t))
#endif
#define DK_ENTRIES(dk) \
- (assert(dk->dk_kind == DICT_KEYS_GENERAL), (PyDictKeyEntry*)(&((int8_t*)((dk)->dk_indices))[(size_t)1 << (dk)->dk_log2_index_bytes]))
+ (assert((dk)->dk_kind == DICT_KEYS_GENERAL), \
+ (PyDictKeyEntry*)(&((int8_t*)((dk)->dk_indices))[(size_t)1 << (dk)->dk_log2_index_bytes]))
#define DK_UNICODE_ENTRIES(dk) \
- (assert(dk->dk_kind != DICT_KEYS_GENERAL), (PyDictUnicodeEntry*)(&((int8_t*)((dk)->dk_indices))[(size_t)1 << (dk)->dk_log2_index_bytes]))
+ (assert((dk)->dk_kind != DICT_KEYS_GENERAL), \
+ (PyDictUnicodeEntry*)(&((int8_t*)((dk)->dk_indices))[(size_t)1 << (dk)->dk_log2_index_bytes]))
#define DK_IS_UNICODE(dk) ((dk)->dk_kind != DICT_KEYS_GENERAL)
extern uint64_t _pydict_global_version;
diff --git a/Include/internal/pycore_hashtable.h b/Include/internal/pycore_hashtable.h
index 18757ab..2aa23a2 100644
--- a/Include/internal/pycore_hashtable.h
+++ b/Include/internal/pycore_hashtable.h
@@ -18,9 +18,9 @@ typedef struct {
_Py_slist_item_t *head;
} _Py_slist_t;
-#define _Py_SLIST_ITEM_NEXT(ITEM) (((_Py_slist_item_t *)ITEM)->next)
+#define _Py_SLIST_ITEM_NEXT(ITEM) (((_Py_slist_item_t *)(ITEM))->next)
-#define _Py_SLIST_HEAD(SLIST) (((_Py_slist_t *)SLIST)->head)
+#define _Py_SLIST_HEAD(SLIST) (((_Py_slist_t *)(SLIST))->head)
/* _Py_hashtable: table entry */
diff --git a/Include/internal/pycore_initconfig.h b/Include/internal/pycore_initconfig.h
index a2f4cd1..69f88d7 100644
--- a/Include/internal/pycore_initconfig.h
+++ b/Include/internal/pycore_initconfig.h
@@ -36,13 +36,13 @@ struct pyruntimestate;
._type = _PyStatus_TYPE_EXIT, \
.exitcode = (EXITCODE)}
#define _PyStatus_IS_ERROR(err) \
- (err._type == _PyStatus_TYPE_ERROR)
+ ((err)._type == _PyStatus_TYPE_ERROR)
#define _PyStatus_IS_EXIT(err) \
- (err._type == _PyStatus_TYPE_EXIT)
+ ((err)._type == _PyStatus_TYPE_EXIT)
#define _PyStatus_EXCEPTION(err) \
- (err._type != _PyStatus_TYPE_OK)
+ ((err)._type != _PyStatus_TYPE_OK)
#define _PyStatus_UPDATE_FUNC(err) \
- do { err.func = _PyStatus_GET_FUNC(); } while (0)
+ do { (err).func = _PyStatus_GET_FUNC(); } while (0)
PyObject* _PyErr_SetFromPyStatus(PyStatus status);
diff --git a/Include/internal/pycore_object.h b/Include/internal/pycore_object.h
index cc50418..d4f66b6 100644
--- a/Include/internal/pycore_object.h
+++ b/Include/internal/pycore_object.h
@@ -17,7 +17,7 @@ extern "C" {
#define _PyObject_IMMORTAL_INIT(type) \
{ \
.ob_refcnt = 999999999, \
- .ob_type = type, \
+ .ob_type = (type), \
}
#define _PyVarObject_IMMORTAL_INIT(type, size) \
{ \
@@ -29,7 +29,8 @@ PyAPI_FUNC(void) _Py_NO_RETURN _Py_FatalRefcountErrorFunc(
const char *func,
const char *message);
-#define _Py_FatalRefcountError(message) _Py_FatalRefcountErrorFunc(__func__, message)
+#define _Py_FatalRefcountError(message) \
+ _Py_FatalRefcountErrorFunc(__func__, (message))
static inline void
_Py_DECREF_SPECIALIZED(PyObject *op, const destructor destruct)
@@ -275,7 +276,7 @@ extern PyObject* _PyType_GetSubclasses(PyTypeObject *);
// Access macro to the members which are floating "behind" the object
#define _PyHeapType_GET_MEMBERS(etype) \
- ((PyMemberDef *)(((char *)etype) + Py_TYPE(etype)->tp_basicsize))
+ ((PyMemberDef *)(((char *)(etype)) + Py_TYPE(etype)->tp_basicsize))
PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *);
@@ -296,7 +297,7 @@ PyAPI_FUNC(PyObject *) _PyObject_LookupSpecial(PyObject *, PyObject *);
#if defined(__EMSCRIPTEN__) && defined(PY_CALL_TRAMPOLINE)
#define _PyCFunction_TrampolineCall(meth, self, args) \
_PyCFunctionWithKeywords_TrampolineCall( \
- (*(PyCFunctionWithKeywords)(void(*)(void))meth), self, args, NULL)
+ (*(PyCFunctionWithKeywords)(void(*)(void))(meth)), (self), (args), NULL)
extern PyObject* _PyCFunctionWithKeywords_TrampolineCall(
PyCFunctionWithKeywords meth, PyObject *, PyObject *, PyObject *);
#else
diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h
index e2d7c5b..b4a39b6 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -97,7 +97,7 @@ _Py_EnsureFuncTstateNotNULL(const char *func, PyThreadState *tstate)
// Call Py_FatalError() if tstate is NULL
#define _Py_EnsureTstateNotNULL(tstate) \
- _Py_EnsureFuncTstateNotNULL(__func__, tstate)
+ _Py_EnsureFuncTstateNotNULL(__func__, (tstate))
/* Get the current interpreter state.
diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h
index b4ce4e3..a7a4360 100644
--- a/Include/internal/pycore_runtime_init.h
+++ b/Include/internal/pycore_runtime_init.h
@@ -84,13 +84,13 @@ extern "C" {
#define _PyBytes_SIMPLE_INIT(CH, LEN) \
{ \
- _PyVarObject_IMMORTAL_INIT(&PyBytes_Type, LEN), \
+ _PyVarObject_IMMORTAL_INIT(&PyBytes_Type, (LEN)), \
.ob_shash = -1, \
- .ob_sval = { CH }, \
+ .ob_sval = { (CH) }, \
}
#define _PyBytes_CHAR_INIT(CH) \
{ \
- _PyBytes_SIMPLE_INIT(CH, 1) \
+ _PyBytes_SIMPLE_INIT((CH), 1) \
}
#define _PyUnicode_ASCII_BASE_INIT(LITERAL, ASCII) \
@@ -101,13 +101,13 @@ extern "C" {
.state = { \
.kind = 1, \
.compact = 1, \
- .ascii = ASCII, \
+ .ascii = (ASCII), \
}, \
}
#define _PyASCIIObject_INIT(LITERAL) \
{ \
- ._ascii = _PyUnicode_ASCII_BASE_INIT(LITERAL, 1), \
- ._data = LITERAL \
+ ._ascii = _PyUnicode_ASCII_BASE_INIT((LITERAL), 1), \
+ ._data = (LITERAL) \
}
#define INIT_STR(NAME, LITERAL) \
._ ## NAME = _PyASCIIObject_INIT(LITERAL)
@@ -116,9 +116,9 @@ extern "C" {
#define _PyUnicode_LATIN1_INIT(LITERAL) \
{ \
._latin1 = { \
- ._base = _PyUnicode_ASCII_BASE_INIT(LITERAL, 0), \
+ ._base = _PyUnicode_ASCII_BASE_INIT((LITERAL), 0), \
}, \
- ._data = LITERAL, \
+ ._data = (LITERAL), \
}
/* The following is auto-generated by Tools/scripts/generate_global_objects.py. */