OSDN Git Service

2014-05-07 Richard Biener <rguenther@suse.de>
[pf3gnuchains/gcc-fork.git] / libobjc / protocols.c
index af62a2d..a02f2cd 100644 (file)
@@ -23,13 +23,14 @@ see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
 <http://www.gnu.org/licenses/>.  */
 
 #include "objc-private/common.h"
-#include "objc/objc.h"
 #include "objc/runtime.h"
 #include "objc-private/module-abi-8.h" /* For runtime structures  */
 #include "objc/thr.h"
 #include "objc-private/runtime.h"      /* the kitchen sink */
 #include "objc-private/hash.h"         /* For the hash table of protocols.  */
-#include "objc-private/protocols.h"    /* For __objc_protocols_init() and __objc_protocols_add_protocol() */
+#include "objc-private/protocols.h"    /* For __objc_protocols_init() and
+                                          __objc_protocols_add_protocol().  */
+#include <stdlib.h>                    /* For malloc.  */
 
 /* This is a table that maps a name to a Protocol instance with that
    name.  Because there may be multiple Protocol instances with the
@@ -54,7 +55,7 @@ __objc_protocols_init (void)
 
 /* Add a protocol to the hashtable.  */
 void
-__objc_protocols_add_protocol (const char *name, Protocol *object)
+__objc_protocols_add_protocol (const char *name, struct objc_protocol *object)
 {
   objc_mutex_lock (__protocols_hashtable_lock);
 
@@ -68,9 +69,7 @@ __objc_protocols_add_protocol (const char *name, Protocol *object)
      Objective-C programs while trying to catch a problem that has
      never been seen in practice, so we don't do it.  */
   if (! objc_hash_is_key_in_hash (__protocols_hashtable, name))
-    {
-      objc_hash_add (&__protocols_hashtable, name, object);
-    }
+    objc_hash_add (&__protocols_hashtable, name, object);
 
   objc_mutex_unlock (__protocols_hashtable_lock);
 }
@@ -146,7 +145,7 @@ class_addProtocol (Class class_, Protocol *protocol)
 
   /* Check that it is a Protocol object before casting it to (struct
      objc_protocol *).  */
-  if (protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol->class_pointer != objc_lookUpClass ("Protocol"))
     return NO;
 
   objc_mutex_lock (__objc_runtime_mutex);
@@ -154,7 +153,7 @@ class_addProtocol (Class class_, Protocol *protocol)
   /* Create the objc_protocol_list.  */
   protocols = malloc (sizeof (struct objc_protocol_list));
   protocols->count = 1;
-  protocols->list[0] = protocol;
+  protocols->list[0] = (struct objc_protocol *)protocol;
 
   /* Attach it to the list of class protocols.  */
   protocols->next = class_->protocols;
@@ -175,7 +174,7 @@ class_conformsToProtocol (Class class_, Protocol *protocol)
 
   /* Check that it is a Protocol object before casting it to (struct
      objc_protocol *).  */
-  if (protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol->class_pointer != objc_lookUpClass ("Protocol"))
     return NO;
 
   /* Acquire the runtime lock because the list of protocols for a
@@ -190,8 +189,8 @@ class_conformsToProtocol (Class class_, Protocol *protocol)
       size_t i;
       for (i = 0; i < proto_list->count; i++)
        {
-         if (proto_list->list[i] == protocol
-             || protocol_conformsToProtocol (proto_list->list[i],
+         if (proto_list->list[i] == (struct objc_protocol *)protocol
+             || protocol_conformsToProtocol ((Protocol *)proto_list->list[i],
                                              protocol))
            {
              objc_mutex_unlock (__objc_runtime_mutex);
@@ -212,6 +211,13 @@ class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols)
   Protocol **returnValue = NULL;
   struct objc_protocol_list* proto_list;
 
+  if (class_ == Nil)
+    {
+      if (numberOfReturnedProtocols)
+       *numberOfReturnedProtocols = 0;
+      return NULL;
+    }
+
   /* Lock the runtime mutex because the class protocols may be
      concurrently modified.  */
   objc_mutex_lock (__objc_runtime_mutex);
@@ -240,7 +246,7 @@ class_copyProtocolList (Class class_, unsigned int *numberOfReturnedProtocols)
          size_t j;
          for (j = 0; j < proto_list->count; j++)
            {
-             returnValue[i] = proto_list->list[j];
+             returnValue[i] = (Protocol *)proto_list->list[j];
              i++;
            }
          proto_list = proto_list->next;
@@ -272,7 +278,7 @@ protocol_conformsToProtocol (Protocol *protocol, Protocol *anotherProtocol)
   if (protocol->class_pointer != anotherProtocol->class_pointer)
     return NO;
   
