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 _Py_NULL macro by vstinner · Pull Request #92253 · python/cpython

Conversation

@vstinner

@vstinner vstinner commented May 3, 2022

Copy link
Copy Markdown
Member

Fix C++ compiler warnings: "zero as null pointer constant"
(clang -Wzero-as-null-pointer-constant).

  • Add the _Py_NULL macro used by static inline functions to use
    nullptr in C++.
  • Replace NULL with nullptr in _testcppext.cpp.

Sorry, something went wrong.

Uh oh!

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

All reactions
@vstinner
gh-91321: Add _Py_NULL macro
924d3bd
Fix C++ compiler warnings: "zero as null pointer constant"
(clang -Wzero-as-null-pointer-constant).

* Add the _Py_NULL macro used by static inline functions to use
  nullptr in C++.
* Replace NULL with nullptr in _testcppext.cpp.
@vstinner vstinner added the skip news label May 3, 2022
@bedevere-bot bedevere-bot added the awaiting core review label May 3, 2022
@vstinner vstinner mentioned this pull request May 3, 2022
Use Python 3.11 _Py_NULL python/pythoncapi-compat#36
Merged
@vstinner

vstinner commented May 3, 2022

Copy link
Copy Markdown
Member Author

I already had this issue and fixed it in pythoncapi-compat. I prepared a PR for pythoncapi-compat to reuse Python 3.11 _Py_NULL macro (this PR): python/pythoncapi-compat#36

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented May 3, 2022

Copy link
Copy Markdown
Member Author

Currently, with gcc -Wzero-as-null-pointer-constant, there is no C++ compiler warning when including <Python.h>. But using clang -Wzero-as-null-pointer-constant, I get many warnings (errors). A few examples:

$ CC=clang ./python -m test -v test_cppext
(...)
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:44:
/home/vstinner/python/main/Include/object.h:590:15: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
    if (op != NULL) {
              ^~~~
              nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
#    define NULL __null
                 ^
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:44:
/home/vstinner/python/main/Include/object.h:600:15: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
    if (op != NULL) {
              ^~~~
              nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
#    define NULL __null
                 ^
In file included from /home/vstinner/python/main/Lib/test/_testcppext.cpp:7:
In file included from /home/vstinner/python/main/Include/Python.h:51:
In file included from /home/vstinner/python/main/Include/unicodeobject.h:1042:
/home/vstinner/python/main/Include/cpython/unicodeobject.h:645:42: error: zero as null pointer constant [-Werror,-Wzero-as-null-pointer-constant]
    if (_PyASCIIObject_CAST(op)->wstr == NULL) {
                                         ^~~~
                                         nullptr
/usr/lib64/clang/13.0.0/include/stddef.h:84:18: note: expanded from macro 'NULL'
#    define NULL __null
                 ^
(...)
Tests result: FAILURE
All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented May 3, 2022

Copy link
Copy Markdown
Member Author

I also got these errors on the CI of the datatabl project: see h2oai/datatable#3231

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner
vstinner merged commit 551d02b into python:main May 3, 2022
@bedevere-bot bedevere-bot removed the awaiting core review label May 3, 2022
@vstinner
vstinner deleted the py_null branch May 3, 2022 19:38
@vstinner vstinner mentioned this pull request May 3, 2022
[C API] Test that the Python C API is compatible with C++ #91321
Closed
@neutrinoceros

neutrinoceros commented Jun 13, 2022

Copy link
Copy Markdown
Contributor

This breaks C-extensions builds with , e.g., -std=c++03, because nullptr is only defined since C++11
Is it desired that Python 3.11 de facto requires C++11 or above ?

All reactions

Sorry, something went wrong.

Uh oh!

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

@neutrinoceros neutrinoceros mentioned this pull request Jun 13, 2022
TST: start testing on Python 3.11 yt-project/yt#3956
Merged
@vstinner

vstinner commented Jun 13, 2022

Copy link
Copy Markdown
Member Author

In Python 3.11, I added test_cppext which checks that the Python C API is compatible with C++11. Do you care about older C++ versions? What is your OS (name and version) and C++ compiler (name and version)?

All reactions

Sorry, something went wrong.

Uh oh!

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

@neutrinoceros

neutrinoceros commented Jun 13, 2022

Copy link
Copy Markdown
Contributor

Actually we're explicitly requiring -std=c++03 in a couple Cython files.
This is probably something we can (and should) update on our side, I just wanted to check if the breaking change was intentional :)

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jun 13, 2022

Copy link
Copy Markdown
Member Author

I wrote #93784 to fix compatibility with C++ older than C++11.

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jun 13, 2022

Copy link
Copy Markdown
Member Author

I just wanted to check if the breaking change was intentional :)

It's not intentional. My initial concern was to prevent C++ compiler warnings.

All reactions

Sorry, something went wrong.

Uh oh!

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

@neutrinoceros

neutrinoceros commented Jun 13, 2022

Copy link
Copy Markdown
Contributor

Awesome, thank you very much !

All reactions

Sorry, something went wrong.

Uh oh!

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

@vstinner

vstinner commented Jun 14, 2022

Copy link
Copy Markdown
Member Author

Python 3.11 is now fixed:

  • [3.11] gh-91321: Fix compatibility with C++ older than C++11 (#93784) #93802
  • ef591cf
neutrinoceros reacted with hooray emoji
All reactions
  • 🎉 1 reaction

Sorry, something went wrong.

Uh oh!

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

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.

3 participants

@vstinner @neutrinoceros @bedevere-bot
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.