OSDN Git Service

2011-05-25 Richard Guenther <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / libobjc / selector.c
index f8a7f14..628b4f6 100644 (file)
@@ -1,5 +1,6 @@
 /* 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.
@@ -357,13 +358,18 @@ SEL
 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)
@@ -371,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.  */
@@ -561,7 +597,7 @@ __sel_register_typed_name (const char *name, const char *types,
                    return s;
                }
            }
-         else if (! strcmp (s->sel_types, types))
+         else if (sel_types_match (s->sel_types, types))
            {
              if (orig)
                {
@@ -658,6 +694,9 @@ SEL
 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
@@ -680,6 +719,9 @@ sel_registerTypedName (const char *name, const char *type)
 {
   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 ==