From 551479f3314293fe3781283f5875840c804c3b21 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Wed, 20 Aug 2025 15:20:57 +0200 Subject: [PATCH 1/5] PEP 7: Reword & split the "C dialect" section The motivation here is to avoid users reading PEP 7 as guarantees about what compilers/settings are required to build Python or extensions. I've also clarified a few things in line with current practice. --- peps/pep-0007.rst | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/peps/pep-0007.rst b/peps/pep-0007.rst index f85ef718295..581dcde0512 100644 --- a/peps/pep-0007.rst +++ b/peps/pep-0007.rst @@ -26,12 +26,21 @@ particular rule: clean up someone else's mess (in true XP style). -C dialect -========= +C standards +=========== + +Follow the following standards. +For features that aren't in the relevant standard (like atomics or some C11 +features in public headers), use CPython-specific wrappers. +When adding such wrappers, try to make them easy to adjust for unsupported +compilers. * Python 3.11 and newer versions use C11 without `optional features `_. - The public C API should be compatible with C++. + +* The public C API should be compatible with C99 and C++. + (This is looser than what we guarantee users. Remember that this PEP allows + exceptions!) * Python 3.6 to 3.10 use C89 with several select C99 features: @@ -44,15 +53,19 @@ C dialect - C++-style line comments * Python versions before 3.6 used ANSI/ISO standard C (the 1989 version - of the standard). This meant (amongst many other things) that all - declarations must be at the top of a block (not necessarily at the - top of function). + of the standard). This meant, amongst many other things, that all + declarations were at the top of a block. + + +Common C code conventions +========================= -* Don't use compiler-specific extensions, such as those of GCC or MSVC - (e.g. don't write multi-line strings without trailing backslashes). +* Don't use compiler-specific extensions, such as those of GCC or MSVC. + For example, don't write multi-line strings without trailing backslashes. -* All function declarations and definitions must use full prototypes - (i.e. specify the types of all arguments). +* All function declarations and definitions must use full prototypes. + That is, specify the types of all arguments and use ``(void)`` to declare + functions with no arguments. * No compiler warnings with major compilers (gcc, VC++, a few others). From 866f500341e86c13182b0b0fd827525f4736cc34 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 21 Aug 2025 08:49:49 +0200 Subject: [PATCH 2/5] "more restrictive" --- peps/pep-0007.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/peps/pep-0007.rst b/peps/pep-0007.rst index 581dcde0512..063dc0d2ff2 100644 --- a/peps/pep-0007.rst +++ b/peps/pep-0007.rst @@ -39,8 +39,8 @@ compilers. `_. * The public C API should be compatible with C99 and C++. - (This is looser than what we guarantee users. Remember that this PEP allows - exceptions!) + (This is more restrictive than what we guarantee users. Remember that this PEP + allows exceptions!) * Python 3.6 to 3.10 use C89 with several select C99 features: From a40584d8a6b632a473744b3619155f5847affdd8 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 22 Aug 2025 09:25:47 +0200 Subject: [PATCH 3/5] Use proper ReST link syntax Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> --- peps/pep-0007.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/peps/pep-0007.rst b/peps/pep-0007.rst index 063dc0d2ff2..28ca598b224 100644 --- a/peps/pep-0007.rst +++ b/peps/pep-0007.rst @@ -36,7 +36,7 @@ When adding such wrappers, try to make them easy to adjust for unsupported compilers. * Python 3.11 and newer versions use C11 without `optional features - `_. + `__. * The public C API should be compatible with C99 and C++. (This is more restrictive than what we guarantee users. Remember that this PEP From 2f1726ecf8abad567cf019efd82b906a24957e4e Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 25 Aug 2025 13:59:38 +0200 Subject: [PATCH 4/5] Add examples of wrappers; make not explicitly for users --- peps/pep-0007.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/peps/pep-0007.rst b/peps/pep-0007.rst index 28ca598b224..18be66bb895 100644 --- a/peps/pep-0007.rst +++ b/peps/pep-0007.rst @@ -30,17 +30,18 @@ C standards =========== Follow the following standards. -For features that aren't in the relevant standard (like atomics or some C11 -features in public headers), use CPython-specific wrappers. +For features that aren't in the relevant standard, use CPython-specific +wrappers (for example: ``_Py_atomic_store_int32``, ``Py_ALWAYS_INLINE``, +``Py_ARITHMETIC_RIGHT_SHIFT``; ``_Py_ALIGNED_DEF`` in public headers). When adding such wrappers, try to make them easy to adjust for unsupported compilers. * Python 3.11 and newer versions use C11 without `optional features `__. + The public C API should be compatible with C99 and C++. -* The public C API should be compatible with C99 and C++. - (This is more restrictive than what we guarantee users. Remember that this PEP - allows exceptions!) + (As a reminder to any users reading this: this PEP is a *style guide*; these + rules are there to be broken.) * Python 3.6 to 3.10 use C89 with several select C99 features: From 24532dd6e0d1099f9e57b23c465a83ab82e78b5c Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 26 Aug 2025 10:59:07 +0200 Subject: [PATCH 5/5] Update peps/pep-0007.rst Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- peps/pep-0007.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/peps/pep-0007.rst b/peps/pep-0007.rst index 18be66bb895..3824513247d 100644 --- a/peps/pep-0007.rst +++ b/peps/pep-0007.rst @@ -26,6 +26,8 @@ particular rule: clean up someone else's mess (in true XP style). +.. _c_dialect: + C standards ===========