8000 [1.x] Fix unrecognized selector crash on static linking by ikesyo · Pull Request #803 · Quick/Quick · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[1.x] Fix unrecognized selector crash on static linking #803

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 5 commits into from
Jun 22, 2018

Conversation

ikesyo
Copy link
Member
@ikesyo ikesyo commented Jun 21, 2018

Extension methods or properties for NSObject subclasses are somehow invisible from the Objective-C runtime on static linking, so let's make a wrapper class.

Extension methods or properties for NSObject subclasses are invisible from the Objective-C runtime on static linking unless the consumers add -ObjC linker flag, so let's make a wrapper class to mitigate that situation.

Fixes #785.

@ikesyo
Copy link
Member Author
ikesyo commented Jun 21, 2018

@zcsipler Could you try this branch?

@QuickBot
Copy link
QuickBot commented Jun 21, 2018
1 Warning
⚠️ Need to add an unit test if you’re modifying swift source

Generated by 🚫 danger

@ikesyo ikesyo force-pushed the fix-static-linking-crash branch from b2713f8 to ed9d1ca Compare June 21, 2018 05:20
@ikesyo ikesyo changed the title [1.x] Fix unrecognized selector crash on static linking [WIP][1.x] Fix unrecognized selector crash on static linking Jun 21, 2018
Extension methods or properties for NSObject subclasses are somehow invisible from the Objective-C runtime on static linking, so let's make a wrapper class.
@ikesyo ikesyo force-pushed the fix-static-linking-crash branch from ed9d1ca to 8af4712 Compare June 21, 2018 09:19
@ikesyo ikesyo changed the title [WIP][1.x] Fix unrecognized selector crash on static linking [1.x] Fix unrecognized selector crash on static linking Jun 21, 2018
@ikesyo ikesyo requested a review from a team June 21, 2018 09:56
Copy link
Contributor
@sharplet sharplet left a comment

Choose a reason for hiding this comment

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

Could we fix this by using the -ObjC linker flag? https://stackoverflow.com/questions/6629979/what-does-the-objc-linker-flag-do

@ikesyo
Copy link
Member Author
ikesyo commented Jun 21, 2018

Oh I completely forgot the linker flag! 💦 Thanks for the tip! Indeed, adding the flag to test targets which use Quick (e.g. Quick - macOSTests, QuickFocused - macOSTests, and so on), not to Quick itself, fixes the issue.

However, forcing consumers to add the flag to their test targets just for this internal implementation detail will/may not be ideal I think. What do you think? Is that an acceptable cost to use static linking?

Copy link
Contributor
@sharplet sharplet left a comment

Choose a reason for hiding this comment

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

However, forcing consumers to add the flag to their test targets just for this internal implementation detail will/may not be ideal I think. What do you think? Is that an acceptable cost to use static linking?

I don't mind hosting the method under a name we control, but I think it still makes sense to preserve the existing API. Left a couple of suggestions, lemme know what you think!

@@ -22,12 +21,25 @@ public extension NSString {
return invalidCharacters
}()

@objc(qck_c99ExtendedIdentifier)
Copy link
Contributor

Choose a reason for hiding this comment

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

Because there's a workaround, I think we should preserve this public API.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm okay to preserve this for 1.x but I'd like to hide this in 2.x, because I assume the reason why this API is public is to expose it to the generated header. We can now expose internal Swift APIs to the generated header thanks to #791, so there will be no need to make it public.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can we explicitly deprecate it?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried adding @available(*, deprecated) but __attribute__ ((deprecated)) is not exposed to the generated header unfortunately.

/// from the Objective-C runtime on static linking, so let's make a wrapper class.
///
/// See: https://github.com/Quick/Quick/issues/785
@objc
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be a good idea to prefix this new class?

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree, QCK prefix should be added.

var c99ExtendedIdentifier: String {
let validComponents = components(separatedBy: NSString.invalidCharacters)
let result = validComponents.joined(separator: "_")

return result.isEmpty ? "_" : result
}
}

/// Extension methods or properties for NSObject subclasses are somehow invisible
/// from the Objective-C runtime on static linking, so let's make a wrapper class.
Copy link
Contributor

Choose a reason for hiding this comment

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

Because we know that -ObjC will expose these to the runtime, this comment might need an update.

@ikesyo
Copy link
Member Author
ikesyo commented Jun 22, 2018

@sharplet Thanks for the detailed review! 💖 I updated the pull request.

@ikesyo ikesyo requested a review from sharplet June 22, 2018 05:37
Copy link
Contributor
@sharplet sharplet left a comment

Choose a reason for hiding this comment

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

Looking good 👍

Is there somewhere in the documentation that we could add a tip about the -ObjC linker flag?

@ikesyo
Copy link
Member Author
ikesyo commented Jun 22, 2018

Thanks!

Is there somewhere in the documentation that we could add a tip about the -ObjC linker flag?

I will try to update InstallingQuick.md in a separate pr. Let's metge this as is.

@ikesyo ikesyo merged commit edfaa98 into 1.x-branch Jun 22, 2018
@ikesyo ikesyo deleted the fix-static-linking-crash branch June 22, 2018 16:03
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
0