]> gcc.gnu.org Git - gcc.git/commitdiff
In libobjc/: 2011-10-08 Richard Frith-Macdonald <rfm@gnu.org> Nicola Pero <nicola...
authorNicola Pero <nicola@gcc.gnu.org>
Sat, 8 Oct 2011 17:52:06 +0000 (17:52 +0000)
committerNicola Pero <nicola@gcc.gnu.org>
Sat, 8 Oct 2011 17:52:06 +0000 (17:52 +0000)
In libobjc/:
2011-10-08  Richard Frith-Macdonald <rfm@gnu.org>
            Nicola Pero  <nicola.pero@meta-innovation.com>

PR libobjc/50428
* sendmsg.c (__objc_send_initialize): If a class does not have an
+initialize method, search for an +initialize method in the
superclass and in the ancestor classes and execute the first one
that is found.  This makes the GNU runtime behave in the same way
as the Apple/NeXT runtime with respect to +initialize methods and
subclassing.

In gcc/:
2011-10-08  Nicola Pero  <nicola.pero@meta-innovation.com>

PR libobjc/50428
* doc/objc.texi (Garbage Collection): Updated example to protect
+initialize against execution in subclasses.

In gcc/testsuite/:
2011-10-08  Nicola Pero  <nicola.pero@meta-innovation.com>

PR libobjc/50428
* objc/execute/initialize-1.m: New test.

From-SVN: r179711

gcc/ChangeLog
gcc/doc/objc.texi
gcc/testsuite/ChangeLog
gcc/testsuite/objc/execute/initialize-1.m [new file with mode: 0644]
libobjc/ChangeLog
libobjc/sendmsg.c

index 2bd1217c763c0c38245162d0f6e40be143face2f..edf17165872dbff7e345b3bc326fd271036538f0 100644 (file)
@@ -1,3 +1,9 @@
+2011-10-08  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       PR libobjc/50428
+       * doc/objc.texi (Garbage Collection): Updated example to protect
+       +initialize against execution in subclasses.
+
 2011-10-07  Richard Henderson  <rth@redhat.com>
 
        * doc/extend.texi (__builtin_shuffle): Improve the description to
index dd04eda82f78c62a478962f4ba39701e68a3af8f..a36b0e70530472f369d8f081a6a603bda4e630db 100644 (file)
@@ -635,7 +635,8 @@ following class does this:
 
 + (void)initialize
 @{
-  class_ivar_set_gcinvisible (self, "weakPointer", YES);
+  if (self == objc_lookUpClass ("WeakPointer"))
+    class_ivar_set_gcinvisible (self, "weakPointer", YES);
 @}
 
 - initWithPointer:(const void*)p
index 02a8ffd119e837b78a98c68ccf6a1d23e91aa948..74ab91220f5082c642ddf42c4472d0796fcea4fe 100644 (file)
@@ -1,3 +1,8 @@
+2011-10-08  Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       PR libobjc/50428        
+       * objc/execute/initialize-1.m: New test.
+
 2011-10-08  Paul Thomas  <pault@gcc.gnu.org>
 
        PR fortran/47844
diff --git a/gcc/testsuite/objc/execute/initialize-1.m b/gcc/testsuite/objc/execute/initialize-1.m
new file mode 100644 (file)
index 0000000..9ca4aeb
--- /dev/null
@@ -0,0 +1,47 @@
+/* Contributed by Nicola Pero - Sat  8 Oct 2011 16:47:48 BST */
+#include <objc/objc.h>
+
+/* Test that if a class has no +initialize method, the superclass
+   implementation is called.  */
+
+static int class_variable = 0;
+
+@interface TestClass
+{
+  Class isa;
+}
++ (void) initialize;
++ (int) classVariable;
+@end
+
+@implementation TestClass
++ (void) initialize
+{
+  class_variable++;
+}
++ (int) classVariable
+{
+  return class_variable;
+}
+@end
+
+@interface TestSubClass : TestClass
+@end
+
+@implementation TestSubClass
+@end
+
+int main (void)
+{
+  if ([TestClass classVariable] != 1)
+    {
+      abort ();
+    }
+
+  if ([TestSubClass classVariable] != 2)
+    {
+      abort ();
+    }
+
+  return 0;
+}
index b9f87fabec9ff4d2da24a80b48b37db17ea4492c..f88f2f45cdf682aeb4c99dc38a2fc40be5986434 100644 (file)
@@ -1,3 +1,14 @@
+2011-10-08  Richard Frith-Macdonald <rfm@gnu.org>
+            Nicola Pero  <nicola.pero@meta-innovation.com>
+
+       PR libobjc/50428
+       * sendmsg.c (__objc_send_initialize): If a class does not have an
+       +initialize method, search for an +initialize method in the
+       superclass and in the ancestor classes and execute the first one
+       that is found.  This makes the GNU runtime behave in the same way
+       as the Apple/NeXT runtime with respect to +initialize methods and
+       subclassing.
+
 2011-08-06  Nicola Pero  <nicola.pero@meta-innovation.com>
 
        PR libobjc/50002
index 8aa266dd11f61b74237a9269910e230608c581c3..ea8ea9702628460e947356df0ef34a284d8e86c4 100644 (file)
@@ -516,34 +516,13 @@ __objc_send_initialize (Class class)
 
       {
        SEL op = sel_registerName ("initialize");
-       IMP imp = 0;
-        struct objc_method_list * method_list = class->class_pointer->methods;
-       
-        while (method_list)
-         {
-           int i;
-           struct objc_method * method;
-           
-           for (i = 0; i < method_list->method_count; i++)
-             {
-               method = &(method_list->method_list[i]);
-               if (method->method_name
-                   && method->method_name->sel_id == op->sel_id)
-                 {
-                   imp = method->method_imp;
-                   break;
-                 }
-             }
-           
-           if (imp)
-             break;
-           
-           method_list = method_list->method_next;
-         }
-       if (imp)
+        struct objc_method *method = search_for_method_in_hierarchy (class->class_pointer, 
+                                                                    op);
+
+       if (method)
          {
            DEBUG_PRINTF (" begin of [%s +initialize]\n", class->name);
-           (*imp) ((id) class, op);
+           (*method->method_imp) ((id)class, op);
            DEBUG_PRINTF (" end of [%s +initialize]\n", class->name);
          }
 #ifdef DEBUG
This page took 0.146662 seconds and 5 git commands to generate.