Skip to content

Added NSPipe implementation #38

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 39 commits into from
Dec 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1895179
Simplify implementation of `init(indexes:length:)`.
BryanHoke Dec 4, 2015
d7838cc
Clarify where timezone is set and return values
syoutsey Dec 4, 2015
b64c87c
Clarify GettingStarted.md
radex Dec 5, 2015
9728639
Verify contents of the file attributes dictionary
bolshedvorsky Dec 4, 2015
539eeb9
Added missing keys for NSURLError
dlbuckley Dec 5, 2015
ae307f7
Clarify the scope of what we're proposing removing the NS prefix from…
parkera Dec 5, 2015
767d4bd
Merge pull request #40 from radex/patch-1
parkera Dec 5, 2015
58ea9d4
Merge pull request #42 from dlbuckley/NSURLError_missing_keys
parkera Dec 5, 2015
759643a
Add legal terms for contributing to CONTRIBUTING.md.
jrose-apple Dec 5, 2015
59e38f3
Fix link in CONTRIBUTING.md.
jrose-apple Dec 5, 2015
0bfcd82
Merge pull request #33 from syoutsey/master
parkera Dec 5, 2015
1b0083f
Removed the TODO comments regarding bounds checking from the methods …
talzag Dec 6, 2015
be23a4e
Repair NSNumber behaviour
argon Dec 6, 2015
e98238e
Test Floating point behaviour of NSNumber
argon Dec 6, 2015
a1aa91b
Remove trailing whitespace
argon Dec 6, 2015
def84d9
Merge pull request #52 from argon/hotfix/repair-NSNumber
parkera Dec 6, 2015
0c39876
Merge pull request #18 from talzag/master
parkera Dec 6, 2015
5f90732
Merge pull request #32 from bolshedvorsky/master
parkera Dec 6, 2015
cfa6894
Merge pull request #27 from BryanHoke/patch-4
parkera Dec 6, 2015
0254bc2
[SR-59] Add information about how the Foundation project wishes to ma…
parkera Dec 6, 2015
a9ee4b2
Add documentatin on reconfiguration passes
phausler Dec 5, 2015
125e117
Glob all tests so that anything named Test*.swift in the TestFoundati…
phausler Dec 5, 2015
0dfaaf8
Add stubs for missing NSData methods
phausler Nov 18, 2015
b337dab
add a few missing NSData methods for writing to files
phausler Dec 5, 2015
0ba6639
Update NSIndexSet enumeration snippets to Swift
christopherweems Dec 7, 2015
5893bfa
Merge pull request #55 from christopherweems/patch-1
phausler Dec 7, 2015
7213002
Fixes test case TestNSFileManger.test_fileAttributes
bolshedvorsky Dec 7, 2015
a347b71
Add string constants
Dec 7, 2015
65cdfac
Merge pull request #58 from bolshedvorsky/master
phausler Dec 7, 2015
cdde78c
Merge pull request #59 from robtimp/constants
parkera Dec 7, 2015
2652002
Add NSProgress string constants
ChrisChares Dec 7, 2015
4a6d90f
Merge pull request #65 from ChrisChares/NSProgress
phausler Dec 7, 2015
47f3f93
Added an implementation for `NSPipe`
terhechte Dec 5, 2015
d4d13f9
Added Unit Test for `NSPipe` implementation.
terhechte Dec 5, 2015
a8e08be
Fixed a small typo
terhechte Dec 5, 2015
6188a35
Removed the libdispatch dependency
terhechte Dec 5, 2015
398856e
Updated the Unit Test
terhechte Dec 7, 2015
9ae815a
Added NSPipe test to main.swift
terhechte Dec 7, 2015
37e4160
Merge branch 'master' of https://github.com/terhechte/swift-corelibs-…
terhechte Dec 7, 2015
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
7 changes: 6 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Contributing

Contributions to Foundation are welcome! This project follows the [contribution guidelines for the Swift project](https://swift.org/contributing/#reporting-bugs). A few additional details are outlined below.
Contributions to Foundation are welcome! This project follows the [contribution guidelines for the Swift project](https://swift.org/contributing/#contributing-code). A few additional details are outlined below.

## Licensing

By submitting a pull request, you represent that you have the right to license your contribution to Apple and the community, and agree by submitting the patch that your contributions are licensed under the [Swift license](https://swift.org/LICENSE.txt).


## Bug Reports

Expand Down
1 change: 1 addition & 0 deletions CoreFoundation/NumberDate.subproj/CFNumber.c
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,7 @@ static inline void _CFNumberInit(CFNumberRef result, CFNumberType type, const vo
case kCFNumberFloat32Type: memmove((void *)&result->_pad, valuePtr, 4); break;
case kCFNumberFloat64Type: memmove((void *)&result->_pad, valuePtr, 8); break;
}
__CFBitfieldSetValue(((struct __CFNumber *)result)->_base._cfinfo[CF_INFO_BITS], 4, 0, (uint8_t)__CFNumberTypeTable[type].canonicalType);
}

CF_EXPORT void _CFNumberInitBool(CFNumberRef result, Boolean value) {
Expand Down
2 changes: 2 additions & 0 deletions Docs/Design.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ In a very limited number of cases, key Foundation API as it exists on Apple plat

A significant portion of the implementation of Foundation on Apple platforms is provided by another framework called CoreFoundation (a.k.a. CF). CF is written primarily in C and is very portable. Therefore we have chosen to use it for the internal implementation of Swift Foundation where possible. As CF is present on all platforms, we can use it to provide a common implementation everywhere.

Another aspect of portability is keeping dependencies to an absolute minimum. With fewer dependencies to port, it is more likely that Foundation will be able to easily compile and run on new platforms. Therefore, we will prefer solutions that are implemented in Foundation itself. Exceptions can be made for major functionality (for example, `ICU`, `libdispatch`, and `libxml2`).

## A Taxonomy of Types

A key to the internal design of the framework is the split between the CF implementation and Swift implementation of the Foundation classes. They can be organized into several categories.
Expand Down
12 changes: 10 additions & 2 deletions Docs/GettingStarted.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ In order to build on OS X, you will need:

Foundation is developed at the same time as the rest of Swift, so the most recent version of the compiler is required in order to build it.

The repository includes an Xcode project file as well as an Xcode workspace. The workspace includes both Foundation and XCTest, which makes it easy to build and run everything together. The workspace assumes that Foundation and XCTest are checked out from GitHub in peer directories. For example:
The repository includes an Xcode project file as well as an Xcode workspace. The workspace includes both Foundation and XCTest, which makes it easy to build and run everything together. The workspace assumes that Foundation and XCTest are checked out from GitHub in sibling directories. For example:

```
% cd Development
Expand All @@ -25,7 +25,7 @@ Build and test steps:

0. Run Xcode with the latest toolchain. Follow [the instructions here](https://swift.org/download/#apple-platforms) to start Xcode with the correct toolchain.
0. Open `Foundation.xcworkspace`.
0. Build the _Foundation_ target. This builds CoreFoundation and Foundation.
0. Build the _SwiftFoundation_ target. This builds CoreFoundation and Foundation.
0. Run (Cmd-R) the _TestFoundation_ target. This builds CoreFoundation, Foundation, XCTest, and TestFoundation, then runs the tests.

> Note: If you see the name of the XCTest project file in red in the workspace, then Xcode cannot find the cloned XCTest repository. Make sure that it is located next to the `swift-corelibs-foundation` directory and has the name `swift-corelibs-xctest`.
Expand Down Expand Up @@ -74,3 +74,11 @@ LD_LIBRARY_PATH=../build/Ninja-ReleaseAssert/foundation-linux-x86_64/Foundation/
```

Just copy & paste the correct line.

When new source files or flags are added to the `build.py` script, the project will need to be reconfigured in order for the build system to pick them up. The top-level `swift/utils/build-script` can be used, but for quicker iteration you can use the following command to limit the reconfiguration to just the Foundation project:

```
% ninja reconfigure
% ninja
```

14 changes: 3 additions & 11 deletions Foundation/NSCalendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -365,11 +365,7 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
public func dateFromComponents(comps: NSDateComponents) -> NSDate? {
var (vector, compDesc) = _convert(comps)

let oldTz = timeZone
let tempTz = comps.timeZone
if let tz = tempTz {
timeZone = tz
}
self.timeZone = comps.timeZone ?? timeZone

var at: CFAbsoluteTime = 0.0
let res: Bool = withUnsafeMutablePointer(&at) { t in
Expand All @@ -378,15 +374,11 @@ public class NSCalendar : NSObject, NSCopying, NSSecureCoding {
}
}

if tempTz != nil {
self.timeZone = oldTz
}

if res {
return NSDate(timeIntervalSinceReferenceDate: at)
} else {
return nil
}

return nil
}

private func _setup(unitFlags: NSCalendarUnit, field: NSCalendarUnit, type: String, inout compDesc: [Int8]) {
Expand Down
49 changes: 49 additions & 0 deletions Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,28 @@ extension NSData {
}
}

public func writeToFile(path: String, atomically useAuxiliaryFile: Bool) -> Bool {
do {
try writeToFile(path, options: useAuxiliaryFile ? .DataWritingAtomic : [])
} catch {
return false
}
return true
}

public func writeToURL(url: NSURL, atomically: Bool) -> Bool {
if url.fileURL {
if let path = url.path {
return writeToFile(path, atomically: atomically)
}
}
return false
}

public func writeToURL(url: NSURL, options writeOptionsMask: NSDataWritingOptions) throws {
NSUnimplemented()
}

internal func enumerateByteRangesUsingBlockRethrows(block: (UnsafePointer<Void>, NSRange, UnsafeMutablePointer<Bool>) throws -> Void) throws {
var err : ErrorType? = nil
self.enumerateByteRangesUsingBlock() { (buf, range, stop) -> Void in
Expand Down Expand Up @@ -482,6 +504,33 @@ public class NSMutableData : NSData {
}
}

extension NSData {

/* Create an NSData from a Base-64 encoded NSString using the given options. By default, returns nil when the input is not recognized as valid Base-64.
*/
public convenience init?(base64EncodedString base64String: String, options: NSDataBase64DecodingOptions) {
NSUnimplemented()
}

/* Create a Base-64 encoded NSString from the receiver's contents using the given options.
*/
public func base64EncodedStringWithOptions(options: NSDataBase64EncodingOptions) -> String {
NSUnimplemented()
}

/* Create an NSData from a Base-64, UTF-8 encoded NSData. By default, returns nil when the input is not recognized as valid Base-64.
*/
public convenience init?(base64EncodedData base64Data: NSData, options: NSDataBase64DecodingOptions) {
NSUnimplemented()
}

/* Create a Base-64, UTF-8 encoded NSData from the receiver's contents using the given options.
*/
public func base64EncodedDataWithOptions(options: NSDataBase64EncodingOptions) -> NSData {
NSUnimplemented()
}
}

extension NSMutableData {

public func appendBytes(bytes: UnsafePointer<Void>, length: Int) {
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSDecimalNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@


/*************** Exceptions ***********/
public let NSDecimalNumberExactnessException: String = "" // NSUnimplemented
public let NSDecimalNumberOverflowException: String = "" // NSUnimplemented
public let NSDecimalNumberUnderflowException: String = "" // NSUnimplemented
public let NSDecimalNumberDivideByZeroException: String = "" // NSUnimplemented
public let NSDecimalNumberExactnessException: String = "NSDecimalNumberExactnessException"
public let NSDecimalNumberOverflowException: String = "NSDecimalNumberOverflowException"
public let NSDecimalNumberUnderflowException: String = "NSDecimalNumberUnderflowException"
public let NSDecimalNumberDivideByZeroException: String = "NSDecimalNumberDivideByZeroException"

/*************** Rounding and Exception behavior ***********/

Expand Down
11 changes: 6 additions & 5 deletions Foundation/NSFileManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,13 @@ public class NSFileManager : NSObject {

This method replaces fileAttributesAtPath:traverseLink:.
*/
public func attributesOfItemAtPath(path: String) throws -> [String : AnyObject] {
/// - Experiment: Note that the return type of this function is different than on Darwin Foundation (Any instead of AnyObject). This is likely to change once we have a more complete story for bridging in place.
public func attributesOfItemAtPath(path: String) throws -> [String : Any] {
var s = stat()
guard lstat(path, &s) == 0 else {
throw _NSErrorWithErrno(errno, reading: true, path: path)
}
var result = [String : AnyObject]()
var result = [String : Any]()
result[NSFileSize] = NSNumber(unsignedLongLong: UInt64(s.st_size))

#if os(OSX) || os(iOS)
Expand All @@ -233,14 +234,14 @@ public class NSFileManager : NSObject {

let pwd = getpwuid(s.st_uid)
if pwd != nil && pwd.memory.pw_name != nil {
if let name = NSString(bytes: pwd.memory.pw_name, length: Int(strlen(pwd.memory.pw_name)), encoding: NSUTF8StringEncoding) {
if let name = String.fromCString(pwd.memory.pw_name) {
result[NSFileOwnerAccountName] = name
}
}

let grd = getgrgid(s.st_gid)
if grd != nil && grd.memory.gr_name != nil {
if let name = NSString(bytes: grd.memory.gr_name, length: Int(strlen(grd.memory.gr_name)), encoding: NSUTF8StringEncoding) {
if let name = String.fromCString(grd.memory.gr_name) {
result[NSFileGroupOwnerAccountID] = name
}
}
Expand All @@ -255,7 +256,7 @@ public class NSFileManager : NSObject {
case S_IFSOCK: type = NSFileTypeSocket
default: type = NSFileTypeUnknown
}
result[NSFileType] = NSString(type)
result[NSFileType] = type

if type == NSFileTypeBlockSpecial || type == NSFileTypeCharacterSpecial {
result[NSFileDeviceIdentifier] = NSNumber(unsignedLongLong: UInt64(s.st_rdev))
Expand Down
5 changes: 1 addition & 4 deletions Foundation/NSIndexPath.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ public class NSIndexPath : NSObject, NSCopying, NSSecureCoding {
_indexes = []
}
public init(indexes: UnsafePointer<Int>, length: Int) {
_indexes = []
for var idx = 0; idx < length; idx++ {
_indexes.append(indexes[idx])
}
_indexes = Array(UnsafeBufferPointer(start: indexes, count: length))
}

private init(indexes: [Int]) {
Expand Down
16 changes: 7 additions & 9 deletions Foundation/NSIndexSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@
The following code snippets can be used to enumerate over the indexes in an NSIndexSet:

// Forward
NSUInteger currentIndex = [set firstIndex];
while (currentIndex != NSNotFound) {
var currentIndex = set.firstIndex
while currentIndex != NSNotFound {
...
currentIndex = [set indexGreaterThanIndex:currentIndex];
currentIndex = set.indexGreaterThanIndex(currentIndex)
}

// Backward
NSUInteger currentIndex = [set lastIndex];
while (currentIndex != NSNotFound) {
var currentIndex = set.lastIndex
while currentIndex != NSNotFound {
...
currentIndex = [set indexLessThanIndex:currentIndex];
currentIndex = set.indexLessThanIndex(currentIndex)
}

To enumerate without doing a call per index, you can use the method getIndexes:maxCount:inIndexRange:.
Expand Down Expand Up @@ -484,12 +484,10 @@ public class NSMutableIndexSet : NSIndexSet {
}

public func addIndex(value: Int) {
// TODO: Bounds checking
self.addIndexesInRange(NSMakeRange(value, 1))
}

public func removeIndex(value: Int) {
// TODO: Bounds checking
self.removeIndexesInRange(NSMakeRange(value, 1))
}

Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSPort.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public typealias NSSocketNativeHandle = Int32

public let NSPortDidBecomeInvalidNotification: String = "" // NSUnimplemented
public let NSPortDidBecomeInvalidNotification: String = "NSPortDidBecomeInvalidNotification"

public class NSPort : NSObject, NSCopying, NSCoding {

Expand Down
22 changes: 11 additions & 11 deletions Foundation/NSProgress.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,35 +154,35 @@ public protocol NSProgressReporting : NSObjectProtocol {

/* How much time is probably left in the operation, as an NSNumber containing a number of seconds.
*/
public let NSProgressEstimatedTimeRemainingKey: String = "" // NSUnimplemented
public let NSProgressEstimatedTimeRemainingKey: String = "NSProgressEstimatedTimeRemainingKey"

/* How fast data is being processed, as an NSNumber containing bytes per second.
*/
public let NSProgressThroughputKey: String = "" // NSUnimplemented
public let NSProgressThroughputKey: String = "NSProgressThroughputKey"

/* The value for the kind property that indicates that the work being done is one of the kind of file operations listed below. NSProgress of this kind is assumed to use bytes as the unit of work being done and the default implementation of -localizedDescription takes advantage of that to return more specific text than it could otherwise. The NSProgressFileTotalCountKey and NSProgressFileCompletedCountKey keys in the userInfo dictionary are used for the overall count of files.
*/
public let NSProgressKindFile: String = "" // NSUnimplemented
public let NSProgressKindFile: String = "NSProgressKindFile"

/* A user info dictionary key, for an entry that is required when the value for the kind property is NSProgressKindFile. The value must be one of the strings listed in the next section. The default implementations of of -localizedDescription and -localizedItemDescription use this value to determine the text that they return.
*/
public let NSProgressFileOperationKindKey: String = "" // NSUnimplemented
public let NSProgressFileOperationKindKey: String = "NSProgressKindFile"

/* Possible values for NSProgressFileOperationKindKey entries.
*/
public let NSProgressFileOperationKindDownloading: String = "" // NSUnimplemented
public let NSProgressFileOperationKindDecompressingAfterDownloading: String = "" // NSUnimplemented
public let NSProgressFileOperationKindReceiving: String = "" // NSUnimplemented
public let NSProgressFileOperationKindCopying: String = "" // NSUnimplemented
public let NSProgressFileOperationKindDownloading: String = "NSProgressFileOperationKindDownloading"
public let NSProgressFileOperationKindDecompressingAfterDownloading: String = "NSProgressFileOperationKindDecompressingAfterDownloading"
public let NSProgressFileOperationKindReceiving: String = "NSProgressFileOperationKindReceiving"
public let NSProgressFileOperationKindCopying: String = "NSProgressFileOperationKindCopying"

/* A user info dictionary key. The value must be an NSURL identifying the item on which progress is being made. This is required for any NSProgress that is published using -publish to be reported to subscribers registered with +addSubscriberForFileURL:withPublishingHandler:.
*/
public let NSProgressFileURLKey: String = "" // NSUnimplemented
public let NSProgressFileURLKey: String = "NSProgressFileURLKey"

/* User info dictionary keys. The values must be NSNumbers containing integers. These entries are optional but if they are both present then the default implementation of -localizedAdditionalDescription uses them to determine the text that it returns.
*/
public let NSProgressFileTotalCountKey: String = "" // NSUnimplemented
public let NSProgressFileCompletedCountKey: String = "" // NSUnimplemented
public let NSProgressFileTotalCountKey: String = "NSProgressFileTotalCountKey"
public let NSProgressFileCompletedCountKey: String = "NSProgressFileCompletedCountKey"



4 changes: 2 additions & 2 deletions Foundation/NSRunLoop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
//


public let NSDefaultRunLoopMode: String = "" // NSUnimplemented
public let NSRunLoopCommonModes: String = "" // NSUnimplemented
public let NSDefaultRunLoopMode: String = "NSDefaultRunLoopMode"
public let NSRunLoopCommonModes: String = "NSRunLoopCommonModes"

public class NSRunLoop : NSObject {

Expand Down
10 changes: 5 additions & 5 deletions Foundation/NSURLError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@
@discussion Constants used by NSError to differentiate between "domains" of error codes, serving as a discriminator for error codes that originate from different subsystems or sources.
@constant NSURLErrorDomain Indicates an NSURL error.
*/
public let NSURLErrorDomain: String = "" // NSUnimplemented
public let NSURLErrorDomain: String = "NSURLErrorDomain"

/*!
@const NSURLErrorFailingURLErrorKey
@abstract The NSError userInfo dictionary key used to store and retrieve the URL which caused a load to fail.
*/
public let NSURLErrorFailingURLErrorKey: String = "" // NSUnimplemented
public let NSURLErrorFailingURLErrorKey: String = "NSErrorFailingURLKey"

/*!
@const NSURLErrorFailingURLStringErrorKey
@abstract The NSError userInfo dictionary key used to store and retrieve the NSString object for the URL which caused a load to fail.
@discussion This constant supersedes NSErrorFailingURLStringKey, which was deprecated in Mac OS X 10.6. Both constants refer to the same value for backward-compatibility, but this symbol name has a better prefix.
*/
public let NSURLErrorFailingURLStringErrorKey: String = "" // NSUnimplemented
public let NSURLErrorFailingURLStringErrorKey: String = "NSErrorFailingURLStringKey"

/*!
@const NSErrorFailingURLStringKey
Expand All @@ -37,14 +37,14 @@ public let NSURLErrorFailingURLStringErrorKey: String = "" // NSUnimplemented
@const NSURLErrorFailingURLPeerTrustErrorKey
@abstract The NSError userInfo dictionary key used to store and retrieve the SecTrustRef object representing the state of a failed SSL handshake.
*/
public let NSURLErrorFailingURLPeerTrustErrorKey: String = "" // NSUnimplemented
public let NSURLErrorFailingURLPeerTrustErrorKey: String = "NSURLErrorFailingURLPeerTrustErrorKey"

/*!
@const NSURLErrorBackgroundTaskCancelledReasonKey
@abstract The NSError userInfo dictionary key used to store and retrieve the NSNumber corresponding to the reason why a background
NSURLSessionTask was cancelled
*/
public let NSURLErrorBackgroundTaskCancelledReasonKey: String = "" // NSUnimplemented
public let NSURLErrorBackgroundTaskCancelledReasonKey: String = "NSURLErrorBackgroundTaskCancelledReasonKey"

/*!
@enum Codes associated with NSURLErrorBackgroundTaskCancelledReasonKey
Expand Down
Loading