Make it safe to use -mkt_arguments as a generic helper #175
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently it is not safe to use
-[NSInvocation mkt_arguments]
withNSInvocation
objects that don't come from OCMockito itself, as it doesn't call-[NSInvocation retainArguments]
before adding the argument values to an autoreleasedNSArray
. Meaning that if theNSInvocation
object has a stack block argument, it would be added as is to theNSArray
as-[__NSStackBlock__ retain]
does nothing. And the program might crash if the autorelease elision optimisation happens to not be performed by the objc runtime on the array, and the array ends up in an autorelease pool outliving the stack block and segfaults when trying to release the block during deallocation when the pool is finally popped.It is safe to use
-mkt_arguments
withNSInvocation
objects produced by OCMockito itself as-[NSInvocation retainArguments]
is automatically called via:-[NSInvocation mkt_retainArgumentsWithWeakTarget]
-[MKTInvocationContainer setInvocationForPotentialStubbing:]
-[MKTBaseMockObject forwardInvocation:]
It is trivial, safe and cheap to add a call to
-retainArguments
at the start of-mkt_arguments
as it doesn't do anything in case if the arguments have already been retained, which is the case forNSInvocation
objects produced by OCMockito itself.And this makes it safe and convenient to use
-mkt_arguments
as a generic helper for anyNSInvocation
objects regardless of their provenance.