RFR: 8263136: C4530 was reported from VS 2019 at access bridge
Yasumasa Suenaga
ysuenaga at openjdk.java.net
Mon Mar 8 01:01:06 UTC 2021
On Sun, 7 Mar 2021 22:00:41 GMT, Sergey Bylokhov <serb at openjdk.org> wrote:
>> Yes, including c++ standard library headers like <ostream> means you need to deal with C++ exceptions thrown from library functions, and the code needs to be compiled with unwind capabilities. If its not switched on, and a C++ exception happens, the behavior is undefined. In my experience it results in the process being terminated.
>>
>> I wondered why C++ std headers are even used. The source code looks C-ish; but "8196681: Java Access Bridge logging and debug flags dynamically controlled" added some coding, adding a bunch of C++11x semantics and included C++ std headers. Using "/Ehsc" had even been discussed: https://mail.openjdk.java.net/pipermail/awt-dev/2018-December/014847.html but not done.
>>
>> Adding /Ehsc is fine of course, but I think thats not enough. Now C++ exceptions can pass through the code, but if they do, then what? E.g. this function `getTimeStamp()` added with 8196681:
>>
>> https://github.com/openjdk/jdk/blob/113b5184cfc78fde057a7fe4d5872b463930da00/src/jdk.accessibility/windows/native/common/AccessBridgeDebug.cpp#L85
>>
>> calls into the C++ standard library to get a time stamp. Can't these function not throw C++ exceptions? Is that not what the compiler is warning about? If they throw, exceptions propagate through the code unbounded, until they either end the process or cause havoc at the next upper C-only-interface.
>>
>> Or, maybe, rewrite this coding to use standard C- and Windows-APIs. I think 8196681 could had been done with traditional windows- or standard C APIs. In particular, `getTimeStamp()` could probably be done simply with `GetTickCount` or `GetSystemTime` or functions from time.h.
>>
>> Cheers, Thomas
>
>> I wondered why C++ std headers are even used. The source code looks C-ish; but "8196681: Java Access Bridge logging and debug flags dynamically controlled" added some coding, adding a bunch of C++11x semantics and included C++ std headers. Using "/Ehsc" had even been discussed: https://mail.openjdk.java.net/pipermail/awt-dev/2018-December/014847.html but not done.
>
> After that discussion the usage of "string.h"/etc was dropped and "C string manipulation API" was used instead, and that suppressed the warning. I do not know why it was not complaining about "getTimeStamp". I think the fix should refactor the code again.
Thank you for comments! I refactored `getTimeStamp()` not to use STL functions in new commit. The error messages have gone without /EHsc.
I use `11644473600000ULL` to rebase Epoch from 1601 to 1970, it comes from ProcessHandleImpl_win.c:
https://github.com/openjdk/jdk/blob/22a3117d229cba10c690a4e66baf9c754a09e57c/src/java.base/windows/native/libjava/ProcessHandleImpl_win.c#L342
-------------
PR: https://git.openjdk.java.net/jdk/pull/2859
More information about the build-dev
mailing list