From patchwork Tue Dec 21 12:49:37 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 76288 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 967C3B6F1E for ; Tue, 21 Dec 2010 23:50:01 +1100 (EST) Received: (qmail 8145 invoked by alias); 21 Dec 2010 12:49:54 -0000 Received: (qmail 8130 invoked by uid 22791); 21 Dec 2010 12:49:50 -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; Tue, 21 Dec 2010 12:49:44 +0000 Received: from eggs.gnu.org ([140.186.70.92]:56023) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PV1er-0002zF-NS for gcc-patches@gnu.org; Tue, 21 Dec 2010 07:49:39 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PV1es-00052P-OK for gcc-patches@gnu.org; Tue, 21 Dec 2010 07:49:40 -0500 Received: from smtp201.iad.emailsrvr.com ([207.97.245.201]:38452) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PV1es-00052E-KE for gcc-patches@gnu.org; Tue, 21 Dec 2010 07:49:38 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp40.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id D99DB3501E2 for ; Tue, 21 Dec 2010 07:49:37 -0500 (EST) Received: from dynamic11.wm-web.iad.mlsrvr.com (dynamic11.wm-web.iad1a.rsapps.net [192.168.2.218]) by smtp40.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id C6AAA350155 for ; Tue, 21 Dec 2010 07:49:37 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic11.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id B8652E0086 for ; Tue, 21 Dec 2010 07:49:37 -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 13:49:37 +0100 (CET) Date: Tue, 21 Dec 2010 13:49:37 +0100 (CET) Subject: libobjc: Very minor tidyup in init.c and selector.c From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1292935777.75424769@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-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 tidies up the internal interface between init.c and selector.c; it makes __sel_register_typed_name() a private, static function in selector.c and provides init.c with a higher-level replacement to register all selectors in a module. Not much to see really; it's only slightly higher-level than a reindentation patch. Committed. Thanks Index: init.c =================================================================== --- init.c (revision 168108) +++ init.c (working copy) @@ -549,7 +549,7 @@ struct objc_list **cell; /* The table of selector references for this module. */ - SEL selectors = symtab->refs; + struct objc_selector *selectors = symtab->refs; int i; @@ -585,22 +585,9 @@ objc_mutex_lock (__objc_runtime_mutex); __objc_module_list = list_cons (module, __objc_module_list); - /* Replace referenced selectors from names to SEL's. */ + /* Replace referenced selectors from names to SELs. */ if (selectors) - { - for (i = 0; selectors[i].sel_id; ++i) - { - const char *name, *type; - name = (char *) selectors[i].sel_id; - type = (char *) selectors[i].sel_types; - /* Constructors are constant static data so we can safely - store pointers to them in the runtime - structures. is_const == YES. */ - __sel_register_typed_name (name, type, - (struct objc_selector *) &(selectors[i]), - YES); - } - } + __objc_register_selectors_from_module (selectors); /* Parse the classes in the load module and gather selector information. */ Index: selector.c =================================================================== --- selector.c (revision 168108) +++ selector.c (working copy) @@ -43,6 +43,11 @@ /* Number of selectors stored in each of the above tables. */ unsigned int __objc_selector_max_index = 0; /* !T:MUTEX */ +/* Forward-declare an internal function. */ +static SEL +__sel_register_typed_name (const char *name, const char *types, + struct objc_selector *orig, BOOL is_const); + void __objc_init_selector_tables (void) { __objc_selector_array = sarray_new (SELECTOR_HASH_SIZE, 0); @@ -53,6 +58,29 @@ (compare_func_type) objc_compare_strings); } +/* Register a bunch of selectors from the table of selectors in a + module. 'selectors' should not be NULL. The list is terminated by + a selectors with a NULL sel_id. The selectors are assumed to + contain the 'name' in the sel_id field; this is replaced with the + final selector id after they are registered. */ +void +__objc_register_selectors_from_module (struct objc_selector *selectors) +{ + int i; + + for (i = 0; selectors[i].sel_id; ++i) + { + const char *name, *type; + name = (char *) selectors[i].sel_id; + type = (char *) selectors[i].sel_types; + /* Constructors are constant static data and we can safely store + pointers to them in the runtime structures, so we set + is_const == YES. */ + __sel_register_typed_name (name, type, (struct objc_selector *) &(selectors[i]), + /* is_const */ YES); + } +} + /* This routine is given a class and records all of the methods in its class structure in the record table. */ void @@ -403,11 +431,16 @@ /* Store the passed selector name in the selector record and return its selector value (value returned by sel_get_uid). Assume that the calling function has locked down __objc_runtime_mutex. The - is_const parameter tells us if the name and types parameters are + 'is_const' parameter tells us if the name and types parameters are really constant or not. If YES then they are constant and we can just store the pointers. If NO then we need to copy name and types - because the pointers may disappear later on. */ -SEL + because the pointers may disappear later on. If the 'orig' + parameter is not NULL, then we are registering a selector from a + module, and 'orig' is that selector. In this case, we can put the + selector in the tables if needed, and orig->sel_id is updated with + the selector ID of the registered selector, and 'orig' is + returned. */ +static SEL __sel_register_typed_name (const char *name, const char *types, struct objc_selector *orig, BOOL is_const) { Index: objc-private/selector.h =================================================================== --- objc-private/selector.h (revision 168108) +++ objc-private/selector.h (working copy) @@ -43,6 +43,7 @@ void __objc_register_selectors_from_list (struct objc_method_list *); void __objc_register_selectors_from_description_list (struct objc_method_description_list *method_list); +void __objc_register_selectors_from_module (struct objc_selector *selectors); /* Return whether a selector is mapped or not ("mapped" meaning that it has been inserted into the selector table). This is private as @@ -57,10 +58,6 @@ SEL sel_get_any_uid (const char *name); -SEL -__sel_register_typed_name (const char *name, const char *types, - struct objc_selector *orig, BOOL is_const); - #ifdef __cplusplus } #endif /* __cplusplus */ Index: objc-private/module-abi-8.h =================================================================== --- objc-private/module-abi-8.h (revision 168108) +++ objc-private/module-abi-8.h (working copy) @@ -48,10 +48,16 @@ struct objc_symtab { unsigned long sel_ref_cnt; /* Unused (always set to 0). */ - SEL refs; /* The table of selectors referenced in + struct objc_selector *refs; /* The table of selectors referenced in this module. This is terminated by a selector with NULL sel_id and NULL - sel_types. */ + sel_types. Note that we use the type + 'struct objc_selector *' and not + 'SEL' (which is 'const struct + objc_selector *') because the sel_id + of these selectors is patched up by + the runtime when the module is + loaded. */ unsigned short cls_def_cnt; /* Number of classes compiled (defined) in the module. */ unsigned short cat_def_cnt; /* Number of categories compiled Index: ChangeLog =================================================================== --- ChangeLog (revision 168112) +++ ChangeLog (working copy) @@ -1,5 +1,18 @@ 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 + __objc_register_selectors_from_module instead of iterating over + each selector and calling __sel_register_typed_name for each. + * objc-private/selector.h: Declare + __objc_register_selectors_from_module instead of + __sel_register_typed_name. + * selector.c (__objc_register_selectors_from_module): New. + (__sel_register_typed_name): Made static. + +2010-12-21 Nicola Pero + * linking.m: Do not include objc/NXConstStr.h. 2010-12-21 Nicola Pero