-
-
Notifications
You must be signed in to change notification settings - Fork 34k
gh-144490: Fix C++ compatibility in pycore_cell.h #144482
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
base: main
Are you sure you want to change the base?
Conversation
|
Do we do this kind of stuff for every calls? do we support |
|
The internal headers ( The change itself seems fine, but I'm curious how this came up. What's including |
|
To answer @picnixz, we generally do this sort of thing when people ask, especially when the changes are tiny, but we don't proactively make the internal header files C++ compatible. |
This came up while I’m adapting CinderX to FT-Python: C++ codegen path for Also agreed that |
|
Ok, make sense. Can you open an issue like @picnixz asked? Also edit the PR title to associate it with the issue. |
|
Created the issue #144490 @picnixz, @colesbury: Thank you so much for the review. |
ZeroIntensity
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please also add an #include to test_cppext as well, like this:
cpython/Lib/test/test_cppext/extension.cpp
Lines 15 to 19 in b6d8aa4
| #ifdef TEST_INTERNAL_C_API | |
| // gh-135906: Check for compiler warnings in the internal C API | |
| # include "internal/pycore_backoff.h" | |
| # include "internal/pycore_frame.h" | |
| #endif |
That'll make sure we don't break this again someday.
Include/internal/pycore_cell.h
Outdated
| PyObject *value; | ||
| #ifdef Py_GIL_DISABLED | ||
| value = _Py_atomic_load_ptr(&cell->ob_ref); | ||
| value = (PyObject *)_Py_atomic_load_ptr(&cell->ob_ref); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up to you, but I believe we've used _Py_STATIC_CAST for things like this in the past. That will expand to static_cast<type>(expr) in C++, and then the usual (type)(expr) in C.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Most other headers use _PyObject_CAST so I think we should use that instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you. I grepped for _Py_STATIC_CAST and _PyObject_CAST. There were more usages of _PyObject_CAST, so I changed it to that.
Just including the header is not enough to reproduce the issue. test_cppext just pass with the following change: diff --git a/Lib/test/test_cppext/extension.cpp b/Lib/test/test_cppext/extension.cpp
index f95655eccde..881140eb695 100644
--- a/Lib/test/test_cppext/extension.cpp
+++ b/Lib/test/test_cppext/extension.cpp
@@ -15,6 +15,7 @@
#ifdef TEST_INTERNAL_C_API
// gh-135906: Check for compiler warnings in the internal C API
# include "internal/pycore_backoff.h"
+# include "internal/pycore_cell.h"
# include "internal/pycore_frame.h"
#endif
|
vstinner
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@vstinner - I think Also, in case it's not clear, the error here is limited to |
I’m not sure if this is the correct way to run it. When I set TEST_INTERNAL_C_API=1, the test immediately emits many C++ errors. I tried fixing some of them by passing CPPFLAGS, but there are still a lot of errors, so I stopped. Below are a few sample error lines; many seem to originate from mimalloc. It’s also possible that I’m invoking the test incorrectly. Note: This is on the unmodified main branch; I did not add any includes. |
Ooops! I wrote #144536 to fix test_cppext (test the internal C API).
Yeah, I already saw C++ errors/warnings on mimalloc. I'm not sure how to deal with it. |
Added in #144536 |
The header already includes an
extern "C"guard, suggesting it is intended to be C++ compatible. Adding a cast allows it to compile without-fpermissive.cc: @colesbury