Skip to content

gh-116417: Add _testlimitedcapi C extension - #116419

Merged
vstinner merged 8 commits into
python:mainfrom
vstinner:testlimitedcapi
Mar 7, 2024
Merged

gh-116417: Add _testlimitedcapi C extension#116419
vstinner merged 8 commits into
python:mainfrom
vstinner:testlimitedcapi

Conversation

@vstinner

@vstinnervstinner commented Mar 6, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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

@vstinner

Copy link
Copy Markdown
MemberAuthor

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.

@colesburycolesbury left a comment

Copy link
Copy Markdown
Contributor

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.

Comment threadModules/_testlimitedcapi/vectorcall_limited.c Outdated
@zooba

zooba commented Mar 6, 2024

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

@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:

/*Usethisfileasatemplatetostartimplementingamodulethatalsodeclaresobjecttypes. Alloccurrencesof 'Xxo' should be changed

cc @encukou

@vstinner

Copy link
Copy Markdown
MemberAuthor

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

@colesburycolesbury left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@sobolevnsobolevn 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.

This looks like a good idea, thank you!

@erlend-aaslanderlend-aasland left a comment

Copy link
Copy Markdown
Contributor

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
Copy Markdown
MemberAuthor

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.

Comment threadModules/Setup.stdlib.in Outdated
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
@erlend-aasland

Copy link
Copy Markdown
Contributor

Thanks! On more nit :)

@erlend-aasland

Copy link
Copy Markdown
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:mainMar 7, 2024
@vstinner
vstinner deleted the testlimitedcapi branch March 7, 2024 18:31
@vstinner

Copy link
Copy Markdown
MemberAuthor

Thanks for your helpful reviews! I merged my PR.

@vstinner

Copy link
Copy Markdown
MemberAuthor

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 freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@vstinner@zooba@erlend-aasland@colesbury@sobolevn@corona10