diff options
author | Victor Stinner <vstinner@python.org> | 2022-05-27 13:05:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-27 13:05:35 (GMT) |
commit | 22b75d9bef1bffe82bfa1adfcbec0243c9202041 (patch) | |
tree | 2f2670227cb3db6e5209b1586c79d5ffa45145fd /Modules | |
parent | cb04a09d2dfd197436a11de504b92773569e19fb (diff) | |
download | cpython-22b75d9bef1bffe82bfa1adfcbec0243c9202041.zip cpython-22b75d9bef1bffe82bfa1adfcbec0243c9202041.tar.gz cpython-22b75d9bef1bffe82bfa1adfcbec0243c9202041.tar.bz2 |
gh-82616: Add Py_IS_TYPE_SIGNED() macro (#93178)
_posixsubprocess: add a static assertion to ensure that the pid_t
type is signed.
Replace _Py_IntegralTypeSigned() with _Py_IS_TYPE_SIGNED().
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_posixsubprocess.c | 4 | ||||
-rw-r--r-- | Modules/_testcapimodule.c | 15 |
2 files changed, 18 insertions, 1 deletions
diff --git a/Modules/_posixsubprocess.c b/Modules/_posixsubprocess.c index 9132f13..44e60d7 100644 --- a/Modules/_posixsubprocess.c +++ b/Modules/_posixsubprocess.c @@ -612,8 +612,10 @@ child_exec(char *const exec_array[], #endif #ifdef HAVE_SETPGID - if (pgid_to_set >= 0) + static_assert(_Py_IS_TYPE_SIGNED(pid_t), "pid_t is unsigned"); + if (pgid_to_set >= 0) { POSIX_CALL(setpgid(0, pgid_to_set)); + } #endif #ifdef HAVE_SETGROUPS diff --git a/Modules/_testcapimodule.c b/Modules/_testcapimodule.c index 37f4ded..ac0c96a 100644 --- a/Modules/_testcapimodule.c +++ b/Modules/_testcapimodule.c @@ -5858,6 +5858,20 @@ settrace_to_record(PyObject *self, PyObject *list) Py_RETURN_NONE; } +static PyObject * +test_macros(PyObject *self, PyObject *Py_UNUSED(args)) +{ + // Py_MIN(), Py_MAX() + assert(Py_MIN(5, 11) == 5); + assert(Py_MAX(5, 11) == 11); + + // _Py_IS_TYPE_SIGNED() + assert(_Py_IS_TYPE_SIGNED(int)); + assert(!_Py_IS_TYPE_SIGNED(unsigned int)); + + Py_RETURN_NONE; +} + static PyObject *negative_dictoffset(PyObject *, PyObject *); static PyObject *test_buildvalue_issue38913(PyObject *, PyObject *); static PyObject *getargs_s_hash_int(PyObject *, PyObject *, PyObject*); @@ -6149,6 +6163,7 @@ static PyMethodDef TestMethods[] = { {"get_feature_macros", get_feature_macros, METH_NOARGS, NULL}, {"test_code_api", test_code_api, METH_NOARGS, NULL}, {"settrace_to_record", settrace_to_record, METH_O, NULL}, + {"test_macros", test_macros, METH_NOARGS, NULL}, {NULL, NULL} /* sentinel */ }; |