-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Proposal to expose fcntl() API as part of the Swift stdlib. #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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6950205
Added proposal to expose fcntl() API as part of the Swift stdlib.
billabt 69dc8e1
Minor edits based on discussions.
billabt 1f99d5a
Added port of existing APIs in the Darwin overlay that are not in the…
billabt 52fa536
More updates based on forum feedback.
billabt ec9950e
Parameter names optional to be consistent with other C library functi…
billabt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| # Expose fcntl() API as part of the Swift stdlib | ||
|
|
||
| * Proposal: [SE-NNNN] | ||
| * Author(s): [Bill Abt](https://github.com/billabt) | ||
| * Status: **Review** | ||
| * Review manager: TBD | ||
|
|
||
| ## Introduction | ||
|
|
||
| At the present time Swift does not support the calling of variadic / va_list | ||
| functions in other languages. There are a number of these functions in the | ||
| standard "C" library that are critical for various programming tasks. One of | ||
| these is fcntl(2) which is used to manipulate POSIX file descriptors. The need | ||
| for exposing this API in Swift is readily apparent when doing socket programming | ||
| since it's this API that's used to make a socket non-blocking. | ||
|
|
||
| ## Motivation | ||
|
|
||
| The main motivation behind this proposal is outlined above in the | ||
| introduction with regard to socket programming. However, this API is | ||
| extremely powerful and can be used to do many things in different contexts. | ||
| Exposing it to the Swift community is almost a necessity. | ||
|
|
||
| ## Proposed solution | ||
|
|
||
| The fcntl() API comes in 3 basic forms all returning an integer. The | ||
| first form takes 3 integers as parameters but the third is ignored. The | ||
| second take 3 integers and uses all three. Finally, the third take 2 | ||
| integers and a void pointer. The solution is to add 3 exposed Swift | ||
| stdlib APIs representing each of the variations outlined above. | ||
|
|
||
| ## Detailed design | ||
|
|
||
| Three new APIs would be added to both Glibc and Darwin packages. The | ||
| signatures are below: | ||
|
|
||
| ``` | ||
| func fcntl(fd: CInt, cmd: CInt) ->CInt | ||
| func fcntl(fd: CInt, cmd: CInt, value: CInt) ->CInt | ||
| func fcntl(fd: CInt, cmd: CInt, ptr: UnsafeMutablePointer<Void>) ->CInt | ||
| ``` | ||
|
|
||
| Underlying each of these APIs would be an internal Swift shim that | ||
| calls the underlying fcntl() "C" library function. This new code | ||
| would be added to the existing overlay system for both Darwin and | ||
| Glibc. | ||
|
|
||
| **Note:** There are a number of other variadic functions that are | ||
| currently supplied via the Darwin overlay but are not currently | ||
| present in Glibc overlay. This proposal would expose those APIs as | ||
| well in Glibc. The following APIs are in Darwin and would be ported | ||
| as part of this effort over to Glibc overlay: | ||
| ``` | ||
| open(), openat(), sem_open() | ||
| ``` | ||
|
|
||
| ## Impact on existing code | ||
|
|
||
| Since this API is currently not exposed, there's no impact on any | ||
| existing code. | ||
|
|
||
| ## Alternatives considered | ||
|
|
||
| The only other alternative is for Swift programmers to create their | ||
| own shims to their own versions of C functions calling "C" standard | ||
| library functions. This will work but it forces Swift programmers | ||
| to resort to a hybrid model and have at least rudimentary knowledge | ||
| of C. | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Swift does support
va_listfunctions, it only does not support variadic ones.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ll fix the proposal… Thanks.
-Bill