Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-116417: Add _testlimitedcapi C extension #116419

Merged
merged 8 commits into from Mar 7, 2024

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Mar 6, 2024

Add a new C extension "_testlimitedcapi" which is only built with the limited C API.

Move heaptype_relative.c and vectorcall_limited.c from Modules/_testcapi/ to Modules/_testlimitedcapi/.

Add a new C extension "_testlimitedcapi" which is only built with the
limited C API.

Move heaptype_relative.c and vectorcall_limited.c from
Modules/_testcapi/ to Modules/_testlimitedcapi/.
@vstinner
Copy link
Member Author

vstinner commented Mar 6, 2024

@erlend-aasland @encukou @sobolevn @colesbury: What do you think of this change? (See the issue for the rationale.)

@vstinner
Copy link
Member Author

vstinner commented Mar 6, 2024

If we land this change, should we move tests which don't use the non-limited C API (tests only using the limited C API) to _testlimitedapi?

This change should be backported to 3.11 and 3.12 branches to ease backport of future changes.

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

This seems like a good idea to me.

  • The #include "pyconfig.h" can be removed from vectorcall_limited.c and heaptype_relative.c now that it's part of parts.h
  • heaptype_relative.c can also remove the Py_LIMITED_API define now that it's defined in parts.h.

Modules/_testlimitedcapi/vectorcall_limited.c Outdated Show resolved Hide resolved
@zooba
Copy link
Member

zooba commented Mar 6, 2024

Can we remove xxlimited.c then? I'm pretty sure that's only in there to test the limited API, so if we have another module doing it, there isn't a need for that one.

@vstinner
Copy link
Member Author

vstinner commented Mar 6, 2024

@colesbury:

This seems like a good idea to me. (...)

Fixed: nicely spotted for remaining code in heaptype_relative.c.

I had a lot of build issues to build the new C extension properly on Linux and Windows, and then I forgot these lines.

@zooba:

Can we remove xxlimited.c then? I'm pretty sure that's only in there to test the limited API, so if we have another module doing it, there isn't a need for that one.

I don't think that it's a test, but more an example to write code using the limited C API. I started with the comment:

/* Use this file as a template to start implementing a module that
   also declares object types. All occurrences of 'Xxo' should be changed

cc @encukou

@vstinner
Copy link
Member Author

vstinner commented Mar 7, 2024

@colesbury: I addressed your remarks and tests now pass. You can review the updated PR ;-)

Copy link
Contributor

@colesbury colesbury left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

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

This looks like a good idea, thank you!

Copy link
Contributor

@erlend-aasland erlend-aasland left a comment

Choose a reason for hiding this comment

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

I'd like it if you could create an entry for this module in configure.ac; that way it is easier to see if this module is enabled or not. Relevant output from sample ./configure and make invocations:

The following modules are *disabled* in configure script:
_ctypes_test              _testbuffer               _testcapi              
_testclinic               _testclinic_limited       _testexternalinspection
_testimportmultiple       _testinternalcapi         _testmultiphase        
_testsinglephase          _xxtestfuzz               xxsubtype              
checking for stdlib extension module _testcapi... disabled
checking for stdlib extension module _testclinic... disabled
checking for stdlib extension module _testclinic_limited... disabled
checking for stdlib extension module _testinternalcapi... disabled
checking for stdlib extension module _testbuffer... disabled
checking for stdlib extension module _testimportmultiple... disabled
checking for stdlib extension module _testmultiphase... disabled
checking for stdlib extension module _testsinglephase... disabled
checking for stdlib extension module _testexternalinspection... disabled

If you "hide" this new extension module behind the _testcapi module, it will not show up in these outputs.

@vstinner
Copy link
Member Author

vstinner commented Mar 7, 2024

I'd like it if you could create an entry for this module in configure.ac; that way it is easier to see if this module is enabled or not.

Sure! It's done.

Example:

$ ./configure --disable-test-modules|grep testlimited
checking for stdlib extension module _testlimitedcapi... disabled

The test extension is now disabled as expected.

Modules/Setup.stdlib.in Outdated Show resolved Hide resolved
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@erlend-aasland
Copy link
Contributor

Thanks! On more nit :)

@erlend-aasland
Copy link
Contributor

It's a nice change; it makes sense to have this as a separate test module IMO.

@vstinner vstinner enabled auto-merge (squash) March 7, 2024 17:57
@vstinner vstinner merged commit d9bcdda into python:main Mar 7, 2024
35 checks passed
@vstinner vstinner deleted the testlimitedcapi branch March 7, 2024 18:31
@vstinner
Copy link
Member Author

vstinner commented Mar 7, 2024

Thanks for your helpful reviews! I merged my PR.

@vstinner
Copy link
Member Author

vstinner commented Mar 7, 2024

Backporting this change to Python 3.12 looks non trivial, I get many conflicts:

Unmerged paths:
  (use "git add <file>..." to mark resolution)
	both modified:   Lib/test/support/__init__.py
	both modified:   Lib/test/test_capi/test_misc.py
	both modified:   Modules/Setup.stdlib.in
	both modified:   Modules/_testcapi/parts.h
	both modified:   Modules/_testcapimodule.c
	both modified:   Modules/_testlimitedcapi/heaptype_relative.c
	both modified:   Modules/_testlimitedcapi/vectorcall_limited.c
	both modified:   PCbuild/pcbuild.proj
	both modified:   PCbuild/pcbuild.sln
	both modified:   PCbuild/readme.txt
	both modified:   Tools/c-analyzer/c_parser/preprocessor/gcc.py
	both modified:   Tools/msi/test/test_files.wxs
	both modified:   configure
	both modified:   configure.ac

The split of Modules/_testinternalcapi.c was not backported. Maybe we should not backport these changes to 3.11 and 3.12.

adorilson pushed a commit to adorilson/cpython that referenced this pull request Mar 25, 2024
Add a new C extension "_testlimitedcapi" which is only built with the
limited C API.

Move heaptype_relative.c and vectorcall_limited.c from
Modules/_testcapi/ to Modules/_testlimitedcapi/.

* configure: add _testlimitedcapi test extension.
* Update generate_stdlib_module_names.py.
* Update make check-c-globals.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
diegorusso pushed a commit to diegorusso/cpython that referenced this pull request Apr 17, 2024
Add a new C extension "_testlimitedcapi" which is only built with the
limited C API.

Move heaptype_relative.c and vectorcall_limited.c from
Modules/_testcapi/ to Modules/_testlimitedcapi/.

* configure: add _testlimitedcapi test extension.
* Update generate_stdlib_module_names.py.
* Update make check-c-globals.

Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants