| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Using MSVC (on Windows), prefer decltype() over __typeof__() on C++.
|
!buildbot AMD64 Windows11 Non-Debug 3.x PR |
Sorry, something went wrong.
|
The regex 'AMD64 Windows11 Non-Debug 3.x PR' did not match any buildbot builder. Is the requested builder in the list of stable builders? |
Sorry, something went wrong.
|
Right now, I don't access to a Windows machine to test my change, so I will rely on Windows buildbots for now. |
Sorry, something went wrong.
|
!buildbot AMD64 Windows11 Non-Debug 3.x |
Sorry, something went wrong.
|
The regex 'AMD64 Windows11 Non-Debug 3.x' did not match any buildbot builder. Is the requested builder in the list of stable builders? |
Sorry, something went wrong.
|
!buildbot AMD64 Windows11 Non-Debug |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @chris-eibl for commit 85a6ba9 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F157267%2Fmerge The command will test the builders whose names match following regular expression: AMD64 Windows11 Non-Debug The builders matched are:
|
Sorry, something went wrong.
|
Oh, test_cppext failed on "Ubuntu / build and test (ubuntu-26.04-arm)" CI: ERROR: test_build (test.test_cppext.TestInteralCAPI.test_build)
(...)
/usr/bin/g++ -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -fno-strict-overflow -Wsign-compare -g -Og -Wall -fPIC -I/home/runner/work/cpython/cpython-builddir/build/test_python_61202æ/tempcwd/env/include -I/home/runner/work/cpython/cpython-ro-srcdir/Include -I/home/runner/work/cpython/cpython-builddir -c extension.cpp -o build/temp.linux-aarch64-cpython-316-pydebug/extension.o -Werror -DMODULE_NAME=_testcppext_internal -DTEST_INTERNAL_C_API=1
In file included from /home/runner/work/cpython/cpython-ro-srcdir/Include/object.h:742,
from /home/runner/work/cpython/cpython-ro-srcdir/Include/Python.h:79,
from extension.cpp:13:
/home/runner/work/cpython/cpython-ro-srcdir/Include/internal/pycore_object.h: In function ‘void _PyObject_XSetRefDelayed(PyObject**, PyObject*)’:
Error: /home/runner/work/cpython/cpython-ro-srcdir/Include/cpython/object.h:377:26: error: cannot declare pointer to ‘PyObject*&’ {aka ‘struct _object*&’}
377 | _Py_TYPEOF(dst)* _tmp_dst_ptr = &(dst); \
| ^~~~~~~~~~~~
/home/runner/work/cpython/cpython-ro-srcdir/Include/internal/pycore_object.h:757:5: note: in expansion of macro ‘Py_XSETREF’
757 | Py_XSETREF(*p_obj, obj);
| ^~~~~~~~~~
error: command '/usr/bin/g++' failed with exit code 1
test.pythoninfo says CC.version: gcc (Ubuntu 15.2.0-16ubuntu1) 15.2.0. |
Sorry, something went wrong.
|
Sadly, it still fails with the same error. I suppose that MSVC doesn't target C++11 by default. test_build (test.test_cppext.TestInteralCAPI.test_build) ... Processing b:\uildarea\pull_request.ware-win11.nondebug\build\Lib\test\wheeldata\setuptools-79.0.1-py3-none-any.whl extension.cpp(299): error C3861: '__typeof__': identifier not found Even internal__testcpp14ext which uses /std:c++14 also fails: extension.cpp(299): error C3861: '__typeof__': identifier not found By the way, test_limited_cpp03ext logs a compiler warning: cl : Command line warning D9002 : ignoring unknown option '/std:c++03' |
Sorry, something went wrong.
Without /Zc:__cplusplus MSVC always sets __cplusplus=199711L.
Maybe we can use the _MSVC_LANG preprocessor macro, because many people do not use /Zc:__cplusplus?
Yupp, that's not a valid option per https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=msvc-170. It "starts" with /std:c++14.
But again, without /Zc:__cplusplus we won't see anything else than __cplusplus=199711L and would need to query _MSVC_LANG. |
Sorry, something went wrong.
|
!buildbot AMD64 Windows11 Non-Debug PR |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @vstinner for commit 13de0a0 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F157267%2Fmerge The command will test the builders whose names match following regular expression: AMD64 Windows11 Non-Debug PR The builders matched are:
|
Sorry, something went wrong.
Ok, let me retry with _MSVC_LANG macro :-) |
Sorry, something went wrong.
Replace "_Py_TYPEOF(dst)*" with "_Py_TYPEOF(&(dst))". In C++, "_Py_TYPEOF(dst)*" can fail with a compiler error.
|
For the Ubuntu failure, I can reproduce it locally on Fedora 44 (GCC 16.2.1) with the C program: struct object {
int data;
};
typedef struct object PyObject;
#define Py_CLEAR(obj) \
do { \
decltype(obj)* ptr = &obj; \
*ptr = nullptr; \
} while (0)
void func(PyObject **obj)
{
Py_CLEAR(*obj);
}
int main()
{
PyObject *obj = nullptr;
func(&obj);
}
It fails to build with: x.cpp: In function ‘void func(PyObject**)’:
x.cpp:9:24: error: cannot declare pointer to ‘PyObject*&’ {aka ‘struct object*&’}
9 | decltype(obj)* ptr = &obj; \
| ^~~
x.cpp:16:5: note: in expansion of macro ‘Py_CLEAR’
16 | Py_CLEAR(*obj);
| ^~~~~~~~
The fix is to replace decltype(obj)* ptr with decltype(&(obj)) ptr. C++ is more strict about types, especially when using & in the type declaration. |
Sorry, something went wrong.
|
Since _MSVC_LANG is always set when __cplusplus is defined, I've just successfully tried #elif defined(__cplusplus) && (__cplusplus >= 201103L || _MSVC_LANG >= 201103L) locally. Given that MSVC doesn't support anything older than /std:c++14, I'd also mark the other tests like @unittest.skipIf(support.MS_WINDOWS, "MSVC doesn't support /std:c++11")
def test_build_cpp11(self): |
Sorry, something went wrong.
|
!buildbot AMD64 Windows11 Non-Debug PR |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @chris-eibl for commit ae56459 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F157267%2Fmerge The command will test the builders whose names match following regular expression: AMD64 Windows11 Non-Debug PR The builders matched are:
|
Sorry, something went wrong.
I pushed a change for that. |
Sorry, something went wrong.
|
Ah good, test_cppext passed on "Ubuntu / build and test (ubuntu-26.04-arm)" CI. |
Sorry, something went wrong.
|
Aha, test_cppext also passed on the Windows buildbot. |
Sorry, something went wrong.
|
!buildbot Windows |
Sorry, something went wrong.
|
🤖 New build scheduled with the buildbot fleet by @vstinner for commit dec5373 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F157267%2Fmerge The command will test the builders whose names match following regular expression: Windows The builders matched are:
|
Sorry, something went wrong.
Using MSVC (on Windows), _Py_TYPEOF() prefers decltype() over __typeof__() on C++. Fix also _Py_TYPEOF() usage in Py_CLEAR() and Py_SETREF() macros. Replace "_Py_TYPEOF(dst)*" with "_Py_TYPEOF(&(dst))". In C++, "_Py_TYPEOF(dst)*" can fail with a compiler error.
Using MSVC (on Windows), _Py_TYPEOF() prefers decltype() over __typeof__() on C++. Fix also _Py_TYPEOF() usage in Py_CLEAR() and Py_SETREF() macros. Replace "_Py_TYPEOF(dst)*" with "_Py_TYPEOF(&(dst))". In C++, "_Py_TYPEOF(dst)*" can fail with a compiler error.
|
hello @vstinner @chris-eibl, I'm afraid I have bisected a new SEGV under ASan to this PR: gh-157649. Please see that issue for a one-line reproducer (tested on osx-arm64 so far). |
Sorry, something went wrong.
This seems like a false positive, you're testing with Python 3.15 which does not have this commit? |
Sorry, something went wrong.
|
Quoting #157649
So yeah, reproducible and legit on the main branch ... |
Sorry, something went wrong.
|
Let's continue the discussion in issue #157649. |
Sorry, something went wrong.
* gh-121647: Fix _Py_TYPEOF() on C++ (#157267) Using MSVC (on Windows), _Py_TYPEOF() prefers decltype() over __typeof__() on C++. Fix also _Py_TYPEOF() usage in Py_CLEAR() and Py_SETREF() macros. Replace "_Py_TYPEOF(dst)*" with "_Py_TYPEOF(&(dst))". In C++, "_Py_TYPEOF(dst)*" can fail with a compiler error. (cherry picked from commit bba99f2) * gh-157649: Fix Py_CLEAR()/Py_SETREF() on C++ (#158070) On C++, do not use decltype() in _Py_TYPEOF since it produces invalid code in Py_CLEAR() and Py_SETREF(). Instead, implement Py_CLEAR(), Py_SETREF() and Py_XSETREF() using "auto" on C++11 and newer. Add Py_CLEAR(), Py_SETREF() and Py_XSETREF() tests on an array. (cherry picked from commit 3330712)
| Back | FazBrowse Home | New Git URL |
Using MSVC (on Windows), prefer decltype() over typeof() on C++.