From patchwork Sat Aug 6 09:49:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 108765 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 32021B6F64 for ; Sat, 6 Aug 2011 19:50:10 +1000 (EST) Received: (qmail 30152 invoked by alias); 6 Aug 2011 09:50:08 -0000 Received: (qmail 30144 invoked by uid 22791); 6 Aug 2011 09:50:08 -0000 X-SWARE-Spam-Status: No, hits=-1.8 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; Sat, 06 Aug 2011 09:49:51 +0000 Received: from eggs.gnu.org ([140.186.70.92]:56356) by fencepost.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1QpdVu-0004sn-VV for gcc-patches@gnu.org; Sat, 06 Aug 2011 05:49:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QpdVt-00012M-8V for gcc-patches@gnu.org; Sat, 06 Aug 2011 05:49:50 -0400 Received: from smtp191.iad.emailsrvr.com ([207.97.245.191]:59275) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QpdVt-000126-69 for gcc-patches@gnu.org; Sat, 06 Aug 2011 05:49:49 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp39.relay.iad1a.emailsrvr.com (SMTP Server) with ESMTP id 74546983C3 for ; Sat, 6 Aug 2011 05:49:47 -0400 (EDT) Received: by smtp39.relay.iad1a.emailsrvr.com (Authenticated sender: nicola.pero-AT-meta-innovation.com) with ESMTPSA id E79A0983BA for ; Sat, 6 Aug 2011 05:49:46 -0400 (EDT) From: Nicola Pero Subject: libobjc: fix for PR/49882 ("class_getSuperClass() returns nil on a newly allocated, but not registered, class") Date: Sat, 6 Aug 2011 10:49:43 +0100 Message-Id: <560C940B-E771-49DC-8E50-0F1BD5E8A2B9@meta-innovation.com> 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.191 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 PR libobjc/49882. Applied to trunk. Thanks Index: libobjc/ChangeLog =================================================================== --- libobjc/ChangeLog (revision 177503) +++ libobjc/ChangeLog (working copy) @@ -1,3 +1,10 @@ +2011-08-06 Nicola Pero + + PR libobjc/49882 + * class.c (class_getSuperclass): Return the superclass if the + class is in construction. + * objc/runtime.h (class_getSuperclass): Updated documentation. + 2011-08-05 Rainer Orth * Makefile.in (INCLUDES): Search Index: libobjc/class.c =================================================================== --- libobjc/class.c (revision 177503) +++ libobjc/class.c (working copy) @@ -923,10 +923,13 @@ class_getSuperclass (Class class_) if (class_ == Nil) return Nil; - /* Classes that are in construction are not resolved and can not be - resolved! */ + /* Classes that are in construction are not resolved, and still have + the class name (instead of a class pointer) in the + class_->superclass field. In that case we need to lookup the + superclass name to return the superclass. We can not resolve the + class until it is registered. */ if (CLS_IS_IN_CONSTRUCTION (class_)) - return Nil; + return objc_lookUpClass ((const char *)(class_->super_class)); /* If the class is not resolved yet, super_class would point to a string (the name of the super class) as opposed to the actual Index: libobjc/objc/runtime.h =================================================================== --- libobjc/objc/runtime.h (revision 177503) +++ libobjc/objc/runtime.h (working copy) @@ -497,10 +497,10 @@ objc_EXPORT const char * class_getName (Class clas objc_EXPORT BOOL class_isMetaClass (Class class_); /* Return the superclass of 'class_'. If 'class_' is Nil, or it is a - root class, return Nil. If 'class_' is a class being constructed, - that is, a class returned by objc_allocateClassPair() but before it - has been registered with the runtime using - objc_registerClassPair(), return Nil. */ + root class, return Nil. This function also works if 'class_' is a + class being constructed, that is, a class returned by + objc_allocateClassPair() but before it has been registered with the + runtime using objc_registerClassPair(). */ objc_EXPORT Class class_getSuperclass (Class class_); /* Return the 'version' number of the class, which is an integer that Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 177503) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2011-08-06 Nicola Pero + + PR libobjc/49882 + * objc.dg/gnu-api-2-class.m (main): Test class_getSuperclass() + with classes that are in construction. + 2011-08-05 Jason Merrill PR c++/48993 Index: gcc/testsuite/objc.dg/gnu-api-2-class.m =================================================================== --- gcc/testsuite/objc.dg/gnu-api-2-class.m (revision 177503) +++ gcc/testsuite/objc.dg/gnu-api-2-class.m (working copy) @@ -394,6 +394,14 @@ int main(int argc, void **args) MySubClass *object = [[MySubClass alloc] init]; if (class_getSuperclass (object_getClass (object)) != objc_getClass ("MyRootClass")) abort (); + + /* Test that it works on a newly created, but not registered, class. */ + { + Class new_class = objc_allocateClassPair (objc_getClass ("MyRootClass"), "MySubClass3", 0); + + if (class_getSuperclass (new_class) != objc_getClass ("MyRootClass")) + abort (); + } } printf ("Testing class_getVersion ()...\n");