Skip to content

[SR-2416] allow non-NSObject types to be archived #574

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
Oct 27, 2016

Conversation

lhoward
Copy link
Contributor

@lhoward lhoward commented Aug 19, 2016

This patch fixes a number of issues that were preventing non-NSObject types from being archived, even though the new method signatures imply that they can be (by taking Any).

  • fix regression introduced aa504dc where non-hashable objects could not be encoded
  • fix bug where non-NSObjects would be replaced with nil, causing a crash
  • remove explicit check that the encoded object is a NSObject
  • possibly should be a separate patch: transparently bridge value types to the corresponding reference type before encoding
  • tests for all over the above

@parkera
Copy link
Contributor

parkera commented Oct 6, 2016

I'm pretty sure you can't archive non-NSObject classes on Darwin either, actually.

@parkera
Copy link
Contributor

parkera commented Oct 6, 2016

@swift-ci please test

@lhoward
Copy link
Contributor Author

lhoward commented Oct 7, 2016

On 6 Oct 2016, at 6:59 PM, Tony Parker [email protected] wrote:

I'm pretty sure you can't archive non-NSObject classes on Darwin either, actually.

Right, we discussed this earlier – this is for code portability because conforming to NSCoding without explicitly subclassing NSObject will automatically make a class @objc on Darwin (as I understand it), but not with SwiftFoundation.

@parkera
Copy link
Contributor

parkera commented Oct 7, 2016

Yes, thanks for the reminder.

@parkera
Copy link
Contributor

parkera commented Oct 7, 2016

Build failure:

TestFoundation/TestNSKeyedArchiver.swift:156:63: error: 'Any' is not convertible to 'AnyObject'; did you mean to use 'as!' to force downcast?
        return test_archive(object, classes: [type(of: object as AnyObject)], allowsSecureCoding: allowsSecureCoding)
                                                       ~~~~~~~^~~~~~~~~~~~
                                                              as!
ninja: build stopped: subcommand failed.

@lhoward
Copy link
Contributor Author

lhoward commented Oct 7, 2016

It builds fine with the XCode 8.0 toolchain, I’ll try with a recent snapshot and fix any errors.

@parkera
Copy link
Contributor

parkera commented Oct 7, 2016

It's probably a cross-platform problem with bridging on Linux; I don't think building in Xcode will show the issue.

@lhoward
Copy link
Contributor Author

lhoward commented Oct 7, 2016

OK, should I just make the change suggested by the compiler below then? I can’t test on Linux right now (just off a 30 hour flight).

On 7 Oct 2016, at 6:58 PM, Tony Parker [email protected] wrote:

Build failure:

TestFoundation/TestNSKeyedArchiver.swift:156:63: error: 'Any' is not convertible to 'AnyObject'; did you mean to use 'as!' to force downcast?
return test_archive(object, classes: [type(of: object as AnyObject)], allowsSecureCoding: allowsSecureCoding)
~~~~~~~^~~~~~~~~~~~
as!
ninja: build stopped: subcommand failed.

You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #574 (comment), or mute the thread https://github.com/notifications/unsubscribe-auth/AAhCNwoEAA5fDkqTjpi0FLEWIDqOySpsks5qxnpHgaJpZM4JoIha.

www.lukehoward.com
soundcloud.com/lukehoward

@parkera
Copy link
Contributor

parkera commented Oct 7, 2016

I think that'll just end up creating a warning on Mac. @phausler what's the right incantation here?

@lhoward
Copy link
Contributor Author

lhoward commented Oct 7, 2016

It does create a warning on Mac :(

Sent from my iPhone

On 7 Oct. 2016, at 22:14, Tony Parker [email protected] wrote:

I think that'll just end up creating a warning on Mac. @phausler what's the right incantation here?


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.

// test both XML and binary encodings
test_archive(object, classes: classes, allowsSecureCoding: allowsSecureCoding, outputFormat: PropertyListSerialization.PropertyListFormat.xml)
test_archive(object, classes: classes, allowsSecureCoding: allowsSecureCoding, outputFormat: PropertyListSerialization.PropertyListFormat.binary)
}

private func test_archive(_ object: NSObject, allowsSecureCoding: Bool = true) {
return test_archive(object, classes: [type(of: object)], allowsSecureCoding: allowsSecureCoding)
private func test_archive(_ object: Any, allowsSecureCoding: Bool = true) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be NSObject or AnyObject still.

This patch fixes a number of issues that were preventing non-NSObject types
from being archived, even though the new method signatures imply that they can
be (by taking Any).

* fix regression introduced aa504dc where non-hashable objects could not be
  encoded
* fix bug where non-NSObjects would be replaced with nil, causing a crash
* remove explicit check that the encoded object is a NSObject
* possibly should be a separate patch: transparently bridge value types to the
  corresponding reference type before encoding
* tests for all over the above
@lhoward
Copy link
Contributor Author

lhoward commented Oct 8, 2016

Fixed.

On 7 Oct 2016, at 10:25 PM, Philippe Hausler [email protected] wrote:

@phausler commented on this pull request.

In TestFoundation/TestNSKeyedArchiver.swift #574 (review):

     // test both XML and binary encodings
     test_archive(object, classes: classes, allowsSecureCoding: allowsSecureCoding, outputFormat: PropertyListSerialization.PropertyListFormat.xml)
     test_archive(object, classes: classes, allowsSecureCoding: allowsSecureCoding, outputFormat: PropertyListSerialization.PropertyListFormat.binary)
 }
  • private func test_archive(_ object: NSObject, allowsSecureCoding: Bool = true) {
  •    return test_archive(object, classes: [type(of: object)], allowsSecureCoding: allowsSecureCoding)
    
  • private func test_archive(_ object: Any, allowsSecureCoding: Bool = true) {
    This should probably be NSObject or AnyObject still.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub #574 (review), or mute the thread https://github.com/notifications/unsubscribe-auth/AAhCN1I7vjO0t2jx9mvb9DMxfzQ4jTtyks5qxqq0gaJpZM4JoIha.

www.lukehoward.com
soundcloud.com/lukehoward

@parkera
Copy link
Contributor

parkera commented Oct 10, 2016

@swift-ci please test

@lhoward
Copy link
Contributor Author

lhoward commented Oct 11, 2016

This build failure doesn't seem to be SwiftFoundation related?

@parkera
Copy link
Contributor

parkera commented Oct 11, 2016

Yah, let's try that again.

@parkera
Copy link
Contributor

parkera commented Oct 11, 2016

@swift-ci please test

@parkera
Copy link
Contributor

parkera commented Oct 27, 2016

@swift-ci please test and merge

@swift-ci swift-ci merged commit 762f0c0 into swiftlang:master Oct 27, 2016
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.

4 participants