37
37
#include < objc/message.h>
38
38
#include < objc/objc.h>
39
39
#include < Foundation/Foundation.h>
40
- #include " ../Darwin/Foundation/NSError.h"
41
40
42
41
using namespace swift ;
43
42
using namespace swift ::hashable_support;
@@ -260,19 +259,6 @@ static id getEmptyNSDictionary() {
260
259
object_dispose ((id )error);
261
260
}
262
261
263
- // / Get the error bridging info from the Foundation overlay. If it can't
264
- // / be loaded, return all NULLs.
265
- static ErrorBridgingInfo getErrorBridgingInfo () {
266
- auto *info = SWIFT_LAZY_CONSTANT (
267
- reinterpret_cast <ErrorBridgingInfo *>(
268
- dlsym (RTLD_DEFAULT, ERROR_BRIDGING_SYMBOL_NAME_STRING)));
269
- if (!info) {
270
- ErrorBridgingInfo nulls = {};
271
- return nulls;
272
- }
273
- return *info;
274
- }
275
-
276
262
static const WitnessTable *getNSErrorConformanceToError () {
277
263
// CFError and NSError are toll-free-bridged, so we can use either type's
278
264
// witness table interchangeably. CFError's is potentially slightly more
@@ -281,7 +267,10 @@ static ErrorBridgingInfo getErrorBridgingInfo() {
281
267
// safe to assume that that's been linked in if a user is using NSError in
282
268
// their Swift source.
283
269
284
- auto conformance = getErrorBridgingInfo ().CFErrorErrorConformance ;
270
+ auto *conformance = SWIFT_LAZY_CONSTANT (
271
+ reinterpret_cast <const ProtocolConformanceDescriptor *>(
272
+ dlsym (RTLD_DEFAULT,
273
+ MANGLE_AS_STRING (MANGLE_SYM (So10CFErrorRefas5Error10FoundationMc)))));
285
274
assert (conformance &&
286
275
" Foundation overlay not loaded, or 'CFError : Error' conformance "
287
276
" not available" );
@@ -291,7 +280,10 @@ static ErrorBridgingInfo getErrorBridgingInfo() {
291
280
}
292
281
293
282
static const HashableWitnessTable *getNSErrorConformanceToHashable () {
294
- auto conformance = getErrorBridgingInfo ().NSObjectHashableConformance ;
283
+ auto *conformance = SWIFT_LAZY_CONSTANT (
284
+ reinterpret_cast <const ProtocolConformanceDescriptor *>(
285
+ dlsym (RTLD_DEFAULT,
286
+ MANGLE_AS_STRING (MANGLE_SYM (So8NSObjectCSH10ObjectiveCMc)))));
295
287
assert (conformance &&
296
288
" ObjectiveC overlay not loaded, or 'NSObject : Hashable' conformance "
297
289
" not available" );
@@ -427,7 +419,15 @@ id _swift_stdlib_getErrorDefaultUserInfo(OpaqueValue *error,
427
419
const WitnessTable *Error) {
428
420
// public func Foundation._getErrorDefaultUserInfo<T: Error>(_ error: T)
429
421
// -> AnyObject?
430
- auto foundationGetDefaultUserInfo = getErrorBridgingInfo ().GetErrorDefaultUserInfo ;
422
+ typedef SWIFT_CC (swift) NSDictionary *(*GetErrorDefaultUserInfoFunction)(
423
+ const OpaqueValue *error,
424
+ const Metadata *T,
425
+ const WitnessTable *Error);
426
+ auto foundationGetDefaultUserInfo = SWIFT_LAZY_CONSTANT (
427
+ reinterpret_cast <GetErrorDefaultUserInfoFunction>(
428
+ dlsym (RTLD_DEFAULT,
429
+ MANGLE_AS_STRING (MANGLE_SYM (10Foundation24_getErrorDefaultUserInfoyyXlSgxs0C0RzlF)))));
430
+
431
431
if (!foundationGetDefaultUserInfo) {
432
432
return nullptr ;
433
433
}
@@ -533,9 +533,19 @@ ProtocolDescriptorRef theErrorProtocol(&PROTOCOL_DESCR_SYM(s5Error),
533
533
// public func Foundation._bridgeNSErrorToError<
534
534
// T : _ObjectiveCBridgeableError
535
535
// >(error: NSError, out: UnsafeMutablePointer<T>) -> Bool {
536
- auto bridgeNSErrorToError = getErrorBridgingInfo ().BridgeErrorToNSError ;
536
+ typedef SWIFT_CC (swift) bool (*BridgeErrorToNSErrorFunction)(
537
+ NSError *, OpaqueValue*, const Metadata *,
538
+ const WitnessTable *);
539
+ auto bridgeNSErrorToError = SWIFT_LAZY_CONSTANT (
540
+ reinterpret_cast <BridgeErrorToNSErrorFunction>(
541
+ dlsym (RTLD_DEFAULT,
542
+ MANGLE_AS_STRING (MANGLE_SYM (10Foundation21_bridgeNSErrorToError_3outSbSo0C0C_SpyxGtAA021_ObjectiveCBridgeableE0RzlF)))));
543
+
537
544
// protocol _ObjectiveCBridgeableError
538
- auto TheObjectiveCBridgeableError = getErrorBridgingInfo ().ObjectiveCBridgeableError ;
545
+ auto TheObjectiveCBridgeableError = SWIFT_LAZY_CONSTANT (
546
+ reinterpret_cast <ProtocolDescriptor *>(
547
+ dlsym (RTLD_DEFAULT,
548
+ MANGLE_AS_STRING (MANGLE_SYM (10Foundation26_ObjectiveCBridgeableErrorMp)))));
539
549
540
550
// If the Foundation overlay isn't loaded, then arbitrary NSErrors can't be
541
551
// bridged.
0 commit comments