Skip to content

Commit

Permalink
gh-107603: AC only includes pycore_gc.h if needed
Browse files Browse the repository at this point in the history
Argument Clinic now only includes pycore_gc.h if PyGC_Head is needed,
and only includes pycore_runtime.h if _Py_ID() is needed.

Add Py_ARGUMENT_CLINIC_AVOID_INTERNAL_CAPI macro to opt-out for the
internal C API in Argument Clinic.

The following extensions avoids the internal C API by defining the
macro Py_ARGUMENT_CLINIC_AVOID_INTERNAL_CAPI:

* Modules/_csv.c
* Modules/_multiprocessing/posixshmem.c
* Modules/_testcapi/exceptions.c
* Modules/grpmodule.c
* Modules/syslogmodule.c
  • Loading branch information
vstinner committed Aug 31, 2023
1 parent bd58389 commit df2c754
Show file tree
Hide file tree
Showing 139 changed files with 288 additions and 1,030 deletions.
5 changes: 0 additions & 5 deletions Include/internal/pycore_global_objects_fini_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 0 additions & 5 deletions Include/internal/pycore_global_strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,6 @@ struct _Py_global_strings {
STRUCT_FOR_ID(extend)
STRUCT_FOR_ID(extra_tokens)
STRUCT_FOR_ID(f)
STRUCT_FOR_ID(facility)
STRUCT_FOR_ID(factory)
STRUCT_FOR_ID(false)
STRUCT_FOR_ID(family)
Expand Down Expand Up @@ -460,8 +459,6 @@ struct _Py_global_strings {
STRUCT_FOR_ID(headers)
STRUCT_FOR_ID(hi)
STRUCT_FOR_ID(hook)
STRUCT_FOR_ID(id)
STRUCT_FOR_ID(ident)
STRUCT_FOR_ID(ignore)
STRUCT_FOR_ID(imag)
STRUCT_FOR_ID(importlib)
Expand Down Expand Up @@ -524,7 +521,6 @@ struct _Py_global_strings {
STRUCT_FOR_ID(lo)
STRUCT_FOR_ID(locale)
STRUCT_FOR_ID(locals)
STRUCT_FOR_ID(logoption)
STRUCT_FOR_ID(loop)
STRUCT_FOR_ID(mapping)
STRUCT_FOR_ID(match)
Expand Down Expand Up @@ -560,7 +556,6 @@ struct _Py_global_strings {
STRUCT_FOR_ID(narg)
STRUCT_FOR_ID(ndigits)
STRUCT_FOR_ID(new_file_name)
STRUCT_FOR_ID(new_limit)
STRUCT_FOR_ID(newline)
STRUCT_FOR_ID(newlines)
STRUCT_FOR_ID(next)
Expand Down
5 changes: 0 additions & 5 deletions Include/internal/pycore_runtime_init_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 0 additions & 15 deletions Include/internal/pycore_unicodeobject_generated.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 11 additions & 11 deletions Lib/test/test_clinic.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@

def _make_clinic(*, filename='clinic_tests'):
clang = clinic.CLanguage(None)
c = clinic.Clinic(clang, filename=filename, limited_capi=False)
c = clinic.Clinic(clang,
filename=filename,
limited_capi=False,
internal_capi=True)
c.block_parser = clinic.BlockParser('', clang)
return c

Expand Down Expand Up @@ -125,7 +128,7 @@ def test_parse_with_body_prefix(self):
clang.body_prefix = "//"
clang.start_line = "//[{dsl_name} start]"
clang.stop_line = "//[{dsl_name} stop]"
cl = clinic.Clinic(clang, filename="test.c", limited_capi=False)
cl = clinic.Clinic(clang, filename="test.c", limited_capi=False, internal_capi=True)
raw = dedent("""
//[clinic start]
//module test
Expand Down Expand Up @@ -834,7 +837,7 @@ def _test(self, input, output):
writer = clinic.BlockPrinter(language)
c = _make_clinic()
for block in blocks:
writer.print_block(block, limited_capi=c.limited_capi, header_includes=c.includes)
writer.print_block(block, header_includes=c.includes)
output = writer.f.getvalue()
assert output == input, "output != input!\n\noutput " + repr(output) + "\n\n input " + repr(input)

Expand All @@ -860,7 +863,10 @@ def test_round_trip_2(self):

def _test_clinic(self, input, output):
language = clinic.CLanguage(None)
c = clinic.Clinic(language, filename="file", limited_capi=False)
c = clinic.Clinic(language,
filename="file",
limited_capi=False,
internal_capi=True)
c.parsers['inert'] = InertParser(c)
c.parsers['copy'] = CopyParser(c)
computed = c.parse(input)
Expand Down Expand Up @@ -2673,12 +2679,6 @@ def test_file_dest(self):
preserve
[clinic start generated code]*/
#if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
# include "pycore_gc.h" // PyGC_Head
# include "pycore_runtime.h" // _Py_ID()
#endif
PyDoc_VAR(func__doc__);
PyDoc_STRVAR(func__doc__,
Expand All @@ -2691,7 +2691,7 @@ def test_file_dest(self):
static PyObject *
func(PyObject *module, PyObject *a)
/*[clinic end generated code: output=56c09670e89a0d9a input=a9049054013a1b77]*/
/*[clinic end generated code: output=3dde2d13002165b9 input=a9049054013a1b77]*/
""")
with os_helper.temp_dir() as tmp_dir:
in_fn = os.path.join(tmp_dir, "test.c")
Expand Down
8 changes: 2 additions & 6 deletions Modules/_blake2/clinic/blake2b_impl.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Modules/_blake2/clinic/blake2s_impl.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Modules/_csv.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ module instead.

#define MODULE_VERSION "1.0"

// Argument Clinic avoids the internal C API
#define Py_ARGUMENT_CLINIC_AVOID_INTERNAL_CAPI

#include "Python.h"

#include <stddef.h> // offsetof()
Expand Down
8 changes: 1 addition & 7 deletions Modules/_ctypes/clinic/callproc.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Modules/_io/clinic/_iomodule.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Modules/_io/clinic/bufferedio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Modules/_io/clinic/bytesio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Modules/_io/clinic/fileio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 1 addition & 6 deletions Modules/_io/clinic/iobase.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 2 additions & 6 deletions Modules/_io/clinic/stringio.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit df2c754

Please sign in to comment.