Fix C coverage support in `sphinx.ext.coverage` (#11591)

This commit is contained in:
Stephen Finucane 2023-08-15 14:50:15 +01:00 committed by GitHub
parent 1e0bc26426
commit 53a930f8c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 15 additions and 5 deletions

View File

@ -84,6 +84,8 @@ Bugs fixed
* #11473: Type annotations containing :py:data:`~typing.Literal` enumeration
values now render correctly.
Patch by Bénédikt Tran.
* #11591: Fix support for C coverage in ``sphinx.ext.coverage`` extension.
Patch by Stephen Finucane.
Testing
-------

View File

@ -77,7 +77,7 @@ _macroKeywords = [
'thread_local',
]
# these are ordered by preceedence
# these are ordered by precedence
_expression_bin_ops = [
['||', 'or'],
['&&', 'and'],

View File

@ -114,8 +114,9 @@ class CoverageBuilder(Builder):
self.write_c_coverage()
def build_c_coverage(self) -> None:
# Fetch all the info from the header files
c_objects = self.env.domaindata['c']['objects']
c_objects = {}
for obj in self.env.domains['c'].get_objects():
c_objects[obj[2]] = obj[1]
for filename in self.c_sourcefiles:
undoc: set[tuple[str, str]] = set()
with open(filename, encoding="utf-8") as f:
@ -124,7 +125,11 @@ class CoverageBuilder(Builder):
match = regex.match(line)
if match:
name = match.groups()[0]
if name not in c_objects:
if key not in c_objects:
undoc.add((key, name))
continue
if name not in c_objects[key]:
for exp in self.c_ignorexps.get(key, []):
if exp.match(name):
break

View File

@ -133,6 +133,8 @@ C items
.. c:var:: int sphinx_global
.. c:function:: PyObject* Py_SphinxFoo(void)
Javascript items
================

View File

@ -1 +1,2 @@
PyAPI_FUNC(PyObject *) Py_SphinxTest();
PyAPI_FUNC(PyObject *) Py_SphinxTest(void);
PyAPI_FUNC(PyObject *) Py_SphinxFoo(void);