diff --git a/CHANGES b/CHANGES index 1d1fa0075ec..50962197c99 100644 --- a/CHANGES +++ b/CHANGES @@ -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 ------- diff --git a/sphinx/domains/c.py b/sphinx/domains/c.py index ea5a1a5db2f..f02c72944f2 100644 --- a/sphinx/domains/c.py +++ b/sphinx/domains/c.py @@ -77,7 +77,7 @@ 'thread_local', ] -# these are ordered by preceedence +# these are ordered by precedence _expression_bin_ops = [ ['||', 'or'], ['&&', 'and'], diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py index 030bf84b397..e3d9745e397 100644 --- a/sphinx/ext/coverage.py +++ b/sphinx/ext/coverage.py @@ -114,8 +114,9 @@ def write(self, *ignored: Any) -> None: 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 @@ def build_c_coverage(self) -> None: 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 diff --git a/tests/roots/test-root/objects.txt b/tests/roots/test-root/objects.txt index 1a1392b9e66..ed5f2c25b48 100644 --- a/tests/roots/test-root/objects.txt +++ b/tests/roots/test-root/objects.txt @@ -133,6 +133,8 @@ C items .. c:var:: int sphinx_global +.. c:function:: PyObject* Py_SphinxFoo(void) + Javascript items ================ diff --git a/tests/roots/test-root/special/api.h b/tests/roots/test-root/special/api.h index 7c137e03951..2bf23826b99 100644 --- a/tests/roots/test-root/special/api.h +++ b/tests/roots/test-root/special/api.h @@ -1 +1,2 @@ -PyAPI_FUNC(PyObject *) Py_SphinxTest(); +PyAPI_FUNC(PyObject *) Py_SphinxTest(void); +PyAPI_FUNC(PyObject *) Py_SphinxFoo(void);