-
Notifications
You must be signed in to change notification settings - Fork 471
Create a DISPATCH_PTR_SIZE macro and use it #244
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
Conversation
CC: @MadCoder |
CC: @das |
dispatch/base.h
Outdated
#elif defined(_MSC_VER) | ||
#error "could not determine pointer size as a constant int for MSVC" | ||
#else | ||
#define DISPATCH_PTR_SIZE sizeof(void *) |
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.
you can't do that, it prevents doing comparisons with the preprocessor which is the whole point.
do
#elif defined(__LP64__) || defined(__LLP64__)
#define ... 8
#elif defined(__ILP32__)
#define ... 4
#else
#error ...
#endif // __SIZEOF_POINTER__
src/event/event_kevent.c
Outdated
@@ -1557,7 +1557,7 @@ _dispatch_mach_notify_port_init(void *context DISPATCH_UNUSED) | |||
kern_return_t kr; | |||
#if HAVE_MACH_PORT_CONSTRUCT | |||
mach_port_options_t opts = { .flags = MPO_CONTEXT_AS_GUARD | MPO_STRICT }; | |||
#ifdef __LP64__ | |||
#if DISPATCH_PTR_SIZE == 8 |
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.
that doesn't work with sizeof(void*)
typically
dispatch/base.h
Outdated
@@ -254,4 +254,16 @@ | |||
|
|||
typedef void (*dispatch_function_t)(void *_Nullable); | |||
|
|||
#ifdef __SIZEOF_POINTER__ | |||
#define DISPATCH_PTR_SIZE __SIZEOF_POINTER__ |
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.
DISPATCH_SIZEOF_PTR
or SIZEOF_POINTER or a variant thereof is a better name.
Applied both of the suggestions. |
dispatch/base.h
Outdated
@@ -254,4 +254,20 @@ | |||
|
|||
typedef void (*dispatch_function_t)(void *_Nullable); | |||
|
|||
#ifdef __SIZEOF_POINTER__ |
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 didn't realize this was in base.h, sorry this is internal stuff and should be in "src/shims/hw_config.h"
for the test that uses it today, just use __SIZEOF_POINTER__
it's less of an issue for tests.
This introduces a new macro, `DISPATCH_PTR_SIZE` which is defined much like `LLVM_PTR_SIZE`. We can gracefully fallback to alternate means of checking the width of the pointer and use this rather than `__LP64__` to determine if we are on a 64-bit host.
Moved the definitions to |
@@ -50,7 +50,7 @@ main(void) | |||
{ | |||
dispatch_test_start("Dispatch Queue Finalizer"); | |||
|
|||
#ifdef __LP64__ | |||
#if DISPATCH_SIZEOF_PTR == 8 |
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.
that will not build will it?
@swift-ci please test |
1 similar comment
@swift-ci please test |
At least on Linux, with CMake, all tests build and pass for me. |
Create a DISPATCH_PTR_SIZE macro and use it Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
This introduces a new macro,
DISPATCH_PTR_SIZE
which is defined muchlike
LLVM_PTR_SIZE
. We can gracefully fallback to alternate means ofchecking the width of the pointer and use this rather than
__LP64__
todetermine if we are on a 64-bit host.