From 2af9c6859149fafe048a5c9ac351ef078919331d Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Tue, 4 Dec 2018 10:47:35 -0500 Subject: [PATCH] Annotate the GPBArray enumerate* apis with NS_NOESCAPE. This should help the Swift compiler if these apis are used because it changes the codegen to not need copies/retains. --- objectivec/GPBArray.h | 44 +++++++++++++++++++++---------------------- objectivec/GPBArray.m | 40 +++++++++++++++++++-------------------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/objectivec/GPBArray.h b/objectivec/GPBArray.h index 638b2882d3..3d22cb8173 100644 --- a/objectivec/GPBArray.h +++ b/objectivec/GPBArray.h @@ -134,7 +134,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -146,7 +146,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -306,7 +306,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -318,7 +318,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -478,7 +478,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -490,7 +490,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -650,7 +650,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -662,7 +662,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -822,7 +822,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -834,7 +834,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -994,7 +994,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -1006,7 +1006,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -1166,7 +1166,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -1178,7 +1178,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block; /** * Adds a value to this array. @@ -1369,7 +1369,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -1381,7 +1381,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; // These methods bypass the validationFunc to provide access to values that were not // known at the time the binary was compiled. @@ -1403,7 +1403,7 @@ NS_ASSUME_NONNULL_BEGIN * **idx**: The index of the current value. * **stop**: A pointer to a boolean that when set stops the enumeration. **/ -- (void)enumerateRawValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block; +- (void)enumerateRawValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; /** * Enumerates the values on this array with the given block. @@ -1415,7 +1415,7 @@ NS_ASSUME_NONNULL_BEGIN * **stop**: A pointer to a boolean that when set stops the enumeration. **/ - (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block; + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block; // If value is not a valid enumerator as defined by validationFunc, these // methods will assert in debug, and will log in release and assign the value @@ -1779,7 +1779,7 @@ NS_ASSUME_NONNULL_END //% * **idx**: The index of the current value. //% * **stop**: A pointer to a boolean that when set stops the enumeration. //% **/ -//%- (void)enumerateRawValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block; +//%- (void)enumerateRawValuesWithBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block; //% //%/** //% * Enumerates the values on this array with the given block. @@ -1791,7 +1791,7 @@ NS_ASSUME_NONNULL_END //% * **stop**: A pointer to a boolean that when set stops the enumeration. //% **/ //%- (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts -//% usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block; +//% usingBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block; //% //%// If value is not a valid enumerator as defined by validationFunc, these //%// methods will assert in debug, and will log in release and assign the value @@ -1821,7 +1821,7 @@ NS_ASSUME_NONNULL_END //% * **idx**: The index of the current value. //% * **stop**: A pointer to a boolean that when set stops the enumeration. //% **/ -//%- (void)enumerateValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block; +//%- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block; //% //%/** //% * Enumerates the values on this array with the given block. @@ -1833,7 +1833,7 @@ NS_ASSUME_NONNULL_END //% * **stop**: A pointer to a boolean that when set stops the enumeration. //% **/ //%- (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts -//% usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block; +//% usingBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block; //%PDDM-DEFINE ARRAY_MUTABLE_INTERFACE(NAME, TYPE, HELPER_NAME) //%/** diff --git a/objectivec/GPBArray.m b/objectivec/GPBArray.m index 122e0304b3..5ce1e593cb 100644 --- a/objectivec/GPBArray.m +++ b/objectivec/GPBArray.m @@ -194,12 +194,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { //% return result; //%} //% -//%- (void)enumerate##ACCESSOR_NAME##ValuesWithBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block { +//%- (void)enumerate##ACCESSOR_NAME##ValuesWithBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block { //% [self enumerate##ACCESSOR_NAME##ValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; //%} //% //%- (void)enumerate##ACCESSOR_NAME##ValuesWithOptions:(NSEnumerationOptions)opts -//% ACCESSOR_NAME$S usingBlock:(void (^)(TYPE value, NSUInteger idx, BOOL *stop))block { +//% ACCESSOR_NAME$S usingBlock:(void (NS_NOESCAPE ^)(TYPE value, NSUInteger idx, BOOL *stop))block { //% // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). //% BOOL stop = NO; //% if ((opts & NSEnumerationReverse) == 0) { @@ -405,12 +405,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -653,12 +653,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(uint32_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(uint32_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -901,12 +901,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(int64_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(int64_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -1149,12 +1149,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(uint64_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(uint64_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -1397,12 +1397,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(float value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(float value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -1645,12 +1645,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(double value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(double value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -1893,12 +1893,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateValuesWithBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(BOOL value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(BOOL value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -2165,12 +2165,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return result; } -- (void)enumerateRawValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateRawValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { [self enumerateRawValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateRawValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; if ((opts & NSEnumerationReverse) == 0) { @@ -2217,12 +2217,12 @@ static BOOL ArrayDefault_IsValidValue(int32_t value) { return _values[index]; } -- (void)enumerateValuesWithBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block { +- (void)enumerateValuesWithBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { [self enumerateValuesWithOptions:(NSEnumerationOptions)0 usingBlock:block]; } - (void)enumerateValuesWithOptions:(NSEnumerationOptions)opts - usingBlock:(void (^)(int32_t value, NSUInteger idx, BOOL *stop))block { + usingBlock:(void (NS_NOESCAPE ^)(int32_t value, NSUInteger idx, BOOL *stop))block { // NSEnumerationConcurrent isn't currently supported (and Apple's docs say that is ok). BOOL stop = NO; GPBEnumValidationFunc func = _validationFunc;