signalapp / libsignal

Home to the Signal Protocol as well as other cryptographic primitives which make Signal possible.
GNU Affero General Public License v3.0
3.55k stars 415 forks source link

Swift: ensure deinitializers don't run until Rust calls complete #381

Closed jrose-signal closed 3 years ago

jrose-signal commented 3 years ago

The Swift version of #380. This one's mostly being proactive, since the Swift compiler will not optimize across modules at this time without explicitly marking code as inlinable, but it's possible that an operation that creates and destroys an object entirely within the SignalClient module could have the deinitialization of the Swift wrapper happen before the Rust object pointer's final use. The standard withExtendedLifetime protects against this, and the new withNativeHandle wraps that up to access the native object pointer at the same time.

In order to implement this uniformly, I also brought all wrapper objects under a common superclass.