Skip to content

Commit 388c21a

Browse files
authored
Merge pull request #24000 from Catfish-Man/thread-specific-doh
2 parents b6ca2fb + 584fbfc commit 388c21a

File tree

3 files changed

+33
-14
lines changed

3 files changed

+33
-14
lines changed

stdlib/public/SwiftShims/CoreFoundationShims.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ _swift_shims_CFIndex _swift_stdlib_CFStringGetLength(
8080
SWIFT_RUNTIME_STDLIB_API
8181
__attribute__((ns_returns_retained))
8282
_swift_shims_CFStringRef _Nonnull _swift_stdlib_CFStringCreateWithSubstring(
83-
_swift_shims_CFAllocatorRef _Nullable alloc,
83+
const void * _Nullable unused,
8484
_swift_shims_CFStringRef _Nonnull str, _swift_shims_CFRange range);
8585

8686
SWIFT_RUNTIME_STDLIB_API
@@ -90,13 +90,13 @@ _swift_shims_UniChar _swift_stdlib_CFStringGetCharacterAtIndex(
9090
SWIFT_RUNTIME_STDLIB_API
9191
__attribute__((ns_returns_retained))
9292
_swift_shims_CFStringRef _Nonnull _swift_stdlib_CFStringCreateCopy(
93-
_swift_shims_CFAllocatorRef _Nullable alloc,
93+
const void * _Nullable unused,
9494
_swift_shims_CFStringRef _Nonnull theString);
9595

9696
SWIFT_RUNTIME_STDLIB_API
9797
__attribute__((ns_returns_retained))
9898
_swift_shims_CFStringRef _Nonnull _swift_stdlib_CFStringCreateWithBytes(
99-
_swift_shims_CFAllocatorRef _Nullable alloc,
99+
const void * _Nullable unused,
100100
const __swift_uint8_t *_Nonnull bytes, _swift_shims_CFIndex numBytes,
101101
_swift_shims_CFStringEncoding encoding,
102102
_swift_shims_Boolean isExternalRepresentation);

stdlib/public/core/StringBridge.swift

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -266,18 +266,32 @@ extension String {
266266
}
267267
}
268268

269+
@_effects(releasenone)
270+
private func _createCFString(
271+
_ ptr: UnsafePointer<UInt8>,
272+
_ count: Int,
273+
_ encoding: UInt32
274+
) -> AnyObject {
275+
return _swift_stdlib_CFStringCreateWithBytes(
276+
nil, //ignored in the shim for perf reasons
277+
ptr,
278+
count,
279+
kCFStringEncodingUTF8,
280+
0
281+
) as AnyObject
282+
}
283+
269284
extension String {
270285
@_effects(releasenone)
271286
public // SPI(Foundation)
272287
func _bridgeToObjectiveCImpl() -> AnyObject {
273288
if _guts.isSmall {
274289
return _guts.asSmall.withUTF8 { bufPtr in
275-
// TODO(String bridging): worth isASCII check for different encoding?
276-
return _swift_stdlib_CFStringCreateWithBytes(
277-
nil, bufPtr.baseAddress._unsafelyUnwrappedUnchecked,
290+
return _createCFString(
291+
bufPtr.baseAddress._unsafelyUnwrappedUnchecked,
278292
bufPtr.count,
279-
kCFStringEncodingUTF8, 0)
280-
as AnyObject
293+
kCFStringEncodingUTF8
294+
)
281295
}
282296
}
283297
if _guts._object.isImmortal {

stdlib/public/stubs/FoundationHelpers.mm

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,13 @@ static CFRange cast(_swift_shims_CFRange value) {
7777

7878
_swift_shims_CFStringRef
7979
swift::_swift_stdlib_CFStringCreateWithSubstring(
80-
_swift_shims_CFAllocatorRef alloc,
80+
const void *unused,
8181
_swift_shims_CFStringRef str,
8282
_swift_shims_CFRange range) {
83-
return cast(CFStringCreateWithSubstring(cast(alloc), cast(str), cast(range)));
83+
assert(unused == NULL);
84+
return cast(CFStringCreateWithSubstring(kCFAllocatorSystemDefault,
85+
cast(str),
86+
cast(range)));
8487
}
8588

8689
_swift_shims_CFComparisonResult
@@ -108,17 +111,19 @@ static CFRange cast(_swift_shims_CFRange value) {
108111
}
109112

110113
_swift_shims_CFStringRef
111-
swift::_swift_stdlib_CFStringCreateCopy(_swift_shims_CFAllocatorRef alloc,
114+
swift::_swift_stdlib_CFStringCreateCopy(const void *unused,
112115
_swift_shims_CFStringRef theString) {
113-
return cast(CFStringCreateCopy(cast(alloc), cast(theString)));
116+
assert(unused == NULL);
117+
return cast(CFStringCreateCopy(kCFAllocatorSystemDefault, cast(theString)));
114118
}
115119

116120
_swift_shims_CFStringRef
117121
swift::_swift_stdlib_CFStringCreateWithBytes(
118-
_swift_shims_CFAllocatorRef _Nullable alloc, const uint8_t *bytes,
122+
const void *unused, const uint8_t *bytes,
119123
_swift_shims_CFIndex numBytes, _swift_shims_CFStringEncoding encoding,
120124
_swift_shims_Boolean isExternalRepresentation) {
121-
return cast(CFStringCreateWithBytes(cast(alloc), bytes, numBytes,
125+
assert(unused == NULL);
126+
return cast(CFStringCreateWithBytes(kCFAllocatorSystemDefault, bytes, numBytes,
122127
cast(encoding),
123128
isExternalRepresentation));
124129
}

0 commit comments

Comments
 (0)