From 69502058fa716a93c465dd47adb7f72e4845cacb Mon Sep 17 00:00:00 2001 From: Bill Abt Date: Fri, 4 Dec 2015 14:33:26 -0500 Subject: [PATCH 1/5] Added proposal to expose fcntl() API as part of the Swift stdlib. --- proposals/fcntl-additions-to-stdlib.md | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 proposals/fcntl-additions-to-stdlib.md diff --git a/proposals/fcntl-additions-to-stdlib.md b/proposals/fcntl-additions-to-stdlib.md new file mode 100644 index 0000000000..3020cb756d --- /dev/null +++ b/proposals/fcntl-additions-to-stdlib.md @@ -0,0 +1,57 @@ +# 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) ->CInt +``` + +Underlying each of these APIs would be an internal Swift shim that +calls the underlying fcntl() "C" library function. + +## 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. From 69dc8e15b0017cd3e87be717fe57b900e1e864de Mon Sep 17 00:00:00 2001 From: Bill Abt Date: Mon, 7 Dec 2015 09:27:38 -0500 Subject: [PATCH 2/5] Minor edits based on discussions. --- proposals/fcntl-additions-to-stdlib.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proposals/fcntl-additions-to-stdlib.md b/proposals/fcntl-additions-to-stdlib.md index 3020cb756d..3ab7cf13af 100644 --- a/proposals/fcntl-additions-to-stdlib.md +++ b/proposals/fcntl-additions-to-stdlib.md @@ -41,7 +41,9 @@ func fcntl(fd: CInt, cmd: CInt, ptr: UnsafeMutablePointer) ->CInt ``` Underlying each of these APIs would be an internal Swift shim that -calls the underlying fcntl() "C" library function. +calls the underlying fcntl() "C" library function. This new code +would be added to the existing overlay system for both Darwin and +Glibc. ## Impact on existing code From 1f99d5a3e2b5799835b9b32dde0fe6b657941829 Mon Sep 17 00:00:00 2001 From: Bill Abt Date: Mon, 7 Dec 2015 10:51:36 -0500 Subject: [PATCH 3/5] Added port of existing APIs in the Darwin overlay that are not in the Glibc overlay. --- proposals/fcntl-additions-to-stdlib.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proposals/fcntl-additions-to-stdlib.md b/proposals/fcntl-additions-to-stdlib.md index 3ab7cf13af..48c0ba6f0a 100644 --- a/proposals/fcntl-additions-to-stdlib.md +++ b/proposals/fcntl-additions-to-stdlib.md @@ -45,6 +45,15 @@ 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 From 52fa536bcf31e0ba58ef7371f885c221a75676be Mon Sep 17 00:00:00 2001 From: Bill Abt Date: Mon, 7 Dec 2015 14:12:43 -0500 Subject: [PATCH 4/5] More updates based on forum feedback. --- proposals/fcntl-additions-to-stdlib.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/proposals/fcntl-additions-to-stdlib.md b/proposals/fcntl-additions-to-stdlib.md index 48c0ba6f0a..79b0d0ad0b 100644 --- a/proposals/fcntl-additions-to-stdlib.md +++ b/proposals/fcntl-additions-to-stdlib.md @@ -7,11 +7,11 @@ ## 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 +At the present time Swift does not support the calling of variadic 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 From ec9950e5ec74a86786d7748fb8b1e05e7c12400d Mon Sep 17 00:00:00 2001 From: Bill Abt Date: Wed, 9 Dec 2015 07:34:27 -0500 Subject: [PATCH 5/5] Parameter names optional to be consistent with other C library functions. --- proposals/fcntl-additions-to-stdlib.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/proposals/fcntl-additions-to-stdlib.md b/proposals/fcntl-additions-to-stdlib.md index 79b0d0ad0b..7c2405370d 100644 --- a/proposals/fcntl-additions-to-stdlib.md +++ b/proposals/fcntl-additions-to-stdlib.md @@ -35,9 +35,9 @@ 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) ->CInt +func fcntl(fd: CInt, _ cmd: CInt) ->CInt +func fcntl(fd: CInt, _ cmd: CInt, _ value: CInt) ->CInt +func fcntl(fd: CInt, _ cmd: CInt, _ ptr: UnsafeMutablePointer) ->CInt ``` Underlying each of these APIs would be an internal Swift shim that