-  if (protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol->class_pointer != objc_lookUpClass ("Protocol"))
     return NO;
 
   if (strcmp (((struct objc_protocol *)protocol)->protocol_name,
@@ -288,7 +294,7 @@ protocol_conformsToProtocol (Protocol *protocol, Protocol *anotherProtocol)
       
       for (i = 0; i < proto_list->count; i++)
        {
-         if (protocol_conformsToProtocol (proto_list->list[i], anotherProtocol))
+         if (protocol_conformsToProtocol ((Protocol *)proto_list->list[i], anotherProtocol))
            return YES;
        }
       proto_list = proto_list->next;
@@ -311,7 +317,7 @@ protocol_isEqual (Protocol *protocol, Protocol *anotherProtocol)
   if (protocol->class_pointer != anotherProtocol->class_pointer)
     return NO;
   
-  if (protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol->class_pointer != objc_lookUpClass ("Protocol"))
     return NO;
 
   /* Equality between formal protocols is only formal (nothing to do
@@ -340,7 +346,7 @@ protocol_getName (Protocol *protocol)
 {
   /* Check that it is a Protocol object before casting it to (struct
      objc_protocol *).  */
-  if (protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol->class_pointer != objc_lookUpClass ("Protocol"))
     return NULL;
 
   return ((struct objc_protocol *)protocol)->protocol_name;
@@ -352,7 +358,6 @@ struct objc_method_description protocol_getMethodDescription (Protocol *protocol
                                                              BOOL instanceMethod)
 {
   struct objc_method_description no_result = { NULL, NULL };
-  const char* selector_name;
   struct objc_method_description_list *methods;
   int i;
 
@@ -363,11 +368,9 @@ struct objc_method_description protocol_getMethodDescription (Protocol *protocol
 
   /* Check that it is a Protocol object before casting it to (struct
      objc_protocol *).  */
-  if (protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol->class_pointer != objc_lookUpClass ("Protocol"))
     return no_result;
 
-  selector_name = sel_getName (selector);
-
   if (instanceMethod)
     methods = ((struct objc_protocol *)protocol)->instance_methods;
   else
@@ -377,8 +380,12 @@ struct objc_method_description protocol_getMethodDescription (Protocol *protocol
     {
       for (i = 0; i < methods->count; i++)
        {
-         if (strcmp ((char*)(methods->list[i].name), selector_name) == 0)
+         if (sel_isEqual (methods->list[i].name, selector))
+           return methods->list[i];
+         /*
+         if (strcmp (sel_getName (methods->list[i].name), selector_name) == 0)
            return methods->list[i];
+         */
        }
     }
 
@@ -406,7 +413,7 @@ struct objc_method_description *protocol_copyMethodDescriptionList (Protocol *pr
 
   /* Check that it is a Protocol object before casting it to (struct
      objc_protocol *).  */
-  if (protocol == NULL  ||  protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol == NULL  ||  protocol->class_pointer != objc_lookUpClass ("Protocol"))
     {
       if (numberOfReturnedMethods)
        *numberOfReturnedMethods = 0;
@@ -457,7 +464,7 @@ Property protocol_getProperty (Protocol *protocol, const char *propertyName,
 
   /* Check that it is a Protocol object before casting it to (struct
      objc_protocol *).  */
-  if (protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol->class_pointer != objc_lookUpClass ("Protocol"))
     return NULL;
 
   /* TODO: New ABI.  */
@@ -472,7 +479,7 @@ Property *protocol_copyPropertyList (Protocol *protocol, unsigned int *numberOfR
 
   /* Check that it is a Protocol object before casting it to (struct
      objc_protocol *).  */
-  if (protocol == NULL  ||  protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol == NULL  ||  protocol->class_pointer != objc_lookUpClass ("Protocol"))
     {
       if (numberOfReturnedProperties)
        *numberOfReturnedProperties = 0;
@@ -499,7 +506,7 @@ Protocol **protocol_copyProtocolList (Protocol *protocol, unsigned int *numberOf
 
   /* Check that it is a Protocol object before casting it to (struct
      objc_protocol *).  */
-  if (protocol == NULL  ||  protocol->class_pointer != objc_lookupClass ("Protocol"))
+  if (protocol == NULL  ||  protocol->class_pointer != objc_lookUpClass ("Protocol"))
     {
       if (numberOfReturnedProtocols)
        *numberOfReturnedProtocols = 0;
@@ -534,7 +541,7 @@ Protocol **protocol_copyProtocolList (Protocol *protocol, unsigned int *numberOf
          size_t j;
          for (j = 0; j < proto_list->count; j++)
            {
-             returnValue[i] = proto_list->list[j];
+             returnValue[i] = (Protocol *)proto_list->list[j];
              i++;
            }
          proto_list = proto_list->next;