Skip to content

bpo-43795: PEP-652: Simplify headers for easier static analysis - #25483

Merged
encukou merged 2 commits into
python:masterfrom
encukou:pep652-simplify-headers
Apr 23, 2021
Merged

encukou merged 2 commits into
python:masterfrom
encukou:pep652-simplify-headers

Conversation

@encukou

@encukou encukou commented Apr 20, 2021 •

Copy link
Copy Markdown
Member

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

encukou added 2 commits April 20, 2021 14:21
This makes static analysis easier.

From discussion at https://discuss.python.org/t/pep-652-maintaining-the-stable-abi/6986/13
it is clear that:
- parsing C to get information is okay (though I personally prefer to *generate* it)
- writing a full C parser is a monumental task (and adding an existing one as a dependency
  is not feasible)

I think it's reasonable to simplify our declarations in order to make header checks
easier, rather than write a parser that can handle all C.
This makes static analysis of the headers easier.

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@encukou
encukou merged commit e7cc64e into python:master Apr 23, 2021
@encukou
encukou deleted the pep652-simplify-headers branch April 23, 2021 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

4 participants