Skip to content

Commit a4c20e0

Browse files
Add borrowing _withUnprotectedUnsafePointer (#76446)
* Add non-inout `_withUnprotectedUnsafePointer` For withUnsafePointer we have both an inout and a borrowing form, allowing it to be used with immutable values. Add a parallel form for the unprotected variant. * Update LifetimeManager.swift
1 parent 0a304e1 commit a4c20e0

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

stdlib/public/core/LifetimeManager.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,20 @@ public func _withUnprotectedUnsafePointer<
239239
#endif
240240
}
241241

242+
/// Invokes the given closure with a pointer to the given argument.
243+
///
244+
/// This function is similar to `withUnsafePointer`, except that it
245+
/// doesn't trigger stack protection for the pointer.
246+
@_alwaysEmitIntoClient
247+
public func _withUnprotectedUnsafePointer<
248+
T: ~Copyable, E: Error, Result: ~Copyable
249+
>(
250+
to value: borrowing T,
251+
_ body: (UnsafePointer<T>) throws(E) -> Result
252+
) throws(E) -> Result {
253+
return try body(UnsafePointer<T>(Builtin.unprotectedAddressOfBorrow(value)))
254+
}
255+
242256
extension String {
243257
/// Calls the given closure with a pointer to the contents of the string,
244258
/// represented as a null-terminated sequence of UTF-8 code units.

0 commit comments

Comments
 (0)