From 9b971ff831d21ce2bc91979f68d5d167c136990c Mon Sep 17 00:00:00 2001 From: nicola Date: Mon, 28 Feb 2011 14:48:23 +0000 Subject: In libobjc/: 2011-02-28 Nicola Pero * selector.c (sel_getTypedSelector): Return NULL if there are multiple selectors with conflicting types. * objc/runtime.h (sel_getTypedSelector): Updated documentation. In gcc/testsuite/: 2011-02-28 Nicola Pero * objc.dg/gnu-api-2-sel.m: Test that sel_getTypedSelector return NULL in case of a selector with conflicting types. * obj-c++.dg/gnu-api-2-sel.mm: Same change. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@170563 138bc75d-0d04-0410-961f-82ee72b054a4 --- libobjc/selector.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'libobjc/selector.c') diff --git a/libobjc/selector.c b/libobjc/selector.c index 99efcf87e6c..80d2d800422 100644 --- a/libobjc/selector.c +++ b/libobjc/selector.c @@ -369,6 +369,7 @@ sel_getTypedSelector (const char *name) if (i != 0) { struct objc_list *l; + SEL returnValue = NULL; for (l = (struct objc_list *) sarray_get_safe (__objc_selector_array, i); l; l = l->tail) @@ -376,10 +377,40 @@ sel_getTypedSelector (const char *name) SEL s = (SEL) l->head; if (s->sel_types) { - objc_mutex_unlock (__objc_runtime_mutex); - return s; + if (returnValue == NULL) + { + /* First typed selector that we find. Keep it in + returnValue, but keep checking as we want to + detect conflicts. */ + returnValue = s; + } + else + { + /* We had already found a typed selectors, so we + have multiple ones. Double-check that they have + different types, just in case for some reason we + got duplicates with the same types. If so, it's + OK, we'll ignore the duplicate. */ + if (returnValue->sel_types == s->sel_types) + continue; + else if (sel_types_match (returnValue->sel_types, s->sel_types)) + continue; + else + { + /* The types of the two selectors are different; + it's a conflict. Too bad. Return NULL. */ + objc_mutex_unlock (__objc_runtime_mutex); + return NULL; + } + } } } + + if (returnValue != NULL) + { + objc_mutex_unlock (__objc_runtime_mutex); + return returnValue; + } } /* No typed selector found. Return NULL. */ -- cgit v1.2.1