Skip to content

Commit e7cc64e

Browse files
authored
bpo-43795: PEP-652: Simplify headers for easier static analysis (pythonGH-25483)
As part of the PEP-652 implementation, I'll tighten the CI check for functions/data defined with `Py_LIMITED_API`. Discussion in https://discuss.python.org/t/pep-652-maintaining-the-stable-abi/6986 suggests that parsing C headers is OK (though personally I'd rather generate it...), but writing a full C parser is a monumental task and adding an existing one as a dependency brings too many vendoring/bootstraping issues. So, for the check I'll use a "simple" regex on preprocessor output, and adapt the few trivial places where the regex won't work. - Keep declarations in the limited API to one item per line - Make it possible to override `_Py_NO_RETURN`, so the annotation can be removed from preprocessor output. https://bugs.python.org/issue43795
1 parent 90d02e5 commit e7cc64e

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

Include/boolobject.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ PyAPI_DATA(PyTypeObject) PyBool_Type;
1515
Don't forget to apply Py_INCREF() when returning either!!! */
1616

1717
/* Don't use these directly */
18-
PyAPI_DATA(struct _longobject) _Py_FalseStruct, _Py_TrueStruct;
18+
PyAPI_DATA(struct _longobject) _Py_FalseStruct;
19+
PyAPI_DATA(struct _longobject) _Py_TrueStruct;
1920

2021
/* Use these macros */
2122
#define Py_False ((PyObject *) &_Py_FalseStruct)

Include/pyport.h

+2
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
861861
PyAPI_FUNC(void) _Py_NO_RETURN PyThread_exit_thread(void);
862862
863863
XLC support is intentionally omitted due to bpo-40244 */
864+
#ifndef _Py_NO_RETURN
864865
#if defined(__clang__) || \
865866
(defined(__GNUC__) && \
866867
((__GNUC__ >= 3) || \
@@ -871,6 +872,7 @@ extern _invalid_parameter_handler _Py_silent_invalid_parameter_handler;
871872
#else
872873
# define _Py_NO_RETURN
873874
#endif
875+
#endif
874876

875877

876878
// Preprocessor check for a builtin preprocessor function. Always return 0

0 commit comments

Comments
 (0)