From patchwork Fri Dec 24 20:11:18 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 76637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 1FC10B7088 for ; Sat, 25 Dec 2010 07:11:38 +1100 (EST) Received: (qmail 23510 invoked by alias); 24 Dec 2010 20:11:34 -0000 Received: (qmail 23489 invoked by uid 22791); 24 Dec 2010 20:11:31 -0000 X-SWARE-Spam-Status: No, hits=-1.4 required=5.0 tests=AWL, BAYES_00, TW_BJ, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 24 Dec 2010 20:11:25 +0000 Received: from eggs.gnu.org ([140.186.70.92]:37433) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PWDyy-0007Ib-At for gcc-patches@gnu.org; Fri, 24 Dec 2010 15:11:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PWDyz-0004KT-E2 for gcc-patches@gnu.org; Fri, 24 Dec 2010 15:11:23 -0500 Received: from smtp111.iad.emailsrvr.com ([207.97.245.111]:50773) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PWDyz-0004K2-Ar for gcc-patches@gnu.org; Fri, 24 Dec 2010 15:11:21 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp41.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 795AD290516 for ; Fri, 24 Dec 2010 15:11:20 -0500 (EST) Received: by smtp41.relay.iad1a.emailsrvr.com (Authenticated sender: nicola.pero-AT-meta-innovation.com) with ESMTPA id D44CC290852 for ; Fri, 24 Dec 2010 15:11:19 -0500 (EST) Message-Id: From: Nicola Pero To: gcc-patches@gnu.org Mime-Version: 1.0 (Apple Message framework v936) Subject: libobjc: Fix sel_registerName and similar when passed a NULL argument Date: Fri, 24 Dec 2010 21:11:18 +0100 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch fixes sel_registerName, sel_registerTypedName and sel_getTypedSelector to detect a NULL argument and return NULL for it. It also updates one test (gnu-api-2-sel) to be executed with the Apple runtime as well. The logic is the one outlined in my previous email -- > The purpose wouldn't be to test the Apple runtime; it would > rather be to test that the testcase are correct and that the behaviour they require > from the runtime API is indeed the one of the Apple runtime. Then, if someone makes > a change to the GNU runtime API making it incompatible with the Apple one, and adds > a testcase for it (assuming all changes come with a testcase), they would notice > when the test runs on the Apple runtime, as it would fail there. I'll be updating the other tests (probably tomorrow) as well. Committed to trunk Thanks std::cout << "Testing sel_isEqual () ...\n"; @@ -145,8 +155,12 @@ { if (std::strcmp (sel_getName (sel_registerName ("myMethod")), "myMethod") != 0) abort (); + + if (sel_registerName (NULL) != NULL) + abort (); } +#ifdef __GNU_LIBOBJC__ std::cout << "Testing set_registerTypedName () ...\n"; { const char *types = method_getTypeEncoding (class_getInstanceMethod @@ -159,7 +173,14 @@ if (std::strcmp (sel_getTypeEncoding (selector), types) != 0) abort (); + + if (sel_registerTypedName (NULL, NULL) != NULL) + abort (); + + if (sel_registerTypedName (NULL, types) != NULL) + abort (); } +#endif return (0); } Index: selector.c =================================================================== --- selector.c (revision 168229) +++ selector.c (working copy) @@ -357,8 +357,12 @@ sel_getTypedSelector (const char *name) { sidx i; + + 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) @@ -658,6 +662,9 @@ 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 +687,9 @@ { 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 == Index: ChangeLog =================================================================== --- ChangeLog (revision 168230) +++ ChangeLog (working copy) @@ -1,5 +1,13 @@ 2010-12-24 Nicola Pero + * 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 + * objc/runtime.h (class_addIvar): Updated documentation. The alignment is actually the log_2 of the alignment in bytes. * ivars.c (class_addIvar): Corresponding change to the Index: objc/runtime.h =================================================================== --- objc/runtime.h (revision 168230) +++ objc/runtime.h (working copy) @@ -191,14 +191,14 @@ you know the types, it is better to call sel_registerTypedName(). If a selector with this name and no types already exists, it is 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); /* Register a selector with a given name and types. If a selector with this name and types already exists, it is returned. Note that this function should really be called 'objc_registerTypedSelector', 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, so it does not have this function, which is specific to the GNU @@ -227,7 +227,7 @@ /* 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 - 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 really like to get a selector for it that includes the type Index: ChangeLog =================================================================== --- ChangeLog (revision 168230) +++ ChangeLog (working copy) @@ -1,5 +1,12 @@ 2010-12-24 Nicola Pero + * 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 + * objc.dg/gnu-api-2-class.m: Updated test to pass log_2 of the alignment to class_addIvar, instead of the alignment itself. * obj-c++.dg/gnu-api-2-class.mm: Same change. Index: objc.dg/gnu-api-2-sel.m =================================================================== --- objc.dg/gnu-api-2-sel.m (revision 168229) +++ objc.dg/gnu-api-2-sel.m (working copy) @@ -3,7 +3,6 @@ This is test 'sel', covering all functions starting with 'sel'. */ /* { dg-do run } */ -/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ /* To get the modern GNU Objective-C Runtime API, you include objc/runtime.h. */ @@ -16,11 +15,13 @@ { Class isa; } + alloc; - init; ++ initialize; @end @implementation MyRootClass + alloc { return class_createInstance (self, 0); } - init { return self; } ++ initialize { return self; } @end @protocol MyProtocol @@ -49,6 +50,7 @@ { /* Functions are tested in alphabetical order. */ +#ifdef __GNU_LIBOBJC__ printf ("Testing sel_copyTypedSelectorList ()...\n"); { unsigned int count; @@ -72,6 +74,7 @@ if (list[2] != NULL) abort (); } +#endif printf ("Testing sel_getName () ...\n"); { @@ -82,6 +85,7 @@ abort (); } +#ifdef __GNU_LIBOBJC__ printf ("Testing sel_getTypeEncoding () ...\n"); { /* Get a selector from a real class, so it has interesting @@ -96,7 +100,9 @@ if (sel_getTypeEncoding (NULL) != NULL) abort (); } +#endif +#ifdef __GNU_LIBOBJC__ printf ("Testing sel_getTypedSelector () ...\n"); { /* First try with a selector where we know that a typed one has @@ -128,11 +134,15 @@ if (selector != NULL) abort (); } +#endif printf ("Testing sel_getUid () ...\n"); { if (strcmp (sel_getName (sel_getUid ("myMethod")), "myMethod") ! = 0) abort (); + + if (sel_getUid (NULL) != NULL) + abort (); } printf ("Testing sel_isEqual () ...\n"); @@ -145,8 +155,12 @@ { if (strcmp (sel_getName (sel_registerName ("myMethod")), "myMethod") != 0) abort (); + + if (sel_registerName (NULL) != NULL) + abort (); } +#ifdef __GNU_LIBOBJC__ printf ("Testing set_registerTypedName () ...\n"); { const char *types = method_getTypeEncoding (class_getInstanceMethod @@ -159,7 +173,14 @@ if (strcmp (sel_getTypeEncoding (selector), types) != 0) abort (); + + if (sel_registerTypedName (NULL, NULL) != NULL) + abort (); + + if (sel_registerTypedName (NULL, types) != NULL) + abort (); } +#endif return 0; } Index: obj-c++.dg/gnu-api-2-sel.mm =================================================================== --- obj-c++.dg/gnu-api-2-sel.mm (revision 168229) +++ obj-c++.dg/gnu-api-2-sel.mm (working copy) @@ -3,7 +3,6 @@ This is test 'sel', covering all functions starting with 'sel'. */ /* { dg-do run } */ -/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ /* To get the modern GNU Objective-C Runtime API, you include objc/runtime.h. */ @@ -16,11 +15,13 @@ { Class isa; } + alloc; - init; ++ initialize; @end @implementation MyRootClass + alloc { return class_createInstance (self, 0); } - init { return self; } ++ initialize { return self; } @end @protocol MyProtocol @@ -49,6 +50,7 @@ { /* Functions are tested in alphabetical order. */ +#ifdef __GNU_LIBOBJC__ std::cout << "Testing sel_copyTypedSelectorList ()...\n"; { unsigned int count; @@ -72,6 +74,7 @@ if (list[2] != NULL) abort (); } +#endif std::cout << "Testing sel_getName () ...\n"; { @@ -82,6 +85,7 @@ abort (); } +#ifdef __GNU_LIBOBJC__ std::cout << "Testing sel_getTypeEncoding () ...\n"; { /* Get a selector from a real class, so it has interesting @@ -96,7 +100,9 @@ if (sel_getTypeEncoding (NULL) != NULL) abort (); } +#endif +#ifdef __GNU_LIBOBJC__ std::cout << "Testing sel_getTypedSelector () ...\n"; { /* First try with a selector where we know that a typed one has @@ -128,11 +134,15 @@ if (selector != NULL) abort (); } +#endif std::cout << "Testing sel_getUid () ...\n"; { if (std::strcmp (sel_getName (sel_getUid ("myMethod")), "myMethod") != 0) abort (); + + if (sel_getUid (NULL) != NULL) + abort (); }