mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Remove "illegal" UnsafePointer casts from the stdlib.
Update for SE-0107: UnsafeRawPointer This adds a "mutating" initialize to UnsafePointer to make Immutable -> Mutable conversions explicit. These are quick fixes to stdlib, overlays, and test cases that are necessary in order to remove arbitrary UnsafePointer conversions. Many cases can be expressed better up by reworking the surrounding code, but we first need a working starting point.
This commit is contained in:
@@ -97,11 +97,17 @@ public func _stdlib_select(
|
|||||||
let readAddr = readfds.baseAddress
|
let readAddr = readfds.baseAddress
|
||||||
let writeAddr = writefds.baseAddress
|
let writeAddr = writefds.baseAddress
|
||||||
let errorAddr = errorfds.baseAddress
|
let errorAddr = errorfds.baseAddress
|
||||||
|
func asFdSetPtr(
|
||||||
|
_ p: UnsafeMutablePointer<UInt>?
|
||||||
|
) -> UnsafeMutablePointer<fd_set>? {
|
||||||
|
return UnsafeMutableRawPointer(p)?
|
||||||
|
.assumingMemoryBound(to: fd_set.self)
|
||||||
|
}
|
||||||
return select(
|
return select(
|
||||||
_stdlib_FD_SETSIZE,
|
_stdlib_FD_SETSIZE,
|
||||||
UnsafeMutablePointer(readAddr),
|
asFdSetPtr(readAddr),
|
||||||
UnsafeMutablePointer(writeAddr),
|
asFdSetPtr(writeAddr),
|
||||||
UnsafeMutablePointer(errorAddr),
|
asFdSetPtr(errorAddr),
|
||||||
timeout)
|
timeout)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -113,7 +113,8 @@ public class _stdlib_Barrier {
|
|||||||
var _pthreadBarrier: _stdlib_pthread_barrier_t
|
var _pthreadBarrier: _stdlib_pthread_barrier_t
|
||||||
|
|
||||||
var _pthreadBarrierPtr: UnsafeMutablePointer<_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)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(threadCount: Int) {
|
public init(threadCount: Int) {
|
||||||
|
|||||||
@@ -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`.
|
/// - 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>) {
|
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 * strideof(SourceType.self)) {
|
||||||
|
self.append($0, count: buffer.count * sizeof(SourceType.self))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private func _copyBytesHelper(to pointer: UnsafeMutablePointer<UInt8>, from range: CountableRange<Index>) {
|
private func _copyBytesHelper(to pointer: UnsafeMutableRawPointer, from range: CountableRange<Index>) {
|
||||||
var copiedCount = 0
|
var copiedCount = 0
|
||||||
__dispatch_data_apply(__wrapped) { (data: __DispatchData, offset: Int, ptr: UnsafeRawPointer, size: Int) in
|
__dispatch_data_apply(__wrapped) { (data: __DispatchData, offset: Int, ptr: UnsafeRawPointer, size: Int) in
|
||||||
let limit = Swift.min((range.endIndex - range.startIndex) - copiedCount, size)
|
let limit = Swift.min((range.endIndex - range.startIndex) - copiedCount, size)
|
||||||
@@ -172,8 +174,7 @@ public struct DispatchData : RandomAccessCollection, _ObjectiveCBridgeable {
|
|||||||
|
|
||||||
guard !copyRange.isEmpty else { return 0 }
|
guard !copyRange.isEmpty else { return 0 }
|
||||||
|
|
||||||
let pointer : UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(buffer.baseAddress!)
|
_copyBytesHelper(to: buffer.baseAddress!, from: copyRange)
|
||||||
_copyBytesHelper(to: pointer, from: copyRange)
|
|
||||||
return copyRange.count
|
return copyRange.count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -314,7 +314,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
|
|||||||
_mapUnmanaged { $0.getBytes(pointer, length: count) }
|
_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) }
|
_mapUnmanaged { $0.getBytes(pointer, range: range) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,8 +355,7 @@ public struct Data : ReferenceConvertible, Equatable, Hashable, RandomAccessColl
|
|||||||
guard !copyRange.isEmpty else { return 0 }
|
guard !copyRange.isEmpty else { return 0 }
|
||||||
|
|
||||||
let nsRange = NSMakeRange(copyRange.lowerBound, copyRange.upperBound - copyRange.lowerBound)
|
let nsRange = NSMakeRange(copyRange.lowerBound, copyRange.upperBound - copyRange.lowerBound)
|
||||||
let pointer : UnsafeMutablePointer<UInt8> = UnsafeMutablePointer<UInt8>(buffer.baseAddress!)
|
_copyBytesHelper(to: buffer.baseAddress!, from: nsRange)
|
||||||
_copyBytesHelper(to: pointer, from: nsRange)
|
|
||||||
return copyRange.count
|
return copyRange.count
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -387,12 +387,10 @@ extension String {
|
|||||||
outputArray in
|
outputArray in
|
||||||
// FIXME: completePath(...) is incorrectly annotated as requiring
|
// FIXME: completePath(...) is incorrectly annotated as requiring
|
||||||
// non-optional output parameters. rdar://problem/25494184
|
// non-optional output parameters. rdar://problem/25494184
|
||||||
let outputNonOptionalName = AutoreleasingUnsafeMutablePointer<NSString?>(
|
let outputNonOptionalName = unsafeBitCast(
|
||||||
UnsafeMutablePointer<NSString>(outputName)
|
outputName, to: AutoreleasingUnsafeMutablePointer<NSString?>.self)
|
||||||
)
|
let outputNonOptionalArray = unsafeBitCast(
|
||||||
let outputNonOptionalArray = AutoreleasingUnsafeMutablePointer<NSArray?>(
|
outputArray, to: AutoreleasingUnsafeMutablePointer<NSArray?>.self)
|
||||||
UnsafeMutablePointer<NSArray>(outputArray)
|
|
||||||
)
|
|
||||||
return self._ns.completePath(
|
return self._ns.completePath(
|
||||||
into: outputNonOptionalName,
|
into: outputNonOptionalName,
|
||||||
caseSensitive: caseSensitive,
|
caseSensitive: caseSensitive,
|
||||||
@@ -505,7 +503,7 @@ extension String {
|
|||||||
var stop_ = false
|
var stop_ = false
|
||||||
body(line: line, stop: &stop_)
|
body(line: line, stop: &stop_)
|
||||||
if stop_ {
|
if stop_ {
|
||||||
UnsafeMutablePointer<ObjCBool>(stop).pointee = true
|
stop.pointee = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -541,7 +539,7 @@ extension String {
|
|||||||
var stop_ = false
|
var stop_ = false
|
||||||
body($0, self._range($1), self._range($2), &stop_)
|
body($0, self._range($1), self._range($2), &stop_)
|
||||||
if stop_ {
|
if stop_ {
|
||||||
UnsafeMutablePointer($3).pointee = true
|
$3.pointee = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -823,7 +821,7 @@ extension String {
|
|||||||
freeWhenDone flag: Bool
|
freeWhenDone flag: Bool
|
||||||
) {
|
) {
|
||||||
self = NSString(
|
self = NSString(
|
||||||
charactersNoCopy: UnsafeMutablePointer(utf16CodeUnitsNoCopy),
|
charactersNoCopy: UnsafeMutablePointer(mutating: utf16CodeUnitsNoCopy),
|
||||||
length: count,
|
length: count,
|
||||||
freeWhenDone: flag) as String
|
freeWhenDone: flag) as String
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -170,7 +170,7 @@ extension SCNGeometryElement {
|
|||||||
fatalError("Expected constant number of indices per primitive")
|
fatalError("Expected constant number of indices per primitive")
|
||||||
}
|
}
|
||||||
self.init(
|
self.init(
|
||||||
data: Data(bytes: UnsafePointer<UInt8>(indices), count: indexCount * sizeof(IndexType.self)),
|
data: Data(bytes: indices, count: indexCount * sizeof(IndexType.self)),
|
||||||
primitiveType: primitiveType,
|
primitiveType: primitiveType,
|
||||||
primitiveCount: primitiveCount,
|
primitiveCount: primitiveCount,
|
||||||
bytesPerIndex: sizeof(IndexType.self))
|
bytesPerIndex: sizeof(IndexType.self))
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
|
|||||||
|
|
||||||
SWIFT_RUNTIME_STDLIB_INTERFACE
|
SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||||
__swift_ssize_t
|
__swift_ssize_t
|
||||||
swift_stdlib_readLine_stdin(char * _Nullable * _Nonnull LinePtr);
|
swift_stdlib_readLine_stdin(unsigned char * _Nullable * _Nonnull LinePtr);
|
||||||
|
|
||||||
SWIFT_RUNTIME_STDLIB_INTERFACE
|
SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||||
char * _Nullable * _Nonnull
|
char * _Nullable * _Nonnull
|
||||||
|
|||||||
@@ -66,16 +66,16 @@ _swift_stdlib_unicode_compare_utf16_utf16(const __swift_uint16_t *Left,
|
|||||||
|
|
||||||
SWIFT_RUNTIME_STDLIB_INTERFACE
|
SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||||
__attribute__((__pure__)) __swift_int32_t
|
__attribute__((__pure__)) __swift_int32_t
|
||||||
_swift_stdlib_unicode_compare_utf8_utf16(const char *Left,
|
_swift_stdlib_unicode_compare_utf8_utf16(const unsigned char *Left,
|
||||||
__swift_int32_t LeftLength,
|
__swift_int32_t LeftLength,
|
||||||
const __swift_uint16_t *Right,
|
const __swift_uint16_t *Right,
|
||||||
__swift_int32_t RightLength);
|
__swift_int32_t RightLength);
|
||||||
|
|
||||||
SWIFT_RUNTIME_STDLIB_INTERFACE
|
SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||||
__attribute__((__pure__)) __swift_int32_t
|
__attribute__((__pure__)) __swift_int32_t
|
||||||
_swift_stdlib_unicode_compare_utf8_utf8(const char *Left,
|
_swift_stdlib_unicode_compare_utf8_utf8(const unsigned char *Left,
|
||||||
__swift_int32_t LeftLength,
|
__swift_int32_t LeftLength,
|
||||||
const char *Right,
|
const unsigned char *Right,
|
||||||
__swift_int32_t RightLength);
|
__swift_int32_t RightLength);
|
||||||
|
|
||||||
SWIFT_RUNTIME_STDLIB_INTERFACE
|
SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||||
@@ -84,7 +84,8 @@ _swift_stdlib_unicode_hash(const __swift_uint16_t *Str, __swift_int32_t Length);
|
|||||||
|
|
||||||
SWIFT_RUNTIME_STDLIB_INTERFACE
|
SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||||
__attribute__((__pure__)) __swift_intptr_t
|
__attribute__((__pure__)) __swift_intptr_t
|
||||||
_swift_stdlib_unicode_hash_ascii(const char *Str, __swift_int32_t Length);
|
_swift_stdlib_unicode_hash_ascii(const unsigned char *Str,
|
||||||
|
__swift_int32_t Length);
|
||||||
|
|
||||||
SWIFT_RUNTIME_STDLIB_INTERFACE
|
SWIFT_RUNTIME_STDLIB_INTERFACE
|
||||||
__swift_int32_t _swift_stdlib_unicode_strToUpper(
|
__swift_int32_t _swift_stdlib_unicode_strToUpper(
|
||||||
|
|||||||
@@ -204,7 +204,8 @@ extension _ArrayBuffer {
|
|||||||
location: bounds.lowerBound,
|
location: bounds.lowerBound,
|
||||||
length: bounds.upperBound - 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
|
// Copies the references out of the NSArray without retaining them
|
||||||
nonNative.getObjects(buffer, range: nsSubRange)
|
nonNative.getObjects(buffer, range: nsSubRange)
|
||||||
@@ -242,9 +243,11 @@ extension _ArrayBuffer {
|
|||||||
cocoa.contiguousStorage(Range(self.indices))
|
cocoa.contiguousStorage(Range(self.indices))
|
||||||
|
|
||||||
if let cocoaStorageBaseAddress = cocoaStorageBaseAddress {
|
if let cocoaStorageBaseAddress = cocoaStorageBaseAddress {
|
||||||
|
let basePtr = UnsafeMutableRawPointer(cocoaStorageBaseAddress)
|
||||||
|
.assumingMemoryBound(to: Element.self)
|
||||||
return _SliceBuffer(
|
return _SliceBuffer(
|
||||||
owner: nonNative,
|
owner: nonNative,
|
||||||
subscriptBaseAddress: UnsafeMutablePointer(cocoaStorageBaseAddress),
|
subscriptBaseAddress: basePtr,
|
||||||
indices: bounds,
|
indices: bounds,
|
||||||
hasNativeBuffer: false)
|
hasNativeBuffer: false)
|
||||||
}
|
}
|
||||||
@@ -255,7 +258,8 @@ extension _ArrayBuffer {
|
|||||||
|
|
||||||
// Tell Cocoa to copy the objects into our storage
|
// Tell Cocoa to copy the objects into our storage
|
||||||
cocoa.buffer.getObjects(
|
cocoa.buffer.getObjects(
|
||||||
UnsafeMutablePointer(result.firstElementAddress),
|
UnsafeMutableRawPointer(result.firstElementAddress)
|
||||||
|
.assumingMemoryBound(to: AnyObject.self),
|
||||||
range: _SwiftNSRange(location: bounds.lowerBound, length: boundsCount))
|
range: _SwiftNSRange(location: bounds.lowerBound, length: boundsCount))
|
||||||
|
|
||||||
return _SliceBuffer(result, shiftedToStartIndex: bounds.lowerBound)
|
return _SliceBuffer(result, shiftedToStartIndex: bounds.lowerBound)
|
||||||
|
|||||||
@@ -355,7 +355,7 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
|
|||||||
/// Retrieve the value the pointer points to.
|
/// Retrieve the value the pointer points to.
|
||||||
@_transparent get {
|
@_transparent get {
|
||||||
// We can do a strong load normally.
|
// 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.
|
/// Set the value the pointer points to, copying over the previous value.
|
||||||
///
|
///
|
||||||
@@ -402,6 +402,9 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
|
|||||||
/// This is inherently unsafe; UnsafeMutablePointer assumes the
|
/// This is inherently unsafe; UnsafeMutablePointer assumes the
|
||||||
/// referenced memory has +1 strong ownership semantics, whereas
|
/// referenced memory has +1 strong ownership semantics, whereas
|
||||||
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
|
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
|
||||||
|
///
|
||||||
|
/// - Warning: Accessing `pointee` as a type that is unrelated to
|
||||||
|
/// the underlying memory's bound type is undefined.
|
||||||
@_transparent public
|
@_transparent public
|
||||||
init<U>(_ from: UnsafeMutablePointer<U>) {
|
init<U>(_ from: UnsafeMutablePointer<U>) {
|
||||||
self._rawValue = from._rawValue
|
self._rawValue = from._rawValue
|
||||||
@@ -414,6 +417,9 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
|
|||||||
/// This is inherently unsafe; UnsafeMutablePointer assumes the
|
/// This is inherently unsafe; UnsafeMutablePointer assumes the
|
||||||
/// referenced memory has +1 strong ownership semantics, whereas
|
/// referenced memory has +1 strong ownership semantics, whereas
|
||||||
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
|
/// AutoreleasingUnsafeMutablePointer implies +0 semantics.
|
||||||
|
///
|
||||||
|
/// - Warning: Accessing `pointee` as a type that is unrelated to
|
||||||
|
/// the underlying memory's bound type is undefined.
|
||||||
@_transparent public
|
@_transparent public
|
||||||
init?<U>(_ from: UnsafeMutablePointer<U>?) {
|
init?<U>(_ from: UnsafeMutablePointer<U>?) {
|
||||||
guard let unwrapped = from else { return nil }
|
guard let unwrapped = from else { return nil }
|
||||||
@@ -424,6 +430,9 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
|
|||||||
///
|
///
|
||||||
/// This is inherently unsafe because UnsafePointers do not imply
|
/// This is inherently unsafe because UnsafePointers do not imply
|
||||||
/// mutability.
|
/// mutability.
|
||||||
|
///
|
||||||
|
/// - Warning: Accessing `pointee` as a type that is unrelated to
|
||||||
|
/// the underlying memory's bound type is undefined.
|
||||||
@_transparent
|
@_transparent
|
||||||
init<U>(_ from: UnsafePointer<U>) {
|
init<U>(_ from: UnsafePointer<U>) {
|
||||||
self._rawValue = from._rawValue
|
self._rawValue = from._rawValue
|
||||||
@@ -435,6 +444,9 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
|
|||||||
///
|
///
|
||||||
/// This is inherently unsafe because UnsafePointers do not imply
|
/// This is inherently unsafe because UnsafePointers do not imply
|
||||||
/// mutability.
|
/// mutability.
|
||||||
|
///
|
||||||
|
/// - Warning: Accessing `pointee` as a type that is unrelated to
|
||||||
|
/// the underlying memory's bound type is undefined.
|
||||||
@_transparent
|
@_transparent
|
||||||
init?<U>(_ from: UnsafePointer<U>?) {
|
init?<U>(_ from: UnsafePointer<U>?) {
|
||||||
guard let unwrapped = from else { return nil }
|
guard let unwrapped = from else { return nil }
|
||||||
@@ -442,6 +454,40 @@ public struct AutoreleasingUnsafeMutablePointer<Pointee /* TODO : class */>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension UnsafeMutableRawPointer {
|
||||||
|
/// Convert from `AutoreleasingUnsafeMutablePointer`.
|
||||||
|
@_transparent
|
||||||
|
public init<T>(_ other: AutoreleasingUnsafeMutablePointer<T>) {
|
||||||
|
_rawValue = other._rawValue
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert other `AutoreleasingUnsafeMutablePointer`.
|
||||||
|
///
|
||||||
|
/// Returns nil if `other` is nil.
|
||||||
|
@_transparent
|
||||||
|
public init?<T>(_ other: AutoreleasingUnsafeMutablePointer<T>?) {
|
||||||
|
guard let unwrapped = other else { return nil }
|
||||||
|
self.init(unwrapped)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension UnsafeRawPointer {
|
||||||
|
/// Convert other `AutoreleasingUnsafeMutablePointer`.
|
||||||
|
@_transparent
|
||||||
|
public init<T>(_ other: AutoreleasingUnsafeMutablePointer<T>) {
|
||||||
|
_rawValue = other._rawValue
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert other `AutoreleasingUnsafeMutablePointer`.
|
||||||
|
///
|
||||||
|
/// Returns nil if `other` is nil.
|
||||||
|
@_transparent
|
||||||
|
public init?<T>(_ other: AutoreleasingUnsafeMutablePointer<T>?) {
|
||||||
|
guard let unwrapped = other else { return nil }
|
||||||
|
self.init(unwrapped)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
extension AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
|
extension AutoreleasingUnsafeMutablePointer : CustomDebugStringConvertible {
|
||||||
/// A textual representation of `self`, suitable for debugging.
|
/// A textual representation of `self`, suitable for debugging.
|
||||||
public var debugDescription: String {
|
public var debugDescription: String {
|
||||||
|
|||||||
@@ -88,9 +88,11 @@ internal func _roundUp(_ offset: Int, toAlignment alignment: Int) -> Int {
|
|||||||
return Int(_roundUpImpl(UInt(bitPattern: offset), toAlignment: alignment))
|
return Int(_roundUpImpl(UInt(bitPattern: offset), toAlignment: alignment))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function takes a raw pointer and returns a typed pointer. It implicitly
|
||||||
|
// assumes that memory at the returned pointer is bound to `Destination` type.
|
||||||
@_versioned
|
@_versioned
|
||||||
internal func _roundUp<T, DestinationType>(
|
internal func _roundUp<DestinationType>(
|
||||||
_ pointer: UnsafeMutablePointer<T>,
|
_ pointer: UnsafeMutableRawPointer,
|
||||||
toAlignmentOf destinationType: DestinationType.Type
|
toAlignmentOf destinationType: DestinationType.Type
|
||||||
) -> UnsafeMutablePointer<DestinationType> {
|
) -> UnsafeMutablePointer<DestinationType> {
|
||||||
// Note: unsafe unwrap is safe because this operation can only increase the
|
// Note: unsafe unwrap is safe because this operation can only increase the
|
||||||
@@ -245,11 +247,11 @@ public func unsafeDowncast<T : AnyObject>(_ x: AnyObject, to: T.Type) -> T {
|
|||||||
|
|
||||||
@inline(__always)
|
@inline(__always)
|
||||||
public func _getUnsafePointerToStoredProperties(_ x: AnyObject)
|
public func _getUnsafePointerToStoredProperties(_ x: AnyObject)
|
||||||
-> UnsafeMutablePointer<UInt8> {
|
-> UnsafeMutableRawPointer {
|
||||||
let storedPropertyOffset = _roundUp(
|
let storedPropertyOffset = _roundUp(
|
||||||
sizeof(_HeapObject.self),
|
sizeof(_HeapObject.self),
|
||||||
toAlignment: alignof(Optional<AnyObject>.self))
|
toAlignment: alignof(Optional<AnyObject>.self))
|
||||||
return UnsafeMutablePointer<UInt8>(Builtin.bridgeToRawPointer(x)) +
|
return UnsafeMutableRawPointer(Builtin.bridgeToRawPointer(x)) +
|
||||||
storedPropertyOffset
|
storedPropertyOffset
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -66,7 +66,8 @@ internal struct _CocoaArrayWrapper : RandomAccessCollection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return contiguousCount >= subRange.upperBound
|
return contiguousCount >= subRange.upperBound
|
||||||
? UnsafeMutablePointer<AnyObject>(enumerationState.itemsPtr!)
|
? UnsafeMutableRawPointer(enumerationState.itemsPtr!)
|
||||||
|
.assumingMemoryBound(to: AnyObject.self)
|
||||||
+ subRange.lowerBound
|
+ subRange.lowerBound
|
||||||
: nil
|
: nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,8 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
|
|||||||
) rethrows {
|
) rethrows {
|
||||||
if _isBridgedVerbatimToObjectiveC(Element.self) {
|
if _isBridgedVerbatimToObjectiveC(Element.self) {
|
||||||
let count = __manager.header.count
|
let count = __manager.header.count
|
||||||
let elements = UnsafePointer<AnyObject>(__manager._elementPointer)
|
let elements = UnsafeMutableRawPointer(__manager._elementPointer)
|
||||||
|
.assumingMemoryBound(to: AnyObject.self)
|
||||||
defer { _fixLifetime(__manager) }
|
defer { _fixLifetime(__manager) }
|
||||||
try body(UnsafeBufferPointer(start: elements, count: count))
|
try body(UnsafeBufferPointer(start: elements, count: count))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,10 +57,9 @@ extension ${Self} : LosslessStringConvertible {
|
|||||||
func parseNTBS(_ chars: UnsafePointer<CChar>) -> (${Self}, Int) {
|
func parseNTBS(_ chars: UnsafePointer<CChar>) -> (${Self}, Int) {
|
||||||
var result: ${Self} = 0
|
var result: ${Self} = 0
|
||||||
let endPtr = withUnsafeMutablePointer(to: &result) {
|
let endPtr = withUnsafeMutablePointer(to: &result) {
|
||||||
_swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(
|
_swift_stdlib_strto${cFuncSuffix2[bits]}_clocale(chars, $0)
|
||||||
chars, UnsafeMutablePointer($0))
|
|
||||||
}
|
}
|
||||||
return (result, endPtr == nil ? 0 : UnsafePointer(endPtr!) - chars)
|
return (result, endPtr == nil ? 0 : endPtr! - chars)
|
||||||
}
|
}
|
||||||
|
|
||||||
let (result, n) = text.withCString(parseNTBS)
|
let (result, n) = text.withCString(parseNTBS)
|
||||||
|
|||||||
@@ -2584,7 +2584,7 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> :
|
|||||||
_UnsafeBitMap.sizeInWords(forSizeInBits: _body.capacity),
|
_UnsafeBitMap.sizeInWords(forSizeInBits: _body.capacity),
|
||||||
strideof(UInt.self))
|
strideof(UInt.self))
|
||||||
let start =
|
let start =
|
||||||
UnsafeMutablePointer<UInt8>(_initializedHashtableEntriesBitMapStorage)
|
UnsafeMutableRawPointer(_initializedHashtableEntriesBitMapStorage)
|
||||||
+ bitMapSizeInBytes
|
+ bitMapSizeInBytes
|
||||||
return _roundUp(start, toAlignmentOf: Key.self)
|
return _roundUp(start, toAlignmentOf: Key.self)
|
||||||
}
|
}
|
||||||
@@ -2593,7 +2593,7 @@ final internal class _Native${Self}StorageImpl<${TypeParameters}> :
|
|||||||
// This API is unsafe and needs a `_fixLifetime` in the caller.
|
// This API is unsafe and needs a `_fixLifetime` in the caller.
|
||||||
internal var _values: UnsafeMutablePointer<Value> {
|
internal var _values: UnsafeMutablePointer<Value> {
|
||||||
let keysSizeInBytes = _unsafeMultiply(_body.capacity, strideof(Key.self))
|
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)
|
return _roundUp(start, toAlignmentOf: Value.self)
|
||||||
}
|
}
|
||||||
%end
|
%end
|
||||||
@@ -3359,7 +3359,8 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
|
|||||||
/// Returns the pointer to the stored property, which contains bridged
|
/// Returns the pointer to the stored property, which contains bridged
|
||||||
/// ${Self} elements.
|
/// ${Self} elements.
|
||||||
internal var _heapBufferBridgedPtr: UnsafeMutablePointer<AnyObject?> {
|
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.
|
/// The storage for bridged ${Self} elements, if present.
|
||||||
@@ -4754,12 +4755,14 @@ final internal class _Cocoa${Self}Iterator : IteratorProtocol {
|
|||||||
|
|
||||||
internal var _fastEnumerationStatePtr:
|
internal var _fastEnumerationStatePtr:
|
||||||
UnsafeMutablePointer<_SwiftNSFastEnumerationState> {
|
UnsafeMutablePointer<_SwiftNSFastEnumerationState> {
|
||||||
return UnsafeMutablePointer(_getUnsafePointerToStoredProperties(self))
|
return _getUnsafePointerToStoredProperties(self).assumingMemoryBound(
|
||||||
|
to: _SwiftNSFastEnumerationState.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var _fastEnumerationStackBufPtr:
|
internal var _fastEnumerationStackBufPtr:
|
||||||
UnsafeMutablePointer<_CocoaFastEnumerationStackBuf> {
|
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
|
// These members have to be word-sized integers, they cannot be limited to
|
||||||
@@ -4788,7 +4791,8 @@ final internal class _Cocoa${Self}Iterator : IteratorProtocol {
|
|||||||
// state struct.
|
// state struct.
|
||||||
itemCount = cocoa${Self}.countByEnumerating(
|
itemCount = cocoa${Self}.countByEnumerating(
|
||||||
with: _fastEnumerationStatePtr,
|
with: _fastEnumerationStatePtr,
|
||||||
objects: UnsafeMutablePointer(_fastEnumerationStackBufPtr),
|
objects: UnsafeMutableRawPointer(_fastEnumerationStackBufPtr)
|
||||||
|
.assumingMemoryBound(to: AnyObject.self),
|
||||||
count: stackBufCount)
|
count: stackBufCount)
|
||||||
if itemCount == 0 {
|
if itemCount == 0 {
|
||||||
itemIndex = -1
|
itemIndex = -1
|
||||||
@@ -4796,8 +4800,9 @@ final internal class _Cocoa${Self}Iterator : IteratorProtocol {
|
|||||||
}
|
}
|
||||||
itemIndex = 0
|
itemIndex = 0
|
||||||
}
|
}
|
||||||
let itemsPtrUP: UnsafeMutablePointer<AnyObject> =
|
let itemsPtrUP =
|
||||||
UnsafeMutablePointer(_fastEnumerationState.itemsPtr!)
|
UnsafeMutableRawPointer(_fastEnumerationState.itemsPtr!)
|
||||||
|
.assumingMemoryBound(to: AnyObject.self)
|
||||||
let itemsPtr = _UnmanagedAnyObjectArray(itemsPtrUP)
|
let itemsPtr = _UnmanagedAnyObjectArray(itemsPtrUP)
|
||||||
let key: AnyObject = itemsPtr[itemIndex]
|
let key: AnyObject = itemsPtr[itemIndex]
|
||||||
itemIndex += 1
|
itemIndex += 1
|
||||||
|
|||||||
@@ -92,19 +92,20 @@ struct _HeapBuffer<Value, Element> : Equatable {
|
|||||||
: (heapAlign < elementAlign ? elementAlign : heapAlign))
|
: (heapAlign < elementAlign ? elementAlign : heapAlign))
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var _address: UnsafeMutablePointer<Int8> {
|
internal var _address: UnsafeMutableRawPointer {
|
||||||
return UnsafeMutablePointer(
|
return UnsafeMutableRawPointer(
|
||||||
Builtin.bridgeToRawPointer(self._nativeObject))
|
Builtin.bridgeToRawPointer(self._nativeObject))
|
||||||
}
|
}
|
||||||
|
|
||||||
internal var _value: UnsafeMutablePointer<Value> {
|
internal var _value: UnsafeMutablePointer<Value> {
|
||||||
return UnsafeMutablePointer(
|
return (_HeapBuffer._valueOffset() + _address).assumingMemoryBound(
|
||||||
_HeapBuffer._valueOffset() + _address)
|
to: Value.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
public // @testable
|
public // @testable
|
||||||
var baseAddress: UnsafeMutablePointer<Element> {
|
var baseAddress: UnsafeMutablePointer<Element> {
|
||||||
return UnsafeMutablePointer(_HeapBuffer._elementOffset() + _address)
|
return (_HeapBuffer._elementOffset() + _address).assumingMemoryBound(
|
||||||
|
to: Element.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal func _allocatedSize() -> Int {
|
internal func _allocatedSize() -> Int {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ import SwiftShims
|
|||||||
/// Standard input is interpreted as `UTF-8`. Invalid bytes
|
/// Standard input is interpreted as `UTF-8`. Invalid bytes
|
||||||
/// will be replaced by Unicode [replacement characters](http://en.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character).
|
/// will be replaced by Unicode [replacement characters](http://en.wikipedia.org/wiki/Specials_(Unicode_block)#Replacement_character).
|
||||||
public func readLine(strippingNewline: Bool = true) -> String? {
|
public func readLine(strippingNewline: Bool = true) -> String? {
|
||||||
var linePtrVar: UnsafeMutablePointer<CChar>? = nil
|
var linePtrVar: UnsafeMutablePointer<UInt8>? = nil
|
||||||
var readBytes = swift_stdlib_readLine_stdin(&linePtrVar)
|
var readBytes = swift_stdlib_readLine_stdin(&linePtrVar)
|
||||||
if readBytes == -1 {
|
if readBytes == -1 {
|
||||||
return nil
|
return nil
|
||||||
@@ -41,8 +41,8 @@ public func readLine(strippingNewline: Bool = true) -> String? {
|
|||||||
// <rdar://problem/20013999> Recognize Unicode newlines in readLine()
|
// <rdar://problem/20013999> Recognize Unicode newlines in readLine()
|
||||||
//
|
//
|
||||||
// Recognize only LF and CR+LF combinations for now.
|
// Recognize only LF and CR+LF combinations for now.
|
||||||
let cr = CChar(UInt8(ascii: "\r"))
|
let cr = UInt8(ascii: "\r")
|
||||||
let lf = CChar(UInt8(ascii: "\n"))
|
let lf = UInt8(ascii: "\n")
|
||||||
if readBytes == 1 && linePtr[0] == lf {
|
if readBytes == 1 && linePtr[0] == lf {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
@@ -61,7 +61,7 @@ public func readLine(strippingNewline: Bool = true) -> String? {
|
|||||||
}
|
}
|
||||||
let result = String._fromCodeUnitSequenceWithRepair(UTF8.self,
|
let result = String._fromCodeUnitSequenceWithRepair(UTF8.self,
|
||||||
input: UnsafeMutableBufferPointer(
|
input: UnsafeMutableBufferPointer(
|
||||||
start: UnsafeMutablePointer<UTF8.CodeUnit>(linePtr),
|
start: linePtr,
|
||||||
count: readBytes)).0
|
count: readBytes)).0
|
||||||
_swift_stdlib_free(linePtr)
|
_swift_stdlib_free(linePtr)
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -395,8 +395,8 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// The address of this instance in a convenient pointer-to-bytes form
|
/// The address of this instance in a convenient pointer-to-bytes form
|
||||||
internal var _address: UnsafePointer<UInt8> {
|
internal var _address: UnsafeMutableRawPointer {
|
||||||
return UnsafePointer(Builtin.bridgeToRawPointer(_nativeBuffer))
|
return UnsafeMutableRawPointer(Builtin.bridgeToRawPointer(_nativeBuffer))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Offset from the allocated storage for `self` to the stored `Header`
|
/// Offset from the allocated storage for `self` to the stored `Header`
|
||||||
@@ -412,7 +412,8 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
|
|||||||
/// guarantee it doesn't dangle
|
/// guarantee it doesn't dangle
|
||||||
internal var _headerPointer: UnsafeMutablePointer<Header> {
|
internal var _headerPointer: UnsafeMutablePointer<Header> {
|
||||||
_onFastPath()
|
_onFastPath()
|
||||||
return UnsafeMutablePointer(_address + _My._headerOffset)
|
return (_address + _My._headerOffset).assumingMemoryBound(
|
||||||
|
to: Header.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// An **unmanaged** pointer to the storage for `Element`s. Not
|
/// An **unmanaged** pointer to the storage for `Element`s. Not
|
||||||
@@ -420,7 +421,8 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
|
|||||||
/// dangle.
|
/// dangle.
|
||||||
internal var _elementPointer: UnsafeMutablePointer<Element> {
|
internal var _elementPointer: UnsafeMutablePointer<Element> {
|
||||||
_onFastPath()
|
_onFastPath()
|
||||||
return UnsafeMutablePointer(_address + _My._elementOffset)
|
return (_address + _My._elementOffset).assumingMemoryBound(
|
||||||
|
to: Element.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Offset from the allocated storage for `self` to the `Element` storage
|
/// Offset from the allocated storage for `self` to the `Element` storage
|
||||||
|
|||||||
@@ -120,10 +120,11 @@ func _stdlib_atomicCompareExchangeStrongInt${bits}(
|
|||||||
object target: UnsafeMutablePointer<Int${bits}>,
|
object target: UnsafeMutablePointer<Int${bits}>,
|
||||||
expected: UnsafeMutablePointer<Int${bits}>,
|
expected: UnsafeMutablePointer<Int${bits}>,
|
||||||
desired: Int${bits}) -> Bool {
|
desired: Int${bits}) -> Bool {
|
||||||
return _stdlib_atomicCompareExchangeStrongUInt${bits}(
|
|
||||||
object: UnsafeMutablePointer(target),
|
let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int${bits}(
|
||||||
expected: UnsafeMutablePointer(expected),
|
target._rawValue, expected.pointee._value, desired._value)
|
||||||
desired: UInt${bits}(bitPattern: desired))
|
expected.pointee._value = oldValue
|
||||||
|
return Bool(won)
|
||||||
}
|
}
|
||||||
|
|
||||||
@_transparent
|
@_transparent
|
||||||
@@ -138,9 +139,8 @@ func _swift_stdlib_atomicStoreUInt${bits}(
|
|||||||
func _swift_stdlib_atomicStoreInt${bits}(
|
func _swift_stdlib_atomicStoreInt${bits}(
|
||||||
object target: UnsafeMutablePointer<Int${bits}>,
|
object target: UnsafeMutablePointer<Int${bits}>,
|
||||||
desired: Int${bits}) {
|
desired: Int${bits}) {
|
||||||
return _swift_stdlib_atomicStoreUInt${bits}(
|
|
||||||
object: UnsafeMutablePointer(target),
|
Builtin.atomicstore_seqcst_Int${bits}(target._rawValue, desired._value)
|
||||||
desired: UInt${bits}(bitPattern: desired))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public // @testable
|
public // @testable
|
||||||
@@ -153,9 +153,9 @@ func _swift_stdlib_atomicLoadUInt${bits}(
|
|||||||
|
|
||||||
func _swift_stdlib_atomicLoadInt${bits}(
|
func _swift_stdlib_atomicLoadInt${bits}(
|
||||||
object target: UnsafeMutablePointer<Int${bits}>) -> Int${bits} {
|
object target: UnsafeMutablePointer<Int${bits}>) -> Int${bits} {
|
||||||
return Int${bits}(bitPattern:
|
|
||||||
_swift_stdlib_atomicLoadUInt${bits}(
|
let value = Builtin.atomicload_seqcst_Int${bits}(target._rawValue)
|
||||||
object: UnsafeMutablePointer(target)))
|
return Int${bits}(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
% for operation in ['Add', 'And', 'Or', 'Xor']:
|
% for operation in ['Add', 'And', 'Or', 'Xor']:
|
||||||
@@ -176,10 +176,11 @@ func _swift_stdlib_atomicFetch${operation}UInt${bits}(
|
|||||||
func _swift_stdlib_atomicFetch${operation}Int${bits}(
|
func _swift_stdlib_atomicFetch${operation}Int${bits}(
|
||||||
object target: UnsafeMutablePointer<Int${bits}>,
|
object target: UnsafeMutablePointer<Int${bits}>,
|
||||||
operand: Int${bits}) -> Int${bits} {
|
operand: Int${bits}) -> Int${bits} {
|
||||||
return Int${bits}(bitPattern:
|
|
||||||
_swift_stdlib_atomicFetch${operation}UInt${bits}(
|
let value = Builtin.atomicrmw_${operation.lower()}_seqcst_Int${bits}(
|
||||||
object: UnsafeMutablePointer(target),
|
target._rawValue, operand._value)
|
||||||
operand: UInt${bits}(bitPattern: operand)))
|
|
||||||
|
return Int${bits}(value)
|
||||||
}
|
}
|
||||||
% end
|
% end
|
||||||
|
|
||||||
@@ -190,29 +191,23 @@ func _stdlib_atomicCompareExchangeStrongInt(
|
|||||||
expected: UnsafeMutablePointer<Int>,
|
expected: UnsafeMutablePointer<Int>,
|
||||||
desired: Int) -> Bool {
|
desired: Int) -> Bool {
|
||||||
#if arch(i386) || arch(arm)
|
#if arch(i386) || arch(arm)
|
||||||
return _stdlib_atomicCompareExchangeStrongUInt32(
|
let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int32(
|
||||||
object: UnsafeMutablePointer(target),
|
target._rawValue, expected.pointee._value, desired._value)
|
||||||
expected: UnsafeMutablePointer(expected),
|
|
||||||
desired: UInt32(bitPattern: Int32(desired)))
|
|
||||||
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
|
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
|
||||||
return _stdlib_atomicCompareExchangeStrongUInt64(
|
let (oldValue, won) = Builtin.cmpxchg_seqcst_seqcst_Int64(
|
||||||
object: UnsafeMutablePointer(target),
|
target._rawValue, expected.pointee._value, desired._value)
|
||||||
expected: UnsafeMutablePointer(expected),
|
|
||||||
desired: UInt64(bitPattern: Int64(desired)))
|
|
||||||
#endif
|
#endif
|
||||||
|
expected.pointee._value = oldValue
|
||||||
|
return Bool(won)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _swift_stdlib_atomicStoreInt(
|
func _swift_stdlib_atomicStoreInt(
|
||||||
object target: UnsafeMutablePointer<Int>,
|
object target: UnsafeMutablePointer<Int>,
|
||||||
desired: Int) {
|
desired: Int) {
|
||||||
#if arch(i386) || arch(arm)
|
#if arch(i386) || arch(arm)
|
||||||
return _swift_stdlib_atomicStoreUInt32(
|
Builtin.atomicstore_seqcst_Int32(target._rawValue, desired._value)
|
||||||
object: UnsafeMutablePointer(target),
|
|
||||||
desired: UInt32(bitPattern: Int32(desired)))
|
|
||||||
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
|
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
|
||||||
return _swift_stdlib_atomicStoreUInt64(
|
Builtin.atomicstore_seqcst_Int64(target._rawValue, desired._value)
|
||||||
object: UnsafeMutablePointer(target),
|
|
||||||
desired: UInt64(bitPattern: Int64(desired)))
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,13 +215,11 @@ func _swift_stdlib_atomicStoreInt(
|
|||||||
public func _swift_stdlib_atomicLoadInt(
|
public func _swift_stdlib_atomicLoadInt(
|
||||||
object target: UnsafeMutablePointer<Int>) -> Int {
|
object target: UnsafeMutablePointer<Int>) -> Int {
|
||||||
#if arch(i386) || arch(arm)
|
#if arch(i386) || arch(arm)
|
||||||
return Int(Int32(bitPattern:
|
let value = Builtin.atomicload_seqcst_Int32(target._rawValue)
|
||||||
_swift_stdlib_atomicLoadUInt32(
|
return Int(value)
|
||||||
object: UnsafeMutablePointer(target))))
|
|
||||||
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
|
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
|
||||||
return Int(Int64(bitPattern:
|
let value = Builtin.atomicload_seqcst_Int64(target._rawValue)
|
||||||
_swift_stdlib_atomicLoadUInt64(
|
return Int(value)
|
||||||
object: UnsafeMutablePointer(target))))
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,7 +238,7 @@ func _stdlib_atomicLoadARCRef(
|
|||||||
object target: UnsafeMutablePointer<AnyObject?>
|
object target: UnsafeMutablePointer<AnyObject?>
|
||||||
) -> AnyObject? {
|
) -> AnyObject? {
|
||||||
let result = _swift_stdlib_atomicLoadPtrImpl(
|
let result = _swift_stdlib_atomicLoadPtrImpl(
|
||||||
object: UnsafeMutablePointer(target))
|
object: unsafeBitCast(target, to: UnsafeMutablePointer<OpaquePointer>.self))
|
||||||
if let unwrapped = result {
|
if let unwrapped = result {
|
||||||
return Unmanaged<AnyObject>.fromOpaque(
|
return Unmanaged<AnyObject>.fromOpaque(
|
||||||
UnsafePointer(unwrapped)).takeUnretainedValue()
|
UnsafePointer(unwrapped)).takeUnretainedValue()
|
||||||
@@ -261,12 +254,12 @@ public func _swift_stdlib_atomicFetch${operation}Int(
|
|||||||
#if arch(i386) || arch(arm)
|
#if arch(i386) || arch(arm)
|
||||||
return Int(Int32(bitPattern:
|
return Int(Int32(bitPattern:
|
||||||
_swift_stdlib_atomicFetch${operation}UInt32(
|
_swift_stdlib_atomicFetch${operation}UInt32(
|
||||||
object: UnsafeMutablePointer(target),
|
object: unsafeBitCast(target, to: UnsafeMutablePointer<UInt32>.self),
|
||||||
operand: UInt32(bitPattern: Int32(operand)))))
|
operand: UInt32(bitPattern: Int32(operand)))))
|
||||||
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
|
#elseif arch(x86_64) || arch(arm64) || arch(powerpc64) || arch(powerpc64le) || arch(s390x)
|
||||||
return Int(Int64(bitPattern:
|
return Int(Int64(bitPattern:
|
||||||
_swift_stdlib_atomicFetch${operation}UInt64(
|
_swift_stdlib_atomicFetch${operation}UInt64(
|
||||||
object: UnsafeMutablePointer(target),
|
object: unsafeBitCast(target, to: UnsafeMutablePointer<UInt64>.self),
|
||||||
operand: UInt64(bitPattern: Int64(operand)))))
|
operand: UInt64(bitPattern: Int64(operand)))))
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -276,7 +269,8 @@ public final class _stdlib_AtomicInt {
|
|||||||
var _value: Int
|
var _value: Int
|
||||||
|
|
||||||
var _valuePtr: UnsafeMutablePointer<Int> {
|
var _valuePtr: UnsafeMutablePointer<Int> {
|
||||||
return UnsafeMutablePointer(_getUnsafePointerToStoredProperties(self))
|
return _getUnsafePointerToStoredProperties(self).assumingMemoryBound(
|
||||||
|
to: Int.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(_ value: Int = 0) {
|
public init(_ value: Int = 0) {
|
||||||
@@ -321,23 +315,34 @@ public final class _stdlib_AtomicInt {
|
|||||||
|
|
||||||
/// A 32 byte buffer.
|
/// A 32 byte buffer.
|
||||||
internal struct _Buffer32 {
|
internal struct _Buffer32 {
|
||||||
internal var _x0: UInt64 = 0
|
% for i in range(32):
|
||||||
internal var _x1: UInt64 = 0
|
internal var _x${i}: UInt8 = 0
|
||||||
internal var _x2: UInt64 = 0
|
% end
|
||||||
internal var _x3: UInt64 = 0
|
|
||||||
|
mutating func withBytes<Result>(
|
||||||
|
_ body: @noescape (UnsafeMutablePointer<UInt8>) throws -> Result
|
||||||
|
) rethrows -> Result
|
||||||
|
{
|
||||||
|
return try withUnsafeMutablePointer(to: &self) {
|
||||||
|
try body(UnsafeMutableRawPointer($0).assumingMemoryBound(to: UInt8.self))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A 72 byte buffer.
|
/// A 72 byte buffer.
|
||||||
internal struct _Buffer72 {
|
internal struct _Buffer72 {
|
||||||
internal var _x0: UInt64 = 0
|
% for i in range(72):
|
||||||
internal var _x1: UInt64 = 0
|
internal var _x${i}: UInt8 = 0
|
||||||
internal var _x2: UInt64 = 0
|
% end
|
||||||
internal var _x3: UInt64 = 0
|
|
||||||
internal var _x4: UInt64 = 0
|
mutating func withBytes<Result>(
|
||||||
internal var _x5: UInt64 = 0
|
_ body: @noescape (UnsafeMutablePointer<UInt8>) throws -> Result
|
||||||
internal var _x6: UInt64 = 0
|
) rethrows -> Result
|
||||||
internal var _x7: UInt64 = 0
|
{
|
||||||
internal var _x8: UInt64 = 0
|
return try withUnsafeMutablePointer(to: &self) {
|
||||||
|
try body(UnsafeMutableRawPointer($0).assumingMemoryBound(to: UInt8.self))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
% for bits in [ 32, 64, 80 ]:
|
% for bits in [ 32, 64, 80 ]:
|
||||||
@@ -381,14 +386,11 @@ func _float${bits}ToString(_ value: Float${bits}, debug: Bool) -> String {
|
|||||||
_sanityCheck(sizeof(_Buffer72.self) == 72)
|
_sanityCheck(sizeof(_Buffer72.self) == 72)
|
||||||
|
|
||||||
var buffer = _Buffer32()
|
var buffer = _Buffer32()
|
||||||
return withUnsafeMutablePointer(to: &buffer) {
|
return buffer.withBytes { (bufferPtr) in
|
||||||
(bufferPtr) in
|
let actualLength = _float${bits}ToStringImpl(bufferPtr, 32, value, debug)
|
||||||
let bufferUTF8Ptr = UnsafeMutablePointer<UTF8.CodeUnit>(bufferPtr)
|
|
||||||
let actualLength = _float${bits}ToStringImpl(bufferUTF8Ptr, 32, value, debug)
|
|
||||||
return String._fromWellFormedCodeUnitSequence(
|
return String._fromWellFormedCodeUnitSequence(
|
||||||
UTF8.self,
|
UTF8.self,
|
||||||
input: UnsafeBufferPointer(
|
input: UnsafeBufferPointer(start: bufferPtr, count: Int(actualLength)))
|
||||||
start: bufferUTF8Ptr, count: Int(actualLength)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -410,27 +412,21 @@ func _int64ToString(
|
|||||||
) -> String {
|
) -> String {
|
||||||
if radix >= 10 {
|
if radix >= 10 {
|
||||||
var buffer = _Buffer32()
|
var buffer = _Buffer32()
|
||||||
return withUnsafeMutablePointer(to: &buffer) {
|
return buffer.withBytes { (bufferPtr) in
|
||||||
(bufferPtr) in
|
let actualLength
|
||||||
let bufferUTF8Ptr = UnsafeMutablePointer<UTF8.CodeUnit>(bufferPtr)
|
= _int64ToStringImpl(bufferPtr, 32, value, radix, uppercase)
|
||||||
let actualLength =
|
|
||||||
_int64ToStringImpl(bufferUTF8Ptr, 32, value, radix, uppercase)
|
|
||||||
return String._fromWellFormedCodeUnitSequence(
|
return String._fromWellFormedCodeUnitSequence(
|
||||||
UTF8.self,
|
UTF8.self,
|
||||||
input: UnsafeBufferPointer(
|
input: UnsafeBufferPointer(start: bufferPtr, count: Int(actualLength)))
|
||||||
start: bufferUTF8Ptr, count: Int(actualLength)))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var buffer = _Buffer72()
|
var buffer = _Buffer72()
|
||||||
return withUnsafeMutablePointer(to: &buffer) {
|
return buffer.withBytes { (bufferPtr) in
|
||||||
(bufferPtr) in
|
let actualLength
|
||||||
let bufferUTF8Ptr = UnsafeMutablePointer<UTF8.CodeUnit>(bufferPtr)
|
= _int64ToStringImpl(bufferPtr, 72, value, radix, uppercase)
|
||||||
let actualLength =
|
|
||||||
_int64ToStringImpl(bufferUTF8Ptr, 72, value, radix, uppercase)
|
|
||||||
return String._fromWellFormedCodeUnitSequence(
|
return String._fromWellFormedCodeUnitSequence(
|
||||||
UTF8.self,
|
UTF8.self,
|
||||||
input: UnsafeBufferPointer(
|
input: UnsafeBufferPointer(start: bufferPtr, count: Int(actualLength)))
|
||||||
start: bufferUTF8Ptr, count: Int(actualLength)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -447,27 +443,21 @@ func _uint64ToString(
|
|||||||
) -> String {
|
) -> String {
|
||||||
if radix >= 10 {
|
if radix >= 10 {
|
||||||
var buffer = _Buffer32()
|
var buffer = _Buffer32()
|
||||||
return withUnsafeMutablePointer(to: &buffer) {
|
return buffer.withBytes { (bufferPtr) in
|
||||||
(bufferPtr) in
|
let actualLength
|
||||||
let bufferUTF8Ptr = UnsafeMutablePointer<UTF8.CodeUnit>(bufferPtr)
|
= _uint64ToStringImpl(bufferPtr, 32, value, radix, uppercase)
|
||||||
let actualLength =
|
|
||||||
_uint64ToStringImpl(bufferUTF8Ptr, 32, value, radix, uppercase)
|
|
||||||
return String._fromWellFormedCodeUnitSequence(
|
return String._fromWellFormedCodeUnitSequence(
|
||||||
UTF8.self,
|
UTF8.self,
|
||||||
input: UnsafeBufferPointer(
|
input: UnsafeBufferPointer(start: bufferPtr, count: Int(actualLength)))
|
||||||
start: bufferUTF8Ptr, count: Int(actualLength)))
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
var buffer = _Buffer72()
|
var buffer = _Buffer72()
|
||||||
return withUnsafeMutablePointer(to: &buffer) {
|
return buffer.withBytes { (bufferPtr) in
|
||||||
(bufferPtr) in
|
let actualLength
|
||||||
let bufferUTF8Ptr = UnsafeMutablePointer<UTF8.CodeUnit>(bufferPtr)
|
= _uint64ToStringImpl(bufferPtr, 72, value, radix, uppercase)
|
||||||
let actualLength =
|
|
||||||
_uint64ToStringImpl(bufferUTF8Ptr, 72, value, radix, uppercase)
|
|
||||||
return String._fromWellFormedCodeUnitSequence(
|
return String._fromWellFormedCodeUnitSequence(
|
||||||
UTF8.self,
|
UTF8.self,
|
||||||
input: UnsafeBufferPointer(
|
input: UnsafeBufferPointer(start: bufferPtr, count: Int(actualLength)))
|
||||||
start: bufferUTF8Ptr, count: Int(actualLength)))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -584,28 +584,20 @@ extension String {
|
|||||||
#else
|
#else
|
||||||
switch (_core.isASCII, rhs._core.isASCII) {
|
switch (_core.isASCII, rhs._core.isASCII) {
|
||||||
case (true, false):
|
case (true, false):
|
||||||
let lhsPtr = UnsafePointer<Int8>(_core.startASCII)
|
|
||||||
let rhsPtr = UnsafePointer<UTF16.CodeUnit>(rhs._core.startUTF16)
|
|
||||||
|
|
||||||
return Int(_swift_stdlib_unicode_compare_utf8_utf16(
|
return Int(_swift_stdlib_unicode_compare_utf8_utf16(
|
||||||
lhsPtr, Int32(_core.count), rhsPtr, Int32(rhs._core.count)))
|
_core.startASCII, Int32(_core.count),
|
||||||
|
rhs._core.startUTF16, Int32(rhs._core.count)))
|
||||||
case (false, true):
|
case (false, true):
|
||||||
// Just invert it and recurse for this case.
|
// Just invert it and recurse for this case.
|
||||||
return -rhs._compareDeterministicUnicodeCollation(self)
|
return -rhs._compareDeterministicUnicodeCollation(self)
|
||||||
case (false, false):
|
case (false, false):
|
||||||
let lhsPtr = UnsafePointer<UTF16.CodeUnit>(_core.startUTF16)
|
|
||||||
let rhsPtr = UnsafePointer<UTF16.CodeUnit>(rhs._core.startUTF16)
|
|
||||||
|
|
||||||
return Int(_swift_stdlib_unicode_compare_utf16_utf16(
|
return Int(_swift_stdlib_unicode_compare_utf16_utf16(
|
||||||
lhsPtr, Int32(_core.count),
|
_core.startUTF16, Int32(_core.count),
|
||||||
rhsPtr, Int32(rhs._core.count)))
|
rhs._core.startUTF16, Int32(rhs._core.count)))
|
||||||
case (true, true):
|
case (true, true):
|
||||||
let lhsPtr = UnsafePointer<Int8>(_core.startASCII)
|
|
||||||
let rhsPtr = UnsafePointer<Int8>(rhs._core.startASCII)
|
|
||||||
|
|
||||||
return Int(_swift_stdlib_unicode_compare_utf8_utf8(
|
return Int(_swift_stdlib_unicode_compare_utf8_utf8(
|
||||||
lhsPtr, Int32(_core.count),
|
_core.startASCII, Int32(_core.count),
|
||||||
rhsPtr, Int32(rhs._core.count)))
|
rhs._core.startASCII, Int32(rhs._core.count)))
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -699,15 +691,10 @@ extension String : Hashable {
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
if self._core.isASCII {
|
if self._core.isASCII {
|
||||||
return _core.startASCII.withMemoryRebound(
|
return _swift_stdlib_unicode_hash_ascii(
|
||||||
to: CChar.self, capacity: _core.count) {
|
_core.startASCII, Int32(_core.count))
|
||||||
_swift_stdlib_unicode_hash_ascii($0, Int32(_core.count))
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return _core.startUTF16.withMemoryRebound(
|
return _swift_stdlib_unicode_hash(_core.startUTF16, Int32(_core.count))
|
||||||
to: UInt16.self, capacity: _core.count) {
|
|
||||||
_swift_stdlib_unicode_hash($0, Int32(_core.count))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -822,9 +809,12 @@ internal func _nativeUnicodeLowercaseString(_ str: String) -> String {
|
|||||||
var buffer = _StringBuffer(
|
var buffer = _StringBuffer(
|
||||||
capacity: str._core.count, initialSize: str._core.count, elementWidth: 2)
|
capacity: str._core.count, initialSize: str._core.count, elementWidth: 2)
|
||||||
|
|
||||||
// Try to write it out to the same length.
|
// Allocation of a StringBuffer requires binding the memory to the correct
|
||||||
|
// encoding type.
|
||||||
let dest = buffer.start.bindMemory(
|
let dest = buffer.start.bindMemory(
|
||||||
to: UTF16.CodeUnit.self, capacity: str._core.count)
|
to: UTF16.CodeUnit.self, capacity: str._core.count)
|
||||||
|
|
||||||
|
// Try to write it out to the same length.
|
||||||
let z = _swift_stdlib_unicode_strToLower(
|
let z = _swift_stdlib_unicode_strToLower(
|
||||||
dest, Int32(str._core.count),
|
dest, Int32(str._core.count),
|
||||||
str._core.startUTF16, Int32(str._core.count))
|
str._core.startUTF16, Int32(str._core.count))
|
||||||
@@ -847,9 +837,12 @@ internal func _nativeUnicodeUppercaseString(_ str: String) -> String {
|
|||||||
var buffer = _StringBuffer(
|
var buffer = _StringBuffer(
|
||||||
capacity: str._core.count, initialSize: str._core.count, elementWidth: 2)
|
capacity: str._core.count, initialSize: str._core.count, elementWidth: 2)
|
||||||
|
|
||||||
// Try to write it out to the same length.
|
// Allocation of a StringBuffer requires binding the memory to the correct
|
||||||
|
// encoding type.
|
||||||
let dest = buffer.start.bindMemory(
|
let dest = buffer.start.bindMemory(
|
||||||
to: UTF16.CodeUnit.self, capacity: str._core.count)
|
to: UTF16.CodeUnit.self, capacity: str._core.count)
|
||||||
|
|
||||||
|
// Try to write it out to the same length.
|
||||||
let z = _swift_stdlib_unicode_strToUpper(
|
let z = _swift_stdlib_unicode_strToUpper(
|
||||||
dest, Int32(str._core.count),
|
dest, Int32(str._core.count),
|
||||||
str._core.startUTF16, Int32(str._core.count))
|
str._core.startUTF16, Int32(str._core.count))
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public // @testable
|
|||||||
func _stdlib_binary_CFStringGetCharactersPtr(
|
func _stdlib_binary_CFStringGetCharactersPtr(
|
||||||
_ source: _CocoaString
|
_ source: _CocoaString
|
||||||
) -> UnsafeMutablePointer<UTF16.CodeUnit>? {
|
) -> UnsafeMutablePointer<UTF16.CodeUnit>? {
|
||||||
return UnsafeMutablePointer(_swift_stdlib_CFStringGetCharactersPtr(source))
|
return UnsafeMutablePointer(mutating: _swift_stdlib_CFStringGetCharactersPtr(source))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Bridges `source` to `Swift.String`, assuming that `source` has non-ASCII
|
/// Bridges `source` to `Swift.String`, assuming that `source` has non-ASCII
|
||||||
|
|||||||
@@ -241,7 +241,8 @@ public struct _StringBuffer {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// &StringBufferIVars.usedEnd
|
// &StringBufferIVars.usedEnd
|
||||||
let usedEndPhysicalPtr = _PointerToPointer(_storage._value)
|
let usedEndPhysicalPtr = UnsafeMutableRawPointer(_storage._value)
|
||||||
|
.assumingMemoryBound(to: Optional<UnsafeRawPointer>.self)
|
||||||
// Create a temp var to hold the exchanged `expected` value.
|
// Create a temp var to hold the exchanged `expected` value.
|
||||||
var expected : UnsafeRawPointer? = bounds.upperBound
|
var expected : UnsafeRawPointer? = bounds.upperBound
|
||||||
if _stdlib_atomicCompareExchangeStrongPtr(
|
if _stdlib_atomicCompareExchangeStrongPtr(
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ extension _SwiftNativeNSArrayWithContiguousStorage : _NSArrayCore {
|
|||||||
internal let _nativeStorage: _ContiguousArrayStorageBase
|
internal let _nativeStorage: _ContiguousArrayStorageBase
|
||||||
|
|
||||||
internal var _heapBufferBridgedPtr: UnsafeMutablePointer<AnyObject?> {
|
internal var _heapBufferBridgedPtr: UnsafeMutablePointer<AnyObject?> {
|
||||||
return UnsafeMutablePointer(_getUnsafePointerToStoredProperties(self))
|
return _getUnsafePointerToStoredProperties(self).assumingMemoryBound(
|
||||||
|
to: Optional<AnyObject>.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
internal typealias HeapBufferStorage = _HeapBufferStorage<Int, AnyObject>
|
internal typealias HeapBufferStorage = _HeapBufferStorage<Int, AnyObject>
|
||||||
|
|||||||
@@ -427,7 +427,9 @@ public struct UTF8 : UnicodeCodec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static func _nullCodeUnitOffset(in input: UnsafePointer<CodeUnit>) -> Int {
|
public static func _nullCodeUnitOffset(in input: UnsafePointer<CodeUnit>) -> Int {
|
||||||
return Int(_swift_stdlib_strlen(UnsafePointer(input)))
|
// Relying on a permissive memory model in C.
|
||||||
|
let cstr = unsafeBitCast(input, to: UnsafePointer<CChar>.self)
|
||||||
|
return Int(_swift_stdlib_strlen(cstr))
|
||||||
}
|
}
|
||||||
// Support parsing C strings as-if they are UTF8 strings.
|
// Support parsing C strings as-if they are UTF8 strings.
|
||||||
public static func _nullCodeUnitOffset(in input: UnsafePointer<CChar>) -> Int {
|
public static func _nullCodeUnitOffset(in input: UnsafePointer<CChar>) -> Int {
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ public struct ${Self}<Pointee>
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Construct ${a_Self} with a given pattern of bits.
|
/// Construct ${a_Self} with a given pattern of bits.
|
||||||
|
///
|
||||||
|
/// Returns nil if `bitPattern` is zero.
|
||||||
@_transparent
|
@_transparent
|
||||||
public init?(bitPattern: UInt) {
|
public init?(bitPattern: UInt) {
|
||||||
if bitPattern == 0 { return nil }
|
if bitPattern == 0 { return nil }
|
||||||
@@ -121,6 +123,25 @@ public struct ${Self}<Pointee>
|
|||||||
self.init(unwrapped)
|
self.init(unwrapped)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
% if mutable:
|
||||||
|
/// Convert from `UnsafePointer` to `UnsafeMutablePointer` of the same
|
||||||
|
/// `Pointee`.
|
||||||
|
@_transparent
|
||||||
|
public init(mutating other: UnsafePointer<Pointee>) {
|
||||||
|
self._rawValue = other._rawValue
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert from `UnsafePointer` to `UnsafeMutablePointer` of the same
|
||||||
|
/// `Pointee`.
|
||||||
|
///
|
||||||
|
/// Returns nil if `bitPattern` is zero.
|
||||||
|
@_transparent
|
||||||
|
public init?(mutating other: UnsafePointer<Pointee>?) {
|
||||||
|
guard let unwrapped = other else { return nil }
|
||||||
|
self.init(mutating: unwrapped)
|
||||||
|
}
|
||||||
|
% end
|
||||||
|
|
||||||
% if mutable:
|
% if mutable:
|
||||||
/// Allocate and point at uninitialized aligned memory for `count`
|
/// Allocate and point at uninitialized aligned memory for `count`
|
||||||
/// instances of `Pointee`.
|
/// instances of `Pointee`.
|
||||||
|
|||||||
@@ -27,13 +27,21 @@ public struct Unsafe${Mutable}RawPointer : Strideable, Hashable, _Pointer {
|
|||||||
/// Implements conformance to the public protocol `_Pointer`.
|
/// Implements conformance to the public protocol `_Pointer`.
|
||||||
public let _rawValue: Builtin.RawPointer
|
public let _rawValue: Builtin.RawPointer
|
||||||
|
|
||||||
// Construct ${a_Self} from another ${a_Self}.
|
/// Construct ${a_Self} from another ${a_Self}.
|
||||||
// FIXME: Why is this necessary?
|
|
||||||
@_transparent
|
@_transparent
|
||||||
public init(_ other: Unsafe${Mutable}RawPointer) {
|
public init(_ other: Unsafe${Mutable}RawPointer) {
|
||||||
self = other
|
self = other
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Construct ${a_Self} from another ${a_Self}.
|
||||||
|
///
|
||||||
|
/// Returns nil if `other` is nil.
|
||||||
|
@_transparent
|
||||||
|
public init?(_ other: Unsafe${Mutable}RawPointer?) {
|
||||||
|
guard let unwrapped = other else { return nil }
|
||||||
|
self = unwrapped
|
||||||
|
}
|
||||||
|
|
||||||
/// Convert a builtin raw pointer to ${a_Self}.
|
/// Convert a builtin raw pointer to ${a_Self}.
|
||||||
@_transparent
|
@_transparent
|
||||||
public init(_ _rawValue: Builtin.RawPointer) {
|
public init(_ _rawValue: Builtin.RawPointer) {
|
||||||
|
|||||||
@@ -261,14 +261,14 @@ extern "C" uint64_t swift_float80ToString(char *Buffer, size_t BufferLength,
|
|||||||
///
|
///
|
||||||
/// \returns Size of character data returned in \c LinePtr, or -1
|
/// \returns Size of character data returned in \c LinePtr, or -1
|
||||||
/// if an error occurred, or EOF was reached.
|
/// if an error occurred, or EOF was reached.
|
||||||
ssize_t swift::swift_stdlib_readLine_stdin(char **LinePtr) {
|
ssize_t swift::swift_stdlib_readLine_stdin(unsigned char **LinePtr) {
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
if (LinePtr == nullptr)
|
if (LinePtr == nullptr)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ssize_t Capacity = 0;
|
ssize_t Capacity = 0;
|
||||||
ssize_t Pos = 0;
|
ssize_t Pos = 0;
|
||||||
char *ReadBuf = nullptr;
|
unsigned char *ReadBuf = nullptr;
|
||||||
|
|
||||||
_lock_file(stdin);
|
_lock_file(stdin);
|
||||||
|
|
||||||
@@ -285,7 +285,8 @@ ssize_t swift::swift_stdlib_readLine_stdin(char **LinePtr) {
|
|||||||
if (Capacity - Pos <= 1) {
|
if (Capacity - Pos <= 1) {
|
||||||
// Capacity changes to 128, 128*2, 128*4, 128*8, ...
|
// Capacity changes to 128, 128*2, 128*4, 128*8, ...
|
||||||
Capacity = Capacity ? Capacity * 2 : 128;
|
Capacity = Capacity ? Capacity * 2 : 128;
|
||||||
char *NextReadBuf = static_cast<char *>(realloc(ReadBuf, Capacity));
|
char *NextReadBuf =
|
||||||
|
static_cast<unsigned char *>(realloc(ReadBuf, Capacity));
|
||||||
if (NextReadBuf == nullptr) {
|
if (NextReadBuf == nullptr) {
|
||||||
if (ReadBuf)
|
if (ReadBuf)
|
||||||
free(ReadBuf);
|
free(ReadBuf);
|
||||||
@@ -308,7 +309,7 @@ ssize_t swift::swift_stdlib_readLine_stdin(char **LinePtr) {
|
|||||||
return Pos;
|
return Pos;
|
||||||
#else
|
#else
|
||||||
size_t Capacity = 0;
|
size_t Capacity = 0;
|
||||||
return getline(LinePtr, &Capacity, stdin);
|
return getline((char **)LinePtr, &Capacity, stdin);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ swift::_swift_stdlib_unicode_compare_utf16_utf16(const uint16_t *LeftString,
|
|||||||
/// ==0 the strings are equal according to their collation.
|
/// ==0 the strings are equal according to their collation.
|
||||||
/// >0 the left string is greater than the right string.
|
/// >0 the left string is greater than the right string.
|
||||||
int32_t
|
int32_t
|
||||||
swift::_swift_stdlib_unicode_compare_utf8_utf16(const char *LeftString,
|
swift::_swift_stdlib_unicode_compare_utf8_utf16(const unsigned char *LeftString,
|
||||||
int32_t LeftLength,
|
int32_t LeftLength,
|
||||||
const uint16_t *RightString,
|
const uint16_t *RightString,
|
||||||
int32_t RightLength) {
|
int32_t RightLength) {
|
||||||
@@ -183,9 +183,9 @@ swift::_swift_stdlib_unicode_compare_utf8_utf16(const char *LeftString,
|
|||||||
/// ==0 the strings are equal according to their collation.
|
/// ==0 the strings are equal according to their collation.
|
||||||
/// >0 the left string is greater than the right string.
|
/// >0 the left string is greater than the right string.
|
||||||
int32_t
|
int32_t
|
||||||
swift::_swift_stdlib_unicode_compare_utf8_utf8(const char *LeftString,
|
swift::_swift_stdlib_unicode_compare_utf8_utf8(const unsigned char *LeftString,
|
||||||
int32_t LeftLength,
|
int32_t LeftLength,
|
||||||
const char *RightString,
|
const unsigned char *RightString,
|
||||||
int32_t RightLength) {
|
int32_t RightLength) {
|
||||||
UCharIterator LeftIterator;
|
UCharIterator LeftIterator;
|
||||||
UCharIterator RightIterator;
|
UCharIterator RightIterator;
|
||||||
@@ -266,7 +266,7 @@ swift::_swift_stdlib_unicode_hash(const uint16_t *Str, int32_t Length) {
|
|||||||
return hashFinish(HashState);
|
return hashFinish(HashState);
|
||||||
}
|
}
|
||||||
|
|
||||||
intptr_t swift::_swift_stdlib_unicode_hash_ascii(const char *Str,
|
intptr_t swift::_swift_stdlib_unicode_hash_ascii(const unsigned char *Str,
|
||||||
int32_t Length) {
|
int32_t Length) {
|
||||||
const ASCIICollation *Table = ASCIICollation::getTable();
|
const ASCIICollation *Table = ASCIICollation::getTable();
|
||||||
intptr_t HashState = HASH_SEED;
|
intptr_t HashState = HASH_SEED;
|
||||||
|
|||||||
@@ -88,9 +88,9 @@ func testScope() {
|
|||||||
objects.withUnsafeMutableBufferPointer {
|
objects.withUnsafeMutableBufferPointer {
|
||||||
// FIXME: Can't elide signature and use $0 here <rdar://problem/17770732>
|
// FIXME: Can't elide signature and use $0 here <rdar://problem/17770732>
|
||||||
(buf: inout UnsafeMutableBufferPointer<Int>) -> () in
|
(buf: inout UnsafeMutableBufferPointer<Int>) -> () in
|
||||||
nsx.getObjects(
|
let objPtr = UnsafeMutableRawPointer(buf.baseAddress!).bindMemory(
|
||||||
UnsafeMutablePointer<AnyObject>(buf.baseAddress!),
|
to: AnyObject.self, capacity: 2)
|
||||||
range: _SwiftNSRange(location: 1, length: 2))
|
nsx.getObjects(objPtr, range: _SwiftNSRange(location: 1, length: 2))
|
||||||
}
|
}
|
||||||
|
|
||||||
// CHECK-NEXT: getObjects yields them at +0: true
|
// CHECK-NEXT: getObjects yields them at +0: true
|
||||||
|
|||||||
@@ -204,7 +204,9 @@ NSStringAPIs.test("init(utf8String:)") {
|
|||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
up[i] = 0
|
up[i] = 0
|
||||||
expectOptionalEqual(s, String(utf8String: UnsafePointer(up)))
|
let cstr = UnsafeMutableRawPointer(up)
|
||||||
|
.bindMemory(to: CChar.self, capacity: 100)
|
||||||
|
expectOptionalEqual(s, String(utf8String: cstr))
|
||||||
up.deallocate(capacity: 100)
|
up.deallocate(capacity: 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -325,19 +325,19 @@ StringTests.test("CompareStringsWithUnpairedSurrogates")
|
|||||||
|
|
||||||
var CStringTests = TestSuite("CStringTests")
|
var CStringTests = TestSuite("CStringTests")
|
||||||
|
|
||||||
func getNullCString() -> UnsafeMutablePointer<CChar>? {
|
func getNullUTF8() -> UnsafeMutablePointer<UInt8>? {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getASCIICString() -> (UnsafeMutablePointer<CChar>, dealloc: () -> ()) {
|
func getASCIIUTF8() -> (UnsafeMutablePointer<UInt8>, dealloc: () -> ()) {
|
||||||
let up = UnsafeMutablePointer<CChar>.allocate(capacity: 100)
|
let up = UnsafeMutablePointer<UInt8>.allocate(capacity: 100)
|
||||||
up[0] = 0x61
|
up[0] = 0x61
|
||||||
up[1] = 0x62
|
up[1] = 0x62
|
||||||
up[2] = 0
|
up[2] = 0
|
||||||
return (up, { up.deallocate(capacity: 100) })
|
return (up, { up.deallocate(capacity: 100) })
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNonASCIICString() -> (UnsafeMutablePointer<CChar>, dealloc: () -> ()) {
|
func getNonASCIIUTF8() -> (UnsafeMutablePointer<UInt8>, dealloc: () -> ()) {
|
||||||
let up = UnsafeMutablePointer<UInt8>.allocate(capacity: 100)
|
let up = UnsafeMutablePointer<UInt8>.allocate(capacity: 100)
|
||||||
up[0] = 0xd0
|
up[0] = 0xd0
|
||||||
up[1] = 0xb0
|
up[1] = 0xb0
|
||||||
@@ -348,7 +348,7 @@ func getNonASCIICString() -> (UnsafeMutablePointer<CChar>, dealloc: () -> ()) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getIllFormedUTF8String1(
|
func getIllFormedUTF8String1(
|
||||||
) -> (UnsafeMutablePointer<CChar>, dealloc: () -> ()) {
|
) -> (UnsafeMutablePointer<UInt8>, dealloc: () -> ()) {
|
||||||
let up = UnsafeMutablePointer<UInt8>.allocate(capacity: 100)
|
let up = UnsafeMutablePointer<UInt8>.allocate(capacity: 100)
|
||||||
up[0] = 0x41
|
up[0] = 0x41
|
||||||
up[1] = 0xed
|
up[1] = 0xed
|
||||||
@@ -360,7 +360,7 @@ func getIllFormedUTF8String1(
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getIllFormedUTF8String2(
|
func getIllFormedUTF8String2(
|
||||||
) -> (UnsafeMutablePointer<CChar>, dealloc: () -> ()) {
|
) -> (UnsafeMutablePointer<UInt8>, dealloc: () -> ()) {
|
||||||
let up = UnsafeMutablePointer<UInt8>.allocate(capacity: 100)
|
let up = UnsafeMutablePointer<UInt8>.allocate(capacity: 100)
|
||||||
up[0] = 0x41
|
up[0] = 0x41
|
||||||
up[0] = 0x41
|
up[0] = 0x41
|
||||||
@@ -376,7 +376,7 @@ func asCCharArray(_ a: [UInt8]) -> [CChar] {
|
|||||||
return a.map { CChar(bitPattern: $0) }
|
return a.map { CChar(bitPattern: $0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
func getCStringLength(_ cString: UnsafePointer<CChar>) -> Int {
|
func getUTF8Length(_ cString: UnsafePointer<UInt8>) -> Int {
|
||||||
var length = 0
|
var length = 0
|
||||||
while cString[length] != 0 {
|
while cString[length] != 0 {
|
||||||
length += 1
|
length += 1
|
||||||
@@ -384,13 +384,13 @@ func getCStringLength(_ cString: UnsafePointer<CChar>) -> Int {
|
|||||||
return length
|
return length
|
||||||
}
|
}
|
||||||
|
|
||||||
func bindAsUTF8(_ cString: UnsafePointer<CChar>) -> UnsafePointer<UInt8> {
|
func bindAsCChar(_ utf8: UnsafePointer<UInt8>) -> UnsafePointer<CChar> {
|
||||||
return UnsafeRawPointer(cString).bindMemory(to: UInt8.self,
|
return UnsafeRawPointer(utf8).bindMemory(to: CChar.self,
|
||||||
capacity: getCStringLength(cString))
|
capacity: getUTF8Length(utf8))
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectEqualCString(_ lhs: UnsafePointer<CChar>,
|
func expectEqualCString(_ lhs: UnsafePointer<UInt8>,
|
||||||
_ rhs: UnsafePointer<CChar>) {
|
_ rhs: UnsafePointer<UInt8>) {
|
||||||
|
|
||||||
var index = 0
|
var index = 0
|
||||||
while lhs[index] != 0 {
|
while lhs[index] != 0 {
|
||||||
@@ -400,18 +400,18 @@ func expectEqualCString(_ lhs: UnsafePointer<CChar>,
|
|||||||
expectEqual(0, rhs[index])
|
expectEqual(0, rhs[index])
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectEqualCString(_ lhs: UnsafePointer<CChar>,
|
func expectEqualCString(_ lhs: UnsafePointer<UInt8>,
|
||||||
_ rhs: ContiguousArray<CChar>) {
|
_ rhs: ContiguousArray<UInt8>) {
|
||||||
rhs.withUnsafeBufferPointer {
|
rhs.withUnsafeBufferPointer {
|
||||||
expectEqualCString(lhs, $0.baseAddress!)
|
expectEqualCString(lhs, $0.baseAddress!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func expectEqualCString(_ lhs: UnsafePointer<CChar>,
|
func expectEqualCString(_ lhs: UnsafePointer<UInt8>,
|
||||||
_ rhs: ContiguousArray<UInt8>) {
|
_ rhs: ContiguousArray<CChar>) {
|
||||||
rhs.withUnsafeBufferPointer {
|
rhs.withUnsafeBufferPointer {
|
||||||
$0.baseAddress!.withMemoryRebound(
|
$0.baseAddress!.withMemoryRebound(
|
||||||
to: CChar.self, capacity: rhs.count) {
|
to: UInt8.self, capacity: rhs.count) {
|
||||||
expectEqualCString(lhs, $0)
|
expectEqualCString(lhs, $0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -419,36 +419,36 @@ func expectEqualCString(_ lhs: UnsafePointer<CChar>,
|
|||||||
|
|
||||||
CStringTests.test("String.init(validatingUTF8:)") {
|
CStringTests.test("String.init(validatingUTF8:)") {
|
||||||
do {
|
do {
|
||||||
let (s, dealloc) = getASCIICString()
|
let (s, dealloc) = getASCIIUTF8()
|
||||||
expectOptionalEqual("ab", String(validatingUTF8: s))
|
expectOptionalEqual("ab", String(validatingUTF8: bindAsCChar(s)))
|
||||||
dealloc()
|
dealloc()
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let (s, dealloc) = getNonASCIICString()
|
let (s, dealloc) = getNonASCIIUTF8()
|
||||||
expectOptionalEqual("аб", String(validatingUTF8: s))
|
expectOptionalEqual("аб", String(validatingUTF8: bindAsCChar(s)))
|
||||||
dealloc()
|
dealloc()
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let (s, dealloc) = getIllFormedUTF8String1()
|
let (s, dealloc) = getIllFormedUTF8String1()
|
||||||
expectEmpty(String(validatingUTF8: s))
|
expectEmpty(String(validatingUTF8: bindAsCChar(s)))
|
||||||
dealloc()
|
dealloc()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CStringTests.test("String(cString:)") {
|
CStringTests.test("String(cString:)") {
|
||||||
do {
|
do {
|
||||||
let (s, dealloc) = getASCIICString()
|
let (s, dealloc) = getASCIIUTF8()
|
||||||
let result = String(cString: s)
|
let result = String(cString: s)
|
||||||
expectEqual("ab", result)
|
expectEqual("ab", result)
|
||||||
let su = bindAsUTF8(s)
|
let su = bindAsCChar(s)
|
||||||
expectEqual("ab", String(cString: su))
|
expectEqual("ab", String(cString: su))
|
||||||
dealloc()
|
dealloc()
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let (s, dealloc) = getNonASCIICString()
|
let (s, dealloc) = getNonASCIIUTF8()
|
||||||
let result = String(cString: s)
|
let result = String(cString: s)
|
||||||
expectEqual("аб", result)
|
expectEqual("аб", result)
|
||||||
let su = bindAsUTF8(s)
|
let su = bindAsCChar(s)
|
||||||
expectEqual("аб", String(cString: su))
|
expectEqual("аб", String(cString: su))
|
||||||
dealloc()
|
dealloc()
|
||||||
}
|
}
|
||||||
@@ -456,7 +456,7 @@ CStringTests.test("String(cString:)") {
|
|||||||
let (s, dealloc) = getIllFormedUTF8String1()
|
let (s, dealloc) = getIllFormedUTF8String1()
|
||||||
let result = String(cString: s)
|
let result = String(cString: s)
|
||||||
expectEqual("\u{41}\u{fffd}\u{fffd}\u{fffd}\u{41}", result)
|
expectEqual("\u{41}\u{fffd}\u{fffd}\u{fffd}\u{41}", result)
|
||||||
let su = bindAsUTF8(s)
|
let su = bindAsCChar(s)
|
||||||
expectEqual("\u{41}\u{fffd}\u{fffd}\u{fffd}\u{41}", String(cString: su))
|
expectEqual("\u{41}\u{fffd}\u{fffd}\u{fffd}\u{41}", String(cString: su))
|
||||||
dealloc()
|
dealloc()
|
||||||
}
|
}
|
||||||
@@ -464,14 +464,14 @@ CStringTests.test("String(cString:)") {
|
|||||||
|
|
||||||
CStringTests.test("String.decodeCString") {
|
CStringTests.test("String.decodeCString") {
|
||||||
do {
|
do {
|
||||||
let s = getNullCString()
|
let s = getNullUTF8()
|
||||||
let result = String.decodeCString(UnsafePointer(s), as: UTF8.self)
|
let result = String.decodeCString(s, as: UTF8.self)
|
||||||
expectEmpty(result)
|
expectEmpty(result)
|
||||||
}
|
}
|
||||||
do { // repairing
|
do { // repairing
|
||||||
let (s, dealloc) = getIllFormedUTF8String1()
|
let (s, dealloc) = getIllFormedUTF8String1()
|
||||||
if let (result, repairsMade) = String.decodeCString(
|
if let (result, repairsMade) = String.decodeCString(
|
||||||
UnsafePointer(s), as: UTF8.self, repairingInvalidCodeUnits: true) {
|
s, as: UTF8.self, repairingInvalidCodeUnits: true) {
|
||||||
expectOptionalEqual("\u{41}\u{fffd}\u{fffd}\u{fffd}\u{41}", result)
|
expectOptionalEqual("\u{41}\u{fffd}\u{fffd}\u{fffd}\u{41}", result)
|
||||||
expectTrue(repairsMade)
|
expectTrue(repairsMade)
|
||||||
} else {
|
} else {
|
||||||
@@ -482,7 +482,7 @@ CStringTests.test("String.decodeCString") {
|
|||||||
do { // non repairing
|
do { // non repairing
|
||||||
let (s, dealloc) = getIllFormedUTF8String1()
|
let (s, dealloc) = getIllFormedUTF8String1()
|
||||||
let result = String.decodeCString(
|
let result = String.decodeCString(
|
||||||
UnsafePointer(s), as: UTF8.self, repairingInvalidCodeUnits: false)
|
s, as: UTF8.self, repairingInvalidCodeUnits: false)
|
||||||
expectEmpty(result)
|
expectEmpty(result)
|
||||||
dealloc()
|
dealloc()
|
||||||
}
|
}
|
||||||
@@ -490,13 +490,13 @@ CStringTests.test("String.decodeCString") {
|
|||||||
|
|
||||||
CStringTests.test("String.utf8CString") {
|
CStringTests.test("String.utf8CString") {
|
||||||
do {
|
do {
|
||||||
let (cstr, dealloc) = getASCIICString()
|
let (cstr, dealloc) = getASCIIUTF8()
|
||||||
let str = String(cString: cstr)
|
let str = String(cString: cstr)
|
||||||
expectEqualCString(cstr, str.utf8CString)
|
expectEqualCString(cstr, str.utf8CString)
|
||||||
dealloc()
|
dealloc()
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
let (cstr, dealloc) = getNonASCIICString()
|
let (cstr, dealloc) = getNonASCIIUTF8()
|
||||||
let str = String(cString: cstr)
|
let str = String(cString: cstr)
|
||||||
expectEqualCString(cstr, str.utf8CString)
|
expectEqualCString(cstr, str.utf8CString)
|
||||||
dealloc()
|
dealloc()
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ class TestUUID : TestUUIDSuper {
|
|||||||
var bytes: [UInt8] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
var bytes: [UInt8] = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
|
||||||
let valFromBytes = bytes.withUnsafeMutableBufferPointer { buffer -> UUID in
|
let valFromBytes = bytes.withUnsafeMutableBufferPointer { buffer -> UUID in
|
||||||
ref.getBytes(buffer.baseAddress)
|
ref.getBytes(buffer.baseAddress)
|
||||||
return UUID(uuid: UnsafePointer<uuid_t>(buffer.baseAddress!).pointee)
|
return UUID(uuid: UnsafeRawPointer(buffer.baseAddress!).load(as: uuid_t.self))
|
||||||
}
|
}
|
||||||
let valFromStr = UUID(uuidString: ref.uuidString)
|
let valFromStr = UUID(uuidString: ref.uuidString)
|
||||||
expectEqual(ref.uuidString, valFromRef.uuidString)
|
expectEqual(ref.uuidString, valFromRef.uuidString)
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ func rdar19835413() {
|
|||||||
f1(&a[i])
|
f1(&a[i])
|
||||||
f1(&a[0])
|
f1(&a[0])
|
||||||
f1(pi)
|
f1(pi)
|
||||||
f1(UnsafeMutablePointer(pi))
|
f1(pi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -70,10 +70,11 @@ func driver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spawn the archiver process.
|
// Spawn the archiver process.
|
||||||
|
let str: StaticString = "-archive"
|
||||||
|
let optStr = UnsafeMutableRawPointer(mutating: str.utf8Start).bindMemory(
|
||||||
|
to: CChar.self, capacity: str.utf8CodeUnitCount)
|
||||||
let archiverArgv: [UnsafeMutablePointer<Int8>?] = [
|
let archiverArgv: [UnsafeMutablePointer<Int8>?] = [
|
||||||
CommandLine.unsafeArgv[0],
|
CommandLine.unsafeArgv[0], optStr, nil
|
||||||
UnsafeMutablePointer(("-archive" as StaticString).utf8Start),
|
|
||||||
nil
|
|
||||||
]
|
]
|
||||||
guard posix_spawn(&archiver, CommandLine.unsafeArgv[0],
|
guard posix_spawn(&archiver, CommandLine.unsafeArgv[0],
|
||||||
&archiverActions, nil,
|
&archiverActions, nil,
|
||||||
@@ -99,11 +100,12 @@ func driver() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Spawn the unarchiver process.
|
// Spawn the unarchiver process.
|
||||||
|
let str = "-unarchive" as StaticString
|
||||||
|
let optStr = UnsafeMutableRawPointer(mutating: str.utf8Start).bindMemory(
|
||||||
|
to: CChar.self, capacity: str.utf8CodeUnitCount)
|
||||||
var unarchiver: pid_t = 0
|
var unarchiver: pid_t = 0
|
||||||
let unarchiverArgv: [UnsafeMutablePointer<Int8>?] = [
|
let unarchiverArgv: [UnsafeMutablePointer<Int8>?] = [
|
||||||
CommandLine.unsafeArgv[0],
|
CommandLine.unsafeArgv[0], optStr, nil
|
||||||
UnsafeMutablePointer(("-unarchive" as StaticString).utf8Start),
|
|
||||||
nil
|
|
||||||
]
|
]
|
||||||
guard posix_spawn(&unarchiver, CommandLine.unsafeArgv[0],
|
guard posix_spawn(&unarchiver, CommandLine.unsafeArgv[0],
|
||||||
&unarchiverActions, nil,
|
&unarchiverActions, nil,
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ autoreleasepool {
|
|||||||
repeat {
|
repeat {
|
||||||
let data = NSData(bytes: [2, 3, 5, 7] as [UInt8], length: 4)
|
let data = NSData(bytes: [2, 3, 5, 7] as [UInt8], length: 4)
|
||||||
hangCanary(data)
|
hangCanary(data)
|
||||||
bytes = UnsafeMutablePointer<UInt8>(data.bytes.assumingMemoryBound(to: UInt8.self))
|
bytes = UnsafeMutablePointer<UInt8>(mutating: data.bytes.assumingMemoryBound(to: UInt8.self))
|
||||||
} while false // CHECK-NOT: died
|
} while false // CHECK-NOT: died
|
||||||
print(bytes[0]) // CHECK: 2
|
print(bytes[0]) // CHECK: 2
|
||||||
print(bytes[1]) // CHECK-NEXT: 3
|
print(bytes[1]) // CHECK-NEXT: 3
|
||||||
@@ -44,7 +44,7 @@ autoreleasepool {
|
|||||||
let data = NSData(bytes: [11, 13, 17, 19] as [UInt8], length: 4)
|
let data = NSData(bytes: [11, 13, 17, 19] as [UInt8], length: 4)
|
||||||
hangCanary(data)
|
hangCanary(data)
|
||||||
let dataAsAny: AnyObject = data
|
let dataAsAny: AnyObject = data
|
||||||
bytes = UnsafeMutablePointer<UInt8>(dataAsAny.bytes!.assumingMemoryBound(to: UInt8.self))
|
bytes = UnsafeMutablePointer<UInt8>(mutating: dataAsAny.bytes!.assumingMemoryBound(to: UInt8.self))
|
||||||
} while false // CHECK-NOT: died
|
} while false // CHECK-NOT: died
|
||||||
print(bytes[0]) // CHECK: 11
|
print(bytes[0]) // CHECK: 11
|
||||||
print(bytes[1]) // CHECK-NEXT: 13
|
print(bytes[1]) // CHECK-NEXT: 13
|
||||||
|
|||||||
@@ -259,10 +259,6 @@ func stringArguments(_ s: String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func pointerConstructor(_ x: UnsafeMutablePointer<Int>) -> UnsafeMutablePointer<Float> {
|
|
||||||
return UnsafeMutablePointer(x)
|
|
||||||
}
|
|
||||||
|
|
||||||
func optionality(_ op: UnsafeMutablePointer<Float>?) {
|
func optionality(_ op: UnsafeMutablePointer<Float>?) {
|
||||||
takesMutableVoidPointer(op)
|
takesMutableVoidPointer(op)
|
||||||
% if not suffix:
|
% if not suffix:
|
||||||
@@ -286,10 +282,10 @@ func genericPointerArithmetic<T>(_ x: UnsafeMutablePointer<T>, i: Int, t: T) ->
|
|||||||
p.initialize(to: t)
|
p.initialize(to: t)
|
||||||
}
|
}
|
||||||
|
|
||||||
func passPointerToClosure(_ f: (UnsafeMutablePointer<Float>) -> Int) -> Int { }
|
func passPointerToClosure(_ f: (UnsafeMutablePointer<Int>) -> Int) -> Int { }
|
||||||
|
|
||||||
func pointerInClosure(_ f: (UnsafeMutablePointer<Int>) -> Int) -> Int {
|
func pointerInClosure(_ f: (UnsafePointer<Int>) -> Int) -> Int {
|
||||||
return passPointerToClosure { f(UnsafeMutablePointer($0)) }
|
return passPointerToClosure { f($0) }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NotEquatable {}
|
struct NotEquatable {}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ struct AddressorAndGet {
|
|||||||
|
|
||||||
subscript(index: Int) -> Int {
|
subscript(index: Int) -> Int {
|
||||||
unsafeAddress { // expected-error {{subscript cannot provide both 'address' and a getter}}
|
unsafeAddress { // expected-error {{subscript cannot provide both 'address' and a getter}}
|
||||||
return UnsafePointer(base)
|
return base
|
||||||
}
|
}
|
||||||
get {
|
get {
|
||||||
return base.get()
|
return base.get()
|
||||||
@@ -85,7 +85,7 @@ struct AddressorAndSet {
|
|||||||
|
|
||||||
subscript(index: Int) -> Int {
|
subscript(index: Int) -> Int {
|
||||||
unsafeAddress {
|
unsafeAddress {
|
||||||
return UnsafePointer(base)
|
return base
|
||||||
}
|
}
|
||||||
set { // expected-error {{subscript cannot provide both 'address' and a setter; use an ordinary getter instead}}
|
set { // expected-error {{subscript cannot provide both 'address' and a setter; use an ordinary getter instead}}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -704,7 +704,8 @@ struct AtomicInitializeARCRefRaceTest : RaceTestWithPerTrialData {
|
|||||||
var _atomicReference: AnyObject? = nil
|
var _atomicReference: AnyObject? = nil
|
||||||
|
|
||||||
var atomicReferencePtr: UnsafeMutablePointer<AnyObject?> {
|
var atomicReferencePtr: UnsafeMutablePointer<AnyObject?> {
|
||||||
return UnsafeMutablePointer(_getUnsafePointerToStoredProperties(self))
|
return _getUnsafePointerToStoredProperties(self).assumingMemoryBound(
|
||||||
|
to: Optional<AnyObject>.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
init() {}
|
init() {}
|
||||||
|
|||||||
@@ -106,25 +106,25 @@ CoreAudioTestSuite.test(
|
|||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("AudioBufferList.sizeInBytes(maximumBuffers: Int)") {
|
CoreAudioTestSuite.test("AudioBufferList.sizeInBytes(maximumBuffers: Int)") {
|
||||||
expectEqual(ablHeaderSize + strideof(AudioBuffer),
|
expectEqual(ablHeaderSize + strideof(AudioBuffer.self),
|
||||||
AudioBufferList.sizeInBytes(maximumBuffers: 1))
|
AudioBufferList.sizeInBytes(maximumBuffers: 1))
|
||||||
expectEqual(ablHeaderSize + 16 * strideof(AudioBuffer),
|
expectEqual(ablHeaderSize + 16 * strideof(AudioBuffer.self),
|
||||||
AudioBufferList.sizeInBytes(maximumBuffers: 16))
|
AudioBufferList.sizeInBytes(maximumBuffers: 16))
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("AudioBufferList.sizeInBytes(maximumBuffers: Int)/trap/count<0") {
|
CoreAudioTestSuite.test("AudioBufferList.sizeInBytes(maximumBuffers: Int)/trap/count<0") {
|
||||||
expectCrashLater()
|
expectCrashLater()
|
||||||
AudioBufferList.sizeInBytes(maximumBuffers: -1)
|
_ = AudioBufferList.sizeInBytes(maximumBuffers: -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("AudioBufferList.sizeInBytes(maximumBuffers: Int)/trap/count==0") {
|
CoreAudioTestSuite.test("AudioBufferList.sizeInBytes(maximumBuffers: Int)/trap/count==0") {
|
||||||
expectCrashLater()
|
expectCrashLater()
|
||||||
AudioBufferList.sizeInBytes(maximumBuffers: -1)
|
_ = AudioBufferList.sizeInBytes(maximumBuffers: -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("AudioBufferList.sizeInBytes(maximumBuffers: Int)/trap/overflow") {
|
CoreAudioTestSuite.test("AudioBufferList.sizeInBytes(maximumBuffers: Int)/trap/overflow") {
|
||||||
expectCrashLater()
|
expectCrashLater()
|
||||||
AudioBufferList.sizeInBytes(maximumBuffers: Int.max)
|
_ = AudioBufferList.sizeInBytes(maximumBuffers: Int.max)
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)") {
|
CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)") {
|
||||||
@@ -142,17 +142,17 @@ CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)") {
|
|||||||
|
|
||||||
CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)/trap/count==0") {
|
CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)/trap/count==0") {
|
||||||
expectCrashLater()
|
expectCrashLater()
|
||||||
AudioBufferList.allocate(maximumBuffers: 0)
|
_ = AudioBufferList.allocate(maximumBuffers: 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)/trap/count<0") {
|
CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)/trap/count<0") {
|
||||||
expectCrashLater()
|
expectCrashLater()
|
||||||
AudioBufferList.allocate(maximumBuffers: -1)
|
_ = AudioBufferList.allocate(maximumBuffers: -1)
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)/trap/overflow") {
|
CoreAudioTestSuite.test("AudioBufferList.allocate(maximumBuffers: Int)/trap/overflow") {
|
||||||
expectCrashLater()
|
expectCrashLater()
|
||||||
AudioBufferList.allocate(maximumBuffers: Int.max)
|
_ = AudioBufferList.allocate(maximumBuffers: Int.max)
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer/AssociatedTypes") {
|
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer/AssociatedTypes") {
|
||||||
@@ -201,28 +201,36 @@ CoreAudioTestSuite.test(
|
|||||||
|
|
||||||
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.count") {
|
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.count") {
|
||||||
let sizeInBytes = AudioBufferList.sizeInBytes(maximumBuffers: 16)
|
let sizeInBytes = AudioBufferList.sizeInBytes(maximumBuffers: 16)
|
||||||
let ablPtr = UnsafeMutablePointer<AudioBufferList>(
|
let rawPtr = UnsafeMutableRawPointer.allocate(
|
||||||
UnsafeMutablePointer<UInt8>.allocate(capacity: sizeInBytes))
|
bytes: sizeInBytes, alignedTo: alignof(AudioBufferList.self))
|
||||||
|
let ablPtr = rawPtr.bindMemory(to: AudioBufferList.self,
|
||||||
|
capacity: sizeInBytes / strideof(AudioBufferList.self))
|
||||||
|
|
||||||
// It is important that 'ablPtrWrapper' is a 'let'. We are verifying that
|
// It is important that 'ablPtrWrapper' is a 'let'. We are verifying that
|
||||||
// the 'count' property has a nonmutating setter.
|
// the 'count' property has a nonmutating setter.
|
||||||
let ablPtrWrapper = UnsafeMutableAudioBufferListPointer(ablPtr)
|
let ablPtrWrapper = UnsafeMutableAudioBufferListPointer(ablPtr)
|
||||||
|
|
||||||
// Test getter.
|
// Test getter.
|
||||||
UnsafeMutablePointer<UInt32>(ablPtr).pointee = 0x1234_5678
|
rawPtr.storeBytes(of: 0x1234_5678, as: UInt32.self)
|
||||||
expectEqual(0x1234_5678, ablPtrWrapper.count)
|
expectEqual(0x1234_5678, ablPtrWrapper.count)
|
||||||
|
|
||||||
// Test setter.
|
// Test setter.
|
||||||
ablPtrWrapper.count = 0x7765_4321
|
ablPtrWrapper.count = 0x7765_4321
|
||||||
expectEqual(0x7765_4321, UnsafeMutablePointer<UInt32>(ablPtr).pointee)
|
expectEqual(0x7765_4321, rawPtr.load(as: UInt32.self))
|
||||||
|
|
||||||
ablPtr.deallocate(capacity: sizeInBytes)
|
rawPtr.deallocate(
|
||||||
|
bytes: sizeInBytes, alignedTo: alignof(AudioBufferList.self))
|
||||||
}
|
}
|
||||||
|
|
||||||
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.subscript(_: Int)") {
|
CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.subscript(_: Int)") {
|
||||||
let sizeInBytes = AudioBufferList.sizeInBytes(maximumBuffers: 16)
|
let sizeInBytes = AudioBufferList.sizeInBytes(maximumBuffers: 16)
|
||||||
let ablPtr = UnsafeMutablePointer<AudioBufferList>(
|
|
||||||
UnsafeMutablePointer<UInt8>.allocate(capacity: sizeInBytes))
|
let rawPtr = UnsafeMutableRawPointer.allocate(
|
||||||
|
bytes: sizeInBytes, alignedTo: 1)
|
||||||
|
|
||||||
|
let ablPtr = rawPtr.bindMemory(
|
||||||
|
to: AudioBufferList.self,
|
||||||
|
capacity: sizeInBytes / sizeof(AudioBufferList.self))
|
||||||
|
|
||||||
// It is important that 'ablPtrWrapper' is a 'let'. We are verifying that
|
// It is important that 'ablPtrWrapper' is a 'let'. We are verifying that
|
||||||
// the subscript has a nonmutating setter.
|
// the subscript has a nonmutating setter.
|
||||||
@@ -234,9 +242,9 @@ CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.subscript(_: Int)")
|
|||||||
mNumberChannels: 2, mDataByteSize: 1024,
|
mNumberChannels: 2, mDataByteSize: 1024,
|
||||||
mData: UnsafeMutableRawPointer(bitPattern: 0x1234_5678))
|
mData: UnsafeMutableRawPointer(bitPattern: 0x1234_5678))
|
||||||
|
|
||||||
UnsafeMutablePointer<AudioBuffer>(
|
let bufPtr = (rawPtr + ablHeaderSize).assumingMemoryBound(
|
||||||
UnsafeMutablePointer<UInt8>(ablPtr) + ablHeaderSize
|
to: AudioBuffer.self)
|
||||||
).pointee = audioBuffer
|
bufPtr.pointee = audioBuffer
|
||||||
ablPtrWrapper.count = 1
|
ablPtrWrapper.count = 1
|
||||||
|
|
||||||
expectEqual(2, ablPtrWrapper[0].mNumberChannels)
|
expectEqual(2, ablPtrWrapper[0].mNumberChannels)
|
||||||
@@ -253,8 +261,8 @@ CoreAudioTestSuite.test("UnsafeMutableAudioBufferListPointer.subscript(_: Int)")
|
|||||||
ablPtrWrapper.count = 2
|
ablPtrWrapper.count = 2
|
||||||
ablPtrWrapper[1] = audioBuffer
|
ablPtrWrapper[1] = audioBuffer
|
||||||
|
|
||||||
let audioBufferPtr = UnsafeMutablePointer<AudioBuffer>(
|
let audioBufferPtr = (rawPtr + ablHeaderSize).assumingMemoryBound(
|
||||||
UnsafeMutablePointer<UInt8>(ablPtr) + ablHeaderSize) + 1
|
to: AudioBuffer.self) + 1
|
||||||
expectEqual(5, audioBufferPtr.pointee.mNumberChannels)
|
expectEqual(5, audioBufferPtr.pointee.mNumberChannels)
|
||||||
expectEqual(256, audioBufferPtr.pointee.mDataByteSize)
|
expectEqual(256, audioBufferPtr.pointee.mDataByteSize)
|
||||||
expectEqual(audioBuffer.mData, audioBufferPtr.pointee.mData)
|
expectEqual(audioBuffer.mData, audioBufferPtr.pointee.mData)
|
||||||
|
|||||||
@@ -190,7 +190,10 @@ func nsArrayOfStrings() -> Array<NSString> {
|
|||||||
let src: ContiguousArray<NSString> = ["foo", "bar", "baz"]
|
let src: ContiguousArray<NSString> = ["foo", "bar", "baz"]
|
||||||
|
|
||||||
return src.withUnsafeBufferPointer {
|
return src.withUnsafeBufferPointer {
|
||||||
let ns = NSArray(objects: UnsafePointer($0.baseAddress!), count: $0.count)
|
let ns = NSArray(
|
||||||
|
objects: unsafeBitCast($0.baseAddress!,
|
||||||
|
to: UnsafeMutablePointer<AnyObject>.self),
|
||||||
|
count: $0.count)
|
||||||
return ns as! [NSString]
|
return ns as! [NSString]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,20 +104,16 @@ import SwiftShims
|
|||||||
//
|
//
|
||||||
|
|
||||||
func allocBytes(count: Int, alignment: Int)
|
func allocBytes(count: Int, alignment: Int)
|
||||||
-> UnsafeMutablePointer<UInt8> {
|
-> UnsafeMutableRawPointer {
|
||||||
return UnsafeMutablePointer(
|
return UnsafeMutableRawPointer.allocate(bytes: count, alignedTo: alignment)
|
||||||
Builtin.allocRaw(count._builtinWordValue, alignment._builtinWordValue))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func deallocBytes(
|
func deallocBytes(
|
||||||
_ pointer: UnsafeMutablePointer<UInt8>,
|
_ pointer: UnsafeMutableRawPointer,
|
||||||
byteCount: Int,
|
byteCount: Int,
|
||||||
alignment: Int
|
alignment: Int
|
||||||
) {
|
) {
|
||||||
Builtin.deallocRaw(
|
pointer.deallocate(bytes: byteCount, alignedTo: alignment)
|
||||||
pointer._rawValue,
|
|
||||||
byteCount._builtinWordValue,
|
|
||||||
alignment._builtinWordValue)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func _swift_stdlib_atomicStoreInt(
|
func _swift_stdlib_atomicStoreInt(
|
||||||
@@ -125,7 +121,7 @@ func _swift_stdlib_atomicStoreInt(
|
|||||||
desired: Int) {
|
desired: Int) {
|
||||||
#if arch(x86_64)
|
#if arch(x86_64)
|
||||||
return _swift_stdlib_atomicStoreUInt64(
|
return _swift_stdlib_atomicStoreUInt64(
|
||||||
object: UnsafeMutablePointer(target),
|
object: unsafeBitCast(target, to: UnsafeMutablePointer<UInt64>.self),
|
||||||
desired: UInt64(UInt(bitPattern: desired)))
|
desired: UInt64(UInt(bitPattern: desired)))
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@@ -357,10 +353,10 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
|
|||||||
return _valueVectorOffset(layout: layout) + _valueVectorSize(layout: layout)
|
return _valueVectorOffset(layout: layout) + _valueVectorSize(layout: layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _nodePointer: UnsafeMutablePointer<UInt8>
|
var _nodePointer: UnsafeMutableRawPointer
|
||||||
|
|
||||||
var _referenceCountPointer: UnsafeMutablePointer<Int> {
|
var _referenceCountPointer: UnsafeMutablePointer<Int> {
|
||||||
return UnsafeMutablePointer(_nodePointer)
|
return _nodePointer.assumingMemoryBound(to: Int.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
var layoutParameters: _PVSparseVectorNodeLayoutParameters {
|
var layoutParameters: _PVSparseVectorNodeLayoutParameters {
|
||||||
@@ -403,23 +399,23 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
|
|||||||
|
|
||||||
var childNodePopulationBitmap: _Int32Bitmap {
|
var childNodePopulationBitmap: _Int32Bitmap {
|
||||||
unsafeAddress {
|
unsafeAddress {
|
||||||
return UnsafePointer(
|
return UnsafePointer((_nodePointer + _Self._childNodePopulationBitmapOffset)
|
||||||
_nodePointer + _Self._childNodePopulationBitmapOffset)
|
.assumingMemoryBound(to: _Int32Bitmap.self))
|
||||||
}
|
}
|
||||||
nonmutating unsafeMutableAddress {
|
nonmutating unsafeMutableAddress {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._childNodePopulationBitmapOffset)
|
||||||
_nodePointer + _Self._childNodePopulationBitmapOffset)
|
.assumingMemoryBound(to: _Int32Bitmap.self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyPopulationBitmap: _Int32Bitmap {
|
var keyPopulationBitmap: _Int32Bitmap {
|
||||||
unsafeAddress {
|
unsafeAddress {
|
||||||
return UnsafePointer(
|
return UnsafePointer((_nodePointer + _Self._keyPopulationBitmapOffset)
|
||||||
_nodePointer + _Self._keyPopulationBitmapOffset)
|
.assumingMemoryBound(to: _Int32Bitmap.self))
|
||||||
}
|
}
|
||||||
nonmutating unsafeMutableAddress {
|
nonmutating unsafeMutableAddress {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._keyPopulationBitmapOffset)
|
||||||
_nodePointer + _Self._keyPopulationBitmapOffset)
|
.assumingMemoryBound(to: _Int32Bitmap.self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,8 +428,8 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
|
|||||||
}
|
}
|
||||||
|
|
||||||
var _childNodeVector: UnsafeMutablePointer<_PVAnyNodePointer<Key, Value>?> {
|
var _childNodeVector: UnsafeMutablePointer<_PVAnyNodePointer<Key, Value>?> {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._childNodeVectorOffset)
|
||||||
_nodePointer + _Self._childNodeVectorOffset)
|
.assumingMemoryBound(to: Optional<_PVAnyNodePointer<Key, Value>>.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
var childNodes: UnsafeMutableBufferPointer<_PVAnyNodePointer<Key, Value>?> {
|
var childNodes: UnsafeMutableBufferPointer<_PVAnyNodePointer<Key, Value>?> {
|
||||||
@@ -444,17 +440,17 @@ struct _PVSparseVectorNodePointer<Key : Hashable, Value>
|
|||||||
|
|
||||||
func _keyVector(layout: _PVSparseVectorNodeLayoutParameters)
|
func _keyVector(layout: _PVSparseVectorNodeLayoutParameters)
|
||||||
-> UnsafeMutablePointer<Key> {
|
-> UnsafeMutablePointer<Key> {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._keyVectorOffset(layout: layout))
|
||||||
_nodePointer + _Self._keyVectorOffset(layout: layout))
|
.assumingMemoryBound(to: Key.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _valueVector(layout: _PVSparseVectorNodeLayoutParameters)
|
func _valueVector(layout: _PVSparseVectorNodeLayoutParameters)
|
||||||
-> UnsafeMutablePointer<Value> {
|
-> UnsafeMutablePointer<Value> {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._valueVectorOffset(layout: layout))
|
||||||
_nodePointer + _Self._valueVectorOffset(layout: layout))
|
.assumingMemoryBound(to: Value.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(_nodePointer: UnsafeMutablePointer<UInt8>) {
|
init(_nodePointer: UnsafeMutableRawPointer) {
|
||||||
self._nodePointer = _nodePointer
|
self._nodePointer = _nodePointer
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1025,10 +1021,10 @@ struct _PVArrayNodePointer<Key : Hashable, Value>
|
|||||||
return _valueArrayOffset + _valueArraySize
|
return _valueArrayOffset + _valueArraySize
|
||||||
}
|
}
|
||||||
|
|
||||||
var _nodePointer: UnsafeMutablePointer<UInt8>
|
var _nodePointer: UnsafeMutableRawPointer
|
||||||
|
|
||||||
var _referenceCountPointer: UnsafeMutablePointer<Int> {
|
var _referenceCountPointer: UnsafeMutablePointer<Int> {
|
||||||
return UnsafeMutablePointer(_nodePointer)
|
return _nodePointer.assumingMemoryBound(to: Int.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func retain() {
|
func retain() {
|
||||||
@@ -1049,14 +1045,14 @@ struct _PVArrayNodePointer<Key : Hashable, Value>
|
|||||||
|
|
||||||
func dealloc() {
|
func dealloc() {
|
||||||
for i in childNodePopulationBitmap.setBitIndices {
|
for i in childNodePopulationBitmap.setBitIndices {
|
||||||
UnsafeMutablePointer<_PVAnyNodePointer<Key, Value>>(
|
(_childNodeOrKeyArray + _Self._childNodeOrKeyStride * i)
|
||||||
_childNodeOrKeyArray + _Self._childNodeOrKeyStride * i)
|
.assumingMemoryBound(to: _PVAnyNodePointer<Key, Value>.self)
|
||||||
.pointee.release()
|
.pointee.release()
|
||||||
}
|
}
|
||||||
if !_isPOD(Key.self) {
|
if !_isPOD(Key.self) {
|
||||||
for i in keyPopulationBitmap.setBitIndices {
|
for i in keyPopulationBitmap.setBitIndices {
|
||||||
UnsafeMutablePointer<Key>(
|
(_childNodeOrKeyArray + _Self._childNodeOrKeyStride * i)
|
||||||
_childNodeOrKeyArray + _Self._childNodeOrKeyStride * i)
|
.assumingMemoryBound(to: Key.self)
|
||||||
.deinitialize()
|
.deinitialize()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1076,23 +1072,23 @@ struct _PVArrayNodePointer<Key : Hashable, Value>
|
|||||||
|
|
||||||
var childNodePopulationBitmap: _Int32Bitmap {
|
var childNodePopulationBitmap: _Int32Bitmap {
|
||||||
unsafeAddress {
|
unsafeAddress {
|
||||||
return UnsafePointer(
|
return UnsafePointer((_nodePointer + _Self._childNodePopulationBitmapOffset)
|
||||||
_nodePointer + _Self._childNodePopulationBitmapOffset)
|
.assumingMemoryBound(to: _Int32Bitmap.self))
|
||||||
}
|
}
|
||||||
nonmutating unsafeMutableAddress {
|
nonmutating unsafeMutableAddress {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._childNodePopulationBitmapOffset)
|
||||||
_nodePointer + _Self._childNodePopulationBitmapOffset)
|
.assumingMemoryBound(to: _Int32Bitmap.self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var keyPopulationBitmap: _Int32Bitmap {
|
var keyPopulationBitmap: _Int32Bitmap {
|
||||||
unsafeAddress {
|
unsafeAddress {
|
||||||
return UnsafePointer(
|
return UnsafePointer((_nodePointer + _Self._keyPopulationBitmapOffset)
|
||||||
_nodePointer + _Self._keyPopulationBitmapOffset)
|
.assumingMemoryBound(to: _Int32Bitmap.self))
|
||||||
}
|
}
|
||||||
nonmutating unsafeMutableAddress {
|
nonmutating unsafeMutableAddress {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._keyPopulationBitmapOffset)
|
||||||
_nodePointer + _Self._keyPopulationBitmapOffset)
|
.assumingMemoryBound(to: _Int32Bitmap.self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1104,17 +1100,16 @@ struct _PVArrayNodePointer<Key : Hashable, Value>
|
|||||||
return keyPopulationBitmap.setBitCount
|
return keyPopulationBitmap.setBitCount
|
||||||
}
|
}
|
||||||
|
|
||||||
var _childNodeOrKeyArray: UnsafeMutablePointer<UInt8> {
|
var _childNodeOrKeyArray: UnsafeMutableRawPointer {
|
||||||
return UnsafeMutablePointer(
|
return _nodePointer + _Self._childNodeOrKeyArrayOffset
|
||||||
_nodePointer + _Self._childNodeOrKeyArrayOffset)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _valueArray: UnsafeMutablePointer<Value> {
|
var _valueArray: UnsafeMutablePointer<Value> {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._valueArrayOffset)
|
||||||
_nodePointer + _Self._valueArrayOffset)
|
.assumingMemoryBound(to: Value.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(_nodePointer: UnsafeMutablePointer<UInt8>) {
|
init(_nodePointer: UnsafeMutableRawPointer) {
|
||||||
self._nodePointer = _nodePointer
|
self._nodePointer = _nodePointer
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1138,9 +1133,8 @@ struct _PVArrayNodePointer<Key : Hashable, Value>
|
|||||||
precondition(!childNodePopulationBitmap[i]) // sanity check
|
precondition(!childNodePopulationBitmap[i]) // sanity check
|
||||||
precondition(!keyPopulationBitmap[i]) // sanity check
|
precondition(!keyPopulationBitmap[i]) // sanity check
|
||||||
|
|
||||||
UnsafeMutablePointer<Key>(
|
(_childNodeOrKeyArray + _Self._childNodeOrKeyStride * i)
|
||||||
_childNodeOrKeyArray + _Self._childNodeOrKeyStride * i)
|
.initializeMemory(as: Key.self, to: key)
|
||||||
.initialize(to: key)
|
|
||||||
(_valueArray + i).initialize(to: value)
|
(_valueArray + i).initialize(to: value)
|
||||||
|
|
||||||
keyPopulationBitmap[i] = true
|
keyPopulationBitmap[i] = true
|
||||||
@@ -1242,10 +1236,10 @@ struct _PVCollisionNodePointer<Key : Hashable, Value>
|
|||||||
return _valueArrayOffset(layout: layout) + _valueArraySize(layout: layout)
|
return _valueArrayOffset(layout: layout) + _valueArraySize(layout: layout)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _nodePointer: UnsafeMutablePointer<UInt8>
|
var _nodePointer: UnsafeMutableRawPointer
|
||||||
|
|
||||||
var _referenceCountPointer: UnsafeMutablePointer<Int> {
|
var _referenceCountPointer: UnsafeMutablePointer<Int> {
|
||||||
return UnsafeMutablePointer(_nodePointer)
|
return _nodePointer.assumingMemoryBound(to: Int.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
var layoutParameters: _PVCollisionNodePointerLayoutParameters {
|
var layoutParameters: _PVCollisionNodePointerLayoutParameters {
|
||||||
@@ -1284,25 +1278,27 @@ struct _PVCollisionNodePointer<Key : Hashable, Value>
|
|||||||
|
|
||||||
var keyCount: Int {
|
var keyCount: Int {
|
||||||
unsafeAddress {
|
unsafeAddress {
|
||||||
return UnsafePointer(_nodePointer + _Self._countOffset)
|
return UnsafePointer((_nodePointer + _Self._countOffset)
|
||||||
|
.assumingMemoryBound(to: Int.self))
|
||||||
}
|
}
|
||||||
nonmutating unsafeMutableAddress {
|
nonmutating unsafeMutableAddress {
|
||||||
return UnsafeMutablePointer(_nodePointer + _Self._countOffset)
|
return (_nodePointer + _Self._countOffset)
|
||||||
|
.assumingMemoryBound(to: Int.self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var _keyArray: UnsafeMutablePointer<Key> {
|
var _keyArray: UnsafeMutablePointer<Key> {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._keyArrayOffset)
|
||||||
_nodePointer + _Self._keyArrayOffset)
|
.assumingMemoryBound(to: Key.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
func _valueArray(layout: _PVCollisionNodePointerLayoutParameters)
|
func _valueArray(layout: _PVCollisionNodePointerLayoutParameters)
|
||||||
-> UnsafeMutablePointer<Value> {
|
-> UnsafeMutablePointer<Value> {
|
||||||
return UnsafeMutablePointer(
|
return (_nodePointer + _Self._valueArrayOffset(layout: layout))
|
||||||
_nodePointer + _Self._valueArrayOffset(layout: layout))
|
.assumingMemoryBound(to: Value.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
init(_nodePointer: UnsafeMutablePointer<UInt8>) {
|
init(_nodePointer: UnsafeMutableRawPointer) {
|
||||||
self._nodePointer = _nodePointer
|
self._nodePointer = _nodePointer
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1486,9 +1482,9 @@ struct _PVCollisionNodePointer<Key : Hashable, Value>
|
|||||||
struct _PVAnyNodePointer<Key : Hashable, Value>
|
struct _PVAnyNodePointer<Key : Hashable, Value>
|
||||||
: CustomReflectable, Equatable {
|
: CustomReflectable, Equatable {
|
||||||
|
|
||||||
let taggedPointer: UnsafeMutablePointer<UInt8>
|
let taggedPointer: UnsafeMutableRawPointer
|
||||||
|
|
||||||
init(taggedPointer: UnsafeMutablePointer<UInt8>) {
|
init(taggedPointer: UnsafeMutableRawPointer) {
|
||||||
self.taggedPointer = taggedPointer
|
self.taggedPointer = taggedPointer
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1501,14 +1497,14 @@ struct _PVAnyNodePointer<Key : Hashable, Value>
|
|||||||
init(_ arrayNode: _PVArrayNodePointer<Key, Value>) {
|
init(_ arrayNode: _PVArrayNodePointer<Key, Value>) {
|
||||||
precondition(
|
precondition(
|
||||||
Int(bitPattern: arrayNode._nodePointer) & 0x3 == 0) // sanity check
|
Int(bitPattern: arrayNode._nodePointer) & 0x3 == 0) // sanity check
|
||||||
self.taggedPointer = UnsafeMutablePointer(bitPattern:
|
self.taggedPointer = UnsafeMutableRawPointer(bitPattern:
|
||||||
Int(bitPattern: arrayNode._nodePointer) | 1)!
|
Int(bitPattern: arrayNode._nodePointer) | 1)!
|
||||||
}
|
}
|
||||||
|
|
||||||
init(_ collisionNode: _PVCollisionNodePointer<Key, Value>) {
|
init(_ collisionNode: _PVCollisionNodePointer<Key, Value>) {
|
||||||
precondition(
|
precondition(
|
||||||
Int(bitPattern: collisionNode._nodePointer) & 0x3 == 0) // sanity check
|
Int(bitPattern: collisionNode._nodePointer) & 0x3 == 0) // sanity check
|
||||||
self.taggedPointer = UnsafeMutablePointer(bitPattern:
|
self.taggedPointer = UnsafeMutableRawPointer(bitPattern:
|
||||||
Int(bitPattern: collisionNode._nodePointer) | 2)!
|
Int(bitPattern: collisionNode._nodePointer) | 2)!
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1516,13 +1512,13 @@ struct _PVAnyNodePointer<Key : Hashable, Value>
|
|||||||
return Int(bitPattern: taggedPointer) & 0x3
|
return Int(bitPattern: taggedPointer) & 0x3
|
||||||
}
|
}
|
||||||
|
|
||||||
var _untaggedPointer: UnsafeMutablePointer<UInt8> {
|
var _untaggedPointer: UnsafeMutableRawPointer {
|
||||||
return UnsafeMutablePointer(bitPattern:
|
return UnsafeMutableRawPointer(bitPattern:
|
||||||
Int(bitPattern: taggedPointer) & ~0x3)!
|
Int(bitPattern: taggedPointer) & ~0x3)!
|
||||||
}
|
}
|
||||||
|
|
||||||
var _referenceCountPointer: UnsafeMutablePointer<Int> {
|
var _referenceCountPointer: UnsafeMutablePointer<Int> {
|
||||||
return UnsafeMutablePointer(_untaggedPointer)
|
return _untaggedPointer.assumingMemoryBound(to: Int.self)
|
||||||
}
|
}
|
||||||
|
|
||||||
var asSparseVectorNode: _PVSparseVectorNodePointer<Key, Value> {
|
var asSparseVectorNode: _PVSparseVectorNodePointer<Key, Value> {
|
||||||
|
|||||||
Reference in New Issue
Block a user