Commit 0e0677a2 by Nicola Pero Committed by Nicola Pero

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

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

	PR libobjc/50002
	* class.c (__objc_update_classes_with_methods): Iterate over meta
	classes as well as normal classes when refreshing the method
	implementations.  This fixes replacing class methods.

2011-08-06  Nicola Pero  <nicola.pero@meta-innovation.com>

	* class.c (class_getSuperclass): Fixed to work with meta classes
	still in construction too.

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

	PR libobjc/50002
	* objc.dg/gnu-api-2-class.m: Updated comments.
	* obj-c++.dg/gnu-api-2-class.mm: Likewise.
	* objc.dg/gnu-api-2-class-meta.m: New test.
	* obj-c++.dg/gnu-api-2-class-meta.mm: Likewise.
	
2011-08-06  Nicola Pero  <nicola.pero@meta-innovation.com>
	
	PR libobjc/49882
	* obj-c++.dg/gnu-api-2-class.mm (main): Test class_getSuperclass()
	with classes that are in construction.

From-SVN: r177510
parent 7dff453e
2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com>
PR libobjc/50002
* objc.dg/gnu-api-2-class.m: Updated comments.
* obj-c++.dg/gnu-api-2-class.mm: Likewise.
* objc.dg/gnu-api-2-class-meta.m: New test.
* obj-c++.dg/gnu-api-2-class-meta.mm: Likewise.
2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com>
PR libobjc/49882
* obj-c++.dg/gnu-api-2-class.mm (main): Test class_getSuperclass()
with classes that are in construction.
2011-08-06 H.J. Lu <hongjiu.lu@intel.com> 2011-08-06 H.J. Lu <hongjiu.lu@intel.com>
PR target/48084 PR target/48084
......
/* Test the Modern GNU Objective-C Runtime API. /* Test the Modern GNU Objective-C Runtime API.
This is test 'class', covering all functions starting with 'class'. */ This is test 'class', covering all functions starting with 'class'.
Tests calling the functions with a meta class as argument are covered
in the separate file, gnu-api-2-class-meta.mm. */
/* { dg-do run } */ /* { dg-do run } */
/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
...@@ -394,6 +396,14 @@ int main () ...@@ -394,6 +396,14 @@ int main ()
MySubClass *object = [[MySubClass alloc] init]; MySubClass *object = [[MySubClass alloc] init];
if (class_getSuperclass (object_getClass (object)) != objc_getClass ("MyRootClass")) if (class_getSuperclass (object_getClass (object)) != objc_getClass ("MyRootClass"))
abort (); abort ();
/* Test that it works on a newly created, but not registered, class. */
{
Class new_class = objc_allocateClassPair (objc_getClass ("MyRootClass"), "MySubClass3", 0);
if (class_getSuperclass (new_class) != objc_getClass ("MyRootClass"))
abort ();
}
} }
std::cout << "Testing class_getVersion ()...\n"; std::cout << "Testing class_getVersion ()...\n";
......
/* Test the Modern GNU Objective-C Runtime API. /* Test the Modern GNU Objective-C Runtime API.
This is test 'class', covering all functions starting with 'class'. */ This is test 'class', covering all functions starting with 'class'.
Tests calling the functions with a meta class as argument are covered
in the separate file, gnu-api-2-class-meta.m. */
/* { dg-do run } */ /* { dg-do run } */
/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ /* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */
...@@ -401,7 +403,7 @@ int main(int argc, void **args) ...@@ -401,7 +403,7 @@ int main(int argc, void **args)
if (class_getSuperclass (new_class) != objc_getClass ("MyRootClass")) if (class_getSuperclass (new_class) != objc_getClass ("MyRootClass"))
abort (); abort ();
} }
} }
printf ("Testing class_getVersion ()...\n"); printf ("Testing class_getVersion ()...\n");
......
2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com> 2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com>
PR libobjc/50002
* class.c (__objc_update_classes_with_methods): Iterate over meta
classes as well as normal classes when refreshing the method
implementations. This fixes replacing class methods.
2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com>
* class.c (class_getSuperclass): Fixed to work with meta classes
still in construction too.
2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com>
* class.c (class_getSuperclass): Fixed typo in comment. * class.c (class_getSuperclass): Fixed typo in comment.
2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com> 2011-08-06 Nicola Pero <nicola.pero@meta-innovation.com>
......
...@@ -781,35 +781,57 @@ __objc_update_classes_with_methods (struct objc_method *method_a, struct objc_me ...@@ -781,35 +781,57 @@ __objc_update_classes_with_methods (struct objc_method *method_a, struct objc_me
while (node != NULL) while (node != NULL)
{ {
/* Iterate over all methods in the class. */ /* We execute this loop twice: the first time, we iterate
Class class = node->pointer; over all methods in the class (instance methods), while
struct objc_method_list * method_list = class->methods; the second time we iterate over all methods in the meta
class (class methods). */
while (method_list) Class class = Nil;
BOOL done = NO;
while (done == NO)
{ {
int i; struct objc_method_list * method_list;
for (i = 0; i < method_list->method_count; ++i) if (class == Nil)
{
/* The first time, we work on the class. */
class = node->pointer;
}
else
{ {
struct objc_method *method = &method_list->method_list[i]; /* The second time, we work on the meta class. */
class = class->class_pointer;
done = YES;
}
/* If the method is one of the ones we are looking method_list = class->methods;
for, update the implementation. */
if (method == method_a)
sarray_at_put_safe (class->dtable,
(sidx) method_a->method_name->sel_id,
method_a->method_imp);
if (method == method_b) while (method_list)
{
int i;
for (i = 0; i < method_list->method_count; ++i)
{ {
if (method_b != NULL) struct objc_method *method = &method_list->method_list[i];
/* If the method is one of the ones we are
looking for, update the implementation. */
if (method == method_a)
sarray_at_put_safe (class->dtable, sarray_at_put_safe (class->dtable,
(sidx) method_b->method_name->sel_id, (sidx) method_a->method_name->sel_id,
method_b->method_imp); method_a->method_imp);
if (method == method_b)
{
if (method_b != NULL)
sarray_at_put_safe (class->dtable,
(sidx) method_b->method_name->sel_id,
method_b->method_imp);
}
} }
method_list = method_list->method_next;
} }
method_list = method_list->method_next;
} }
node = node->next; node = node->next;
} }
...@@ -929,7 +951,12 @@ class_getSuperclass (Class class_) ...@@ -929,7 +951,12 @@ class_getSuperclass (Class class_)
superclass name to return the superclass. We can not resolve the superclass name to return the superclass. We can not resolve the
class until it is registered. */ class until it is registered. */
if (CLS_IS_IN_CONSTRUCTION (class_)) if (CLS_IS_IN_CONSTRUCTION (class_))
return objc_lookUpClass ((const char *)(class_->super_class)); {
if (CLS_ISMETA (class_))
return object_getClass ((id)objc_lookUpClass ((const char *)(class_->super_class)));
else
return objc_lookUpClass ((const char *)(class_->super_class));
}
/* If the class is not resolved yet, super_class would point to a /* If the class is not resolved yet, super_class would point to a
string (the name of the super class) as opposed to the actual string (the name of the super class) as opposed to the actual
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment