Balance the call to allocateBufferIn with a call to deallocateBufferIn. When an error value is small, the missing deallocateBufferIn doesn't do anything. But when the error value is a larger struct that doesn't fit inline, we need deallocateBufferIn to avoid leaking the allocation.
rdar://109933822
getDescription takes its argument at +1, but the implementation was passing the value directly. This caused the contained error value to be destroyed.
rdar://problem/59512630
* SR-7732: Dynamic casting CFError to Error results in a memory leak
The special handling for casting CFError/NSError to Swift Error
type was using cleanup code that didn't correctly handle this case.
This replaces the cleanup code with a more targeted version.
Fixes: SR-7732
Fixes: rdar://problem/40423061
* Whitespace fixes
* Don't rely on localizable strings to verify test behavior.
I've verified this simplified test still leaks with
the original code and does not leak with the fixed code.
* Don't test against old runtimes that predate this fix
* Explicitly test both NSError and CFError
getErrorDomainStringForObjC() now includes the parent types in the error domain string. Its implementation does not support generic types or private discriminators, but those types can’t be PrintAsObjC’d anyway, so we should never see them.
Otherwise we generate a call to String(reflecting:), which correctly handles many things we may not be able to (like private types), and which matches the default implementation of Error._domain.
Completely mechanical changes:
- Explicit @objc in a few places
- Some imported APIs changed
- For the mix-and-match tests, just test version 4/5 instead of 3/4
When working with Error types with unsigned raw values, numeric-cast into
a UInt and then map the bits over to an Int so we preserve values not
representable in an Int without wrapping.
Thanks to @jrose-apple for pointing this out!
Provide default implementations for all of the CustomNSError requirements:
* errorDomain: default to the name of the enum type
* errorCode: default to the same thing "_code" gets, e.g., the enum tag or
raw value
* errorUserInfo: default to empty
This makes it significantly easier to customize just one aspect of the
NSError view of an error type, e.g., just the user-info dictionary,
without having to write boilerplate for the others. This was actually
part of SE-0112, but I missed it in the original implementation and we
thought it was an amendment.
Fixes rdar://problem/23511842.