Skip to content

Conversation

@vstinner
Copy link
Member

@vstinnervstinner 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
MemberAuthor

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

@vstinner
Copy link
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.

Copy link
Contributor

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

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

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

Copy link
Contributor

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

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

Co-authored-by: Erlend E. Aasland <[email protected]>
@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.

@vstinnervstinner enabled auto-merge (squash) March 7, 2024 17:57
@vstinnervstinner merged commit d9bcdda into python:mainMar 7, 2024
@vstinnervstinner deleted the testlimitedcapi branch March 7, 2024 18:31
@vstinner
Copy link
MemberAuthor

Thanks for your helpful reviews! I merged my PR.

@vstinner
Copy link
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 <[email protected]>
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 <[email protected]>
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