Skip to content

Fixed _CFThreadSetName line for Android #1309

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
Nov 29, 2017

Conversation

amraboelela
Copy link
Contributor

No description provided.

@alblue
Copy link
Contributor

alblue commented Nov 10, 2017

Does Android only allow the current thread's native name to be changed?

@spevans
Copy link
Contributor

spevans commented Nov 10, 2017

If might be better to modify _CFThreadSetName as that already checks the thread is pthread_self() on Darwin platforms, so adding Android in there will keep the checks in one place.

@alblue alblue self-requested a review November 22, 2017 11:49
Copy link
Contributor

@alblue alblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @spevans suggested, can you move this down into the _CFThreadSetName code instead?

@amraboelela
Copy link
Contributor Author

amraboelela commented Nov 22, 2017

The error happens in this line if let thread = _thread {
Do you want to change _CFThreadSetName(thread, name ?? "" )
to make the thread parameter optional? so we won't need to unwrap it here?

But this function is a c function!

*CF_SWIFT_EXPORT int _CFThreadSetName(pthread_t thread, const char _Nonnull name) {

@alblue
Copy link
Contributor

alblue commented Nov 22, 2017

Leave the Swift code as is, do the fix in the c function instead was @spevans suggestion, I believe.

@amraboelela
Copy link
Contributor Author

any suggestion of how to fix the c code?

@spevans
Copy link
Contributor

spevans commented Nov 22, 2017

@amraboelela I mis-read your original patch and thought the thread name could only be set for the current thread hence my suggestion of fixing _CFThreadSetName.

However on re-reading it I think the issue might be because on android the _thread is not an optional it is defined as:

#if os(Android)
    private var _thread = pthread_t()
#else
    private var _thread: pthread_t? = nil
#endif

I wonder if the special case for Android could be removed so it just uses the pthread_t? that other platforms use? That may be sufficient to fix it.

@amraboelela
Copy link
Contributor Author

But there must be a reason why they did this code:

#if os(Android)
    private var _thread = pthread_t()
#else
    private var _thread: pthread_t? = nil
#endif

@spevans
Copy link
Contributor

spevans commented Nov 22, 2017

I don't think its correct. It used to be like that for Linux as well however _thread = pthread_t() sets _thread to a pthread_t with value 0 which is a valid ID that should not be used for an uninitialised thread ID. I changed it for Linux but not for Android as I could not test it for Android. So I would just try changing it and seeing if the tests still work.

@amraboelela
Copy link
Contributor Author

Ok let me check it later

@amraboelela
Copy link
Contributor Author

@spevans I made the update and was able to build it successfully for Android

@spevans
Copy link
Contributor

spevans commented Nov 28, 2017

@swift-ci please test

@alblue
Copy link
Contributor

alblue commented Nov 28, 2017

Can we squash these two commits please?

@amraboelela amraboelela force-pushed the android_thread branch 3 times, most recently from 2e671a0 to a2f0625 Compare November 28, 2017 18:10
@amraboelela
Copy link
Contributor Author

Done

@alblue
Copy link
Contributor

alblue commented Nov 29, 2017

@swift-ci please test and merge

@swift-ci swift-ci merged commit 427cb49 into swiftlang:master Nov 29, 2017
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.

4 participants