-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add definition for _Bool in C++ mode #4629
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
Add definition for _Bool in C++ mode #4629
Conversation
CoreFoundation/Base.subproj/CFBase.h
Outdated
|
||
#ifdef __cplusplus | ||
#define _Bool bool | ||
#endif |
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.
I wonder if we want to use stdbool.h
here as well as we do on the other platforms.
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.
So include stdbool.h
, and then fix the uses of _Bool
through the codebase to use bool
?
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.
Yeah, that seems like a better approach - using the standard to use the proper spelling irrespective of the language.
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.
Are there any other uses of _Bool
in CF?
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.
This is the list I have. I just need to find a cycle or two to go through and change them and run the tests.
./CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h:static inline _Bool _resizeConditionalAllocationBuffer(_ConditionalAllocationBuffer *_Nonnull buffer, size_t amt) {
./CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h:static inline _Bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(_ConditionalAllocationBuffer *_Nonnull)) {
./CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h:static inline _Bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(_ConditionalAllocationBuffer *_Nonnull)) {
./CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h:static inline _Bool _withStackOrHeapBufferWithResultInArguments(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(void *_Nonnull memory, size_t capacity, _Bool onStack)) {
./CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h:static _Bool const _CFHasRenameat2 = 1;
./CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h:static _Bool const _CFHasRenameat2 = 0;
./CoreFoundation/Base.subproj/CFBase.h: typedef _Bool Boolean;
./CoreFoundation/Base.subproj/ForFoundationOnly.h:#define BOOL _Bool
./CoreFoundation/Base.subproj/CFOverflow.h: static _Bool __os_warn_unused(_Bool x) __attribute__((__warn_unused_result__));
./CoreFoundation/Base.subproj/CFOverflow.h: static _Bool __os_warn_unused(_Bool x) { return x; }
./Darwin/shims/FoundationOverlayShims.h: _Bool onStack;
./Darwin/shims/FoundationOverlayShims.h:static inline _Bool _resizeConditionalAllocationBuffer(_ConditionalAllocationBuffer *_Nonnull buffer, size_t amt) {
./Darwin/shims/FoundationOverlayShims.h:static inline _Bool _withStackOrHeapBuffer(size_t amount, void (__attribute__((noescape)) ^ _Nonnull applier)(_ConditionalAllocationBuffer *_Nonnull)) {
./CoreFoundation/PlugIn.subproj/CFBundle_Grok.c:static inline _Bool _CF_isspace(int c) {
I agree with @compnerd's approach. |
7f947ff
to
c866611
Compare
Alright, I've gone though and replaced uses of |
@swift-ci please test |
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.
Thanks!
ForFoundationOnly.h L89-102 needs adjustment. |
_Bool is not defined in C++, so Foundation fails to import with C++ interop enabled. This patch replaces the uses of `_Bool` with `bool` pulled from stdbool.h.
c866611
to
9277186
Compare
@swift-ci please test |
Yeah, the issue is that #ifdef __OBJC__
#define NSISARGTYPE id _Nullable
#else
#define NSISARGTYPE void * _Nullable
#define BOOL bool
#endif |
That seems really sketchy, why does |
I think it's for ObjC compatibility since we're also building this code without ObjC. // Arguments to these are id, but this header is non-Objc
#ifdef __OBJC__
#define NSISARGTYPE id _Nullable
#else
#define NSISARGTYPE void * _Nullable
#define BOOL _Bool
#endif |
Yeah, the |
Including <objc/objc.h> would be a lot better, I think it's ok to do that from pure C. Declaring it yourself is likely to eventually cause module problems |
The definition was in the original code, I'm just trying to allow C++ to work, so I think that's maybe for another PR? |
Yeah true, not really related to this PR. I'm not sure what provides the objc runtime on Windows and Linux. |
_Bool
is not defined when importing Foundation with C++ interop enabledresulting in the missing type. This patch defines
_Bool
tobool
whencompiling for C++.
I'm not entire sure how to test this. The test itself is fairly simple, it's just
with the invocation
swiftc -Xcc -std=c++17 -enable-experimental-cxx-interop
, but I don't know how to tell XCTest to do that so I would like pointers there.rdar://99713881