From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26217 invoked by alias); 21 Dec 2010 13:44:40 -0000 Received: (qmail 25970 invoked by uid 22791); 21 Dec 2010 13:44:37 -0000 X-SWARE-Spam-Status: No, hits=-1.3 required=5.0 tests=AWL,BAYES_00,TW_BJ,TW_CP,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; Tue, 21 Dec 2010 13:44:31 +0000 Received: from eggs.gnu.org ([140.186.70.92]:56437) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PV2Vu-0005st-9E for gcc-patches@gnu.org; Tue, 21 Dec 2010 08:44:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PV2Vu-0000qm-Vd for gcc-patches@gnu.org; Tue, 21 Dec 2010 08:44:29 -0500 Received: from smtp191.iad.emailsrvr.com ([207.97.245.191]:34338) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PV2Vu-0000qU-RR for gcc-patches@gnu.org; Tue, 21 Dec 2010 08:44:26 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp49.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 05D4B19034B for ; Tue, 21 Dec 2010 08:44:26 -0500 (EST) Received: from dynamic10.wm-web.iad.mlsrvr.com (dynamic10.wm-web.iad1a.rsapps.net [192.168.2.217]) by smtp49.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 8EF25190499 for ; Tue, 21 Dec 2010 08:44:23 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic10.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 633B1478807F for ; Tue, 21 Dec 2010 08:44:23 -0500 (EST) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Tue, 21 Dec 2010 14:44:23 +0100 (CET) Date: Tue, 21 Dec 2010 14:48:00 -0000 Subject: Fix for PR libobjc/45953 From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 Content-Type: text/plain;charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Type: plain Message-ID: <1292939063.40476389@192.168.2.228> 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-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2010-12/txt/msg01617.txt.bz2 This patch fixes libobjc/45953. A testcase (fixed by the patch) is include= d. Committed to trunk. Thanks Index: gcc/testsuite/ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/testsuite/ChangeLog (revision 168113) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2010-12-21 Nicola Pero + + PR libobjc/45953 + * objc.dg/libobjc-selector-1.m: New test. + 2010-12-21 Jakub Jelinek =20 PR middle-end/45852 Index: gcc/testsuite/objc.dg/libobjc-selector-1.m =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gcc/testsuite/objc.dg/libobjc-selector-1.m (revision 0) +++ gcc/testsuite/objc.dg/libobjc-selector-1.m (revision 0) @@ -0,0 +1,39 @@ +/* Test a little inefficiency that was fixed in libobjc when dealing + with selectors (PR libobjc/45953). */ + +/* { dg-do run } */ +/* { dg-skip-if "" { *-*-* } { "-fnext-runtime" } { "" } } */ + +/* To get the modern GNU Objective-C Runtime API, you include + objc/runtime.h. */ +#include +#include + +/* Test that registering a new selector, with the same name but a + different type than the previous one, does not change the original + name string. It is actually fine to change it (there is no + guarantee that it won't change), except for runtime performance / + memory consumption, since changing it means that the runtime is + doing an unneeded objc_malloc()/strcpy(), which is inefficient. */ + +int main (void) +{ + SEL selector_1; + SEL selector_2; + const char *name_1; + const char *name_2; + + /* These method type strings may well be invalid. Please don't use + them as examples. They are irrelevant for this test; any string + will do. */ + selector_1 =3D sel_registerTypedName ("method", "v@:"); + name_1 =3D sel_getName (selector_1); + + selector_2 =3D sel_registerTypedName ("method", "i@:"); + name_2 =3D sel_getName (selector_1); + + if (name_1 !=3D name_2) + abort (); + + return 0; +} Index: libobjc/selector.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- libobjc/selector.c (revision 168113) +++ libobjc/selector.c (working copy) @@ -451,17 +451,19 @@ __sel_register_typed_name (const char *name, const i =3D (sidx) objc_hash_value_for_key (__objc_selector_hash, name); if (soffset_decode (i) !=3D 0) { - for (l =3D (struct objc_list *) sarray_get_safe (__objc_selector_arr= ay, i); + /* There are already selectors with that name. Examine them to + see if the one we're registering already exists. */ + for (l =3D (struct objc_list *)sarray_get_safe (__objc_selector_arra= y, i); l; l =3D l->tail) { - SEL s =3D (SEL) l->head; + SEL s =3D (SEL)l->head; if (types =3D=3D 0 || s->sel_types =3D=3D 0) { if (s->sel_types =3D=3D types) { if (orig) { - orig->sel_id =3D (void *) i; + orig->sel_id =3D (void *)i; return orig; } else @@ -472,79 +474,93 @@ __sel_register_typed_name (const char *name, const { if (orig) { - orig->sel_id =3D (void *) i; + orig->sel_id =3D (void *)i; return orig; } else return s; } } + /* A selector with this specific name/type combination does not + exist yet. We need to register it. */ if (orig) j =3D orig; else j =3D pool_alloc_selector (); =20=20=20=20=20=20=20 - j->sel_id =3D (void *) i; - /* Can we use the pointer or must copy types? Don't copy if + j->sel_id =3D (void *)i; + /* Can we use the pointer or must we copy types ? Don't copy if NULL. */ if ((is_const) || (types =3D=3D 0)) - j->sel_types =3D (const char *) types; + j->sel_types =3D types; else { - j->sel_types =3D (char *) objc_malloc (strlen (types) + 1); - strcpy ((char *) j->sel_types, types); + j->sel_types =3D (char *)objc_malloc (strlen (types) + 1); + strcpy ((char *)j->sel_types, types); } - l =3D (struct objc_list *) sarray_get_safe (__objc_selector_array, i= ); + l =3D (struct objc_list *)sarray_get_safe (__objc_selector_array, i); } else { + /* There are no other selectors with this name registered in the + runtime tables. */ + const char *new_name; + + /* Determine i. */ __objc_selector_max_index +=3D 1; i =3D soffset_encode (__objc_selector_max_index); + + /* Prepare the selector. */ if (orig) j =3D orig; else j =3D pool_alloc_selector (); =20=20=20=20=20=20=20 - j->sel_id =3D (void *) i; - /* Can we use the pointer or must copy types? Don't copy if + j->sel_id =3D (void *)i; + /* Can we use the pointer or must we copy types ? Don't copy if NULL. */ - if ((is_const) || (types =3D=3D 0)) - j->sel_types =3D (const char *) types; + if (is_const || (types =3D=3D 0)) + j->sel_types =3D types; else { - j->sel_types =3D (char *) objc_malloc (strlen (types) + 1); - strcpy ((char *) j->sel_types, types); + j->sel_types =3D (char *)objc_malloc (strlen (types) + 1); + strcpy ((char *)j->sel_types, types); } + + /* Since this is the first selector with this name, we need to + register the correspondence between 'i' (the sel_id) and + 'name' (the actual string) in __objc_selector_names and + __objc_selector_hash. */ +=20=20=20=20=20=20 + /* Can we use the pointer or must we copy name ? Don't copy if + NULL. (FIXME: Can the name really be NULL here ?) */ + if (is_const || (name =3D=3D 0)) + new_name =3D name; + else + { + new_name =3D (char *)objc_malloc (strlen (name) + 1); + strcpy ((char *)new_name, name); + } +=20=20=20=20=20=20 + /* This maps the sel_id to the name. */ + sarray_at_put_safe (__objc_selector_names, i, (void *)new_name); + + /* This maps the name to the sel_id. */ + objc_hash_add (&__objc_selector_hash, (void *)new_name, (void *)i); + l =3D 0; } =20 DEBUG_PRINTF ("Record selector %s[%s] as: %ld\n", name, types,=20 - (long) soffset_decode (i)); -=20=20 - { - int is_new =3D (l =3D=3D 0); - const char *new_name; + (long)soffset_decode (i)); =20 - /* Can we use the pointer or must copy name? Don't copy if - NULL. */ - if ((is_const) || (name =3D=3D 0)) - new_name =3D name; - else - { - new_name =3D (char *) objc_malloc (strlen (name) + 1); - strcpy ((char *) new_name, name); - } -=20=20=20=20 - l =3D list_cons ((void *) j, l); - sarray_at_put_safe (__objc_selector_names, i, (void *) new_name); - sarray_at_put_safe (__objc_selector_array, i, (void *) l); - if (is_new) - objc_hash_add (&__objc_selector_hash, (void *) new_name, (void *) i); - } -=20=20 + /* Now add the selector to the list of selectors with that id. */ + l =3D list_cons ((void *)j, l); + sarray_at_put_safe (__objc_selector_array, i, (void *)l); + sarray_realloc (__objc_uninstalled_dtable, __objc_selector_max_index + 1= ); =20=20=20 - return (SEL) j; + return (SEL)j; } =20 SEL Index: libobjc/ChangeLog =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- libobjc/ChangeLog (revision 168113) +++ libobjc/ChangeLog (working copy) @@ -1,5 +1,13 @@ 2010-12-21 Nicola Pero =20 + PR libobjc/45953 + * selector.c (__sel_register_typed_name): When registering a new + selector with the same name as an existing one, reuse the existing + name string. Also updated types, casts and comments in the whole + function. + +2010-12-21 Nicola Pero + * objc-private/module-abi-8.h (struct objc_symtab): Declare 'refs' to be 'struct objc_selector *' and not 'SEL'. * init.c (__objc_exec_class): Call