GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-91321: Add _testcppext C++ extension by vstinner · Pull Request #32175 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented Mar 29, 2022 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Build a C++ test extension to check that the Python C API is
compatible with C++ and does not emit C++ compiler warnings.

Add test_cppext.py and setup_testcppext.py to Lib/test/.

https://bugs.python.org/issue39355

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-bot bedevere-bot added the awaiting core review label Mar 29, 2022
@the-knights-who-say-ni the-knights-who-say-ni added the CLA signed label Mar 29, 2022
@vstinner

vstinner commented Mar 29, 2022

Copy link
Copy Markdown
Member Author

Quick & dirty hack of the Python C API (Include/ header files) to make it compatible with C++.

By the way, using NULL in a macro doesn't emit a warning even with clang -Wzero-as-null-pointer-constant. It's a clang feature! Extract of a LLVM clang comment:

// If it is a macro from system header, and if the macro name is not "NULL",
// do not warn
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Mar 30, 2022
bpo-39355: making Python.h compatible with C++20 compilers #31282
Closed
@iritkatriel

iritkatriel commented Apr 11, 2022

Copy link
Copy Markdown
Member

https://bugs.python.org/issue39355 is closed. What is the status of this PR?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 19, 2022

Copy link
Copy Markdown
Member Author

This PR is now for https://bugs.python.org/issue47165

I'm working on fixing C++ compiler warnings: https://bugs.python.org/issue47164

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner changed the title bpo-39355: WIP: Add _testcppext C++ extension gh-91320: WIP: Add _testcppext C++ extension Apr 26, 2022
@vstinner

vstinner commented Apr 26, 2022

Copy link
Copy Markdown
Member Author

I updated this PR for #91320

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner changed the title gh-91320: WIP: Add _testcppext C++ extension gh-91321: WIP: Add _testcppext C++ extension Apr 26, 2022
@vstinner

vstinner commented Apr 26, 2022

Copy link
Copy Markdown
Member Author

Oops, sorry, this PR is for #91321

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner added the skip news label Apr 26, 2022
@vstinner

vstinner commented Apr 26, 2022

Copy link
Copy Markdown
Member Author

I created #91959 for the "CAST" commit.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner changed the title gh-91321: WIP: Add _testcppext C++ extension gh-91321: Add _testcppext C++ extension Apr 27, 2022
@vstinner
vstinner marked this pull request as ready for review April 27, 2022 10:15
@vstinner vstinner mentioned this pull request Apr 27, 2022
[C API] Test that the Python C API is compatible with C++ #91321
Closed
@vstinner

vstinner commented Apr 27, 2022

Copy link
Copy Markdown
Member Author

Oh, the build fails with MSVC:

Error: Modules/_testcppext.cpp(229): error C7555: use of designated initializers requires at least '/std:c++20'
test test_cppext failed
Error: Modules/_testcppext.cpp(244): error C7555: use of designated initializers requires at least '/std:c++20'
Error: Modules/_testcppext.cpp(364): error C7555: use of designated initializers requires at least '/std:c++20'

I initialize structures with .attr = value syntax:

static PyType_Spec Xxo_Type_spec = {
    .name = "_testcppext.Xxo",
    .basicsize = sizeof(XxoObject),
    .itemsize = 0,
    .flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
    .slots = Xxo_Type_slots,
};
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 27, 2022

Copy link
Copy Markdown
Member Author

Tests / Windows (x64) (pull_request) Failing after 19m

Error:

LINK : fatal error LNK1104: cannot open file 'python311.lib'
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@steve-s

steve-s commented Apr 28, 2022

Copy link
Copy Markdown
Contributor

FYI we were/are trying to address the same issue with HPy headers. My understanding is that this only tests the static inline functions and macros that are used in the example extension. It is still possible that some other macro or static inline function could cause warnings or for macros even errors. So my conclusion so far has been that to have a fully C++ compat tested headers, one has to write a C++ extension(s) that use all the static inline functions and macros from the headers. Something tested is way better than nothing tested, so no objections to this PR -- just wanted to check if you see it the same way?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 29, 2022

Copy link
Copy Markdown
Member Author

