Skip to content

Foundation: make some functions more visible #3144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Sources/Foundation/NSCharacterSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ fileprivate extension String {

open class NSCharacterSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
typealias CFType = CFCharacterSet
private var _base = _CFInfo(typeID: CFCharacterSetGetTypeID())
private var _hashValue = UInt(0) // CFHashCode
private var _buffer: UnsafeMutableRawPointer? = nil
private var _length = Int(0) // CFIndex
private var _annex: UnsafeMutableRawPointer? = nil
internal var _base = _CFInfo(typeID: CFCharacterSetGetTypeID())
internal var _hashValue = UInt(0) // CFHashCode
internal var _buffer: UnsafeMutableRawPointer? = nil
internal var _length = Int(0) // CFIndex
internal var _annex: UnsafeMutableRawPointer? = nil

internal var _cfObject: CFType {
return unsafeBitCast(self, to: CFType.self)
Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/NSCoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ open class NSCoder : NSObject {
_hasFailed = true
}

internal private(set) var _hasFailed = false
internal var _hasFailed = false

open internal(set) var decodingFailurePolicy: NSCoder.DecodingFailurePolicy = .raiseException

Expand Down
18 changes: 9 additions & 9 deletions Sources/Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension NSData {
}
}

private final class _NSDataDeallocator {
internal final class _NSDataDeallocator {
var handler: (UnsafeMutableRawPointer, Int) -> Void = {_,_ in }
}

Expand All @@ -70,12 +70,12 @@ private let __kCFDontDeallocate: CFOptionFlags = 4
open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
typealias CFType = CFData

private var _base = _CFInfo(typeID: CFDataGetTypeID())
private var _length: Int = 0 // CFIndex
private var _capacity: Int = 0 // CFIndex
private var _deallocator: UnsafeMutableRawPointer? = nil // for CF only
private var _deallocHandler: _NSDataDeallocator? = _NSDataDeallocator() // for Swift
private var _bytes: UnsafeMutablePointer<UInt8>? = nil
internal var _base = _CFInfo(typeID: CFDataGetTypeID())
internal var _length: Int = 0 // CFIndex
internal var _capacity: Int = 0 // CFIndex
internal var _deallocator: UnsafeMutableRawPointer? = nil // for CF only
internal var _deallocHandler: _NSDataDeallocator? = _NSDataDeallocator() // for Swift
internal var _bytes: UnsafeMutablePointer<UInt8>? = nil

internal final var _cfObject: CFType {
if type(of: self) === NSData.self || type(of: self) === NSMutableData.self {
Expand Down Expand Up @@ -112,7 +112,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
}
}

fileprivate init(bytes: UnsafeMutableRawPointer?, length: Int, copy: Bool = false, deallocator: ((UnsafeMutableRawPointer, Int) -> Void)? = nil) {
internal init(bytes: UnsafeMutableRawPointer?, length: Int, copy: Bool = false, deallocator: ((UnsafeMutableRawPointer, Int) -> Void)? = nil) {
super.init()
_init(bytes: bytes, length: length, copy: copy, deallocator: deallocator)
}
Expand Down Expand Up @@ -340,7 +340,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
return NSMutableData(bytes: UnsafeMutableRawPointer(mutating: bytes), length: length, copy: true, deallocator: nil)
}

private func byteDescription(limit: Int? = nil) -> String {
internal func byteDescription(limit: Int? = nil) -> String {
var s = ""
var i = 0
while i < self.length {
Expand Down
43 changes: 22 additions & 21 deletions Sources/Foundation/NSDictionary.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@
import Dispatch
#endif

fileprivate func getDescription(of object: Any) -> String? {
switch object {
case let nsArray as NSArray:
return nsArray.description(withLocale: nil, indent: 1)
case let nsDecimalNumber as NSDecimalNumber:
return nsDecimalNumber.description(withLocale: nil)
case let nsDate as NSDate:
return nsDate.description(with: nil)
case let nsOrderedSet as NSOrderedSet:
return nsOrderedSet.description(withLocale: nil)
case let nsSet as NSSet:
return nsSet.description(withLocale: nil)
case let nsDictionary as NSDictionary:
return nsDictionary.description(withLocale: nil)
case let hashableObject as Dictionary<AnyHashable, Any>:
return hashableObject._nsObject.description(withLocale: nil, indent: 1)
default:
return nil
}
}


open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCoding, ExpressibleByDictionaryLiteral {
private let _cfinfo = _CFInfo(typeID: CFDictionaryGetTypeID())
internal var _storage: [NSObject: AnyObject]
Expand Down Expand Up @@ -299,27 +321,6 @@ open class NSDictionary : NSObject, NSCopying, NSMutableCopying, NSSecureCoding,
return description(withLocale: nil)
}

private func getDescription(of object: Any) -> String? {
switch object {
case let nsArray as NSArray:
return nsArray.description(withLocale: nil, indent: 1)
case let nsDecimalNumber as NSDecimalNumber:
return nsDecimalNumber.description(withLocale: nil)
case let nsDate as NSDate:
return nsDate.description(with: nil)
case let nsOrderedSet as NSOrderedSet:
return nsOrderedSet.description(withLocale: nil)
case let nsSet as NSSet:
return nsSet.description(withLocale: nil)
case let nsDictionary as NSDictionary:
return nsDictionary.description(withLocale: nil)
case let hashableObject as Dictionary<AnyHashable, Any>:
return hashableObject._nsObject.description(withLocale: nil, indent: 1)
default:
return nil
}
}

open var descriptionInStringsFileFormat: String {
var lines = [String]()
for key in self.allKeys {
Expand Down
8 changes: 4 additions & 4 deletions Sources/Foundation/NSNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ extension NSNumber : ExpressibleByFloatLiteral, ExpressibleByIntegerLiteral, Exp

}

private struct CFSInt128Struct {
internal struct CFSInt128Struct {
var high: Int64
var low: UInt64
}
Expand All @@ -606,8 +606,8 @@ fileprivate func cast<T, U>(_ t: T) -> U {
open class NSNumber : NSValue {
typealias CFType = CFNumber
// This layout MUST be the same as CFNumber so that they are bridgeable
private var _base = _CFInfo(typeID: CFNumberGetTypeID())
private var _pad: UInt64 = 0
internal var _base = _CFInfo(typeID: CFNumberGetTypeID())
internal var _pad: UInt64 = 0

internal final var _cfObject: CFType {
return unsafeBitCast(self, to: CFType.self)
Expand Down Expand Up @@ -903,7 +903,7 @@ open class NSNumber : NSValue {
return .init(truncatingIfNeeded: value.low)
}

private var int128Value: CFSInt128Struct {
internal var int128Value: CFSInt128Struct {
var value = CFSInt128Struct(high: 0, low: 0)
CFNumberGetValue(_cfObject, kCFNumberSInt128Type, &value)
return value
Expand Down
2 changes: 1 addition & 1 deletion Sources/Foundation/NSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ open class NSObject : NSObjectProtocol, Equatable, Hashable {
// Please note:
// the following methods are not overridable in swift-corelibs-foundation.

private class var nsObjectSuperclass: NSObject.Type? {
internal class var nsObjectSuperclass: NSObject.Type? {
// Pretend that {Swift,}Foundation.NSObject is the top of the class hierarchy.
// On Darwin, avoids dipping into the class hierarchy that exists above this class,
// which is ultimately rooted in the ObjC NSObject class.
Expand Down
20 changes: 10 additions & 10 deletions Sources/Foundation/Progress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ import Dispatch
*/
open class Progress : NSObject {

private weak var _parent : Progress?
private var _children : Set<Progress>
private var _selfFraction : _ProgressFraction
private var _childFraction : _ProgressFraction
private var _userInfo : [ProgressUserInfoKey : Any]
internal weak var _parent : Progress?
internal var _children : Set<Progress>
internal var _selfFraction : _ProgressFraction
internal var _childFraction : _ProgressFraction
internal var _userInfo : [ProgressUserInfoKey : Any]

// This is set once, but after initialization
private var _portionOfParent : Int64
internal var _portionOfParent : Int64

static private var _tsdKey = "_Foundation_CurrentProgressKey"

Expand Down Expand Up @@ -167,7 +167,7 @@ open class Progress : NSObject {
}
}

private func _setParent(_ parent: Progress, portion: Int64) {
internal func _setParent(_ parent: Progress, portion: Int64) {
_parent = parent
_portionOfParent = portion

Expand Down Expand Up @@ -416,18 +416,18 @@ open class Progress : NSObject {
// MARK: -
// MARK: Implementation of unit counts

private var _overallFraction : _ProgressFraction {
internal var _overallFraction : _ProgressFraction {
return _selfFraction + _childFraction
}

private func _addCompletedUnitCount(_ unitCount : Int64) {
internal func _addCompletedUnitCount(_ unitCount : Int64) {
let old = _overallFraction
_selfFraction.completed += unitCount
let new = _overallFraction
_updateFractionCompleted(from: old, to: new)
}

private func _updateFractionCompleted(from: _ProgressFraction, to: _ProgressFraction) {
internal func _updateFractionCompleted(from: _ProgressFraction, to: _ProgressFraction) {
if from != to {
_parent?._updateChild(self, from: from, to: to, portion: _portionOfParent)
}
Expand Down
26 changes: 13 additions & 13 deletions Tests/Foundation/Tests/TestNSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ import CoreFoundation
class TestNSData: LoopbackServerTest {

class AllOnesImmutableData : NSData {
private var _length : Int
private var __length : Int
var _pointer : UnsafeMutableBufferPointer<UInt8>? {
willSet {
if let p = _pointer { free(p.baseAddress) }
}
}

init(length: Int) {
_length = length
__length = length
super.init()
}

Expand All @@ -45,7 +45,7 @@ class TestNSData: LoopbackServerTest {

override var length : Int {
get {
return _length
return __length
}
}

Expand Down Expand Up @@ -78,15 +78,15 @@ class TestNSData: LoopbackServerTest {

class AllOnesData : NSMutableData {

private var _length : Int
private var __length : Int
var _pointer : UnsafeMutableBufferPointer<UInt8>? {
willSet {
if let p = _pointer { free(p.baseAddress) }
}
}

override init(length: Int) {
_length = length
__length = length
super.init()
}

Expand All @@ -103,22 +103,22 @@ class TestNSData: LoopbackServerTest {

override var length : Int {
get {
return _length
return __length
}
set {
if let ptr = _pointer {
// Copy the data to our new length buffer
let newBuffer = malloc(newValue)!
if newValue <= _length {
if newValue <= __length {
memmove(newBuffer, ptr.baseAddress!, newValue)
} else if newValue > _length {
memmove(newBuffer, ptr.baseAddress!, _length)
memset(newBuffer + _length, 1, newValue - _length)
} else if newValue > __length {
memmove(newBuffer, ptr.baseAddress!, __length)
memset(newBuffer + __length, 1, newValue - __length)
}
let bytePtr = newBuffer.bindMemory(to: UInt8.self, capacity: newValue)
_pointer = UnsafeMutableBufferPointer(start: bytePtr, count: newValue)
}
_length = newValue
__length = newValue
}
}

Expand All @@ -138,7 +138,7 @@ class TestNSData: LoopbackServerTest {
}

override var mutableBytes: UnsafeMutableRawPointer {
let newBufferLength = _length
let newBufferLength = __length
let newBuffer = malloc(newBufferLength)
if let ptr = _pointer {
// Copy the existing data to the new box, then return its pointer
Expand All @@ -150,7 +150,7 @@ class TestNSData: LoopbackServerTest {
let bytePtr = newBuffer!.bindMemory(to: UInt8.self, capacity: newBufferLength)
let result = UnsafeMutableBufferPointer(start: bytePtr, count: newBufferLength)
_pointer = result
_length = newBufferLength
__length = newBufferLength
return UnsafeMutableRawPointer(result.baseAddress!)
}

Expand Down