Commit Graph

8 Commits

Author SHA1 Message Date
Neil Schemenauer 713eb184b5
gh-93442: Add test for _Py_CAST(nullptr). (gh-93505) 2022-06-05 12:53:16 +09:00
Neil Schemenauer 8bcc3fa345
gh-93442: Make C++ version of _Py_CAST work with 0/NULL. (#93500)
Add C++ overloads for _Py_CAST_impl() to handle 0/NULL.  This will allow
C++ extensions that pass 0 or NULL to macros using _Py_CAST() to
continue to compile.  Without this, you get an error like:

    invalid ‘static_cast’ from type ‘int’ to type ‘_object*’

The modern way to use a NULL value in C++ is to use nullptr.  However,
we want to not break extensions that do things the old way.

Co-authored-by: serge-sans-paille
2022-06-04 18:49:39 -07:00
Victor Stinner 20d30ba2cc
gh-92898: Enhance _testcppext test on cast to PyObject* (#93111)
* Add StrongRef class.
* Rename and reformat functions of the _Py_CAST() implementation.
2022-05-27 01:12:39 +02:00
serge-sans-paille 5b71b519f9
GH-92898: Make _Py_Cast C++ version compatible with cast operator (gh-92951) 2022-05-21 22:16:37 +09:00
Victor Stinner e6fd7992a9
gh-89653: PEP 670: Fix PyUnicode_READ() cast (#92872)
_Py_CAST() cannot be used with a constant type: use _Py_STATIC_CAST()
instead.
2022-05-17 19:20:37 +02:00
Victor Stinner 551d02b3e6
gh-91321: Add _Py_NULL macro (#92253)
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.
2022-05-03 21:38:37 +02:00
Victor Stinner 031397063e
gh-92135: Fix _Py_reinterpret_cast() for const (#92138)
Fix C++ compiler warnings on cast macros, like _PyObject_CAST(), when
casting a constant expression to a non constant type: use
const_cast<> in C++.

* In C++, Py_SAFE_DOWNCAST() now uses static_cast<> rather than
  reinterpret_cast<>.
* Add tests to the _testcppext C++ extension.
* test_cppext no longer captures stdout in verbose mode.
2022-05-02 17:07:00 +02:00
Victor Stinner 79886e7b62
gh-91321: Add _testcppext C++ extension (#32175)
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.
2022-05-02 14:09:22 +02:00