Skip to content

Conversation

@atrick
Copy link
Contributor

@atrick atrick commented Jul 28, 2016

Update for SE-0107: UnsafeRawPointer

This adds a "mutating" initialize to UnsafePointer to make
Immutable -> Mutable conversions explicit.

These are quick fixes to stdlib, overlays, and test cases that are necessary
in order to remove arbitrary UnsafePointer conversions.

Many cases can be expressed better up by reworking the surrounding
code, but we first need a working starting point.

Update for SE-0107: UnsafeRawPointer

This adds a "mutating" initialize to UnsafePointer to make
Immutable -> Mutable conversions explicit.

These are quick fixes to stdlib, overlays, and test cases that are necessary
in order to remove arbitrary UnsafePointer conversions.

Many cases can be expressed better up by reworking the surrounding
code, but we first need a working starting point.
@atrick
Copy link
Contributor Author

atrick commented Jul 28, 2016

@gribozavr What is holding up merging this? It will conflict with my changes and I have to start getting my own pull requests merged and CI tested.

Playgrounds support is not updated for AnyHashable:
/Users/buildnode/jenkins/workspace/swift-PR-osx/swift-xcode-playground-support/PlaygroundSupport/XCPlayground/XCPlaygroundPage.swift:48:119: error: 'NSString' is not implicitly convertible to 'AnyHashable'; did you mean to use 'as' to explicitly convert?

@gribozavr
Copy link
Contributor

@swift-ci Please test

@gribozavr
Copy link
Contributor

Let me review this PR.

let fileName = String(cString: utf8.baseAddress!)
return (fd, fileName)
return utf8.baseAddress!.withMemoryRebound(
to: CChar.self, capacity: Int(suffixlen)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind putting the ") {" on a separate line? Then you won't need a blank line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, you can use String.nulTerminatedUTF8CString, and then you won't need to rebind.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#3816 was merged, and the property nulTerminatedUTF8 is gone. Please switch to utf8CString and I think you won't need to rebind the memory then.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already reworked in #3816. I'll go through and annotate other such instances here. (Sorry if I'm stepping on toes; ignore if this isn't helpful.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's why I wanted your PR merged first. Unfortunately I didn't have permission to do it so had to post this older patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this rebind is gone now.
Incidentally, I much prefer your suggested style, but I can never keep track of what we're supposed to do. Is there a style guideline for stdlib code?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, we don't have a written document.

This would be the most complex case of wrapping the declaration:

func foo<
  T,
  U : Hashable  // Either put all type parameters on one line, on do one per line.
>( // Closing delimiters are put on a new line.
  arg1 x: T,
  arg2 y: U // Same, either everything fits on one line, or each gets its own line.
) -> Int
  where T.Z == U
{
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. Those are good simple rules. I think that would suffice in a document or a Readme.md

@tkremenek
Copy link
Member

This fails on Linux:

/home/buildnode/jenkins/workspace/swift-PR-Linux@2/swift/stdlib/public/core/String.swift:589:44: error: cannot convert value of type 'UnsafeMutablePointer<CodeUnit>' (aka 'UnsafeMutablePointer<UInt16>') to expected argument type 'UnsafeMutablePointer<_>'
      let rhsPtr = UnsafePointer(rhs._core.startUTF16)

@atrick
Copy link
Contributor Author

atrick commented Jul 29, 2016

Please see #3843

@atrick atrick closed this Jul 29, 2016
@atrick atrick deleted the rawptr-stdlib branch September 11, 2016 03:04
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.

5 participants