/* GNU Objective C Runtime selector related functions
- Copyright (C) 1993, 1995, 1996, 1997, 2002, 2004, 2009 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1995, 1996, 1997, 2002, 2004, 2009, 2010
+ Free Software Foundation, Inc.
Contributed by Kresten Krab Thorup
This file is part of GCC.
sel_getTypedSelector (const char *name)
{
sidx i;
- objc_mutex_lock (__objc_runtime_mutex);
+ if (name == NULL)
+ return NULL;
+
+ objc_mutex_lock (__objc_runtime_mutex);
+
/* Look for a typed selector. */
i = (sidx) objc_hash_value_for_key (__objc_selector_hash, 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)
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. */
return s;
}
}
- else if (! strcmp (s->sel_types, types))
+ else if (sel_types_match (s->sel_types, types))
{
if (orig)
{
sel_registerName (const char *name)
{
SEL ret;
+
+ if (name == NULL)
+ return NULL;
objc_mutex_lock (__objc_runtime_mutex);
/* Assume that name is not constant static memory and needs to be
{
SEL ret;
+ if (name == NULL)
+ return NULL;
+
objc_mutex_lock (__objc_runtime_mutex);
/* Assume that name and type are not constant static memory and need
to be copied before put into a runtime structure. is_const ==