Skip to content

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

Merged
merged 1 commit into from
May 7, 2017

Conversation

compnerd
Copy link
Member

@compnerd compnerd commented May 3, 2017

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.

@compnerd
Copy link
Member Author

compnerd commented May 3, 2017

CC: @MadCoder

@compnerd
Copy link
Member Author

compnerd commented May 4, 2017

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 *)
Copy link
Contributor

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__

@@ -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
Copy link
Contributor

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__
Copy link
Contributor

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.

@compnerd
Copy link
Member Author

compnerd commented May 5, 2017

Applied both of the suggestions.

dispatch/base.h Outdated
@@ -254,4 +254,20 @@

typedef void (*dispatch_function_t)(void *_Nullable);

#ifdef __SIZEOF_POINTER__
Copy link
Contributor

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.
@compnerd
Copy link
Member Author

compnerd commented May 7, 2017

Moved the definitions to hw_config.h.

@@ -50,7 +50,7 @@ main(void)
{
dispatch_test_start("Dispatch Queue Finalizer");

#ifdef __LP64__
#if DISPATCH_SIZEOF_PTR == 8
Copy link
Contributor

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?

@MadCoder
Copy link
Contributor

MadCoder commented May 7, 2017

@swift-ci please test

1 similar comment
@MadCoder
Copy link
Contributor

MadCoder commented May 7, 2017

@swift-ci please test

@compnerd
Copy link
Member Author

compnerd commented May 7, 2017

At least on Linux, with CMake, all tests build and pass for me.

@MadCoder MadCoder merged commit 3828fbb into swiftlang:master May 7, 2017
das pushed a commit that referenced this pull request May 25, 2017
Create a DISPATCH_PTR_SIZE macro and use it

Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
@compnerd compnerd deleted the ptrsize branch June 21, 2017 22:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants