Skip to content

SR-1005: [Foundation] Use NSFileHandle instead of fopen #292

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 1 commit into from
May 9, 2016

Conversation

Bouke
Copy link
Contributor

@Bouke Bouke commented Apr 28, 2016

A partial implementation of SR-1005, replacing POSIX file handling by NSFileHandle.

Instead of passing file descriptors, references to NSFileHandle are passed around. fclose has been replaced by closeFile(), however not strictly necessary as NSFileHandle automatically closes the pointer on deallocation.

Rationale for reading the whole file when enumerating the lines:

  • Iterating over a File instance would read using a buffer,
    however most usages would concatenate the chunks
    and work on the complete file (no memory savings).
  • Files that are read are mostly small files, should not
    take lots of memory.

Remarks:

  • Tested on both OSX and Linux. The SwiftFoundation has some differing API, #if os(OSX) has been used for in the interim.
  • Performance of the unit tests did not change.
  • The PR has been based on the latest development snapshot.

@mxcl
Copy link
Contributor

mxcl commented Apr 29, 2016

LGTM but conflicts.

@Bouke
Copy link
Contributor Author

Bouke commented Apr 30, 2016

Indeed it does, it was written against the latest development toolchain snapshot. The Foundation API is being imported now with new rules, so I'm unable to compile until I have an updated toolchain. I've yet to learn to build my own toolchain, maybe I'll just wait for a new toolchain snapshot.

@Bouke Bouke force-pushed the sr-1005-nsfilehandle branch from 70d71c0 to 282f165 Compare May 1, 2016 18:00
@Bouke
Copy link
Contributor Author

Bouke commented May 1, 2016

I've updated the PR and tested on OS X and Linux against Swift's master branch.

@Bouke Bouke force-pushed the sr-1005-nsfilehandle branch from 282f165 to 665ffd5 Compare May 2, 2016 08:39
@mxcl
Copy link
Contributor

mxcl commented May 2, 2016

I use this script to build my own toolchain: https://gist.github.com/mxcl/05ced0268bbd5db6ab0c

@mxcl
Copy link
Contributor

mxcl commented May 2, 2016

@ddunbar how do you feel about starting to depend on Foundation?

@ddunbar
Copy link
Contributor

ddunbar commented May 2, 2016

Let's do it! :)

@mxcl
Copy link
Contributor

mxcl commented May 2, 2016

@swift-ci Please test and merge

@Bouke
Copy link
Contributor Author

Bouke commented May 3, 2016

Any ideas why the CI reports a failure? From the log I can see that;

  • On OSX: Some Swift test is failing (typeref_decoding_objc.swift), is this related to this PR?
  • On Linux: cannot import Foundation, should SwiftPM require that somewhere in the build scripts?

@kostiakoval
Copy link
Contributor

kostiakoval commented May 3, 2016

@Bouke the abspath is changed to a property in other PR, #304
Maybe it has something to do with this error. Could it be a CI error?

@briancroom
Copy link
Contributor

Hey @Bouke, you are correct that the build scripts will need some changes to facilitate a dependency on Foundation here. Here are some notes and source references that should help get you started on this:

@briancroom
Copy link
Contributor

As a side note (and this may not be the right place for this discussion..), @parkera mentioned recently that a longer-term goal may be to make SwiftPM able to build "all the things on all the platforms". Does a Foundation dependency potentially interfere with that?

@mxcl @ddunbar

@parkera
Copy link
Contributor

parkera commented May 3, 2016

I'm hoping that Foundation is available everywhere that Swift is, so using it should not prevent portability of swiftpm.

@parkera
Copy link
Contributor

parkera commented May 3, 2016

In fact, Foundation has an important role to play as an insulator of those same platform differences.

@briancroom
Copy link
Contributor

Sure, that makes sense. So to be clear, you're invisioning that swift-corelibs-foundation will keep its own build system indefinitely, while swift-corelibs-xctest could eventually migrate to be built by SwiftPM, since SwiftPM has no build-time dependency on XCTest. Is that right?

@Bouke
Copy link
Contributor Author

Bouke commented May 4, 2016

@briancroom thanks for the pointers in the build script. I'm however stuck at building SwiftPM's stage1, which calls out to swift-build-tool.

swiftpm/Sources/POSIX/mkdir.swift:19:12: error: no such module 'Foundation'
import Foundation
       ^

swift-build-tool doesn't expose any -Xlinker arguments like other tools do. I can set LD_LIBRARY_PATH, but that doesn't have any effect. I symlinked Foundation.swiftmodule, Foundation.swiftdoc and libFoundation.so into build/Ninja-ReleaseAssert/swiftpm-linux-x86_64/.bootstrap/modules, but now it cannot find CoreFoundation:

swiftpm/Sources/OptionsParser/OptionsParser.swift:12:12: 
    error: missing required module 'CoreFoundation'
import Foundation
       ^

Update
I've also symlinked usr/lib/include/CoreFoundation. I'm not sure if this is the correct way?

@ddunbar
Copy link
Contributor

ddunbar commented May 4, 2016

You need to make sure Foundation is accessible through the search paths used during the stage1 build.

The stage2 build does this by setting up a dummy toolchain inside the build directory, you might be able to just move that logic early and then use that.

@parkera
Copy link
Contributor

parkera commented May 4, 2016

We have a kind of circular dependency today in the build system for all of the OSes: Foundation builds using xcodebuild, which uses Foundation. Once we get the entire system bootstrapped I don't see a real issue with having these depend on each other. Foundation can continue to use its custom python scripts in the meantime though.

@Bouke Bouke force-pushed the sr-1005-nsfilehandle branch from 665ffd5 to 8a99614 Compare May 6, 2016 21:14
@Bouke
Copy link
Contributor Author

Bouke commented May 6, 2016

Rebased the PR. The tests should run fine now Foundation is available.

@ddunbar
Copy link
Contributor

ddunbar commented May 9, 2016

Conflicts again. :(

Instead of passing file descriptors, references to
NSFileHandle are passed around. `fclose` has been
replaced by `closeFile()`, however not strictly necessary
as NSFileHandle automatically closes the pointer on
deallocation.

Rationale for reading the whole file when enumerating the
lines:

* Iterating over a File instance would read using a buffer,
  however most usages would concatenate the chunks
  and work on the complete file (no memory savings).
* Files that are read are mostly small files, should not
  take lots of memory.
@Bouke Bouke force-pushed the sr-1005-nsfilehandle branch from 8a99614 to c61b4a0 Compare May 9, 2016 07:39
@ddunbar
Copy link
Contributor

ddunbar commented May 9, 2016

@swift-ci please test and merge

@swift-ci swift-ci merged commit d572614 into swiftlang:master May 9, 2016
@Bouke Bouke deleted the sr-1005-nsfilehandle branch May 9, 2016 13:29
aciidgh pushed a commit to aciidgh/swift-package-manager that referenced this pull request Jan 11, 2019
Change LaneBasedExecutionQueue scheduling algorithm to be a priority queue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants