-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[SR-953] Implement Bundle(for: class) #1573
Conversation
This requires new specific tests before merging. |
Please test with the following: @swift-ci please test |
Foundation/Bundle.swift
Outdated
|
||
// dladdr() on Linux is documented to return argv[0] | ||
// If this is argv[0], do not create a new bundle (which will use the main bundle below). | ||
let pathNS = unsafeBitCast(path, to: NSString.self) |
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 don't need this intermediate anymore.
Foundation/Bundle.swift
Outdated
|
||
let url = unsafeBitCast(NSURL(fileURLWithPath: pathString), to: CFURL.self) | ||
if let bundleURL = _CFBundleCopyBundleURLForExecutableURL(url) { | ||
_bundle = CFBundleCreate(kCFAllocatorSystemDefault, bundleURL.takeRetainedValue()) |
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 should probably .takeRetainedValue above.
Foundation/Bundle.swift
Outdated
// If this is argv[0], do not create a new bundle (which will use the main bundle below). | ||
let pathNS = unsafeBitCast(path, to: NSString.self) | ||
let pathString = pathNS as String | ||
if ProcessInfo.processInfo.arguments.first != pathString { |
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.
Maybe Bundle.main.executablePath
would be clearer?
Looks good, and from a quick eyeballing it seems like it should work on Android too 👍 |
Please test with the following: @swift-ci please test |
1 similar comment
Please test with the following: @swift-ci please test |
@@ -54,7 +54,26 @@ open class Bundle: NSObject { | |||
} | |||
|
|||
public init(for aClass: AnyClass) { | |||
NSUnimplemented() | |||
let pointer = unsafeBitCast(aClass, to: UnsafeRawPointer.self) |
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.
Just wondering, why are we using unsafeBitCast here and not an inout?
var theClass = aClass
if let path = _CFBundleBlah(&theClass) {...}
My understanding is they do the same thing but the latter is more resilient to changes in ABI
@swift-ci please test |
1 similar comment
@swift-ci please test |
And I didn’t see the merge conflict marker. Whoops. |
The Swift project moved the default branch to More detail about the branch update - https://forums.swift.org/t/updating-branch-names/40412 |
Implements Bundle(for:) by using
dladdr()
on the type descriptor of a class. For further discussion, see swiftlang/swift#16964, which is a dependency of this patch.Resolves SR-953.