File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -56,8 +56,11 @@ typedef BOOL (*objc_hook_getImageName)(
56
56
// / Get the image name corresponding to a Swift class, accounting for
57
57
// / dynamically-initialized class metadata. Returns NO for ObjC classes.
58
58
static BOOL
59
- getImageNameFromSwiftClass (Class _Nonnull objcClass,
59
+ getImageNameFromSwiftClass (Class _Nullable objcClass,
60
60
const char * _Nullable * _Nonnull outImageName) {
61
+ if (objcClass == Nil )
62
+ return NO ;
63
+
61
64
auto *classAsMetadata = reinterpret_cast <const ClassMetadata *>(objcClass);
62
65
63
66
// Is this a Swift class?
Original file line number Diff line number Diff line change
1
+ // RUN: %target-run-simple-swift
2
+ // REQUIRES: executable_test
3
+ // REQUIRES: objc_interop
4
+
5
+ import Foundation
6
+ import StdlibUnittest
7
+
8
+ var BundleTests = TestSuite ( " BundleTests " )
9
+
10
+ BundleTests . test ( " Bundle.bundleForNilClass " ) {
11
+ // Ensure that bundleForClass: tolerates a nil parameter. The
12
+ // Foundation implementation does. The patched version from
13
+ // ObjCRuntimeGetImageNameFromClass did not.
14
+ //
15
+ // SR-9188
16
+ typealias BundleForClassFunc =
17
+ @convention ( c) ( AnyObject , Selector , AnyObject ? ) -> Bundle
18
+
19
+ let sel = #selector( Bundle . init ( for: ) )
20
+ let imp = unsafeBitCast ( Bundle . method ( for: sel) , to: BundleForClassFunc . self)
21
+ let bundleForNil = imp ( Bundle . self, sel, nil ) ;
22
+ expectEqual ( Bundle . main, bundleForNil)
23
+ }
24
+
25
+ runAllTests ( )
You can’t perform that action at this time.
0 commit comments