Skip to content

Update for SE-0055: Making pointer nullability explicit. #304

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

Merged
merged 1 commit into from
Apr 12, 2016

Conversation

jrose-apple
Copy link
Contributor

See swiftlang/swift#1878. Note: this needs a coordinated merge, i.e. it must go in ASAP after that request!

@phausler or someone else, would you mind reviewing? I tried to keep APIs matching the nullability audit of the Darwin Foundation, and attempted to change as little behavior as possible besides that, but there were definitely a few rough spots.

encodeValueOfObjCType("[\(count)\(String(cString: type))]", at: array)
public func encodeArrayOfObjCType(type: UnsafePointer<Int8>, count: Int, at array: UnsafePointer<Void>?) {
// FIXME: What about empty arrays at null addresses?
encodeValueOfObjCType("[\(count)\(String(cString: type))]", at: array!)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't sure what to do in this case; this method can be called from encodeBytes(_:length:) with a null array. Maybe they should both have a separate helper function?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is not nullable

@@ -73,11 +73,11 @@ struct _NSDictionaryBridge {
CFIndex (*countForKey)(CFTypeRef dictionary, CFTypeRef key);
bool (*containsKey)(CFTypeRef dictionary, CFTypeRef key);
_Nullable CFTypeRef (*_Nonnull objectForKey)(CFTypeRef dictionary, CFTypeRef key);
bool (*_getValueIfPresent)(CFTypeRef dictionary, CFTypeRef key, CFTypeRef _Nonnull * _Nullable value);
bool (*_getValueIfPresent)(CFTypeRef dictionary, CFTypeRef key, CFTypeRef _Nullable *_Nonnull value);
Copy link
Contributor

Choose a reason for hiding this comment

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

from a pedantic standpoint iirc this is doubly nullable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, are you permitted to use this to ask if a value is present? Okay, will change. Good catch!

@phausler
Copy link
Contributor

phausler commented Apr 5, 2016

This does not seem to build at all for me from the Xcode project, there are some errors in the interface for NSXMLParser. We need to have this compile for both darwin and linux

@jrose-apple
Copy link
Contributor Author

Oooops. Will get on the Darwin side today.

@jrose-apple
Copy link
Contributor Author

Fixed the Darwin side. Now doing a second pass to (a) keep the public API in sync with the SDK shipped with Xcode 7.3, and (b) make sure no behavior changes snuck in. Also planning to rebase after the update for the new parameter naming rules.

@jrose-apple jrose-apple force-pushed the optional-pointers branch 3 times, most recently from 10f1625 to 2099831 Compare April 5, 2016 23:50
@jrose-apple
Copy link
Contributor Author

I'm sorry, this is as small as the patch is going to get. This is the minimal nice patch to get swift-corelibs-foundation to build (on both Linux and Darwin) under the compiler branch above. What I mean by a "nice" patch is preferring if let and guard let to putting ! in bodies, if there was nothing else interesting going on. I suspect the "not nice" patch would end up with more lines changed.

There are three actual behavior changes here:

  • NSUUID's initializer does not take an optional input, and so the special behavior for null pointers has been removed.
  • NSNumber non-keyed decoding was logically broken; the old code would have immediately led to a null pointer dereference.
  • _NSXMLParserStartElementNs had a number of logic inversions (x == nil instead of x != nil); previously these were silently ignored, but they started being caught by tests. These have been fixed.

All public APIs involving pointers ought to match their Darwin equivalents now, except for those in the following classes:

  • NSAttributedString
  • NSFormatter subclasses
  • NSScanner
  • NSStream
  • NSDivideRect(_:_:_:_:_:) (not a class)

There's also an idiom of replacing calls passing nil to pass [] instead. This will generate a pointer referencing Swift's shared empty array buffer; in optimized builds I expect it to be fast. It's also something that can be improved later.

@parkera
Copy link
Contributor

parkera commented Apr 6, 2016

@swift-ci please test

@jrose-apple
Copy link
Contributor Author

Unfortunately that won't work; this depends on the branch in swiftlang/swift#1878.

@parkera
Copy link
Contributor

parkera commented Apr 6, 2016

Ok, I think we decided to hold off on this for the time being then.

shahmishal added a commit to shahmishal/swift-integration-tests that referenced this pull request Apr 12, 2016
shahmishal added a commit to shahmishal/swift-integration-tests that referenced this pull request Apr 12, 2016
shahmishal added a commit to swiftlang/swift-integration-tests that referenced this pull request Apr 12, 2016
shahmishal added a commit to swiftlang/swift-integration-tests that referenced this pull request Apr 12, 2016
shahmishal added a commit to swiftlang/swift-integration-tests that referenced this pull request Apr 12, 2016
@parkera
Copy link
Contributor

parkera commented Apr 12, 2016

We're merging this to unblock the compiler work on this feature. We may have to iterate in master if it causes unintended fallout. @jroose-apple will coordinate.

@parkera parkera merged commit f5d35ed into swiftlang:master Apr 12, 2016
@jrose-apple
Copy link
Contributor Author

I reverted for now so that we can get all related PRs in at roughly the same time.

jrose-apple added a commit that referenced this pull request Apr 12, 2016
We're going to take the changes on all branches now. Re-applies #304,
temporarily reverted in #312.
@jrose-apple jrose-apple deleted the optional-pointers branch April 13, 2016 02:15
atrick pushed a commit to atrick/swift-corelibs-foundation that referenced this pull request Jan 12, 2021
Adopt swift-argument-parser for argument parsing
kateinoigakukun pushed a commit to kateinoigakukun/swift-corelibs-foundation that referenced this pull request Oct 11, 2023
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.

3 participants