gh-144490: Fix C++ compatibility in pycore_cell.h#144482
gh-144490: Fix C++ compatibility in pycore_cell.h#144482yoney wants to merge 1 commit intopython:mainfrom
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.
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
That'll make sure we don't break this again someday.
| 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.
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.
Most other headers use _PyObject_CAST so I think we should use that instead.
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 - 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. |
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