Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions stdlib/private/SwiftPrivateLibcExtras/SwiftPrivateLibcExtras.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ public func _stdlib_mkstemps(_ template: inout String, _ suffixlen: CInt) -> CIn
var utf8 = template.nulTerminatedUTF8
let (fd, fileName) = utf8.withUnsafeMutableBufferPointer {
(utf8) -> (CInt, String) in
let fd = mkstemps(UnsafeMutablePointer(utf8.baseAddress!), suffixlen)
let fileName = String(cString: utf8.baseAddress!)
return (fd, fileName)
return utf8.baseAddress!.withMemoryRebound(
to: CChar.self, capacity: Int(suffixlen)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind putting the ") {" on a separate line? Then you won't need a blank line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you can use String.nulTerminatedUTF8CString, and then you won't need to rebind.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3816 was merged, and the property nulTerminatedUTF8 is gone. Please switch to utf8CString and I think you won't need to rebind the memory then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already reworked in #3816. I'll go through and annotate other such instances here. (Sorry if I'm stepping on toes; ignore if this isn't helpful.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's why I wanted your PR merged first. Unfortunately I didn't have permission to do it so had to post this older patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this rebind is gone now.
Incidentally, I much prefer your suggested style, but I can never keep track of what we're supposed to do. Is there a style guideline for stdlib code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we don't have a written document.

This would be the most complex case of wrapping the declaration:

func foo<
  T,
  U : Hashable  // Either put all type parameters on one line, on do one per line.
>( // Closing delimiters are put on a new line.
  arg1 x: T,
  arg2 y: U // Same, either everything fits on one line, or each gets its own line.
) -> Int
  where T.Z == U
{
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Those are good simple rules. I think that would suffice in a document or a Readme.md


let fd = mkstemps($0, suffixlen)
let fileName = String(cString: $0)
return (fd, fileName)
}
}
template = fileName
return fd
Expand Down Expand Up @@ -97,11 +101,13 @@ public func _stdlib_select(
let readAddr = readfds.baseAddress
let writeAddr = writefds.baseAddress
let errorAddr = errorfds.baseAddress
let bindAsFdSet = { (p: UnsafeMutablePointer<UInt>?) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to deserve a real function. You can define it right here if you want, y’know.

UnsafeMutableRawPointer(p)?.assumingMemoryBound(to: fd_set.self) }
return select(
_stdlib_FD_SETSIZE,
UnsafeMutablePointer(readAddr),
UnsafeMutablePointer(writeAddr),
UnsafeMutablePointer(errorAddr),
bindAsFdSet(readAddr),
bindAsFdSet(writeAddr),
bindAsFdSet(errorAddr),
timeout)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public class _stdlib_Barrier {
var _pthreadBarrier: _stdlib_pthread_barrier_t

var _pthreadBarrierPtr: UnsafeMutablePointer<_stdlib_pthread_barrier_t> {
return UnsafeMutablePointer(_getUnsafePointerToStoredProperties(self))
return _getUnsafePointerToStoredProperties(self).assumingMemoryBound(to: _stdlib_pthread_barrier_t.self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

80 columns (please break before the dot).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Must've thought I was in an overlay.
My emacs always does this:
return _getXXX()
.assumingMem(...)

but I think you want me to indent the second line which continues the statement.

}

public init(threadCount: Int) {
Expand Down
9 changes: 5 additions & 4 deletions stdlib/public/SDK/Dispatch/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,12 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
///
/// - parameter buffer: The buffer of bytes to append. The size is calculated from `SourceType` and `buffer.count`.
public mutating func append<SourceType>(_ buffer : UnsafeBufferPointer<SourceType>) {
self.append(UnsafePointer(buffer.baseAddress!), count: buffer.count * sizeof(SourceType.self))
buffer.baseAddress!.withMemoryRebound(to: UInt8.self, capacity: buffer.count * sizeof(SourceType.self)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dispatch uses tabs for indentation 😕, let's be consistent with the style choice made in this file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, believe me I'm trying to be consistent. But I guess that means actively inserting tab characters in places.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes :(

self.append($0, count: buffer.count * sizeof(SourceType.self))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be strideof? I see that the old code used sizeof, but it looks like a bug to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sizeof was a bug. I'll fix it.

}
}

private func _copyBytesHelper(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<Index>) {
private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: CountableRange<Index>) {
var copiedCount = 0
__dispatch_data_apply(__wrapped) { (data: __DispatchData, offset: Int, ptr: UnsafeRawPointer, size: Int) in
let limit = Swift.min((range.endIndex - range.startIndex) - copiedCount, size)
Expand Down Expand Up @@ -172,8 +174,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {

guard !copyRange.isEmpty else { return 0 }

let pointer : UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(buffer.baseAddress!)
_copyBytesHelper(to: pointer, from: copyRange)
_copyBytesHelper(to: buffer.baseAddress!, from: copyRange)
return copyRange.count
}

Expand Down
5 changes: 2 additions & 3 deletions stdlib/public/SDK/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
_mapUnmanaged { $0.getBytes(pointer, length: count) }
}

private func _copyBytesHelper(to pointer: UnsafeMutablePointer<UInt8>, from range: NSRange) {
private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: NSRange) {
_mapUnmanaged { $0.getBytes(pointer, range: range) }
}

Expand Down Expand Up @@ -357,8 +357,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
guard !copyRange.isEmpty else { return 0 }

let nsRange = NSMakeRange(copyRange.lowerBound, copyRange.upperBound - copyRange.lowerBound)
let pointer : UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(buffer.baseAddress!)
_copyBytesHelper(to: pointer, from: nsRange)
_copyBytesHelper(to: buffer.baseAddress!, from: nsRange)
return copyRange.count
}

Expand Down
16 changes: 7 additions & 9 deletions stdlib/public/SDK/Foundation/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -387,12 +387,10 @@ extension String {
outputArray in
// FIXME: completePath(...) is incorrectly annotated as requiring
// non-optional output parameters. rdar://problem/25494184
let outputNonOptionalName = AutoreleasingUnsafeMutablePointer<NSString?>(
UnsafeMutablePointer<NSString>(outputName)
)
let outputNonOptionalArray = AutoreleasingUnsafeMutablePointer<NSArray?>(
UnsafeMutablePointer<NSArray>(outputArray)
)
let outputNonOptionalName = unsafeBitCast(outputName,
to: AutoreleasingUnsafeMutablePointer<NSString?>.self)
let outputNonOptionalArray = unsafeBitCast(outputArray,
to: AutoreleasingUnsafeMutablePointer<NSArray?>.self)
return self._ns.completePath(
into: outputNonOptionalName,
caseSensitive: caseSensitive,
Expand Down Expand Up @@ -505,7 +503,7 @@ extension String {
var stop_ = false
body(line: line, stop: &stop_)
if stop_ {
UnsafeMutablePointer<ObjCBool>(stop).pointee = true
stop.pointee = true
}
}
}
Expand Down Expand Up @@ -541,7 +539,7 @@ extension String {
var stop_ = false
body($0, self._range($1), self._range($2), &stop_)
if stop_ {
UnsafeMutablePointer($3).pointee = true
($3).pointee = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extra parens?

}
}
}
Expand Down Expand Up @@ -823,7 +821,7 @@ extension String {
freeWhenDone flag: Bool
) {
self = NSString(
charactersNoCopy: UnsafeMutablePointer(utf16CodeUnitsNoCopy),
charactersNoCopy: UnsafeMutablePointer(mutating: utf16CodeUnitsNoCopy),
length: count,
freeWhenDone: flag) as String
}
Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/SDK/SceneKit/SceneKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,10 @@ extension SCNGeometryElement {
case .polygon:
fatalError("Expected constant number of indices per primitive")
}
// FIXME: Data should have an initializer for raw pointers.
let bytePtr = unsafeBitCast(UnsafeRawPointer(indices), to: UnsafePointer<UInt8>.self)
self.init(
data: Data(bytes: UnsafePointer<UInt8>(indices), count: indexCount * sizeof(IndexType.self)),
data: Data(bytes: bytePtr, count: indexCount * sizeof(IndexType.self)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnsafeRawPointer(indices) does not extend the lifetime, should this code call indices.withUnsafeBufferPointer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a fixLifetime later in the code. Anyway I'll back out this as soon as @parkera lands
#3832

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, we can't use withUnsafeBufferPointer because we need to call self.init, and the compiler won't let us do that from the closure.

primitiveType: primitiveType,
primitiveCount: primitiveCount,
bytesPerIndex: sizeof(IndexType.self))
Expand Down
10 changes: 7 additions & 3 deletions stdlib/public/core/ArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ extension _ArrayBuffer {
location: bounds.lowerBound,
length: bounds.upperBound - bounds.lowerBound)

let buffer = UnsafeMutablePointer<AnyObject>(target)
let buffer = UnsafeMutableRawPointer(target).assumingMemoryBound(
to: AnyObject.self)

// Copies the references out of the NSArray without retaining them
nonNative.getObjects(buffer, range: nsSubRange)
Expand Down Expand Up @@ -242,9 +243,11 @@ extension _ArrayBuffer {
cocoa.contiguousStorage(Range(self.indices))

if let cocoaStorageBaseAddress = cocoaStorageBaseAddress {
let basePtr = UnsafeMutableRawPointer(cocoaStorageBaseAddress)
.assumingMemoryBound(to: Element.self)
return _SliceBuffer(
owner: nonNative,
subscriptBaseAddress: UnsafeMutablePointer(cocoaStorageBaseAddress),
subscriptBaseAddress: basePtr,
indices: bounds,
hasNativeBuffer: false)
}
Expand All @@ -255,7 +258,8 @@ extension _ArrayBuffer {

// Tell Cocoa to copy the objects into our storage
cocoa.buffer.getObjects(
UnsafeMutablePointer(result.firstElementAddress),
UnsafeMutableRawPointer(result.firstElementAddress)
.assumingMemoryBound(to: AnyObject.self),
range: _SwiftNSRange(location: bounds.lowerBound, length: boundsCount))

return _SliceBuffer(result, shiftedToStartIndex: bounds.lowerBound)
Expand Down
30 changes: 29 additions & 1 deletion stdlib/public/core/BridgeObjectiveC.swift
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
/// Retrieve the value the pointer points to.
@_transparent get {
// We can do a strong load normally.
return UnsafeMutablePointer<Pointee>(self).pointee
return unsafeBitCast(self, to: UnsafeMutablePointer<Pointee>.self).pointee
}
/// Set the value the pointer points to, copying over the previous value.
///
Expand Down Expand Up @@ -409,6 +409,9 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
/// This is inherently unsafe; UnsafeMutablePointer assumes the
/// referenced memory has +1 strong ownership semantics, whereas
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
///
/// - Warning: Accessing `pointee` as a type that is unrelated to
/// the underlying memory's bound type is undefined.
@_transparent public
init<U>(_ from: UnsafeMutablePointer<U>) {
self._rawValue = from._rawValue
Expand All @@ -421,6 +424,9 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
/// This is inherently unsafe; UnsafeMutablePointer assumes the
/// referenced memory has +1 strong ownership semantics, whereas
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
///
/// - Warning: Accessing `pointee` as a type that is unrelated to
/// the underlying memory's bound type is undefined.
@_transparent public
init?<U>(_ from: UnsafeMutablePointer<U>?) {
guard let unwrapped = from else { return nil }
Expand All @@ -431,6 +437,9 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
///
/// This is inherently unsafe because UnsafePointers do not imply
/// mutability.
///
/// - Warning: Accessing `pointee` as a type that is unrelated to
/// the underlying memory's bound type is undefined.
@_transparent
init<U>(_ from: UnsafePointer<U>) {
self._rawValue = from._rawValue
Expand All @@ -442,13 +451,32 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
///
/// This is inherently unsafe because UnsafePointers do not imply
/// mutability.
///
/// - Warning: Accessing `pointee` as a type that is unrelated to
/// the underlying memory's bound type is undefined.
@_transparent
init?<U>(_ from: UnsafePointer<U>?) {
guard let unwrapped = from else { return nil }
self.init(unwrapped)
}
}

extension UnsafeMutableRawPointer {
/// Convert from `AutoreleasingUnsafeMutablePointer`.
@_transparent
public init<T>(_ from: AutoreleasingUnsafeMutablePointer<T>) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not failable init?()?

_rawValue = from._rawValue
}
}

extension UnsafeRawPointer {
/// Convert from `AutoreleasingUnsafeMutablePointer`.
@_transparent
public init<T>(_ from: AutoreleasingUnsafeMutablePointer<T>) {
_rawValue = from._rawValue
}
}

extension AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
/// A textual representation of `self`, suitable for debugging.
public var debugDescription: String {
Expand Down
8 changes: 4 additions & 4 deletions stdlib/public/core/Builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ internal func _roundUp(_ offset: Int, toAlignment alignment: Int) -> Int {
}

@_versioned
internal func _roundUp<T, DestinationType>(
_ pointer: UnsafeMutablePointer<T>,
internal func _roundUp<DestinationType>(
_ pointer: UnsafeMutableRawPointer,
toAlignmentOf destinationType: DestinationType.Type
) -> UnsafeMutablePointer<DestinationType> {
// Note: unsafe unwrap is safe because this operation can only increase the
Expand Down Expand Up @@ -245,11 +245,11 @@ public func unsafeDowncast<T : AnyObject>(_ x: AnyObject, to: T.Type) -> T {

@inline(__always)
public func _getUnsafePointerToStoredProperties(_ x: AnyObject)
-> UnsafeMutablePointer<UInt8> {
-> UnsafeMutableRawPointer {
let storedPropertyOffset = _roundUp(
sizeof(_HeapObject.self),
toAlignment: alignof(Optional<AnyObject>.self))
return UnsafeMutablePointer<UInt8>(Builtin.bridgeToRawPointer(x)) +
return UnsafeMutableRawPointer(Builtin.bridgeToRawPointer(x)) +
storedPropertyOffset
}

Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/core/CocoaArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ internal struct _CocoaArrayWrapper : RandomAccessCollection {
}

return contiguousCount >= subRange.upperBound
? UnsafeMutablePointer<AnyObject>(enumerationState.itemsPtr!)
? UnsafeMutableRawPointer(enumerationState.itemsPtr!)
.assumingMemoryBound(to: AnyObject.self)
+ subRange.lowerBound
: nil
}
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/core/ContiguousArrayBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
) rethrows {
if _isBridgedVerbatimToObjectiveC(Element.self) {
let count = __manager.header.count
let elements = UnsafePointer<AnyObject>(__manager._elementPointer)
let elements = UnsafeMutableRawPointer(__manager._elementPointer)
.assumingMemoryBound(to: AnyObject.self)
defer { _fixLifetime(__manager) }
try body(UnsafeBufferPointer(start: elements, count: count))
}
Expand Down
5 changes: 2 additions & 3 deletions stdlib/public/core/FloatingPointParsing.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,9 @@ extension ${Self} {
func parseNTBS(_ chars: UnsafePointer<CChar>) -> (${Self}, Int) {
var result: ${Self} = 0
let endPtr = withUnsafeMutablePointer(to: &result) {
_swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(
chars, UnsafeMutablePointer($0))
_swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(chars, $0)
}
return (result, endPtr == nil ? 0 : UnsafePointer(endPtr!) - chars)
return (result, endPtr == nil ? 0 : endPtr! - chars)
}

let (result, n) = text.withCString(parseNTBS)
Expand Down
21 changes: 13 additions & 8 deletions stdlib/public/core/HashedCollections.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,7 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> :
_UnsafeBitMap.sizeInWords(forSizeInBits: _body.capacity),
strideof(UInt.self))
let start =
UnsafeMutablePointer<UInt8>(_initializedHashtableEntriesBitMapStorage)
UnsafeMutableRawPointer(_initializedHashtableEntriesBitMapStorage)
+ bitMapSizeInBytes
return _roundUp(start, toAlignmentOf: Key.self)
}
Expand All @@ -2594,7 +2594,7 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> :
// This API is unsafe and needs a `_fixLifetime` in the caller.
internal var _values: UnsafeMutablePointer<Value> {
let keysSizeInBytes = _unsafeMultiply(_body.capacity, strideof(Key.self))
let start = UnsafeMutablePointer<UInt8>(_keys) + keysSizeInBytes
let start = UnsafeMutableRawPointer(_keys) + keysSizeInBytes
return _roundUp(start, toAlignmentOf: Value.self)
}
%end
Expand Down Expand Up @@ -3360,7 +3360,8 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
/// Returns the pointer to the stored property, which contains bridged
/// ${Self} elements.
internal var _heapBufferBridgedPtr: UnsafeMutablePointer<AnyObject?> {
return UnsafeMutablePointer(_getUnsafePointerToStoredProperties(self))
return _getUnsafePointerToStoredProperties(self).assumingMemoryBound(
to: Optional<AnyObject>.self)
}

/// The storage for bridged ${Self} elements, if present.
Expand Down Expand Up @@ -4755,12 +4756,14 @@ final internal class _Cocoa${Self}Iterator : IteratorProtocol {

internal var _fastEnumerationStatePtr:
UnsafeMutablePointer<_SwiftNSFastEnumerationState> {
return UnsafeMutablePointer(_getUnsafePointerToStoredProperties(self))
return _getUnsafePointerToStoredProperties(self).assumingMemoryBound(
to: _SwiftNSFastEnumerationState.self)
}

internal var _fastEnumerationStackBufPtr:
UnsafeMutablePointer<_CocoaFastEnumerationStackBuf> {
return UnsafeMutablePointer(_fastEnumerationStatePtr + 1)
return UnsafeMutableRawPointer(_fastEnumerationStatePtr + 1)
.assumingMemoryBound(to: _CocoaFastEnumerationStackBuf.self)
}

// These members have to be word-sized integers, they cannot be limited to
Expand Down Expand Up @@ -4789,16 +4792,18 @@ final internal class _Cocoa${Self}Iterator : IteratorProtocol {
// state struct.
itemCount = cocoa${Self}.countByEnumerating(
with: _fastEnumerationStatePtr,
objects: UnsafeMutablePointer(_fastEnumerationStackBufPtr),
objects: UnsafeMutableRawPointer(_fastEnumerationStackBufPtr)
.assumingMemoryBound(to: AnyObject.self),
count: stackBufCount)
if itemCount == 0 {
itemIndex = -1
return nil
}
itemIndex = 0
}
let itemsPtrUP: UnsafeMutablePointer<AnyObject> =
UnsafeMutablePointer(_fastEnumerationState.itemsPtr!)
let itemsPtrUP =
UnsafeMutableRawPointer(_fastEnumerationState.itemsPtr!)
.assumingMemoryBound(to: AnyObject.self)
let itemsPtr = _UnmanagedAnyObjectArray(itemsPtrUP)
let key: AnyObject = itemsPtr[itemIndex]
itemIndex += 1
Expand Down
11 changes: 6 additions & 5 deletions stdlib/public/core/HeapBuffer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,20 @@ struct _HeapBuffer<Value, Element> : Equatable {
: (heapAlign < elementAlign ? elementAlign : heapAlign))
}

internal var _address: UnsafeMutablePointer<Int8> {
return UnsafeMutablePointer(
internal var _address: UnsafeMutableRawPointer {
return UnsafeMutableRawPointer(
Builtin.bridgeToRawPointer(self._nativeObject))
}

internal var _value: UnsafeMutablePointer<Value> {
return UnsafeMutablePointer(
_HeapBuffer._valueOffset() + _address)
return (_HeapBuffer._valueOffset() + _address).assumingMemoryBound(
to: Value.self)
}

public // @testable
var baseAddress: UnsafeMutablePointer<Element> {
return UnsafeMutablePointer(_HeapBuffer._elementOffset() + _address)
return (_HeapBuffer._elementOffset() + _address).assumingMemoryBound(
to: Element.self)
}

internal func _allocatedSize() -> Int {
Expand Down
Loading