In libobjc/: 2010-12-24 Nicola Pero <nicola.pero@meta-innovation.com>

In libobjc/:
2010-12-24  Nicola Pero  <nicola.pero@meta-innovation.com>

	* selector.c (sel_getTypedSelector): Return NULL if given a NULL
	argument.
	(sel_registerTypedName): Same.
	(sel_registerName): Same.
	* objc/runtime.h: Updated documentation.
	
In gcc/testsuite/:
2010-12-24  Nicola Pero  <nicola.pero@meta-innovation.com>

	* objc.dg/gnu-api-2-sel.m: Test calling sel_getUid,
	sel_registerName and sel_registerTypedName with NULL arguments.
	Updated the test to work with the Apple runtime as well.
	* obj-c++.dg/gnu-api-2-sel.mm: Same change.

From-SVN: r168231
This commit is contained in:
Nicola Pero 2010-12-24 20:10:46 +00:00 committed by Nicola Pero
parent 410644c41a
commit 9cacfc3eb3
6 changed files with 73 additions and 6 deletions

View File

@ -1,3 +1,10 @@
2010-12-24 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/gnu-api-2-sel.m: Test calling sel_getUid,
sel_registerName and sel_registerTypedName with NULL arguments.
Updated the test to work with the Apple runtime as well.
* obj-c++.dg/gnu-api-2-sel.mm: Same change.
2010-12-24 Nicola Pero <nicola.pero@meta-innovation.com> 2010-12-24 Nicola Pero <nicola.pero@meta-innovation.com>
* objc.dg/gnu-api-2-class.m: Updated test to pass log_2 of the * objc.dg/gnu-api-2-class.m: Updated test to pass log_2 of the

View File

