From patchwork Fri Oct 14 17:10:31 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 119859 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 622A4B6F97 for ; Sat, 15 Oct 2011 04:11:11 +1100 (EST) Received: (qmail 21625 invoked by alias); 14 Oct 2011 17:11:05 -0000 Received: (qmail 21605 invoked by uid 22791); 14 Oct 2011 17:11:00 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, TW_BJ 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, 14 Oct 2011 17:10:45 +0000 Received: from eggs.gnu.org ([140.186.70.92]:54025) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1RElHQ-0005FA-RJ for gcc-patches@gnu.org; Fri, 14 Oct 2011 13:10:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RElHP-0006eh-Et for gcc-patches@gnu.org; Fri, 14 Oct 2011 13:10:44 -0400 Received: from smtp161.iad.emailsrvr.com ([207.97.245.161]:36240) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RElHP-0006eT-8a for gcc-patches@gnu.org; Fri, 14 Oct 2011 13:10:43 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp56.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 614813D851C for ; Fri, 14 Oct 2011 13:10:39 -0400 (EDT) Received: by smtp56.relay.iad1a.emailsrvr.com (Authenticated sender: nicola.pero-AT-meta-innovation.com) with ESMTPSA id 7871E3D8444 for ; Fri, 14 Oct 2011 13:10:38 -0400 (EDT) From: Nicola Pero Subject: libobjc/50002: Applied fix to 4.6 branch as well Date: Fri, 14 Oct 2011 18:10:31 +0100 Message-Id: To: gcc-patches@gnu.org Mime-Version: 1.0 (Apple Message framework v1084) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 207.97.245.161 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 I applied the following patch to the 4.6 branch to backport the fix for libobjc/50002. It makes sense to backport it to 4.6.x so that it appears in 4.6.2. It really is quite a bug, and the fix is simple/safe (and, the ObjFW guys were particularly keen on it). Thanks Index: class.c =================================================================== --- class.c (revision 179967) +++ class.c (working copy) @@ -850,35 +850,57 @@ __objc_update_classes_with_methods (struct objc_me while (node != NULL) { - /* Iterate over all methods in the class. */ - Class class = node->pointer; - struct objc_method_list * method_list = class->methods; + /* We execute this loop twice: the first time, we iterate + over all methods in the class (instance methods), while + the second time we iterate over all methods in the meta + class (class methods). */ + Class class = Nil; + BOOL done = NO; - while (method_list) + while (done == NO) { - int i; + struct objc_method_list * method_list; - for (i = 0; i < method_list->method_count; ++i) + if (class == Nil) { - struct objc_method *method = &method_list->method_list[i]; + /* The first time, we work on the class. */ + class = node->pointer; + } + else + { + /* The second time, we work on the meta class. */ + class = class->class_pointer; + done = YES; + } - /* If the method is one of the ones we are looking - for, update the implementation. */ - if (method == method_a) - sarray_at_put_safe (class->dtable, - (sidx) method_a->method_name->sel_id, - method_a->method_imp); + method_list = class->methods; - if (method == method_b) + while (method_list) + { + int i; + + for (i = 0; i < method_list->method_count; ++i) { - if (method_b != NULL) + struct objc_method *method = &method_list->method_list[i]; + + /* If the method is one of the ones we are + looking for, update the implementation. */ + if (method == method_a) sarray_at_put_safe (class->dtable, - (sidx) method_b->method_name->sel_id, - method_b->method_imp); + (sidx) method_a->method_name->sel_id, + method_a->method_imp); + + if (method == method_b) + { + if (method_b != NULL) + sarray_at_put_safe (class->dtable, + (sidx) method_b->method_name->sel_id, + method_b->method_imp); + } } + + method_list = method_list->method_next; } - - method_list = method_list->method_next; } node = node->next; } Index: ChangeLog =================================================================== --- ChangeLog (revision 179967) +++ ChangeLog (working copy) @@ -1,3 +1,13 @@ +2011-10-14 Nicola Pero + + Backport from mainline + 2011-08-06 Nicola Pero + + PR libobjc/50002 + * class.c (__objc_update_classes_with_methods): Iterate over meta + classes as well as normal classes when refreshing the method + implementations. This fixes replacing class methods. + 2011-06-27 Release Manager * GCC 4.6.1 released.