From 2d1c5e26cb291193ac4d1f4a5179d8f6e1906229 Mon Sep 17 00:00:00 2001 From: Thomas Van Lenten Date: Thu, 2 Mar 2017 14:50:10 -0500 Subject: Handing threading race resolving methods. - Don't prune the extension registry as that can lead to failures when two threads are racing. - If adding the method fails, check and see if it already is bound to decide the return result. Deals with threading races binding the methods. --- objectivec/GPBUtilities.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'objectivec/GPBUtilities.m') diff --git a/objectivec/GPBUtilities.m b/objectivec/GPBUtilities.m index 1843478c..5029ec73 100644 --- a/objectivec/GPBUtilities.m +++ b/objectivec/GPBUtilities.m @@ -1893,6 +1893,25 @@ NSString *GPBDecodeTextFormatName(const uint8_t *decodeData, int32_t key, #pragma clang diagnostic pop +BOOL GPBClassHasSel(Class aClass, SEL sel) { + // NOTE: We have to use class_copyMethodList, all other runtime method + // lookups actually also resolve the method implementation and this + // is called from within those methods. + + BOOL result = NO; + unsigned int methodCount = 0; + Method *methodList = class_copyMethodList(aClass, &methodCount); + for (unsigned int i = 0; i < methodCount; ++i) { + SEL methodSelector = method_getName(methodList[i]); + if (methodSelector == sel) { + result = YES; + break; + } + } + free(methodList); + return result; +} + #pragma mark - GPBMessageSignatureProtocol // A series of selectors that are used solely to get @encoding values -- cgit v1.2.3