From patchwork Tue Dec 21 22:18:08 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 76333 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 EC9FAB7080 for ; Wed, 22 Dec 2010 09:18:26 +1100 (EST) Received: (qmail 8111 invoked by alias); 21 Dec 2010 22:18:22 -0000 Received: (qmail 8079 invoked by uid 22791); 21 Dec 2010 22:18:20 -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 22:18:13 +0000 Received: from eggs.gnu.org ([140.186.70.92]:43484) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1PVAX1-0004e5-RW for gcc-patches@gnu.org; Tue, 21 Dec 2010 17:18:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PVAX3-0000gh-7f for gcc-patches@gnu.org; Tue, 21 Dec 2010 17:18:10 -0500 Received: from smtp201.iad.emailsrvr.com ([207.97.245.201]:42907) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PVAX3-0000gb-48 for gcc-patches@gnu.org; Tue, 21 Dec 2010 17:18:09 -0500 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp40.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 6324C35026B for ; Tue, 21 Dec 2010 17:18:08 -0500 (EST) Received: from dynamic1.wm-web.iad.mlsrvr.com (dynamic1.wm-web.iad1a.rsapps.net [192.168.2.150]) by smtp40.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 51E533501C2 for ; Tue, 21 Dec 2010 17:18:08 -0500 (EST) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic1.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 2669EC98072 for ; Tue, 21 Dec 2010 17:18:08 -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 23:18:08 +0100 (CET) Date: Tue, 21 Dec 2010 23:18:08 +0100 (CET) Subject: libobjc: Minor tidyup in load callbacks From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1292969888.154123810@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 is a tidyup of the code that performs the "load callbacks" for each class and category that is loaded. Mostly comments and a small, minor and obvious code change. Committed to trunk. Thanks Index: init.c =================================================================== --- init.c (revision 168132) +++ init.c (working copy) @@ -45,7 +45,8 @@ see the files COPYING3 and COPYING.RUNTIME respect #define PROTOCOL_VERSION 2 /* This list contains modules currently loaded into the runtime and - for which the +load method has not been called yet. */ + for which the +load method (and the load callback, if any) has not + been called yet. */ static struct objc_list *__objc_module_list = 0; /* !T:MUTEX */ /* This list contains all proto_list's not yet assigned class @@ -84,7 +85,7 @@ static void __objc_init_protocol (struct objc_prot static void __objc_class_add_protocols (Class, struct objc_protocol_list *); /* Load callback hook. */ -void (*_objc_load_callback) (Class class, struct objc_category *category); /* !T:SAFE */ +void (*_objc_load_callback) (Class class, struct objc_category *category) = 0; /* !T:SAFE */ /* Are all categories/classes resolved? */ BOOL __objc_dangling_categories = NO; /* !T:UNUSED */ @@ -101,7 +102,9 @@ static void objc_send_load (void); been already received the +load message. */ static void __objc_create_classes_tree (struct objc_module *module); -static void __objc_call_callback (struct objc_module *module); +/* Calls the _objc_load_callback for each class and category in the + module (if _objc_load_callback is not NULL). */ +static void __objc_call_load_callback (struct objc_module *module); /* A special version that works only before the classes are completely installed in the runtime. */ @@ -754,7 +757,7 @@ objc_send_load (void) /* If we still have classes for whom we don't have yet their super classes known to the runtime we don't send the +load - messages yet. */ + messages (and call the load callback) yet. */ if (unresolved_classes) return; } @@ -765,7 +768,7 @@ objc_send_load (void) return; /* Iterate over all modules in the __objc_module_list and call on - them the __objc_create_classes_tree function. This function + them the __objc_create_classes_tree function. This function creates a tree of classes that resembles the class hierarchy. */ list_mapcar (__objc_module_list, (void (*) (void *)) __objc_create_classes_tree); @@ -783,7 +786,11 @@ objc_send_load (void) list_remove_head (&__objc_class_tree_list); } - list_mapcar (__objc_module_list, (void (*) (void *)) __objc_call_callback); + /* For each module, call the _objc_load_callback if any is + defined. */ + list_mapcar (__objc_module_list, (void (*) (void *)) __objc_call_load_callback); + + /* Empty the list of modules. */ list_free (__objc_module_list); __objc_module_list = NULL; } @@ -825,34 +832,35 @@ __objc_create_classes_tree (struct objc_module *mo } static void -__objc_call_callback (struct objc_module *module) +__objc_call_load_callback (struct objc_module *module) { - /* The runtime mutex is locked at this point. */ - struct objc_symtab *symtab = module->symtab; - int i; - - /* Iterate thru classes defined in this module and call the callback - for each one. */ - for (i = 0; i < symtab->cls_def_cnt; i++) + if (_objc_load_callback) { - Class class = (Class) symtab->defs[i]; - - /* Call the _objc_load_callback for this class. */ - if (_objc_load_callback) - _objc_load_callback (class, 0); + /* The runtime mutex is locked at this point. */ + struct objc_symtab *symtab = module->symtab; + int i; + + /* Iterate thru classes defined in this module and call the callback + for each one. */ + for (i = 0; i < symtab->cls_def_cnt; i++) + { + Class class = (Class) symtab->defs[i]; + + /* Call the _objc_load_callback for this class. */ + _objc_load_callback (class, 0); + } + + /* Call the _objc_load_callback for categories. Don't register + the instance methods as class methods for categories to root + classes since they were already added in the class. */ + for (i = 0; i < symtab->cat_def_cnt; i++) + { + struct objc_category *category = symtab->defs[i + symtab->cls_def_cnt]; + Class class = objc_getClass (category->class_name); + + _objc_load_callback (class, category); + } } - - /* Call the _objc_load_callback for categories. Don't register the - instance methods as class methods for categories to root classes - since they were already added in the class. */ - for (i = 0; i < symtab->cat_def_cnt; i++) - { - struct objc_category *category = symtab->defs[i + symtab->cls_def_cnt]; - Class class = objc_getClass (category->class_name); - - if (_objc_load_callback) - _objc_load_callback (class, category); - } } /* Sanity check the version of gcc used to compile `module'. */ Index: ChangeLog =================================================================== --- ChangeLog (revision 168132) +++ ChangeLog (working copy) @@ -1,5 +1,13 @@ 2010-12-21 Nicola Pero + * init.c (_objc_load_callback): Initialize with 0. + (__objc_call_callback): Renamed to __objc_call_load_callback. + Check _objc_load_callback only once, and if it is not set, return + immediately. + (objc_send_load): Updated call to __objc_call_callback. + +2010-12-21 Nicola Pero + PR libobjc/16110 * init.c (__objc_send_message_in_list): Renamed to __objc_send_load_using_method_list. Do not take an 'op' argument.