@ -3,7 +3,6 @@
This is test 'sel', covering all functions starting with 'sel'. */ This is test 'sel', covering all functions starting with 'sel'. */
/* { dg-do run } */ /* { dg-do run } */
/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */
/* To get the modern GNU Objective-C Runtime API, you include /* To get the modern GNU Objective-C Runtime API, you include
objc/runtime.h. */ objc/runtime.h. */
@ -16,11 +15,13 @@
{ Class isa; } { Class isa; }
+ alloc; + alloc;
- init; - init;
+ initialize;
@end @end
@implementation MyRootClass @implementation MyRootClass
+ alloc { return class_createInstance (self, 0); } + alloc { return class_createInstance (self, 0); }
- init { return self; } - init { return self; }
+ initialize { return self; }
@end @end
@protocol MyProtocol @protocol MyProtocol
@ -49,6 +50,7 @@ int main ()
{ {
/* Functions are tested in alphabetical order. */ /* Functions are tested in alphabetical order. */
#ifdef __GNU_LIBOBJC__
std::cout << "Testing sel_copyTypedSelectorList ()...\n"; std::cout << "Testing sel_copyTypedSelectorList ()...\n";
{ {
unsigned int count; unsigned int count;
@ -72,6 +74,7 @@ int main ()
if (list[2] != NULL) if (list[2] != NULL)
abort (); abort ();
} }
#endif
std::cout << "Testing sel_getName () ...\n"; std::cout << "Testing sel_getName () ...\n";
{ {
@ -82,6 +85,7 @@ int main ()
abort (); abort ();
} }
#ifdef __GNU_LIBOBJC__
std::cout << "Testing sel_getTypeEncoding () ...\n"; std::cout << "Testing sel_getTypeEncoding () ...\n";
{ {
/* Get a selector from a real class, so it has interesting /* Get a selector from a real class, so it has interesting
@ -96,7 +100,9 @@ int main ()
if (sel_getTypeEncoding (NULL) != NULL) if (sel_getTypeEncoding (NULL) != NULL)
abort (); abort ();
} }
#endif
#ifdef __GNU_LIBOBJC__
std::cout << "Testing sel_getTypedSelector () ...\n"; std::cout << "Testing sel_getTypedSelector () ...\n";
{ {
/* First try with a selector where we know that a typed one has /* First try with a selector where we know that a typed one has
@ -128,11 +134,15 @@ int main ()
if (selector != NULL) if (selector != NULL)
abort (); abort ();
} }
#endif
std::cout << "Testing sel_getUid () ...\n"; std::cout << "Testing sel_getUid () ...\n";
{ {
if (std::strcmp (sel_getName (sel_getUid ("myMethod")), "myMethod") != 0) if (std::strcmp (sel_getName (sel_getUid ("myMethod")), "myMethod") != 0)
abort (); abort ();
if (sel_getUid (NULL) != NULL)
abort ();
} }
std::cout << "Testing sel_isEqual () ...\n"; std::cout << "Testing sel_isEqual () ...\n";
@ -145,8 +155,12 @@ int main ()
{ {
if (std::strcmp (sel_getName (sel_registerName ("myMethod")), "myMethod") != 0) if (std::strcmp (sel_getName (sel_registerName ("myMethod")), "myMethod") != 0)
abort (); abort ();
if (sel_registerName (NULL) != NULL)
abort ();
} }
#ifdef __GNU_LIBOBJC__
std::cout << "Testing set_registerTypedName () ...\n"; std::cout << "Testing set_registerTypedName () ...\n";
{ {
const char *types = method_getTypeEncoding (class_getInstanceMethod const char *types = method_getTypeEncoding (class_getInstanceMethod
@ -159,7 +173,14 @@ int main ()
if (std::strcmp (sel_getTypeEncoding (selector), types) != 0) if (std::strcmp (sel_getTypeEncoding (selector), types) != 0)
abort (); abort ();
if (sel_registerTypedName (NULL, NULL) != NULL)
abort ();
if (sel_registerTypedName (NULL, types) != NULL)
abort ();
} }
#endif
return (0); return (0);
} }

View File

@ -3,7 +3,6 @@
This is test 'sel', covering all functions starting with 'sel'. */ This is test 'sel', covering all functions starting with 'sel'. */
/* { dg-do run } */ /* { dg-do run } */
/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */
/* To get the modern GNU Objective-C Runtime API, you include /* To get the modern GNU Objective-C Runtime API, you include
objc/runtime.h. */ objc/runtime.h. */
@ -16,11 +15,13 @@
{ Class isa; } { Class isa; }
+ alloc; + alloc;
- init; - init;
+ initialize;
@end @end
@implementation MyRootClass @implementation MyRootClass
+ alloc { return class_createInstance (self, 0); } + alloc { return class_createInstance (self, 0); }
- init { return self; } - init { return self; }
+ initialize { return self; }
@end @end
@protocol MyProtocol @protocol MyProtocol
@ -49,6 +50,7 @@ int main(int argc, void **args)
{ {
/* Functions are tested in alphabetical order. */ /* Functions are tested in alphabetical order. */
#ifdef __GNU_LIBOBJC__
printf ("Testing sel_copyTypedSelectorList ()...\n"); printf ("Testing sel_copyTypedSelectorList ()...\n");
{ {
unsigned int count; unsigned int count;
@ -72,6 +74,7 @@ int main(int argc, void **args)
if (list[2] != NULL) if (list[2] != NULL)
abort (); abort ();
} }
#endif
printf ("Testing sel_getName () ...\n"); printf ("Testing sel_getName () ...\n");
{ {
@ -82,6 +85,7 @@ int main(int argc, void **args)
abort (); abort ();
} }
#ifdef __GNU_LIBOBJC__
printf ("Testing sel_getTypeEncoding () ...\n"); printf ("Testing sel_getTypeEncoding () ...\n");
{ {
/* Get a selector from a real class, so it has interesting /* Get a selector from a real class, so it has interesting
@ -96,7 +100,9 @@ int main(int argc, void **args)
if (sel_getTypeEncoding (NULL) != NULL) if (sel_getTypeEncoding (NULL) != NULL)
abort (); abort ();
} }
#endif
#ifdef __GNU_LIBOBJC__
printf ("Testing sel_getTypedSelector () ...\n"); printf ("Testing sel_getTypedSelector () ...\n");
{ {
/* First try with a selector where we know that a typed one has /* First try with a selector where we know that a typed one has
@ -128,11 +134,15 @@ int main(int argc, void **args)
if (selector != NULL) if (selector != NULL)
abort (); abort ();
} }
#endif
printf ("Testing sel_getUid () ...\n"); printf ("Testing sel_getUid () ...\n");
{ {
if (strcmp (sel_getName (sel_getUid ("myMethod")), "myMethod") != 0) if (strcmp (sel_getName (sel_getUid ("myMethod")), "myMethod") != 0)
abort (); abort ();
if (sel_getUid (NULL) != NULL)
abort ();
} }
printf ("Testing sel_isEqual () ...\n"); printf ("Testing sel_isEqual () ...\n");
@ -145,8 +155,12 @@ int main(int argc, void **args)
{ {
if (strcmp (sel_getName (sel_registerName ("myMethod")), "myMethod") != 0) if (strcmp (sel_getName (sel_registerName ("myMethod")), "myMethod") != 0)
abort (); abort ();
if (sel_registerName (NULL) != NULL)
abort ();
} }
#ifdef __GNU_LIBOBJC__
printf ("Testing set_registerTypedName () ...\n"); printf ("Testing set_registerTypedName () ...\n");
{ {
const char *types = method_getTypeEncoding (class_getInstanceMethod const char *types = method_getTypeEncoding (class_getInstanceMethod
@ -159,7 +173,14 @@ int main(int argc, void **args)
if (strcmp (sel_getTypeEncoding (selector), types) != 0) if (strcmp (sel_getTypeEncoding (selector), types) != 0)
abort (); abort ();
if (sel_registerTypedName (NULL, NULL) != NULL)
abort ();
if (sel_registerTypedName (NULL, types) != NULL)
abort ();
} }
#endif
return 0; return 0;
} }

View File

@ -1,3 +1,11 @@
2010-12-24 Nicola Pero <nicola.pero@meta-innovation.com>
* selector.c (sel_getTypedSelector): Return NULL if given a NULL
argument.
(sel_registerTypedName): Same.
(sel_registerName): Same.
* objc/runtime.h: Updated documentation.
2010-12-24 Nicola Pero <nicola.pero@meta-innovation.com> 2010-12-24 Nicola Pero <nicola.pero@meta-innovation.com>
* objc/runtime.h (class_addIvar): Updated documentation. The * objc/runtime.h (class_addIvar): Updated documentation. The

View File

@ -191,14 +191,14 @@ objc_EXPORT SEL sel_getUid (const char *name);
you know the types, it is better to call sel_registerTypedName(). you know the types, it is better to call sel_registerTypedName().
If a selector with this name and no types already exists, it is If a selector with this name and no types already exists, it is
returned. Note that this function should really be called returned. Note that this function should really be called
'objc_registerSelector'. */ 'objc_registerSelector'. Return NULL if 'name' is NULL. */
objc_EXPORT SEL sel_registerName (const char *name); objc_EXPORT SEL sel_registerName (const char *name);
/* Register a selector with a given name and types. If a selector /* Register a selector with a given name and types. If a selector
with this name and types already exists, it is returned. Note that with this name and types already exists, it is returned. Note that
this function should really be called 'objc_registerTypedSelector', this function should really be called 'objc_registerTypedSelector',
and it's called 'sel_registerTypedName' only for consistency with and it's called 'sel_registerTypedName' only for consistency with
'sel_registerName'. 'sel_registerName'. Return NULL if 'name' is NULL.
Compatibility Note: the Apple/NeXT runtime has untyped selectors, Compatibility Note: the Apple/NeXT runtime has untyped selectors,
so it does not have this function, which is specific to the GNU so it does not have this function, which is specific to the GNU
@ -227,7 +227,7 @@ objc_EXPORT SEL * sel_copyTypedSelectorList (const char *name,
/* Return a selector with name 'name' and a non-zero type encoding, if /* Return a selector with name 'name' and a non-zero type encoding, if
any such selector is registered with the runtime. If there is no any such selector is registered with the runtime. If there is no
such selector, NULL is returned. such selector, NULL is returned. Return NULL if 'name' is NULL.
This is useful if you have the name of the selector, and would This is useful if you have the name of the selector, and would
really like to get a selector for it that includes the type really like to get a selector for it that includes the type

View File

@ -357,6 +357,10 @@ SEL
sel_getTypedSelector (const char *name) sel_getTypedSelector (const char *name)
{ {
sidx i; sidx i;
if (name == NULL)
return NULL;
objc_mutex_lock (__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
/* Look for a typed selector. */ /* Look for a typed selector. */
@ -659,6 +663,9 @@ sel_registerName (const char *name)
{ {
SEL ret; SEL ret;
if (name == NULL)
return NULL;
objc_mutex_lock (__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
/* Assume that name is not constant static memory and needs to be /* Assume that name is not constant static memory and needs to be
copied before put into a runtime structure. is_const == NO. */ copied before put into a runtime structure. is_const == NO. */
@ -680,6 +687,9 @@ sel_registerTypedName (const char *name, const char *type)
{ {
SEL ret; SEL ret;
if (name == NULL)
return NULL;
objc_mutex_lock (__objc_runtime_mutex); objc_mutex_lock (__objc_runtime_mutex);
/* Assume that name and type are not constant static memory and need /* Assume that name and type are not constant static memory and need
to be copied before put into a runtime structure. is_const == to be copied before put into a runtime structure. is_const ==