Commit Graph

11 Commits

Author SHA1 Message Date
Mishal Shah
e7cd5ab17f Update master to build with Xcode 11.4 2020-03-24 11:30:45 -07:00
Xiaodi Wu
1d7ec4c129 [NFC][Foundation] Remove or replace unnecessary uses of 'fileprivate' 2020-02-23 13:45:13 -05:00
Shengqi Zhu
45112229b6 [Foundation]Fix newValue/oldValue in swift KVO when keyPath having a optional value
Fix https://bugs.swift.org/browse/SR-6066.
2019-05-23 23:32:42 +08:00
Lily Vulcano
bdb4686375 Take 2 of “[SDK] Fix multiple issues with Swift KVO”
This reproposes @lilyball’s fixes in https://github.com/apple/swift/pull/20103 while adding her fix to ensure observations are removed before observed objects in 32-bit testing.
2019-02-01 14:07:44 -08:00
Lily Vulcano
ac7a93963c Revert "Merge pull request #20103 from lilyball/fix_kvo"
This reverts commit 7c514196fc, reversing
changes made to 2d7c31b24c.

This patch will be reproposed with fixes.
2019-02-01 10:55:06 -08:00
Lily Ballard
4dd8bcc548 [SDK] Clean up the KVO swizzles slightly 2019-01-30 12:41:14 -08:00
Lily Ballard
fafaa33f9b [SDK] Replace global KeyPath table with a per-thread table
The global table was vulnerable to race conditions when making
observations concurrently on multiple threads. We can assume the
`NSKeyValueObservingCustomization` methods are invoked synchronously
when creating the observation, so we can use a per-thread table instead.
This per-thread table is still vulnerable in the event that an
implementation of `automaticallyNotifiesObservers(for:)` creates a new
observation using a different `KeyPath` with the same Obj-C path, but
this method really shouldn't be creating any observations of its own.

Unfortunately we can't include the class in the per-thread table key, as
this may produce incorrect results in the presence of subclasses.

rdar://problem/45567020 https://bugs.swift.org/browse/SR-9077
2019-01-30 12:41:14 -08:00
Lily Ballard
e5ba2c8356 [SDK] Fix NSSortDescriptor.keyPath
The previous implementation could return keyPaths other than the one
used to create the `NSSortDescriptor` in the event that any subsequent
observation, `NSExpression`, or `NSSortDescriptor` was created using a
different `KeyPath` that had the same Obj-C keypath value.

https://bugs.swift.org/browse/SR-9076
2019-01-30 12:41:13 -08:00
Lily Ballard
82e3171556 [SDK] Fix potential race with NSKeyValueObservation
If the `NSKeyValueObservation` was being deinited on one thread while a
KVO change notice was being broadcast on another, it could end up trying
to handle the change notice concurrently with deiniting, which will
probably crash.

This also fixes a problem where it was swizzling `NSObject`'s
`observeValue(forKeyPath:of:change:context:)` implementation, which
resulted in potentially invoking undefined behavior if an observer ever
called up to `NSObject`'s implementation.

https://bugs.swift.org/browse/SR-9074
https://bugs.swift.org/browse/SR-9075
2019-01-30 12:41:13 -08:00
Lily Ballard
dd51e9d4bb [SDK] Fix thread safety of KVO swizzling
Swizzling the methods in a different order ensures we don't overwrite
the public `NSObject` method until it's safe to call our replacement.

rdar://problem/36663633 https://bugs.swift.org/browse/SR-6795
2019-01-30 12:41:13 -08:00
Saleem Abdulrasool
41d9c2cc59 stdlib: restructure for OS family layout of SDK overlay
The SDK directory is now confusing as the Windows target also has a SDK
overlay.  In order to make this more uniform, move the SDK directory to
Darwin which covers the fact that this covers the XNU family of OSes.
The Windows directory contains the SDK overlay for the Windows target.
2018-12-06 11:32:05 -08:00