aboutsummaryrefslogtreecommitdiff
path: root/libobjc/selector.c
diff options
context:
space:
mode:
authorNicola Pero <nicola.pero@meta-innovation.com>2011-02-28 14:48:23 +0000
committerNicola Pero <nicola@gcc.gnu.org>2011-02-28 14:48:23 +0000
commit68ade9e4e84617fd5c613618cfdc0cc1fa6d6d81 (patch)
tree2206ef603597ed2c4ee93c47cebe6a18a1f3fcb0 /libobjc/selector.c
parent2f2935b6d5c7d9976710d40b79036bec4c7087aa (diff)
In libobjc/: 2011-02-28 Nicola Pero <nicola.pero@meta-innovation.com>
In libobjc/: 2011-02-28 Nicola Pero <nicola.pero@meta-innovation.com> * 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 <nicola.pero@meta-innovation.com> * 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. From-SVN: r170563
Diffstat (limited to 'libobjc/selector.c')
-rw-r--r--libobjc/selector.c35
1 files changed, 33 insertions, 2 deletions
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. */