Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve pointer hygeine in SocketAddresses.swift (apple#1588)
Motivation: The socket address types are some of the worst types for handling in Swift. They pervasively type-pun in a way that Swift strongly wants to resist, and they expose a bunch of data through awkward fixed-length arrays. We've done a number of passes over this code to improve its pointer hygeine. This is another one. Here, we remove some uses of the memory binding APIs that were unnecessary, and that can instead take advantage of the way Swift handles binding memory of homogeneous tuple types. In Swift, whenever we have a homogeneous tuple (i.e. a tuple whose elements are all the same type), that memory is actually bound to _two_ types: to the tuple type, and to the type of the elements. This allows us to use `assumingMemoryBound(to:)` to convert between the pointer to the tuple and the pointer to the first element of the tuple. This knowledge lets us remove calls to `bindMemory` and `withMemoryRebound`. Neither call is correct to use in this situation, and while we were unlikely to encounter any damage, this is the best possible use of the Swift pointer APIs for this work. Modifications: - Rewrite accesses to the UNIX domain socket path to use appropriately typed pointers without binding or rebinding memory. - Added some assertions about the static types of the stored elements. Result: Better management of pointer type bindings.
- Loading branch information