@steve-s:

FYI we were/are trying to address the same issue with HPy headers. My understanding is that this only tests the static inline functions and macros that are used in the example extension. It is still possible that some other macro or static inline function could cause warnings or for macros even errors. So my conclusion so far has been that to have a fully C++ compat tested headers, one has to write a C++ extension(s) that use all the static inline functions and macros from the headers. Something tested is way better than nothing tested, so no objections to this PR -- just wanted to check if you see it the same way?

Sadly, my experience is the same: a C++ compiler doesn't complain when a static inline function is defined. Only when it's being used.

My practical plan is:

  • Write a bare minimum C++ extension which does nothing and check in the Python test suite that we can build it for C++11.
  • First, I tried to load the extension but my code didn't work when Python is installed. Maybe we can try to load and test the built C++ extension later. But for now, I prefer to skip that.
  • Slowly test more and more static inline functions in this C++ extension.
  • Test more C++ versions.

Right now, my main blocker issue is to test if Python has a working C++ compiler. For example, the "Tests / Windows (x64)" fails with cannot open file 'python311.lib'. This CI has a C++ compiler but not the required python library to link the C++ extension :-( Maybe it's just a matter of using the right compiler command line. I don't know.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 29, 2022
@bedevere-bot

bedevere-bot commented Apr 29, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit 31b7a4f7ab6092998865e06dd0f4b0d5ea79b13f 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Apr 29, 2022
@vstinner

vstinner commented Apr 29, 2022

Copy link
Copy Markdown
Member Author

I simplified Modules/_testcppext.cpp to make it as small as possible. I prefer to start with a small extension and then extend it slowly. As I wrote, right now, my practical issue is more to ensure that there is a working C++ compiler all on CIs used by Python.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner

vstinner commented Apr 29, 2022

Copy link
Copy Markdown
Member Author

Oh, when Python is installed, the test fails with:

error: could not create 'build': Permission denied

For example, it failed on these buildbots:

  • AMD64 Fedora Stable Clang Installed PR
  • s390x Fedora Clang Installed PR
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
gh-91321: Add basic _testcppext C++ extension
1ef44f4
Build a basic C++ test extension to check that the Python C API is
compatible with C++ and does not emit C++ compiler warnings.

* Add Modules/_testcppext.cpp: C++ extension
* Add Lib/test/test_cppext.py: test building the C++ extension.
@vstinner

vstinner commented Apr 29, 2022

Copy link
Copy Markdown
Member Author

I rewrote the PR to build the C++ extension in a temporary directory and fix the test on installed Python: _testcppext.cpp is now part of Lib/test/ and so is installed.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
Save/restore distutils.sysconfig._config_vars
e067677
@vstinner vstinner added the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 2, 2022
@bedevere-bot

bedevere-bot commented May 2, 2022

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @vstinner for commit e067677 🤖

If you want to schedule another build, you need to add the ":hammer: test-with-buildbots" label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label May 2, 2022
@vstinner

vstinner commented May 2, 2022

Copy link
Copy Markdown
Member Author

buildbot/s390x RHEL7 PR — Build done.

The error is unrelated to my change:

1 test altered the execution environment: test_threading
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner
vstinner merged commit 79886e7 into python:main May 2, 2022
@bedevere-bot bedevere-bot removed the awaiting core review label May 2, 2022
@vstinner
vstinner deleted the testcppext branch May 2, 2022 12:09
@vstinner vstinner mentioned this pull request May 2, 2022
gh-92135: Fix _Py_reinterpret_cast() for const #92138
Merged
@steve-s steve-s mentioned this pull request May 5, 2022
Testing full C++ compatibility of the headers hpyproject/hpy#319
Closed
@encukou

encukou commented Jul 12, 2022

Copy link
Copy Markdown
Member

reinterpret_cast breaks existing code, see #94731.
#94782 is a PR to revert back to C-style casts.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vstinner vstinner mentioned this pull request Sep 22, 2022
PEP 670: Convert static inline functions to functions #97016
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

6 participants

@vstinner @iritkatriel @steve-s @bedevere-bot @encukou @the-knights-who-say-ni
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.