-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix against se-0184a #1247
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
Fix against se-0184a #1247
Conversation
Foundation/Host.swift
Outdated
@@ -38,8 +38,8 @@ open class Host: NSObject { | |||
static internal func currentHostName() -> String { | |||
let hname = UnsafeMutablePointer<Int8>.allocate(capacity: Int(NI_MAXHOST)) | |||
defer { | |||
hname.deinitialize() | |||
hname.deallocate(capacity: Int(NI_MAXHOST)) | |||
hname.deinitialize(count: 1) |
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've always found this method confusing. What does it actually do?
https://developer.apple.com/documentation/swift/unsafemutablepointer/1641720-deinitialize is no help, it just says that deinitialize()
deinitializes! Does it zero the memory, for example? I assume not otherwise the documentation would say so.
If it is just changing the "state" of the memory then I question the meaning/utility of the "states".
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.
@ianpartridge Isn't deinitialize
for objects where the deinit
method is called on them? If Im correct its not needed for arrays of Int8
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.
No I think this is unrelated to deinit
which only applies to classes. UnsafeMutablePointer
et al are structs.
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 was referring to the type stored in the allocated memory not the UnsafeMutablePointer
itself.
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.
Oh I see what you mean, sorry :) If that's correct then the doc doesn't mention it!
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.
deinitialize does nothing for trivial types, it doesn’t actually need to be there
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.
Oh OK! Could you update this PR to remove it then?
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’ve removed those calls in Host.swift
though I would hold off removing them elsewhere because it could inadvertently introduce memory bugs if the type isn’t absolutely a trivial type and will never be anything but a trivial type in the future
self._storage = UnsafeMutableRawPointer.allocate(bytes: self._typeInfo.size, alignedTo: 1) | ||
self._storage.copyBytes(from: value, count: self._typeInfo.size) | ||
self._storage = UnsafeMutableRawPointer.allocate(byteCount: self._typeInfo.size, alignment: 1) | ||
self._storage.copyMemory(from: value, byteCount: self._typeInfo.size) |
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.
This one doesn't read as an improvement to me - the previous API seemed quite clear as to what it would do. Maybe you are fixing some overloading of the meaning of count:
though? I'm not sure.
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.
this was discussed heavily during the review of SE-0184. The core team felt strongly that it should be copyMemory
and byteCount
.
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.
Could you link me to SE-0184a - I couldn't find it?
Please take my comments as a non-expert's comment to the proposal not this PR per se. Hopefully seeing how someone who has not been immersed in the discussions reacts when confronted with the changes is interesting.
@swift-ci please test |
you have to test against the |
@swift-ci please test |
1 similar comment
@swift-ci please test |
The errors in the build are:
|
OK, so when swiftlang/swift#12200 is merged then we can revisit this request |
Although SE-184 has been accepted, this PR seems to be for SE-184a - I'm not sure how that relates? @Kelvin13 will SE-184a require a separate Swift Evolution review cycle? Is this PR dependent on another Swift Evolution proposal beyond SE-184? If so, I don't think we should keep this PR open for potentially months while that process proceeds. We should close it and reopen it when it's ready. The evolution proposal can link to the closed PR in the meantime. Thoughts? |
@ianpartridge SE-184a is SE-184, SE-184b will likely get a completely different Swift evolution number. It’s confusing I know. Originally it was all one proposal, it got split up in review. |
Oh great, thanks for clarifying! In that case, as SE-184 is Accepted we should keep this open. Do you have an estimate of when you hope to land the implementation of SE-184 into |
ask @atrick it could be as early as today if we can get the |
Great. By the way, this needs rebasing as it has a conflict now. |
done |
@Kelvin13 has SE-184 landed in Swift yet, and if so, can this be merged? If not, do you have a link for the PR in swift that is blocking this PR? |
This is being blocked by swiftlang/swift#12200 |
Revert "Merge pull request #1247 from kelvin13/se-0184a"
Patch for SE 0184a