Re: RFA: Update copyright for libobjc
OK. Thanks On 3 Feb 2013, at 10:33, Richard Sandiford wrote: > Update the copyright notices for libobjc. > > Tested on x86_64-linux-gnu. OK to install? > > Richard > > > libbjc/ > Update copyright years. > > Index: libobjc/Makefile.in > === > --- libobjc/Makefile.in 2013-02-02 21:33:00.727873787 + > +++ libobjc/Makefile.in 2013-02-03 10:31:00.272954078 + > @@ -1,6 +1,5 @@ > # Makefile for GNU Objective C runtime library. > -# Copyright 1993, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, > -# 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. > +# Copyright (C) 1993-2013 Free Software Foundation, Inc. > > #This file is part of GCC. > > Index: libobjc/NXConstStr.m > === > --- libobjc/NXConstStr.m 2013-02-02 21:33:00.724873765 + > +++ libobjc/NXConstStr.m 2013-02-03 10:31:00.225953831 + > @@ -1,5 +1,5 @@ > /* Implementation of the NXConstantString class for Objective-C. > - Copyright (C) 1995, 2009, 2010 Free Software Foundation, Inc. > + Copyright (C) 1995-2013 Free Software Foundation, Inc. >Contributed by Pieter J. Schoenmakers > > This file is part of GCC. > Index: libobjc/Object.m > === > --- libobjc/Object.m 2013-02-02 21:33:00.728873795 + > +++ libobjc/Object.m 2013-02-03 10:31:00.226953836 + > @@ -1,6 +1,5 @@ > /* The implementation of class Object for Objective-C. > - Copyright (C) 1993, 1994, 1995, 1997, 2002, 2009, 2010, 2011 > - Free Software Foundation, Inc. > + Copyright (C) 1993-2013 Free Software Foundation, Inc. > > This file is part of GCC. > > Index: libobjc/Protocol.m > === > --- libobjc/Protocol.m2013-02-02 21:33:00.724873765 + > +++ libobjc/Protocol.m2013-02-03 10:31:00.243953925 + > @@ -1,5 +1,5 @@ > /* This file contains the implementation of class Protocol. > - Copyright (C) 1993, 2004, 2009, 2010, 2011 Free Software Foundation, Inc. > + Copyright (C) 1993-2013 Free Software Foundation, Inc. > > This file is part of GCC. > > Index: libobjc/accessors.m > === > --- libobjc/accessors.m 2013-02-02 21:33:00.725873772 + > +++ libobjc/accessors.m 2013-02-03 10:31:00.272954078 + > @@ -1,5 +1,5 @@ > /* GNU Objective C Runtime accessors functions > - Copyright (C) 2010 Free Software Foundation, Inc. > + Copyright (C) 2010-2013 Free Software Foundation, Inc. >Contributed by Nicola Pero > > This file is part of GCC. > Index: libobjc/acinclude.m4 > === > --- libobjc/acinclude.m4 2013-02-02 21:33:00.723873757 + > +++ libobjc/acinclude.m4 2013-02-03 10:31:00.244953931 + > @@ -1,5 +1,4 @@ > -dnl Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2010 > -dnl Free Software Foundation, Inc. > +dnl Copyright (C) 1994-2013 Free Software Foundation, Inc. > dnl This file is free software; the Free Software Foundation > dnl gives unlimited permission to copy and/or distribute it, > dnl with or without modifications, as long as this notice is preserved. > Index: libobjc/class.c > === > --- libobjc/class.c 2013-02-02 21:33:00.728873795 + > +++ libobjc/class.c 2013-02-03 10:31:00.251953967 + > @@ -1,6 +1,5 @@ > /* GNU Objective C Runtime class related functions > - Copyright (C) 1993, 1995, 1996, 1997, 2001, 2002, 2009, 2010, 2011 > - Free Software Foundation, Inc. > + Copyright (C) 1993-2013 Free Software Foundation, Inc. >Contributed by Kresten Krab Thorup and Dennis Glatting. > >Lock-free class table code designed and written from scratch by > Index: libobjc/configure.ac > === > --- libobjc/configure.ac 2013-02-02 21:33:00.728873795 + > +++ libobjc/configure.ac 2013-02-03 10:31:00.252953972 + > @@ -1,6 +1,5 @@ > # Process this file with autoconf to produce a configure script. > -# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004 > -# 2005, 2006, 2009, 2011, 2012 Free Software Foundation, Inc. > +# Copyright (C) 1994-2013 Free Software Foundation, Inc. > # Originally contributed by Dave Love (d.l...@dl.ac.uk). > # > #This file is part of GCC. > Index: libobjc/encoding.c >
Re: [PATCH] fix -Wsign-compare error in objc-act.c (PR objc/50743)
> (I don't have svn write access so I'll need someone else to commit it if > it's approved.) I can apply it for you. But ... do you have a copyright assignment in place for contributions to GCC ? The patch looks small and trivial enough that I think I can apply it without a signed copyright assignment form, but if you plan on contributing more, it would make sense to sign one. :-) Thanks
Re: [patch] C6X unwinding/exception handling
>> I checked the attached patch, test results at >> http://gcc.gnu.org/ml/gcc-testresults/2011-10/msg01377.html >> >> which are the same as with my suggested patch. >> >> Ok for the trunk? > > I probably don't have authority to approve this, but looks OK to me. The libobjc bits are Ok for trunk. Thanks
Re: [PATCH] fix -Wsign-compare error in objc-act.c (PR objc/50743)
> The FSF has had my papers since Feb '11, but are stalling trying to decide > whether to accept my employer's slightly non-standard disclaimer or not. Ah. That seems a long time even for this kind of things. Anyhow, this particular patch consisted of exactly 4 casts, so it seems to fall in the case of a "tiny patch" which doesn't require copyright assignment, so I applied it for you. Thanks
libobjc: fix for PR/49882 ("class_getSuperClass() returns nil on a newly allocated, but not registered, class")
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");
libobjc: Fix obvious typo in comment
Fixes a typo in a comment in my last patch. Applied to trunk. Thanks Index: ChangeLog === --- ChangeLog (revision 177505) +++ ChangeLog (working copy) @@ -1,5 +1,9 @@ 2011-08-06 Nicola Pero + * class.c (class_getSuperclass): Fixed typo in comment. + +2011-08-06 Nicola Pero + PR libobjc/49882 * class.c (class_getSuperclass): Return the superclass if the class is in construction. Index: class.c === --- class.c (revision 177505) +++ class.c (working copy) @@ -925,7 +925,7 @@ /* 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 + class_->super_class 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_))
libobjc: Fix PR libobjc/50002 ("class_replaceMethod does not work on class methods")
This patch fixes PR libobjc/50002. The problem was that replacing an existing class method wouldn't work because the messaging tables weren't being refreshed for class methods when a method was replaced. This patch also includes three other related changes: * a new couple of comprehensive testcases, gnu-api-2-class-meta.m and gnu-api-2-class-meta.mm, covering calling various runtime functions with a meta class (as opposed to a normal class) as argument. This tests the above-mentioned fix for libobjc/50002, but also a variety of other similar functions and situations (this is mostly for peace of mind - I wanted to be sure that there aren't other problems similar to libobjc/50002). * a fix for a small issue with class_getSuperclass() (when used on a meta class in construction), which was identified by the testcases above. The actual problem is actually related to libobjc/49882 - which I fixed this morning. * synchronizes the ObjC++ testsuite with the ObjC one. In particular, when fixing libobjc/49882 this morning I added an ObjC testcase but forgot to add an ObjC++ one. This patch includes it. Tested with GNU and Apple runtime. Committed to trunk. Thanks Index: libobjc/ChangeLog === --- libobjc/ChangeLog (revision 177506) +++ libobjc/ChangeLog (working copy) @@ -1,5 +1,17 @@ 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-08-06 Nicola Pero + + * class.c (class_getSuperclass): Fixed to work with meta classes + still in construction too. + +2011-08-06 Nicola Pero + * class.c (class_getSuperclass): Fixed typo in comment. 2011-08-06 Nicola Pero Index: libobjc/class.c === --- libobjc/class.c (revision 177506) +++ libobjc/class.c (working copy) @@ -781,35 +781,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->d
Patch for PR libobjc/50428 ("Consider changing semantics of +initialize so that it is inherited")
This patch implements the change discussed in libobjc/50428. Traditionally, the Apple runtime "inherits" +initialize, meaning that if a class doesn't implement it, but the superclass does, the superclass's implementation gets executed the first time a method of the class is invoked. Instead, the GNU runtime traditionally doesn't "inherit" +initialize, meaning in that situation, no +initialize is executed. The idea is that with the GNU runtime you wouldn't have to worry about protecting your +initialize against multiple executions. But, in practice, people seem to protect +initialize methods all the same even with the GNU runtime, and they supply the following two explanations of why: * It is generally considered good practice to protect +initialize methods against multiple exclusions because it allows the code to run without changes with the Apple/NeXT runtime. * The runtime doesn't prevent programmers from invoking +initialize directly. You are not supposed to do it, but some beginners do, which is why a number of frameworks (including GNUstep) protect all +initialize methods against multiple executions all the same even when using the GNU runtime and even ignoring the existence of the Apple/NeXT runtime (!!). Because of these two reasons, it seems that everyone's really protecting their +initialize methods against multiple executions all the same! So the difference in behaviour between the GNU runtime and the Apple/NeXT one is not really helping anyone; but it makes it harder to port code written for the Apple/NeXT runtime to the GNU runtime. Programmers writing code for the Apple/NeXT runtime assume that +initialize methods are "inherited", so they may write code which expects such methods to be called multiple times, once per subclass. That code would compile on the GNU runtime but not work. Fixing the code so that it works with both runtimes is not necessarily trivial in some situations, for example if the classes are dynamically created at runtime. So the difference in behaviour is not really helping anyone, but it's making life hard for some people who are porting software to run on the GNU runtime. This patch (originally submitted by Richard Frith-Macdonald in a private email, and revised by me) changes the behaviour of the GNU runtime to match the one of the Apple/NeXT one. This makes it easier to port software to use the GNU runtime. A testcase is included; I tested the patch on an Apple Mac OS X 10.6.8, making sure that the testcase behaves in the same way with the Apple/NeXT and GNU runtimes. Committed to trunk. Thanks PS: This change absolutely deserves a mention in the GCC 4.7 release notes. But I'll work on the release notes separately, once we are in stage 2 or so. :-) Index: gcc/doc/objc.texi === --- gcc/doc/objc.texi (revision 179710) +++ gcc/doc/objc.texi (working copy) @@ -635,7 +635,8 @@ following class does this: + (void)initialize @{ - class_ivar_set_gcinvisible (self, "weakPointer", YES); + if (self == objc_lookUpClass ("WeakPointer")) +class_ivar_set_gcinvisible (self, "weakPointer", YES); @} - initWithPointer:(const void*)p Index: gcc/ChangeLog === --- gcc/ChangeLog (revision 179710) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2011-10-08 Nicola Pero + + PR libobjc/50428 + * doc/objc.texi (Garbage Collection): Updated example to protect + +initialize against execution in subclasses. + 2011-10-07 Richard Henderson * doc/extend.texi (__builtin_shuffle): Improve the description to Index: gcc/testsuite/ChangeLog === --- gcc/testsuite/ChangeLog (revision 179710) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-10-08 Nicola Pero + + PR libobjc/50428 + * objc/execute/initialize-1.m: New test. + 2011-10-08 Paul Thomas PR fortran/47844 Index: gcc/testsuite/objc/execute/initialize-1.m === --- gcc/testsuite/objc/execute/initialize-1.m (revision 0) +++ gcc/testsuite/objc/execute/initialize-1.m (revision 0) @@ -0,0 +1,47 @@ +/* Contributed by Nicola Pero - Sat 8 Oct 2011 16:47:48 BST */ +#include + +/* Test that if a class has no +initialize method, the superclass + implementation is called. */ + +static int class_variable = 0; + +@interface TestClass +{ + Class isa; +} ++ (void) initialize; ++ (int) classVariable; +@end + +@implementation TestClass ++ (void) initialize +{ + class_variable++; +} ++ (int) classVariable +{ + return class_variable; +} +@end + +@interface TestSubClass : TestClass +@end + +@implementation TestSubClass +@end + +int main (v
Fix for PR libobjc/49883 ("clang + gcc 4.6 runtime = broken") and a small related clang fix
This patch fixes PR libobjc/49883. To fix it, I installed clang and tried out what happens if you compile Objective-C code using clang and targetting the GCC runtime. Unfortunately, the report was correct in that clang is producing incorrect code and abusing the higher bits of the class->info field to store some other information. On the good side, the fix I proposed in the discussion of PR libobjc/49883 actually works. :-) So, I applied that fix. I also found that clang still emits calls to the objc_lookup_class() function, so this patch also adds that function back into the runtime to get code compiled with clang work. Committed to trunk. Thanks PS: In case anyone wonders, I do want the GNU Objective-C Runtime to be usable with free, non-GCC Objective-C compilers. It should obviously work perfectly with GCC, the GNU compiler, which is its natural partner, but some people would like to use it with other free compilers and that seems a reasonable request. Refusing that request just provides an incentive to write and support other Objective-C runtimes, which is a waste of time and resources. ;-) Index: init.c === --- init.c (revision 179711) +++ init.c (working copy) @@ -643,6 +643,15 @@ assert (CLS_ISMETA (class->class_pointer)); DEBUG_PRINTF (" installing class '%s'\n", class->name); + /* Workaround for a bug in clang: Clang may set flags other than +_CLS_CLASS and _CLS_META even when compiling for the +traditional ABI (version 8), confusing our runtime. Try to +wipe these flags out. */ + if (CLS_ISCLASS (class)) + __CLS_INFO (class) = _CLS_CLASS; + else + __CLS_INFO (class) = _CLS_META; + /* Initialize the subclass list to be NULL. In some cases it isn't and this crashes the program. */ class->subclass_list = NULL; Index: class.c === --- class.c (revision 179711) +++ class.c (working copy) @@ -764,6 +764,15 @@ return objc_get_class (name)->class_pointer; } +/* This is not used by GCC, but the clang compiler seems to use it + when targetting the GNU runtime. That's wrong, but we have it to + be compatible. */ +Class +objc_lookup_class (const char *name) +{ + return objc_getClass (name); +} + /* This is used when the implementation of a method changes. It goes through all classes, looking for the ones that have these methods (either method_a or method_b; method_b can be NULL), and reloads Index: ChangeLog === --- ChangeLog (revision 179711) +++ ChangeLog (working copy) @@ -1,3 +1,18 @@ +2011-10-09 Nicola Pero + + PR libobjc/49883 + * init.c (__objc_exec_class): Work around a bug in clang's code + generation. Clang sets the class->info field to values different + from 0x1 or 0x2 (the only allowed values in the traditional GNU + Objective-C runtime ABI) to store some additional information, but + this breaks backwards compatibility. Wipe out all the bits in the + fields other than the first two upon loading a class. + +2011-10-09 Nicola Pero + + * class.c (objc_lookup_class): Added back for compatibility with + clang which seems to emit calls to it. + 2011-10-08 Richard Frith-Macdonald Nicola Pero
Re: Fix for PR libobjc/49883 ("clang + gcc 4.6 runtime = broken") and a small related clang fix
>> Unfortunately, the report was correct in that clang is producing incorrect >> code and >> abusing the higher bits of the class->info field to store some other >> information. > > The clang folks are pretty responsive. I'd always give them a chance to > `fix' thier code, before putting hack-arounds in our code in general. That discussion did happen in private. It wasn't pleasant. They won't change their code. In fact, I just want to fix things and not get into more discussions. Anyhow, summarizing, the traditional GNU runtime ABI has the values 0x1L or 0x2L in the class->info field. But there is no formal definition document for the ABI, so all we can say is that GCC has always set that field to either 0x1L or 0x2L. By the way, the lack of a formal definition document is a problem, and if, at some point, I get to implement a new ABI for the GNU Objective-C runtime (which I want to do) I will produce a formal document describing it - so that anyone can implement a compatible compiler or runtime. But, for the existing ABI, there is no document describing it, hence all that can be said is that GCC only stores the values 0x1L or 0x2L in the class->field. The GNU runtime then uses some of the other bits to store information on the class at runtime - eg. when the class is +initialized it sets a bit, when it is resolved it sets another, etc. clang started abusing a higher bit of that field to store information not normally present in the ABI. That worked with older versions of the GNU runtime, because (by sheer chance in my view) the higher bit they set was not being used. The fact that it was not being used was an implementation accident (in my view) since other higher bits were actually used. The new GNU runtime included in GCC 4.6.x and higher has classes "in construction" (part of the new Objective-C API) and so the next available bit in the class->info field was used to keep track of the fact that a class is in construction. That was just the next available bit, but (unknown to me) it is precisely the bit that clang was (ab)using. As a consequence, code compiled with clang no longer works with the GNU runtime from GCC 4.6.x. As there is no formal definition document for the ABI, while it seems obvious to me that they broke the ABI (since they produce object files with some reserved bits set that no version of GCC would ever produce), they claim they didn't because their hack worked with GCC up to 4.5.x and the GNU runtime ignored whether that bit was set or not - up until 4.5.x. It's a standoff because they use that higher bit to basically produce a richer ABI, so they can't easily get rid of it now, and they won't. The hack-around I added clears this higher bit, unlocks the standoff and gets things to work again. Let's hope there are no more such issues, and if we introduce a new GNU Objective-C runtime ABI, we need to make sure it is well documented so that it is possible to easily ensure compatibility between different compilers and runtimes. Thanks
Re: Fix for PR libobjc/49883 ("clang + gcc 4.6 runtime = broken") and a small related clang fix
> It isn't a standoff, we can choose to just fix the issue and be compatible, > if we want. I guess you're right and I'm probably using the wrong word - English is not my first language. ;-) But I meant that they could have made the same choice to be compatible (by fixing the issue in their compiler and making their GCC-compatible ABI output actually compatible with GCC; they already have other, clang-only, GCC-incompatible ABIs in there, so why not make the GCC-compatible one actually compatible with GCC ?), but they didn't. Anyhow I completely agree with you that life is too short and we spent already way too much time discussing this. It's fixed and let's move on. :-) Thanks
ObjC/ObjC++ Patch: rewrite objc/objc++ frontend hashtables
This patch finally rewrites the hashtables used by the ObjC (and ObjC++) frontend. The new code speeds up the compiler by about 4% when compiling the standard GNUstep ObjC system headers with -fsyntax-only. That's quite good for a change that does nothing but swap a hashtable implementation with another one. PS: This also supersedes the two small ObjC hashtable patches that I sent in the past 12 months or so and that were never applied. The hashtable implemented by the current patch is polished and fast. Bootstrapped and regtested on gnu-linux i686. Ok to commit ? Thanks Index: gcc/objc/ChangeLog === --- gcc/objc/ChangeLog (revision 179864) +++ gcc/objc/ChangeLog (working copy) @@ -1,3 +1,54 @@ +2011-10-14 Nicola Pero + + * objc-map.h: New file. + * objc-map.c: New file. + * config-lang.in (gtfiles): Added objc-map.h. + * Make-lang.in (OBJC_OBJS): Added objc-map.o. + (objc/objc-map.o): New rule. + (objc/objc-act.o): Depend on objc/objc-map.h. + * objc-next-runtime-abi-02.c: Added a TODO comment. + * objc-act.c: Include objc-map.h. + (nst_method_hash_list, cls_method_hash_list): Removed. + (instance_method_map, class_method_map): New. + (cls_name_hash_list, als_name_hash_list): Removed. + (class_name_map, alias_name_map): Removed. + (ivar_offset_hash_list): Removed. + (hash_class_name_enter, hash_class_name_lookup, hash_enter, + hash_lookup, hash_add_attr, add_method_to_hash_list): Removed. + (interface_hash_init): New. + (objc_init): Call interface_hash_init. + (objc_write_global_declarations): Iterate over class_method_map + and instance_method_map instead of cls_method_hash_list and + nst_method_hash_list. + (objc_declare_alias): Use alias_name_map instead of + cls_name_hash_list. + (objc_is_class_name): Use class_name_map and alias_name_map + instead of cls_name_hash_list and als_name_hash_list. + (interface_tuple, interface_htab, hash_interface, eq_interface): + Removed. + (interface_map): New. + (add_class): Renamed to add_interface. Use interface_map instead + of interface_htab. + (lookup_interface): Use interface_map instead of interface_htab. + (check_duplicates): Changed first argument to be a tree, + potentially a TREE_VEC, instead of a hash. Changed implementation + to match. + (lookup_method_in_hash_lists): Use class_method_map and + instance_method_map instead of cls_method_hash_list and + nst_method_hash_list. + (objc_build_selector_expr): Likewise. + (hash_func): Removed. + (hash_init): Create instance_method_map, class_method_map, + class_name_map, and alias_name_map. Do not create + nst_method_hash_list, cls_method_hash_list, cls_name_hash_list, + als_name_hash_list, and ivar_offset_hash_list. + (insert_method_into_method_map): New. + (objc_add_method): Use insert_method_into_method_map instead of + add_method_to_hash_list. + (start_class): Call add_interface instead of add_class. + * objc-act.h (cls_name_hash_list, als_name_hash_list, + nst_method_hash_list, cls_method_hash_list): Removed. + 2011-10-11 Michael Meissner * objc-next-runtime-abi-01.c (objc_build_exc_ptr): Delete old Index: gcc/objc/config-lang.in === --- gcc/objc/config-lang.in (revision 179864) +++ gcc/objc/config-lang.in (working copy) @@ -36,4 +36,4 @@ lang_requires="c" # Order is important. If you change this list, make sure you test # building without C++ as well; that is, remove the gcc/cp directory, # and build with --enable-languages=c,objc. -gtfiles="\$(srcdir)/c-family/c-objc.h \$(srcdir)/objc/objc-act.h \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-runtime-shared-support.c \$(srcdir)/objc/objc-gnu-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-02.c \$(srcdir)/c-parser.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-lang.h \$(srcdir)/c-objc-common.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-cppbuiltin.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c" +gtfiles="\$(srcdir)/objc/objc-map.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/objc/objc-act.h \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-runtime-shared-support.c \$(srcdir)/objc/objc-gnu-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-02.c \$(srcdir)/c-parser.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-lang.h \$(srcdir)/c-objc-common.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-cppbuiltin.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-
RE: ObjC/ObjC++ Patch: rewrite objc/objc++ frontend hashtables
I actually forgot to post a tiny bit that is required to support the additional objc/objc-map.h and objc/objc-map.c files. It's part of the same patch. Apologies. Thanks Index: gengtype.c === --- gengtype.c (revision 179947) +++ gengtype.c (working copy) @@ -1817,6 +1817,11 @@ struct file_rule_st files_rules[] = { REG_EXTENDED, NULL_REGEX, "gt-objc-objc-act.h", "objc/objc-act.c", NULL_FRULACT }, + /* objc/objc-map.h gives gt-objc-objc-map.h for objc/objc-map.c ! */ + { DIR_PREFIX_REGEX "objc/objc-map\\.h$", +REG_EXTENDED, NULL_REGEX, +"gt-objc-objc-map.h", "objc/objc-map.c", NULL_FRULACT }, + /* General cases. For header *.h and source *.c files, we need * special actions to handle the language. */ Index: ChangeLog === --- ChangeLog (revision 179947) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-10-14 Nicola Pero + + * gengtype.c (files_rules): Added rules for objc/objc-map.h and + objc/objc-map.c. + 2011-10-13 Jakub Jelinek * config/i386/sse.md (vec_set): Change V_128 iterator mode
libobjc/50002: Applied fix to 4.6 branch as well
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.
libobjc/49883: Applied fix to 4.6 branch as well
I applied the following patch to backport the fix for libobjc/49883 to GCC 4.6 so that it appears in 4.6.2. This is the clang-related problem that was recently discussed. Again, it's an important fix, but safe, with users (the ObjFW guys) asking for it in 4.6.2, which made total sense, so I backported the fix and committed it to the 4.6 branch. Thanks Index: init.c === --- init.c (revision 179967) +++ init.c (working copy) @@ -643,6 +643,15 @@ assert (CLS_ISMETA (class->class_pointer)); DEBUG_PRINTF (" installing class '%s'\n", class->name); + /* Workaround for a bug in clang: Clang may set flags other than +_CLS_CLASS and _CLS_META even when compiling for the +traditional ABI (version 8), confusing our runtime. Try to +wipe these flags out. */ + if (CLS_ISCLASS (class)) + __CLS_INFO (class) = _CLS_CLASS; + else + __CLS_INFO (class) = _CLS_META; + /* Initialize the subclass list to be NULL. In some cases it isn't and this crashes the program. */ class->subclass_list = NULL; Index: ChangeLog === --- ChangeLog (revision 179996) +++ ChangeLog (working copy) @@ -1,6 +1,19 @@ 2011-10-14 Nicola Pero Backport from mainline + 2011-10-09 Nicola Pero + + PR libobjc/49883 + * init.c (__objc_exec_class): Work around a bug in clang's code + generation. Clang sets the class->info field to values different + from 0x1 or 0x2 (the only allowed values in the traditional GNU + Objective-C runtime ABI) to store some additional information, but + this breaks backwards compatibility. Wipe out all the bits in the + fields other than the first two upon loading a class. + +2011-10-14 Nicola Pero + + Backport from mainline 2011-08-06 Nicola Pero PR libobjc/50002
Re: Fix for PR obj-c++/48275 ("getter=namespace failing with .mm")
Can I apply this fix to the 4.6 branch as well ? Some users are asking for it to be backported to the 4.6 branch. It's not a regression, because the property implementation is new in GCC 4.6, but it is still a serious bug if you're trying to use properties with ObjC++, as you can't use "namespace" as a getter name. It's a simple fix, quite obvious, and very limited in scope (even if it was wrong, it can't really do much harm other than breaking property declarations in ObjC++ which are already broken without the patch), so I'd go for it. OK to commit to the 4.6 branch ? Thanks On 6 Jun 2011, at 20:22, Nicola Pero wrote: > This patch fixes PR obj-c++/48275. It's a routine parser ingenuity. > > OK to commit ? > > Thanks > > Index: testsuite/ChangeLog > === > --- testsuite/ChangeLog (revision 174657) > +++ testsuite/ChangeLog (working copy) > @@ -1,3 +1,9 @@ > +2011-06-06 Nicola Pero > + > + PR objc-++/48275 > + * obj-c++.dg/property/cxx-property-1.mm: New. > + * obj-c++.dg/property/cxx-property-2.mm: New. > + > 2011-06-05 Nicola Pero > >PR testsuite/49287 > Index: testsuite/obj-c++.dg/property/cxx-property-2.mm > === > --- testsuite/obj-c++.dg/property/cxx-property-2.mm (revision 0) > +++ testsuite/obj-c++.dg/property/cxx-property-2.mm (revision 0) > @@ -0,0 +1,22 @@ > +/* { dg-do compile } */ > + > +/* All these C++ keywords are acceptable in ObjC method names, hence > + should be accepted for property getters and setters. */ > + > +@interface Test > +{ > + Class isa; > +} > +@property (getter=namespace) int p0; > +@property (setter=namespace:) int p1; > +@property (getter=and) int p2; > +@property (setter=and:) int p3; > +@property (getter=class) int p4; > +@property (setter=class:) int p5; > +@property (getter=new) int p6; > +@property (setter=new:) int p7; > +@property (getter=delete) int p8; > +@property (setter=delete:) int p9; > +@property (getter=delete) int p10; > +@property (setter=delete:) int p11; > +@end > Index: testsuite/obj-c++.dg/property/cxx-property-1.mm > === > --- testsuite/obj-c++.dg/property/cxx-property-1.mm (revision 0) > +++ testsuite/obj-c++.dg/property/cxx-property-1.mm (revision 0) > @@ -0,0 +1,10 @@ > +/* Testcase from PR obj-c++/48275. */ > +/* { dg-do compile } */ > + > +@interface Test > +{ > +int ns; > +} > +@property (getter=namespace) int ns; > + > +@end > Index: cp/ChangeLog > === > --- cp/ChangeLog(revision 174656) > +++ cp/ChangeLog(working copy) > @@ -1,3 +1,9 @@ > +2011-06-06 Nicola Pero , > + > + PR obj-c++/48275 > + * parser.c (cp_parser_objc_at_property_declaration): Allow setter > + and getter names to use all the allowed method names. > + > 2011-06-04 Jonathan Wakely > >* init.c (build_delete): Warn when deleting type with non-virtual > Index: cp/parser.c > === > --- cp/parser.c (revision 174656) > +++ cp/parser.c (working copy) > @@ -23187,7 +23187,7 @@ cp_parser_objc_at_property_declaration (cp_parser > break; >} > cp_lexer_consume_token (parser->lexer); /* eat the = */ > - if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME)) > + if (!cp_parser_objc_selector_p (cp_lexer_peek_token > (parser->lexer)->type)) >{ > cp_parser_error (parser, "expected identifier"); > syntax_error = true; > @@ -23196,10 +23196,12 @@ cp_parser_objc_at_property_declaration (cp_parser > if (keyword == RID_SETTER) >{ > if (property_setter_ident != NULL_TREE) > - cp_parser_error (parser, "the % attribute may > only be specified once"); > + { > + cp_parser_error (parser, "the % attribute may > only be specified once"); > + cp_lexer_consume_token (parser->lexer); > + } > else > - property_setter_ident = cp_lexer_peek_token > (parser->lexer)->u.value; > - cp_lexer_consume_token (parser->lexer); > + property_setter_ident = cp_parser_objc_selector (parser); > if (cp_lexer_next_token
objc patch (was Re: Problem to install GCC 4.6.0 with Objective-C language)
>I get the error (this time the objc language is detected): > >/bin/bash ../../gcc-4.6.0/gcc/../move-if-change tmp-gi.list >gtyp-input.list >echo timestamp > s-gtyp-input >build/gengtype \ >-S ../../gcc-4.6.0/gcc -I gtyp-input.list -w >gtype.state >../../gcc-4.6.0/gcc/objc/objc-act.h:280: unidentified type >`objc_ivar_visibility_kind' > make[3]: *** [s-gtype] Error 1 Thanks German ... I could reproduce it. You found a bug! :-) Apologies for the bug, and thanks for sticking with us. ;-) (you can ignore the following, it's for gcc-patc...@gnu.org) It's easy to reproduce the bug by simply deleting the gcc/cp directory from a GCC checkout, then trying to compile with the c,objc languages enabled. It fails with the error above, because gengtype then reads objc/objc-act.h before c-family/c-common-objc.h. The problem is in how the list of language-specific gtfiles is produced. It is produced in configure.ac, which: * will iterate over all the ${srcdir}/*/config-lang.in; * will source config-lang.in for all of them, regardless of whether they are enabled or not, and add $gtfiles to the list of gtfiles; * adds the C language last. As a consequence, GTFILES is different depending on whether ${srcdir}/gcc/cp/ exists or not. If it exists, usually the cp gtfiles come before the objc ones (due to alphabetical ordering by the shell, I'd guess ?), and the cp gtfiles contain c-family/c-common-objc.h, which is then processed before objc/objc-act.h. If it doesn't exist, that doesn't happen, and it stops working. :-( Here is a patch to fix it. It just moves c-family/c-objc.h at the beginning of the objc gtfiles list, to make it independent of cp's gtfiles list; with this, I can build c,objc with or without the gcc/cp directory. :-) Ok to commit ? Thanks PS: In my view this fix is a candidate for backporting to 4.6.x; without it, the gcc-objc-4.6.x tarballs are unusable. Index: ChangeLog === --- ChangeLog (revision 173994) +++ ChangeLog (working copy) @@ -1,3 +1,9 @@ +2011-05-21 Nicola Pero + + * config-lang.in (gtfiles): Updated order of files to fix building + when the gcc/cp directory is missing, as in the case of some + release tarballs. + 2011-05-20 Nathan Froyd * objc-act.c (objc_compare_types): Use function_args_iterator Index: config-lang.in === --- config-lang.in (revision 173994) +++ config-lang.in (working copy) @@ -33,4 +33,7 @@ # Most of the object files for cc1obj actually come from C. lang_requires="c" -gtfiles="\$(srcdir)/objc/objc-act.h \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-runtime-shared-support.c \$(srcdir)/objc/objc-gnu-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-02.c \$(srcdir)/c-parser.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-lang.h \$(srcdir)/c-objc-common.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-objc.h \$(srcdir)/c-family/c-cppbuiltin.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c" +# Order is important. If you change this list, make sure you test +# building without C++ as well; that is, remove the gcc/cp directory, +# and build with --enable-languages=c,objc. +gtfiles="\$(srcdir)/c-family/c-objc.h \$(srcdir)/objc/objc-act.h \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-runtime-shared-support.c \$(srcdir)/objc/objc-gnu-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-02.c \$(srcdir)/c-parser.c \$(srcdir)/c-tree.h \$(srcdir)/c-decl.c \$(srcdir)/c-lang.h \$(srcdir)/c-objc-common.c \$(srcdir)/c-family/c-common.c \$(srcdir)/c-family/c-common.h \$(srcdir)/c-family/c-cppbuiltin.c \$(srcdir)/c-family/c-pragma.h \$(srcdir)/c-family/c-pragma.c"
Re: Remove separate tarballs (was: Re: objc patch (was Re: Problem to install GCC 4.6.0 with Objective-C language))
Maybe we can offer an additional compression format like lzma .xz which brings down 4.5.3 compressed size from 66MB bz2 to 52MB (with -7). But that can be decided separately. Yes ... on the other hand, this does not address the other issue, which is the amount of disk space that you need to actually uncompress the tarballs :-( Unpacking gcc-4.6.0.tar.xx requires about 600 MB. Unpacking gcc- core-4.6.0.tar.xx requires about 150 MB. It's a big difference. Compiling a few languages (eg, the C ones) may produce object/build files for about 400 MB or so, meaning if you download gcc-4.6.0 to get a C compiler you'll likely need a minimum of 1 GB of disk space. If you download gcc-core-4.6.0 you may get away with about 550 MB (and get the same compiler). Maybe you could reduce the number of tarballs, but without going to the extreme of having just one. Eg, you could keep the testsuite (expands to approx 150MB) as a separate tarball, and probably Java (due to its size, again expands to approx 150MB) as a separate tarball too, while merging everything else into a single tarball (expanding to approx 300 MB). It may a reasonable compromise. But I'm not sure, just mentioning the idea. The testsuite seems particularly suitable for being kept separate, as most end-users want to just use the software as opposed to test it; moreover testing requires DejaGNU, which (depending on the platform) may require lot more dependencies and work to install - unpacking an additional tarball would be the least of your troubles. And some users may appreciate saving 150 MB of disk space. :-) But I don't have a strong opinion either way. I was just contributing some thoughts. I'm fine with whatever you decide. :-) I generally like the idea of reducing the exposure to untested configurations with missing directories. Thanks
Patch fixing PR objc/48187
This routine patch fixes PR objc/48187. The problem is that the following code @interface A { ] } @end would cause the ObjC parser to enter into an infinite loop. The parser fails to parse ] as an instance variable, but then when it tries to skip to the next semicolon to resume parsing from the next instance variable, the standard c_parser_skip_until_found() doesn't skip the ] because it's a special token that reduces the nesting level. So, the parser tries to parse ] again as an instance variable, and then again and again, failing to ever make any progress ;-) The fix adds an explicit branch to deal with the parsing failure, and carefully skips to the next semicolon (or '}) even in the case of ']' or ')'. -- As I was looking at that chunk of code, I also noticed the error message saying "extra semicolon in struct or union specified" for an extra semicolon found in a list of ObjC instance variables. I think it's incorrect or at least confusing as a list of ObjC instance variables isn't a "struct or union". ;-) I changed it to simply say "extra semicolon" as I like short and clear error messages. But I'm happy to change it to something else (eg, "extra semicolon specified in list of Objective-C instance variables") if other people disagree. -- I added testcases. -- Finally, I also updated the ObjC++ parser so that it would survive the same testcases (previously they would crash the compiler). Ok to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 174112) +++ ChangeLog (working copy) @@ -1,3 +1,11 @@ +2011-05-24 Nicola Pero + + PR objc/48187 + * c-parser.c (c_parser_objc_class_instance_variables): More robust + parsing of syntax error in ObjC instance variable lists. In + particular, avoid an infinite loop if there is a stray ']'. + Updated error message. + 2011-05-24 Joseph Myers * Makefile.in (GCC_OBJS): Remove opts-common.o and options.o. Index: testsuite/ChangeLog === --- testsuite/ChangeLog (revision 174112) +++ testsuite/ChangeLog (working copy) @@ -1,3 +1,10 @@ +2011-05-24 Nicola Pero + + PR objc/48187 + * objc.dg/pr48187.m: New testcase. + * obj-c++.dg/pr48187.mm: New testcase. + * objc.dg/ivar-extra-semicolon.m: New testcase. + 2011-05-24 Tom de Vries PR tree-optimization/49121 Index: testsuite/objc.dg/ivar-extra-semicolon.m === --- testsuite/objc.dg/ivar-extra-semicolon.m(revision 0) +++ testsuite/objc.dg/ivar-extra-semicolon.m(revision 0) @@ -0,0 +1,15 @@ +/* Contributed by Nicola Pero , May 2011. */ +/* { dg-do compile } */ +/* { dg-options "-pedantic" } */ + +#include + +@interface MyClass +{ + ; /* { dg-warning "extra semicolon" } */ + int a; + ; /* { dg-warning "extra semicolon" } */ + int b; + ; /* { dg-warning "extra semicolon" } */ +} +@end Index: testsuite/objc.dg/pr48187.m === --- testsuite/objc.dg/pr48187.m (revision 0) +++ testsuite/objc.dg/pr48187.m (revision 0) @@ -0,0 +1,39 @@ +/* { dg-do compile } */ + +@interface A +{ + ] /* { dg-error "xpected" } */ +} +@end + +@interface B +{ + ]; /* { dg-error "xpected" } */ +} +@end + +@interface C +{ + ]; /* { dg-error "xpected" } */ + int x; +} +@end + +@interface D +{ + ) /* { dg-error "xpected" } */ +} +@end + +@interface E +{ + ); /* { dg-error "xpected" } */ +} +@end + +@interface F +{ + ); /* { dg-error "xpected" } */ + int x; +} +@end Index: testsuite/obj-c++.dg/pr48187.mm === --- testsuite/obj-c++.dg/pr48187.mm (revision 0) +++ testsuite/obj-c++.dg/pr48187.mm (revision 0) @@ -0,0 +1,39 @@ +/* { dg-do compile } */ + +@interface A +{ + ] /* { dg-error "xpected" } */ +} +@end + +@interface B +{ + ]; /* { dg-error "xpected" } */ +} +@end + +@interface C +{ + ]; /* { dg-error "xpected" } */ + int x; +} +@end + +@interface D +{ + ( +} /* { dg-error "xpected" } */ +@end + +@interface E +{ + (; /* { dg-error "xpected" } */ +} +@end + +@interface F +{ + (; /* { dg-error "xpected" } */ + int x; +} +@end Index: cp/ChangeLog === --- cp/ChangeLog(revision 174112) +++ cp/ChangeLog(working copy) @@ -1,3 +1,8 @@ +2011-05-24 Nicola Pero , + + * parser.c (cp_parser_objc_class_ivars): Deal gracefully with a + syntax error in declaring an ObjC instance variable. + 2011-05-24 Joseph Myer
Tiny documentation update in diagnostic.c
Ok to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 174112) +++ ChangeLog (working copy) @@ -1,3 +1,15 @@ +2011-05-24 Nicola Pero + + * diagnostic.c (pedwarn): Updated comment. + Index: diagnostic.c === --- diagnostic.c(revision 174112) +++ diagnostic.c(working copy) @@ -701,8 +701,9 @@ Note that these diagnostics are issued independent of the setting of the -pedantic command-line switch. To get a warning enabled only with that switch, use either "if (pedantic) pedwarn - (OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)". To get a - pedwarn independently of the -pedantic switch use "pedwarn (0,...)". + (,OPT_pedantic,...)" or just "pedwarn (,OPT_pedantic,..)". To get + a pedwarn independently of the -pedantic switch use "pedwarn + (,0,...)". Returns true if the warning was printed, false if it was inhibited. */
Fix for libobjc/48177. Can I apply it to 4.6 as well ?
This patch fixes libobjc/48177. I applied it to trunk. I'd like to apply this patch to the 4.6 branch too. Do I need permission from a Release Manager ? Can I get it ? :-) It is a fairly obvious fix as selector types should generally be compared using sel_types_match() and not strcmp(). But note that this bug has been in libobjc forever; it never mattered much because the traditional API (the only one available before GCC 4.6) had a number of different functions for dealing with typed selectors, and gnustep-base (the main user of this API) was using some other function to do this and the problem wasn't visible. The modern API (recommended from GCC 4.6.0 onwards) has a more limited, and elegant, set of functions, and the code in gnustep-base would be massively simplified ... if only this bug wasn't in the way! :-( Due to this bug, gnustep-base actually has to forcefully use the traditional API in the middle of the modern API, which it does by copying some declarations from the traditional API and it's all quite horrible. Ideally, we'd fix this bug in trunk and in 4.6.1, so that once 4.6.1 is released, gnustep-base can remove the horrible hacks, simply use the Modern API, and just tell everyone running 4.6.0 to upgrade to 4.6.1 to get the fix. :-) So, OK to commit to the 4.6 branch too ? Thanks Index: libobjc/ChangeLog === --- libobjc/ChangeLog (revision 174141) +++ libobjc/ChangeLog (working copy) @@ -1,3 +1,10 @@ +2011-05-24 Nicola Pero + + PR libobjc/48177 + * selector.c (__sel_register_typed_name): Use sel_types_match() + instead of strcmp() to compare selector types (Suggestion by + Richard Frith-Macdonald ). + 2011-04-15 Rainer Orth PR libobjc/32037 Index: libobjc/selector.c === --- libobjc/selector.c (revision 174138) +++ libobjc/selector.c (working copy) @@ -597,7 +597,7 @@ __sel_register_typed_name (const char *name, const return s; } } - else if (! strcmp (s->sel_types, types)) + else if (sel_types_match (s->sel_types, types)) { if (orig) { Index: gcc/testsuite/ChangeLog === --- gcc/testsuite/ChangeLog (revision 174142) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,5 +1,10 @@ 2011-05-24 Nicola Pero + PR libobjc/48177 + * objc.dg/pr48177.m: New testcase. + +2011-05-24 Nicola Pero + PR objc/48187 * objc.dg/pr48187.m: New testcase. * obj-c++.dg/pr48187.mm: New testcase. Index: gcc/testsuite/objc.dg/pr48177.m === --- gcc/testsuite/objc.dg/pr48177.m (revision 0) +++ gcc/testsuite/objc.dg/pr48177.m (revision 0) @@ -0,0 +1,35 @@ +/* Contributed by Nicola Pero , May 2011. */ +/* { dg-do run } */ +/* { dg-skip-if "No API#2 pre-Darwin9" { *-*-darwin[5-8]* } { "-fnext-runtime" } { "" } } */ + +#include +#include + +int main(int argc, void **args) +{ +#ifdef __GNU_LIBOBJC__ + /* This special test tests that, if you have a selector already + registered in the runtime with full type information, you can use + sel_registerTypedName() to get it even if you specify the type + with incorrect argframe information. This is helpful as + selectors generated by the compiler (which have correct argframe + information) are usually registered before hand-written ones + (which often have incorrect argframe information, but need the + correct one). + + Note that in this hand-written test, even the type information of + the first selector may be wrong (on this machine); but that's OK + as we'll never actually use the selectors. */ + SEL selector1 = sel_registerTypedName ("testMethod", "i8@0:4"); + SEL selector2 = sel_registerTypedName ("testMethod", "i8@8:8"); + + /* We compare the selectors using ==, not using sel_isEqual(). This + is because we are testing internals of the runtime and we know + that in the current implementation they should be identical if + the stuff is to work as expected. Don't do this at home. */ + if (selector1 != selector2) +abort (); +#endif + + return 0; +}
Re: Fix for libobjc/48177. Can I apply it to 4.6 as well ?
>> This patch fixes libobjc/48177. I applied it to trunk. >> >> I'd like to apply this patch to the 4.6 branch too. Do I need permission >> from >> a Release Manager ? > > They are always welcome to chime in, though, in this case the libobjc > maintainer can approve it. Thanks Mike I browsed the archives of gcc-patches for a while and as far as I can see, you are right and other maintainers do approve patches for the 4.6 branch (in their own areas) without waiting for a Release Manager to double-approve each patch (and it makes sense). So I applied it to the 4.6 branch too. :-) Thanks
Patch for libobjc/38307
tion, mostly with code from get_imp + updated to support the new +initialize dispatch table logic. + (get_imp): Use get_implementation. + (__objc_responds_to): Updated to support the new +initialize + dispatch table logic. + (class_respondsToSelector): Likewise. + (objc_msg_lookup): Use get_implementation. + (__objc_init_install_dtable): Removed. + (__objc_install_methods_in_dtable): Updated arguments. + (__objc_install_dispatch_table_for_class): Renamed to + __objc_install_dtable_for_class and updated to support the new + +initialize dispatch table logic. + (__objc_update_dispatch_table_for_class): Updated to support the + new +initialize dispatch table logic. + (__objc_forward): Call get_implementation instead of get_imp. + (prepared_dtable_table): New. + (__objc_prepare_dtable_for_class): New. + (__objc_prepared_dtable_for_class): New. + (__objc_get_prepared_imp): New. + (__objc_install_prepared_dtable_for_class): New. + 2011-05-24 Nicola Pero PR libobjc/48177
Fix missing function declaration warnings in yesterday's libobjc patch
This patch fixes a problem with the patch from Richard/David that was committed yesterday; presumably since the patch was originally written before the new libobjc API revamp, it was still using objc_lookup_class(), which is not part of the Modern API, hence currently undeclared in sendmsg.c. I replaced it with the Modern API counter-part, which is objc_getClass(), fixing the compiler warnings, and providing the compiler with the correct function declaration. Applied to trunk. Thanks Index: sendmsg.c === --- sendmsg.c (revision 174267) +++ sendmsg.c (working copy) @@ -,7 +,7 @@ else { /* Retreive the class from the meta class. */ - Class c = objc_lookup_class (cls->name); + Class c = objc_getClass (cls->name); assert (CLS_ISMETA (cls)); assert (c); __objc_send_initialize (c); Index: ChangeLog === --- ChangeLog (revision 174267) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-05-26 Nicola Pero + + * sendmsg.c (__objc_install_dtable_for_class): Use objc_getClass, + not objc_lookupClass. + 2011-05-25 Richard Frith-Macdonald David Ayers
libobjc - indentation patch for sendmsg.c
Applied to trunk. Thanks Index: ChangeLog === --- ChangeLog (revision 174268) +++ ChangeLog (working copy) @@ -1,5 +1,10 @@ 2011-05-26 Nicola Pero + * sendmsg.c: Reindented part of the file. No non-trivial changes + in code. + +2011-05-26 Nicola Pero + * sendmsg.c (__objc_install_dtable_for_class): Use objc_getClass, not objc_lookupClass. Index: sendmsg.c === --- sendmsg.c (revision 174268) +++ sendmsg.c (working copy) @@ -263,29 +263,26 @@ get_implementation (id receiver, Class class, SEL /* Double-checked locking pattern: Check __objc_uninstalled_dtable again in case another thread -installed the dtable while we were waiting for the lock -to be released. */ +installed the dtable while we were waiting for the lock to be +released. */ if (class->dtable == __objc_uninstalled_dtable) - { - __objc_install_dtable_for_class (class); - } + __objc_install_dtable_for_class (class); - /* If the dispatch table is not yet installed, - we are still in the process of executing +initialize. - But the implementation pointer should be available - in the prepared ispatch table if it exists at all. */ + /* If the dispatch table is not yet installed, we are still in +the process of executing +initialize. But the implementation +pointer should be available in the prepared ispatch table if +it exists at all. */ if (class->dtable == __objc_uninstalled_dtable) { assert (__objc_prepared_dtable_for_class (class) != 0); res = __objc_get_prepared_imp (class, sel); } else - { - res = 0; - } + res = 0; + objc_mutex_unlock (__objc_runtime_mutex); - /* Call ourselves with the installed dispatch table and get -the real method. */ + /* Call ourselves with the installed dispatch table and get the +real method. */ if (!res) res = get_implementation (receiver, class, sel); } @@ -295,9 +292,9 @@ get_implementation (id receiver, Class class, SEL res = sarray_get_safe (class->dtable, (size_t) sel->sel_id); if (res == 0) { - /* The dispatch table has been installed, and the method -is not in the dispatch table. So the method just -doesn't exist for the class. */ + /* The dispatch table has been installed, and the method is +not in the dispatch table. So the method just doesn't +exist for the class. */ /* Try going through the +resolveClassMethod: or +resolveInstanceMethod: process. */ @@ -305,9 +302,9 @@ get_implementation (id receiver, Class class, SEL { /* We have the meta class, but we need to invoke the +resolveClassMethod: method on the class. So, we -need to obtain the class from the meta class, -which we do using the fact that both the class -and the meta-class have the same name. */ +need to obtain the class from the meta class, which +we do using the fact that both the class and the +meta-class have the same name. */ Class realClass = objc_lookUpClass (class->name); if (realClass) res = __objc_resolve_class_method (realClass, sel); @@ -316,9 +313,7 @@ get_implementation (id receiver, Class class, SEL res = __objc_resolve_instance_method (class, sel); if (res == 0) - { - res = __objc_get_forward_imp (receiver, sel); - } + res = __objc_get_forward_imp (receiver, sel); } } return res; @@ -365,10 +360,9 @@ method_get_imp (struct objc_method * method) /* Query if an object can respond to a selector, returns YES if the object implements the selector otherwise NO. Does not check if the - method can be forwarded. - Since this requires the dispatch table to installed, this function - will implicitly invoke +initialize for the class of OBJECT if it - hasn't been invoked yet. */ + method can be forwarded. Since this requires the dispatch table to + installed, this function will implicitly invoke +initialize for the + class of OBJECT if it hasn't been invoked yet. */ inline BOOL __objc_responds_to (id object, SEL sel) @@ -384,9 +378,9 @@ __objc_responds_to (id object, SEL sel) if (object->class_pointer->dtable == __objc_uninstalled_dtable) __objc_install_dtable_for_class (object->class_pointer); - /* If the dispatch table is not yet installed, - we are still in the process of executing +initialize. - Yet the dispatch
ObjC/ObjC++: Add support for nonnull attribute for ObjC methods
This patch adds support for the "nonnull" attribute for Objective-C methods (clang has it too). The implementation follows the existing framework and is very similar to the "format" attribute one. Testcases included. Ok to commit ? Thanks PS: There is a small unsatisfactory issue with the generated warnings, which are too correct :-) in that they say something like xxx.m:89:3: warning: null argument where non-null required (argument 3) [-Wnonnull] and the "argument 3" index includes the 2 hidden Objective-C method arguments (self and _cmd). I'd rather it didn't, and I'd rather that the warning said "argument 1" instead. Note that the "format" attribute, as implemented, already has this problem, but you never notice because the warnings it generates never mention the argument index ;-) But, changing the warnings requires refactoring and more radical changes (including changes to c-family), which I'd rather leave for a separate patch. I added a FIXME in the code about the issue. Index: objc/ChangeLog === --- objc/ChangeLog (revision 174335) +++ objc/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-05-27 Nicola Pero + + * objc-act.c (objc_decl_method_attributes): Implement nonnull + attribute for Objective-C methods. + 2011-05-21 Nicola Pero * config-lang.in (gtfiles): Updated order of files to fix building Index: objc/objc-act.c === --- objc/objc-act.c (revision 174335) +++ objc/objc-act.c (working copy) @@ -5042,6 +5042,48 @@ objc_decl_method_attributes (tree *node, tree attr filtered_attributes = chainon (filtered_attributes, new_attribute); } + else if (is_attribute_p ("nonnull", name)) + { + /* We need to fixup all the argument indexes by adding 2 +for the two hidden arguments of an Objective-C method +invocation, similat to what we do above for the +"format" attribute. */ + /* FIXME: This works great in terms of implementing the +functionality, but the warnings that are produced by +nonnull do mention the argument index (while the +format ones don't). For example, you could get +"warning: null argument where non-null required +(argument 3)". Now in that message, "argument 3" +includes the 2 hidden arguments; it would be much +more friendly to call it "argument 1", as that would +be consistent with __attribute__ ((nonnnull (1))). +To do this, we'd need to have the C family code that +checks the arguments know about adding/removing 2 to +the argument index ... or alternatively we could +maybe store the "printable" argument index in +addition to the actual argument index ? Some +refactoring is needed to do this elegantly. */ + tree new_attribute = copy_node (attribute); + tree argument = TREE_VALUE (attribute); + while (argument != NULL_TREE) + { + /* Get the value of the argument and add 2. */ + tree number = TREE_VALUE (argument); + if (number + && TREE_CODE (number) == INTEGER_CST + && TREE_INT_CST_HIGH (number) == 0 + && TREE_INT_CST_LOW (number) != 0) + { + TREE_VALUE (argument) + = build_int_cst (integer_type_node, +TREE_INT_CST_LOW (number) + 2); + } + argument = TREE_CHAIN (argument); + } + + filtered_attributes = chainon (filtered_attributes, +new_attribute); + } else warning (OPT_Wattributes, "%qE attribute directive ignored", name); } Index: testsuite/ChangeLog === --- testsuite/ChangeLog (revision 174335) +++ testsuite/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-05-27 Nicola Pero + + * objc.dg/attributes/method-nonnull-1.m: New test. + * obj-c++.dg/attributes/method-nonnull-1.mm: New test. + 2011-05-27 Richard Guenther * gcc.c-torture/execute/920711-1.x: Add -fwrapv. Index: testsuite/objc.dg/attributes/method-nonnull-1.m === --- testsuite/objc.dg/attributes/method-nonnull-1.m (revision 0)
Remove dependency of all-target-libobjc on maybe-all-target-libiberty
This patch removes the (maybe) dependency of libobjc from target libiberty from the makefiles. I don't know of any reasons why libobjc would need target libiberty; I also looked around and couldn't spot anything. Most other target libraries don't depend on libiberty; I'm not sure why libobjc would need to. I think the dependency is bogus, probably exists for historical reasons and the fact that nobody reviewed that piece of code for a long time, and should go away. :-) It wouldn't matter much, but I saw that some people are keen to remove the target libiberty completely, and I wouldn't want them to spend time trying to figure out why libobjc needs it. It doesn't. ;-) Ok to commit ? Thanks Index: Makefile.in === --- Makefile.in (revision 174141) +++ Makefile.in (working copy) @@ -43412,7 +43412,6 @@ all-target-libjava: maybe-all-target-boehm-gc all-target-libjava: maybe-all-target-libffi configure-target-libobjc: maybe-configure-target-boehm-gc -all-target-libobjc: maybe-all-target-libiberty all-target-libobjc: maybe-all-target-boehm-gc all-target-libstdc++-v3: maybe-all-target-libiberty configure-target-libstdc++-v3: maybe-configure-target-libgomp Index: ChangeLog === --- ChangeLog (revision 174141) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-05-27 Nicola Pero + + * Makefile.in (all-target-libobjc): Do not depend on + maybe-all-target-libiberty. + 2011-05-11 Paul Pluzhnikov * MAINTAINERS (Write After Approval): Add myself.
Fix for PR objc/48539 ("Missing warning when messaging a forward-declared class")
col. I thought about adding a second warning about the @interface not being found, and for a while had it in the patch, but in practice it seemed overkill and I removed it from the final version. -- The warning message that I chose for GCC is -- method-lookup-1.m:42:3: warning: @interface of class ‘NotKnown’ not found [enabled by default] which I hope is clear and to the point (and the action expected from the programmer, which is adding or including the @interface, is hopefully evident). As a comparison, clang has the warning method-lookup-1.m:42:4: warning: receiver 'NotKnown' is a forward class and corresponding @interface may not exist which I find confusing and hard to read (and react to) for various reasons. -- I added testcases with enumerations of cases and combinations to make sure I was covering the various complications. I did add a fair amount of comments to the code as well. :-) Ok to commit to trunk ? Thanks Index: objc/ChangeLog === --- objc/ChangeLog (revision 174551) +++ objc/ChangeLog (working copy) @@ -1,3 +1,12 @@ +2011-06-02 Nicola Pero + + PR objc/48539 + * objc-act.c (objc_finish_message_expr): Warn if messaging a class + that was only declared using @class without an @interface. Warn + if messaging an instance of a class that was only declared using + @class without an @interface, unless the receiver was also typed + with a protocol list. + 2011-06-01 Nicola Pero * objc-act.c (objc_decl_method_attributes): Implement nonnull Index: objc/objc-act.c === --- objc/objc-act.c (revision 174551) +++ objc/objc-act.c (working copy) @@ -5432,15 +5432,21 @@ objc_finish_message_expr (tree receiver, tree sel_ from the implementation context). */ rtype = receiver; while (TREE_CODE (rtype) == COMPOUND_EXPR - || TREE_CODE (rtype) == MODIFY_EXPR - || CONVERT_EXPR_P (rtype) - || TREE_CODE (rtype) == COMPONENT_REF) +|| TREE_CODE (rtype) == MODIFY_EXPR +|| CONVERT_EXPR_P (rtype) +|| TREE_CODE (rtype) == COMPONENT_REF) rtype = TREE_OPERAND (rtype, 0); + /* self is 1 if this is a message to self, 0 otherwise */ self = (rtype == self_decl); + + /* super is 1 if this is a message to super, 0 otherwise. */ super = (rtype == UOBJC_SUPER_decl); + + /* rtype is the type of the receiver. */ rtype = TREE_TYPE (receiver); + /* have_cast is 1 if the receiver is casted. */ have_cast = (TREE_CODE (receiver) == NOP_EXPR || (TREE_CODE (receiver) == COMPOUND_EXPR && !IS_SUPER (rtype))); @@ -5450,7 +5456,10 @@ objc_finish_message_expr (tree receiver, tree sel_ should_call_super_dealloc = 0; /* If the receiver is a class object, retrieve the corresponding - @interface, if one exists. */ + @interface, if one exists. class_tree is the class name + identifier, or NULL_TREE if this is not a class method or the + class name could not be determined (as in the case "Class c; [c + method];"). */ class_tree = receiver_is_class_object (receiver, self, super); /* Now determine the receiver type (if an explicit cast has not been @@ -5458,7 +5467,27 @@ objc_finish_message_expr (tree receiver, tree sel_ if (!have_cast) { if (class_tree) - rtype = lookup_interface (class_tree); + { + /* We are here when we have no cast, and we have a class +name. So, this is a plain method to a class object, as +in [NSObject alloc]. Find the interface corresponding to +the class name. */ + rtype = lookup_interface (class_tree); + + if (rtype == NULL_TREE) + { + /* If 'rtype' is NULL_TREE at this point it means that +we have seen no @interface corresponding to that +class name, only a @class declaration. So, we have a +class name (class_tree) but no actual details of the +class methods. We won't be able to check that the +class responds to the method, and we will have to +guess the method prototype. Emit a warning, then +keep going (this will use any method with a matching +name, as if the receiver was of type 'Class'). */ + warning (0, "@interface of class %qE not found", class_tree); + } + } /* Handle `self' and `super'. */ else if (super) { @@ -5474,28 +5503,41 @@ objc_finish_message_expr (tree receiver, tree sel_ rtype = lookup_interface (CLASS_NAME (implementation_template)); } - /* If receiver is of type `id' or `Class' (or if the @interface for a - class is no
libobjc: remove deprecated API (patch 1)
This patch removes a number of deprecated libobjc functions and methods, which are part of the "Traditional" Objective-C API that was deprecated in GCC 4.6.x and are to be removed in GCC 4.7.0. It's the first of a long sequence of patches that does this removal one bit at a time. This one removes the deprecated objc_error(), objc_verror() and objc_set_error_handler() functions, and all the deprecated Object methods whose implementation used to use these functions. Unfortunately, all of our testcases use the "Traditional" Objective-C API when testing the GNU runtime and they will need to be updated to use the "Modern" Objective-C API because the Traditional Objective-C API is simply going away. I'll update the relevant testcases with each patch. This first patch requires only a tiny update of a single testcase. Committed to trunk. Thanks Index: libobjc/sendmsg.c === --- libobjc/sendmsg.c (revision 174585) +++ libobjc/sendmsg.c (working copy) @@ -977,16 +977,8 @@ __objc_forward (id object, SEL sel, arglist_t args : "instance" ), object->class_pointer->name, sel_getName (sel)); -/* TODO: support for error: is surely deprecated ? */ -err_sel = sel_get_any_uid ("error:"); -if (__objc_responds_to (object, err_sel)) - { - imp = get_implementation (object, object->class_pointer, err_sel); - return (*imp) (object, sel_get_any_uid ("error:"), msg); - } - -/* The object doesn't respond to doesNotRecognize: or error:; - Therefore, a default action is taken. */ +/* The object doesn't respond to doesNotRecognize:. Therefore, a + default action is taken. */ _objc_abort ("%s\n", msg); return 0; Index: libobjc/Makefile.in === --- libobjc/Makefile.in (revision 174585) +++ libobjc/Makefile.in (working copy) @@ -139,7 +139,6 @@ OBJC_DEPRECATED_H = \ STR.h \ hash.h \ objc-list.h \ - objc_error.h \ objc_get_uninstalled_dtable.h \ objc_malloc.h \ objc_msg_sendv.h \ Index: libobjc/libobjc.def === --- libobjc/libobjc.def (revision 174585) +++ libobjc/libobjc.def (working copy) @@ -25,7 +25,6 @@ search_for_method_in_list objc_get_uninstalled_dtable objc_hash_is_key_in_hash hash_is_key_in_hash -objc_verror _objc_load_callback objc_malloc objc_atomic_malloc @@ -53,7 +52,6 @@ objc_thread_remove __objc_class_name_Object __objc_class_name_Protocol __objc_class_name_NXConstantString -objc_error __objc_object_alloc __objc_object_copy __objc_object_dispose Index: libobjc/error.c === --- libobjc/error.c (revision 174585) +++ libobjc/error.c (working copy) @@ -45,53 +45,3 @@ _objc_abort (const char *fmt, ...) abort (); va_end (ap); } - -/* The rest of the file is deprecated. */ -#include "objc/objc-api.h" /* For objc_error_handler. */ - -/* -** Error handler function -** NULL so that default is to just print to stderr -*/ -static objc_error_handler _objc_error_handler = NULL; - -/* Trigger an objc error */ -void -objc_error (id object, int code, const char *fmt, ...) -{ - va_list ap; - - va_start (ap, fmt); - objc_verror (object, code, fmt, ap); - va_end (ap); -} - -/* Trigger an objc error */ -void -objc_verror (id object, int code, const char *fmt, va_list ap) -{ - BOOL result = NO; - - /* Call the error handler if its there - Otherwise print to stderr */ - if (_objc_error_handler) -result = (*_objc_error_handler) (object, code, fmt, ap); - else -vfprintf (stderr, fmt, ap); - - /* Continue if the error handler says its ok - Otherwise abort the program */ - if (result) -return; - else -abort (); -} - -/* Set the error handler */ -objc_error_handler -objc_set_error_handler (objc_error_handler func) -{ - objc_error_handler temp = _objc_error_handler; - _objc_error_handler = func; - return temp; -} Index: libobjc/ChangeLog === --- libobjc/ChangeLog (revision 174585) +++ libobjc/ChangeLog (working copy) @@ -1,3 +1,19 @@ +2011-06-02 Nicola Pero + + * Makefile.in (OBJC_DEPRECATED_H): Removed objc_error.h. + * objc/deprecated/objc_error.h: Removed. + * objc/objc-api.h: Do not include deprecated/objc_error.h. + * libobjc.def (objc_error, objc_verror): Removed. + * error.c (_objc_error_handler, objc_error, objc_verror, + objc_set_error_handler): Removed. + * Object.m ([-error:], [-perform:], [-perform:with:], + [-perform:with:with], [-subclassResponsibility:], + [-notImplemented:], [-shouldNotImplement:], [-doesNotRecognize:]): + Removed. + * objc/depreca
libobjc: remove deprecated API (patch 3)
Another patch in the sequence. This patch removes objc/objc-list.h, a public header that is deprecated and no longer part of the public API. It is still used internally by libobjc, which has got its own private copy (which is now private and may change without notice). Committed to trunk. Thanks Index: gcc/testsuite/ChangeLog === --- gcc/testsuite/ChangeLog (revision 174593) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,5 +1,9 @@ 2011-06-03 Nicola Pero + * objc.dg/headers.m: Do not include objc-list.h. + +2011-06-03 Nicola Pero + * objc.dg/type-stream-1.m: Test removed. * objc.dg/headers.m: Do not include typedstream.h. Index: gcc/testsuite/objc.dg/headers.m === --- gcc/testsuite/objc.dg/headers.m (revision 174593) +++ gcc/testsuite/objc.dg/headers.m (working copy) @@ -18,10 +18,6 @@ #endif #include -#ifndef __NEXT_RUNTIME__ -#include -#endif - #include #ifndef __NEXT_RUNTIME__ Index: libobjc/Makefile.in === --- libobjc/Makefile.in (revision 174593) +++ libobjc/Makefile.in (working copy) @@ -125,7 +125,6 @@ OBJC_H = \ thr.h \ \ hash.h \ - objc-list.h \ sarray.h # User-visible header files containing deprecated APIs, from the @@ -137,7 +136,6 @@ OBJC_DEPRECATED_H = \ Protocol.h \ STR.h \ hash.h \ - objc-list.h \ objc_get_uninstalled_dtable.h \ objc_malloc.h \ objc_msg_sendv.h \ Index: libobjc/ChangeLog === --- libobjc/ChangeLog (revision 174593) +++ libobjc/ChangeLog (working copy) @@ -1,5 +1,12 @@ 2011-06-03 Nicola Pero + * Makefile.in (OBJC_H): Removed objc-list.h. + (OBJC_DEPRECATED_H): Removed objc-list.h. + * objc/objc-list.h: File removed. + * objc/deprecated/objc-list.h: File removed. + +2011-06-03 Nicola Pero + * Makefile.in (OBJC_H): Removed typedstream.h. (OBJC_DEPRECATED_H): Removed typedstream.h. (C_SOURCE_FILES): Removed archive.c. Index: libobjc/objc/deprecated/objc-list.h === --- libobjc/objc/deprecated/objc-list.h (revision 174593) +++ libobjc/objc/deprecated/objc-list.h (working copy) @@ -1,155 +0,0 @@ -/* Generic single linked list to keep various information - Copyright (C) 1993, 1994, 1996, 2009 Free Software Foundation, Inc. - Contributed by Kresten Krab Thorup. - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 3, or (at your option) -any later version. - -GCC is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -Under Section 7 of GPL version 3, you are granted additional -permissions described in the GCC Runtime Library Exception, version -3.1, as published by the Free Software Foundation. - -You should have received a copy of the GNU General Public License and -a copy of the GCC Runtime Library Exception along with this program; -see the files COPYING3 and COPYING.RUNTIME respectively. If not, see -<http://www.gnu.org/licenses/>. */ - - -#ifndef __GNU_OBJC_LIST_H -#define __GNU_OBJC_LIST_H - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -struct objc_list { - void *head; - struct objc_list *tail; -}; - -/* Return a cons cell produced from (head . tail) */ - -static inline struct objc_list* -list_cons(void* head, struct objc_list* tail) -{ - struct objc_list* cell; - - cell = (struct objc_list*)objc_malloc(sizeof(struct objc_list)); - cell->head = head; - cell->tail = tail; - return cell; -} - -/* Return the length of a list, list_length(NULL) returns zero */ - -static inline int -list_length(struct objc_list* list) -{ - int i = 0; - while(list) -{ - i += 1; - list = list->tail; -} - return i; -} - -/* Return the Nth element of LIST, where N count from zero. If N - larger than the list length, NULL is returned */ - -static inline void* -list_nth(int indx, struct objc_list* list) -{ - while(indx-- != 0) -{ - if(list->tail) - list = list->tail; - else - return 0; -} - return list->head; -} - -/* Remove the element at the head by replacing it by its successor */ - -static inline void -list_remove_head(struct objc_list** list) -{ - if ((*list)->tail) -{ - struct objc_list* tail = (*list)->tail; /* fetch next */ - *(*list) = *tail;/* copy next to list head */ - objc_free(tail); /* free next */ -} - else
libobjc: remove deprecated API (patch 4)
This patch removes -forward:: from Object. I was planning to do this later, but the previous patch (patch 3) removed -doesNotRecognize:, which was used in the default implementation of -forward::, which generates some ugly warnings when compiling. Removing -forward:: removes the warnings. Please note that at this stage the runtime may still invoke -forward:: if you have it implemented in your own class, and have not installed a custom forwarding routine. There are testcases in the GCC testsuite that test this. This will all go away later, and will require removing the testcases, but at the same time I'd like to add new testcases for __objc_msg_forward and __objc_msg_forward2, which are the actual hooks used in practice by users of libobjc, but which currently are not really tested. For now, this patch just removes [Object -forward::], which is deprecated, and makes libobjc compile again without warnings. Committed to trunk. Thanks Index: sendmsg.c === --- sendmsg.c (revision 174593) +++ sendmsg.c (working copy) @@ -936,9 +936,12 @@ __objc_block_forward (id rcv, SEL op, ...) } -/* This function is installed in the dispatch table for all methods - which are not implemented. Thus, it is called when a selector is - not recognized. */ +/* This function is called for methods which are not implemented, + unless a custom forwarding routine has been installed. Please note + that most serious users of libobjc (eg, GNUstep base) do install + their own forwarding routines, and hence this is never actually + used. But, if no custom forwarding routine is installed, this is + called when a selector is not recognized. */ static retval_t __objc_forward (id object, SEL sel, arglist_t args) { Index: ChangeLog === --- ChangeLog (revision 174594) +++ ChangeLog (working copy) @@ -1,5 +1,11 @@ 2011-06-03 Nicola Pero + * Object.m ([-forward::]): Removed. + * objc/deprecated/Object.h ([-forward::]): Removed. + * sendmsg.c (__objc_forward): Updated comments. + +2011-06-03 Nicola Pero + * Makefile.in (OBJC_H): Removed objc-list.h. (OBJC_DEPRECATED_H): Removed objc-list.h. * objc/objc-list.h: File removed. Index: Object.m === --- Object.m(revision 174593) +++ Object.m(working copy) @@ -248,12 +248,6 @@ see the files COPYING3 and COPYING.RUNTIME respect :class_get_class_method(self->isa, aSel))); } -- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame -{ - (void) argFrame; /* UNUSED */ - return (retval_t)[self doesNotRecognize: aSel]; -} - - (retval_t)performv:(SEL)aSel :(arglist_t)argFrame { return objc_msg_sendv(self, aSel, argFrame); Index: objc/deprecated/Object.h === --- objc/deprecated/Object.h(revision 174593) +++ objc/deprecated/Object.h(working copy) @@ -49,7 +49,6 @@ - (struct objc_method_description *)descriptionForMethod:(SEL)aSel; /* Forwarding */ -- (retval_t)forward:(SEL)aSel :(arglist_t)argFrame; - (retval_t)performv:(SEL)aSel :(arglist_t)argFrame; /* Posing */
libobjc: remove deprecated API (patch 5)
This patch removes objc/hash.h and objc/sarray.h, which had been deprecated in GCC 4.6.0. Of course, libobjc still has its own private versions, but they are (finally!) private so we have made another step towards being able to change the libobjc internals at will without having to change the public API. :-) Committed to trunk. Thanks Index: libobjc/Makefile.in === --- libobjc/Makefile.in (revision 174594) +++ libobjc/Makefile.in (working copy) @@ -122,10 +122,7 @@ OBJC_H = \ objc-api.h \ objc-decls.h \ runtime.h \ - thr.h \ - \ - hash.h \ - sarray.h + thr.h # User-visible header files containing deprecated APIs, from the # objc/deprecated directory @@ -135,14 +132,12 @@ OBJC_DEPRECATED_H = \ Object.h \ Protocol.h \ STR.h \ - hash.h \ objc_get_uninstalled_dtable.h \ objc_malloc.h \ objc_msg_sendv.h \ objc_object_alloc.h \ objc_unexpected_exception.h \ objc_valloc.h \ - sarray.h \ struct_objc_category.h \ struct_objc_class.h \ struct_objc_ivar.h \ Index: libobjc/objc-private/common.h === --- libobjc/objc-private/common.h (revision 174593) +++ libobjc/objc-private/common.h (working copy) @@ -28,11 +28,6 @@ see the files COPYING3 and COPYING.RUNTIME respect /* This file contains definitions that should be included by all .c and .m files in libobjc. */ -/* This variable allows the public headers to determine when they are - being included by a file inside libobjc itself, or when they are - being included by an external file. */ -#define GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF 1 - /* When debugging libobjc, add #define DEBUG 1 Index: libobjc/libobjc.def === --- libobjc/libobjc.def (revision 174593) +++ libobjc/libobjc.def (working copy) @@ -23,8 +23,6 @@ LIBRARY libobjc EXPORTS search_for_method_in_list objc_get_uninstalled_dtable -objc_hash_is_key_in_hash -hash_is_key_in_hash _objc_load_callback objc_malloc objc_atomic_malloc @@ -106,22 +104,3 @@ objc_get_class objc_get_meta_class objc_lookup_class objc_next_class -sarray_at_put -sarray_at_put_safe -sarray_free -sarray_lazy_copy -sarray_new -sarray_realloc -sarray_remove_garbage -objc_hash_add -hash_add -objc_hash_delete -hash_delete -objc_hash_new -hash_new -objc_hash_next -hash_next -objc_hash_remove -hash_remove -objc_hash_value_for_key -hash_value_for_key Index: libobjc/ChangeLog === --- libobjc/ChangeLog (revision 174607) +++ libobjc/ChangeLog (working copy) @@ -1,5 +1,25 @@ 2011-06-03 Nicola Pero + * Makefile.in (OBJC_H): Removed hash.h and sarray.h. + (OBJC_DEPRECATED_H): Likewise. + * libobjc.def (objc_hash_new, objc_hash_delete, objc_hash_add, + objc_hash_remove, objc_hash_next, objc_hash_value_for_key, + objc_hash_is_key_in_hash, hash_add, hash_delete, hash_new, + hash_next, hash_remove, hash_value_for_key, hash_is_key_in_hash, + sarray_at_put, sarray_at_put_safe, sarray_free, sarray_lazy_copy, + sarray_new, sarray_realloc, sarray_remove_garbage): Removed. + * objc/sarray.h: Removed. + * objc/hash.h: Removed. + * objc/deprecated/sarray.h: Removed. + * objc/deprecated/hash.h: Removed. + * objc/Object.h: Do not include objc/deprecated/hash.h + * Object.m: Include string.h. + * objc/objc-api.h: Do not include objc/deprecated/hash.h. + * objc-private/common.h (GNU_LIBOBJC_COMPILING_LIBOBJC_ITSELF): + Removed. + +2011-06-03 Nicola Pero + * Object.m ([-forward::]): Removed. * objc/deprecated/Object.h ([-forward::]): Removed. * sendmsg.c (__objc_forward): Updated comments. Index: libobjc/Object.m === --- libobjc/Object.m(revision 174607) +++ libobjc/Object.m(working copy) @@ -25,6 +25,7 @@ see the files COPYING3 and COPYING.RUNTIME respect #include "objc-private/common.h" #include +#include /* For strcmp. */ #include #include "objc/Object.h" #include "objc/Protocol.h" Index: libobjc/objc/sarray.h === --- libobjc/objc/sarray.h (revision 174593) +++ libobjc/objc/sarray.h (working copy) @@ -1,2 +0,0 @@ -#include "deprecated/sarray.h" - Index: libobjc/objc/Object.h === --- libobjc/objc/Object.h (revision 174593) +++ libobjc/objc/Object.h (working copy) @@ -57,7 +57,6 @@ extern "C" { /* All of the following includes were deprecated in GCC 4.6 and will be removed in the next release. */ -#include "deprecated/hash.h" #include "deprecated/Object
libobjc: remove deprecate API (patch 6)
This trivial patch removes the deprecated definition of STR. Committed to trunk. Thanks Index: Makefile.in === --- Makefile.in (revision 174610) +++ Makefile.in (working copy) @@ -131,7 +131,6 @@ MetaClass.h \ Object.h \ Protocol.h \ - STR.h \ objc_get_uninstalled_dtable.h \ objc_malloc.h \ objc_msg_sendv.h \ Index: ChangeLog === --- ChangeLog (revision 174610) +++ ChangeLog (working copy) @@ -1,5 +1,11 @@ 2011-06-03 Nicola Pero + * objc/objc.h: Do not include deprecated/STR.h. + * objc/deprecated/STR.h: Removed. + * Makefile.in (OBJC_DEPRECATED_H): removed STR.h. + +2011-06-03 Nicola Pero + * Makefile.in (OBJC_H): Removed hash.h and sarray.h. (OBJC_DEPRECATED_H): Likewise. * libobjc.def (objc_hash_new, objc_hash_delete, objc_hash_add, Index: objc/deprecated/STR.h === --- objc/deprecated/STR.h (revision 174593) +++ objc/deprecated/STR.h (working copy) @@ -1,2 +0,0 @@ -/* Incredibly obsolete. */ -typedef char *STR; /* String alias */ Index: objc/objc.h === --- objc/objc.h (revision 174593) +++ objc/objc.h (working copy) @@ -125,8 +125,6 @@ compiler to do some type-checking. */ #define Nil (Class)0 -#include "deprecated/STR.h" - /* TODO: Move the 'Protocol' declaration into objc/runtime.h. A Protocol is simply an object, not a basic Objective-C type. The Apple runtime defines Protocol in objc/runtime.h too, so it's good
libobjc: remove deprecated API (patch 7)
This patch removes another bunch of deprecated functions and hooks from libobjc, in particular objc_valloc(), the various _objc_alloc and similar hooks and the _objc_unexpected_exception hook. Committed to trunk. Thanks Index: Makefile.in === --- Makefile.in (revision 174614) +++ Makefile.in (working copy) @@ -132,11 +132,8 @@ OBJC_DEPRECATED_H = \ Object.h \ Protocol.h \ objc_get_uninstalled_dtable.h \ - objc_malloc.h \ objc_msg_sendv.h \ objc_object_alloc.h \ - objc_unexpected_exception.h \ - objc_valloc.h \ struct_objc_category.h \ struct_objc_class.h \ struct_objc_ivar.h \ @@ -268,16 +265,14 @@ sendmsg_gc.lo: sendmsg.c runtime-info.h # These files have separate rules because they require special # compiler flags. -# -Wno-deprecated-declarations is to silence warnings from using -# _objc_unexpected_exception. exception.lo: exception.c $(LIBTOOL_COMPILE) $(CC) $< -c \ - $(ALL_CFLAGS) $(INCLUDES) -fexceptions -Wno-deprecated-declarations \ + $(ALL_CFLAGS) $(INCLUDES) -fexceptions \ -o $@ exception_gc.lo: exception.c $(LIBTOOL_COMPILE) $(CC) $< -c \ - $(ALL_CFLAGS) $(INCLUDES) $(OBJC_GCFLAGS) -fexceptions -Wno-deprecated-declarations \ + $(ALL_CFLAGS) $(INCLUDES) $(OBJC_GCFLAGS) -fexceptions \ -o $@ doc: info dvi pdf html Index: libobjc.def === --- libobjc.def (revision 174610) +++ libobjc.def (working copy) @@ -26,7 +26,6 @@ objc_get_uninstalled_dtable _objc_load_callback objc_malloc objc_atomic_malloc -objc_valloc objc_realloc objc_calloc objc_free @@ -36,7 +35,6 @@ objc_mutex_deallocate objc_mutex_lock objc_mutex_trylock objc_mutex_unlock -_objc_unexpected_exception objc_thread_detach objc_thread_exit objc_thread_get_data Index: exception.c === --- exception.c (revision 174593) +++ exception.c (working copy) @@ -31,12 +31,6 @@ see the files COPYING3 and COPYING.RUNTIME respect #include "unwind-pe.h" #include /* For memcpy */ -/* This hook allows libraries to sepecify special actions when an - exception is thrown without a handler in place. This is deprecated - in favour of objc_set_uncaught_exception_handler (). */ -void (*_objc_unexpected_exception) (id exception); /* !T:SAFE */ - - /* 'is_kind_of_exception_matcher' is our default exception matcher - it determines if the object 'exception' is of class 'catch_class', or of a subclass. */ @@ -539,13 +533,6 @@ objc_exception_throw (id exception) (*__objc_uncaught_exception_handler) (exception); } - /* As a last resort support the old, deprecated way of setting an - uncaught exception handler. */ - if (_objc_unexpected_exception != 0) -{ - (*_objc_unexpected_exception) (exception); -} - abort (); } Index: ChangeLog === --- ChangeLog (revision 174614) +++ ChangeLog (working copy) @@ -1,5 +1,24 @@ 2011-06-03 Nicola Pero + * Makefile.in (OBJC_DEPRECATED_H): Removed objc_valloc.h, + objc_malloc.h and objc_unexpected_exception.h. + (exception.lo): Do not use -Wno-deprecated-declarations. + (exception_gc.lo): Likewise. + * objc/objc-api.h: Do not include deprecated/objc_valloc.h, + deprecated/objc_malloc.h and + deprecated/objc_unexpected_exception.h. + * objc/deprecated/objc_valloc.h: Removed. + * objc/deprecated/objc_malloc.h: Removed. + * objc/deprecated/objc_unexpected_exception.h: Removed. + * exception.c (_objc_unexpected_exception): Removed. + (objc_exception_throw): Do not check for + _objc_unexpected_exception. + * memory.c (objc_valloc, _objc_malloc, _objc_atomic_malloc, + _objc_valloc, _objc_realloc, _objc_calloc, _objc_free): Removed. + * libobjc.def (_objc_unexpected_exception, objc_valloc): Removed. + +2011-06-03 Nicola Pero + * objc/objc.h: Do not include deprecated/STR.h. * objc/deprecated/STR.h: Removed. * Makefile.in (OBJC_DEPRECATED_H): removed STR.h. Index: memory.c === --- memory.c(revision 174593) +++ memory.c(working copy) @@ -133,38 +133,3 @@ objc_free (void *mem) } #endif /* !OBJC_WITH_GC */ - -/* The rest of the file contains deprecated code. */ - -#if OBJC_WITH_GC - -void * -objc_valloc (size_t size) -{ - void *res = (void *)(GC_malloc (size)); - if (! res) -_objc_abort ("Virtual memory exhausted\n"); - return res; -} - -#else - -void * -objc_valloc (size_t size) -{ - void *res = (void *)(malloc (size)); - if (! res) -_objc_abort ("Virtual memory exhausted\n"); - return res; -} - -#endif /* !OBJC_
libobjc: remove deprecated API (patch 8)
This patch removes the deprecated definition of METHOD_NULL. Committed to trunk. Thanks Index: Makefile.in === --- Makefile.in (revision 174615) +++ Makefile.in (working copy) @@ -127,7 +127,6 @@ OBJC_H = \ # User-visible header files containing deprecated APIs, from the # objc/deprecated directory OBJC_DEPRECATED_H = \ - METHOD_NULL.h \ MetaClass.h \ Object.h \ Protocol.h \ Index: ChangeLog === --- ChangeLog (revision 174615) +++ ChangeLog (working copy) @@ -1,5 +1,11 @@ 2011-06-03 Nicola Pero + * Makefile.in (OBJC_DEPRECATED_H): Removed METHOD_NULL.h. + * objc/objc-api.h: Do not include deprecated/METHOD_NULL.h. + * objc/deprecated/METHOD_NULL.h: Removed. + +2011-06-03 Nicola Pero + * Makefile.in (OBJC_DEPRECATED_H): Removed objc_valloc.h, objc_malloc.h and objc_unexpected_exception.h. (exception.lo): Do not use -Wno-deprecated-declarations. Index: objc/deprecated/METHOD_NULL.h === --- objc/deprecated/METHOD_NULL.h (revision 174593) +++ objc/deprecated/METHOD_NULL.h (working copy) @@ -1,2 +0,0 @@ -/* For functions which return Method_t */ -#define METHOD_NULL(Method_t)0 Index: objc/objc-api.h === --- objc/objc-api.h (revision 174615) +++ objc/objc-api.h (working copy) @@ -58,8 +58,6 @@ see the files COPYING3 and COPYING.RUNTIME respect extern "C" { #endif /* __cplusplus */ -#include "deprecated/METHOD_NULL.h" - /* Method descriptor returned by introspective Object methods. This is really just the first part of the more complete objc_method structure defined below and used internally by the runtime. */
libobjc: remove deprecated API (patch 9)
This patch removes more deprecated and obsolete hooks/functions from libobjc. Committed to trunk. Thanks Index: Makefile.in === --- Makefile.in (revision 174616) +++ Makefile.in (working copy) @@ -132,7 +132,6 @@ OBJC_DEPRECATED_H = \ Protocol.h \ objc_get_uninstalled_dtable.h \ objc_msg_sendv.h \ - objc_object_alloc.h \ struct_objc_category.h \ struct_objc_class.h \ struct_objc_ivar.h \ Index: libobjc.def === --- libobjc.def (revision 174615) +++ libobjc.def (working copy) @@ -48,9 +48,6 @@ objc_thread_remove __objc_class_name_Object __objc_class_name_Protocol __objc_class_name_NXConstantString -__objc_object_alloc -__objc_object_copy -__objc_object_dispose class_create_instance object_copy object_dispose Index: objects.c === --- objects.c (revision 174593) +++ objects.c (working copy) @@ -123,8 +123,3 @@ object_setClass (id object, Class class_) } } -/* Hook functions for memory allocation and disposal. Deprecated and - currently unused. */ -id (*_objc_object_alloc) (Class) = 0; -id (*_objc_object_dispose) (id)= 0; -id (*_objc_object_copy) (id) = 0; Index: ChangeLog === --- ChangeLog (revision 174616) +++ ChangeLog (working copy) @@ -1,5 +1,15 @@ 2011-06-03 Nicola Pero + * Makefile.in (OBJC_DEPRECATED_H): Removed objc_object_alloc.h. + * objc/deprecated/objc_object_alloc.h: Removed. + * objc/objc-api.h: Do not include deprecated/objc_object_alloc.h. + * objects.c (_objc_object_alloc, _objc_object_dispose, + _objc_object_copy): Removed. + * libobjc.def (__objc_object_alloc, __objc_object_copy, + __objc_object_dispose): Removed. + +2011-06-03 Nicola Pero + * Makefile.in (OBJC_DEPRECATED_H): Removed METHOD_NULL.h. * objc/objc-api.h: Do not include deprecated/METHOD_NULL.h. * objc/deprecated/METHOD_NULL.h: Removed. Index: objc/deprecated/objc_object_alloc.h === --- objc/deprecated/objc_object_alloc.h (revision 174593) +++ objc/deprecated/objc_object_alloc.h (working copy) @@ -1,8 +0,0 @@ -/* These functions are deprecated and currently ignored. */ -/* -** Hook functions for allocating, copying and disposing of instances -*/ -objc_EXPORT id (*_objc_object_alloc)(Class _class);Index: objc/objc-api.h === --- objc/objc-api.h (revision 174616) +++ objc/objc-api.h (working copy) @@ -191,8 +191,6 @@ objc_EXPORT Class (*_objc_lookup_class)(const char */ objc_EXPORT void (*_objc_load_callback)(Class _class, Category* category); -#include "deprecated/objc_object_alloc.h" - /* Standard functions for memory allocation and disposal. Users should use these functions in their ObjC programs so that they work so that -objc_EXPORT id (*_objc_object_copy)(id object); -objc_EXPORT id (*_objc_object_dispose)(id object); -
libobjc: remove deprecated API (patch 10)
This patch removes another couple of deprecated header fragments. Note that this starts to remove pieces of the Traditional API, which will be entirely removed in GCC 4.7.0. Of course, that requires switching all testcases to use the Modern API when compiling for the GNU runtime, but we'll get there. ;-) Committed to trunk. Thanks Index: Makefile.in === --- Makefile.in (revision 174617) +++ Makefile.in (working copy) @@ -130,7 +130,6 @@ MetaClass.h \ Object.h \ Protocol.h \ - objc_get_uninstalled_dtable.h \ objc_msg_sendv.h \ struct_objc_category.h \ struct_objc_class.h \ @@ -142,7 +141,6 @@ struct_objc_protocol.h \ struct_objc_protocol_list.h \ struct_objc_selector.h \ - struct_objc_static_instances.h \ struct_objc_symtab.h # Objective-C source files to compile Index: ChangeLog === --- ChangeLog (revision 174617) +++ ChangeLog (working copy) @@ -1,5 +1,14 @@ 2011-06-03 Nicola Pero + * Makefile.in (OBJC_DEPRECATED_H): Removed struct_objc_static_instances.h + and objc_get_uninstalled_dtable.h. + * objc/deprecated/struct_objc_static_instances.h: Removed. + * objc/deprecated/objc_get_uninstalled_dtable.h: Removed. + * objc/objc-api.h: Do not include deprecated/objc_static_instances.h + and deprecated/objc_get_uninstalled_dtable.h. + +2011-06-03 Nicola Pero + * Makefile.in (OBJC_DEPRECATED_H): Removed objc_object_alloc.h. * objc/deprecated/objc_object_alloc.h: Removed. * objc/objc-api.h: Do not include deprecated/objc_object_alloc.h. Index: objc/deprecated/objc_get_uninstalled_dtable.h === --- objc/deprecated/objc_get_uninstalled_dtable.h (revision 174593) +++ objc/deprecated/objc_get_uninstalled_dtable.h (working copy) @@ -1,2 +0,0 @@ -objc_EXPORT struct sarray* -objc_get_uninstalled_dtable(void); Index: objc/deprecated/struct_objc_static_instances.h === --- objc/deprecated/struct_objc_static_instances.h (revision 174593) +++ objc/deprecated/struct_objc_static_instances.h (working copy) @@ -1,14 +0,0 @@ -/* For every class which happens to have statically allocated instances in - this module, one OBJC_STATIC_INSTANCES is allocated by the compiler. - INSTANCES is NULL terminated and points to all statically allocated - instances of this class. */ -struct objc_static_instances -{ - char *class_name; -#ifdef __cplusplus - id instances[1]; -#else - id instances[0]; -#endif -}; - Index: objc/objc-api.h === --- objc/objc-api.h (revision 174617) +++ objc/objc-api.h (working copy) @@ -104,7 +104,6 @@ equivalent to "*". */ #define _C_ATOM '%' -#include "deprecated/struct_objc_static_instances.h" #include "deprecated/struct_objc_symtab.h" #include "deprecated/struct_objc_module.h" #include "deprecated/struct_objc_ivar.h" @@ -385,8 +384,6 @@ && !object_is_class (object)); } -#include "deprecated/objc_get_uninstalled_dtable.h" - #ifdef __cplusplus } #endif /* __cplusplus */
libobjc: Fixed gnu-api-2-objc.m testcase
This patch fixes two errors in the gnu-api-2-objc.m testcase for libobjc's Modern Objective-C API. One of them is that class_addIvar() was called with the alignment, instead of the log2 of the alignment, being passed as argument. The error slipped in because a previous, buggy version of libobjc's class_addIvar() didn't use the log2, and when fixing libobjc it seems I forgot to update this testcase. It's important to fix this in case people look at the testcase as an example of how to use the API. ;-) The other one is that a root class was created, and an instance of it instantiated, without the required "isa" instance variable to hold the Class. This error slipped in because the instantiation was added later without realizing the root class was a test, fake class without the required variable. This is more serious and could cause the testcase to fail under some conditions, depending on how the memory is allocated. This patch fixes it. :-) Committed to trunk. Thanks PS: I noticed that these testcases, and the gnu-api-2-class.m[m] ones, are failing on Apple m64. That's a separate issue and I'll submit a separate patch. Index: ChangeLog === --- ChangeLog (revision 174655) +++ ChangeLog (working copy) @@ -1,3 +1,10 @@ +2011-06-04 Nicola Pero + + * objc.dg/gnu-api-2-objc.m: Fixed testcase. Use log2 of the + alignment, not the alignment, when calling class_addIvar(). Add + an 'isa' instance variable to the test root class. + * obj-c++.dg/gnu-api-2-objc.mm: Likewise. + 2011-06-04 Jan Hubicka PR tree-optimization/48893 Index: objc.dg/gnu-api-2-objc.m === --- objc.dg/gnu-api-2-objc.m(revision 174655) +++ objc.dg/gnu-api-2-objc.m(working copy) @@ -45,7 +45,24 @@ - (id) variable { return variable_ivar; } @end +/* Hack to calculate the log2 of a byte alignment. */ +unsigned char +log_2_of (unsigned int x) +{ + unsigned char result = 0; + /* We count how many times we need to divide by 2 before we reach 1. + This algorithm is good enough for the small numbers (such as 8, + 16 or 64) that we have to deal with. */ + while (x > 1) +{ + x = x / 2; + result++; +} + + return result; +} + int main(int argc, void **args) { /* Functions are tested in alphabetical order. */ @@ -56,8 +73,9 @@ int main(int argc, void **args) Class new_class = objc_allocateClassPair (objc_getClass ("MyRootClass"), "MyNewSubClass", 0); /* A new root class would obviously need at least an 'isa' - instance variable. We don't add it so we never actually - instantiate an instance of the class, which wouldn't work. */ + instance variable. */ +class_addIvar (new_root_class, "isa", sizeof (Class), log_2_of (__alignof__ (Class)), + @encode (Class)); objc_registerClassPair (new_root_class); objc_registerClassPair (new_class); @@ -114,7 +132,7 @@ int main(int argc, void **args) /* Add a bit of everything to the class to exercise undoing all these changes. */ /* Instance variable. */ -class_addIvar (new_class, "my_variable", sizeof (float), __alignof__ (float), @encode (float)); +class_addIvar (new_class, "my_variable", sizeof (float), log_2_of (__alignof__ (float)), @encode (float)); /* Instance method. */ class_addMethod (new_class, @selector (setVariable:), method_getImplementation (method), Index: obj-c++.dg/gnu-api-2-objc.mm === --- obj-c++.dg/gnu-api-2-objc.mm(revision 174655) +++ obj-c++.dg/gnu-api-2-objc.mm(working copy) @@ -45,7 +45,24 @@ - (id) variable { return variable_ivar; } @end +/* Hack to calculate the log2 of a byte alignment. */ +unsigned char +log_2_of (unsigned int x) +{ + unsigned char result = 0; + /* We count how many times we need to divide by 2 before we reach 1. + This algorithm is good enough for the small numbers (such as 8, + 16 or 64) that we have to deal with. */ + while (x > 1) +{ + x = x / 2; + result++; +} + + return result; +} + int main () { /* Functions are tested in alphabetical order. */ @@ -56,8 +73,9 @@ int main () Class new_class = objc_allocateClassPair (objc_getClass ("MyRootClass"), "MyNewSubClass", 0); /* A new root class would obviously need at least an 'isa' - instance variable. We don't add it so we never actually - instantiate an instance of the class, which wouldn't work. */ + instance variable. */ +class_addIvar (new_root_class, "isa", sizeof (Class), log_2_of (__alignof__ (Class)), + @encode (C
Fix for PR objc/49287
This patch fixes PR objc/49287. The problem is that enabling the compiler checks for missing @interfaces triggered a couple of warnings of missing @interfaces in some testcases (this only showed up with the NeXT runtime because objc_getClass() is treated specially only with the NeXT runtime; we haven't changed the GNU ABI yet). The patch adds a cast to the testcases to remove the warnings and fix the apparent regression. OK to commit ? Thanks PS: I spent time considering whether the compiler behaviour in terms of warnings needed improving in this specific case, and ended up thinking that it's fine as it is. It's a rare issue where our compiler currently behaves identically to the latest Apple GCC in terms of warnings. Apple clang doesn't behave in the same way, as it's unable to check method invocations based on the arguments of objc_getClass() like GCC does, and so can miss serious warnings if objc_getClass() is the receiver of a method invocation not supported by the class, but on the other hand, doesn't emit a warning when objc_getClass() is used as a receiver of a method invocation and the @interface of the class is not available. I wondered for a while if this last behaviour is slightly better, but it's unclear. In the end, I see no compelling reason to change anything. It's a very rare issue anyhow. I added comments to objc-act.c trying to summarize the issues involved so if in the future we want to change things, information is readily available. Index: gcc/objc/ChangeLog === --- gcc/objc/ChangeLog (revision 174624) +++ gcc/objc/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-06-05 Nicola Pero + + * objc-act.c (receiver_is_class_object): Expanded comment. + (objc_finish_message_expr): Likewise. + 2011-06-02 Nicola Pero PR objc/48539 Index: gcc/objc/objc-act.c === --- gcc/objc/objc-act.c (revision 174624) +++ gcc/objc/objc-act.c (working copy) @@ -5270,7 +5270,42 @@ receiver_is_class_object (tree receiver, int self, return exp; /* The receiver is a function call that returns an id. Check if - it is a call to objc_getClass, if so, pick up the class name. */ + it is a call to objc_getClass, if so, pick up the class name. + + This is required by the GNU runtime, which compiles + + [NSObject alloc] + + into + + [objc_get_class ("NSObject") alloc]; + + and then, to check that the receiver responds to the +alloc + method, needs to be able to determine that the objc_get_class() + call returns the NSObject class and not just a generic Class + pointer. + + But, traditionally this is enabled for all runtimes, not just the + GNU one, which means that the compiler is smarter than you'd + expect when dealing with objc_getClass(). For example, with the + Apple runtime, in the code + + [objc_getClass ("NSObject") alloc]; + + the compiler will recognize the objc_getClass() call as special + (due to the code below) and so will know that +alloc is called on + the 'NSObject' class, and can perform the corresponding checks. + + Programmers can disable this behaviour by casting the results of + objc_getClass() to 'Class' (this may seem weird because + objc_getClass() is already declared to return 'Class', but the + compiler treats it as a special function). This may be useful if + the class is never declared, and the compiler would complain + about a missing @interface for it. Then, you can do + + [(Class)objc_getClass ("MyClassNeverDeclared") alloc]; + + to silence the warnings. */ if (TREE_CODE (receiver) == CALL_EXPR && (exp = CALL_EXPR_FN (receiver)) && TREE_CODE (exp) == ADDR_EXPR @@ -5478,13 +5513,16 @@ objc_finish_message_expr (tree receiver, tree sel_ { /* If 'rtype' is NULL_TREE at this point it means that we have seen no @interface corresponding to that -class name, only a @class declaration. So, we have a -class name (class_tree) but no actual details of the -class methods. We won't be able to check that the -class responds to the method, and we will have to -guess the method prototype. Emit a warning, then -keep going (this will use any method with a matching -name, as if the receiver was of type 'Class'). */ +class name, only a @class declaration (alternatively, +this was a call such as [objc_getClass("SomeClass") +alloc], where we've never seen the @interface of +SomeClass). So, we have
Fix for PR obj-c++/48275 ("getter=namespace failing with .mm")
This patch fixes PR obj-c++/48275. It's a routine parser ingenuity. OK to commit ? Thanks Index: testsuite/ChangeLog === --- testsuite/ChangeLog (revision 174657) +++ testsuite/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2011-06-06 Nicola Pero + + PR objc-++/48275 + * obj-c++.dg/property/cxx-property-1.mm: New. + * obj-c++.dg/property/cxx-property-2.mm: New. + 2011-06-05 Nicola Pero PR testsuite/49287 Index: testsuite/obj-c++.dg/property/cxx-property-2.mm === --- testsuite/obj-c++.dg/property/cxx-property-2.mm (revision 0) +++ testsuite/obj-c++.dg/property/cxx-property-2.mm (revision 0) @@ -0,0 +1,22 @@ +/* { dg-do compile } */ + +/* All these C++ keywords are acceptable in ObjC method names, hence + should be accepted for property getters and setters. */ + +@interface Test +{ + Class isa; +} +@property (getter=namespace) int p0; +@property (setter=namespace:) int p1; +@property (getter=and) int p2; +@property (setter=and:) int p3; +@property (getter=class) int p4; +@property (setter=class:) int p5; +@property (getter=new) int p6; +@property (setter=new:) int p7; +@property (getter=delete) int p8; +@property (setter=delete:) int p9; +@property (getter=delete) int p10; +@property (setter=delete:) int p11; +@end Index: testsuite/obj-c++.dg/property/cxx-property-1.mm === --- testsuite/obj-c++.dg/property/cxx-property-1.mm (revision 0) +++ testsuite/obj-c++.dg/property/cxx-property-1.mm (revision 0) @@ -0,0 +1,10 @@ +/* Testcase from PR obj-c++/48275. */ +/* { dg-do compile } */ + +@interface Test +{ +int ns; +} +@property (getter=namespace) int ns; + +@end Index: cp/ChangeLog === --- cp/ChangeLog(revision 174656) +++ cp/ChangeLog(working copy) @@ -1,3 +1,9 @@ +2011-06-06 Nicola Pero , + + PR obj-c++/48275 + * parser.c (cp_parser_objc_at_property_declaration): Allow setter + and getter names to use all the allowed method names. + 2011-06-04 Jonathan Wakely * init.c (build_delete): Warn when deleting type with non-virtual Index: cp/parser.c === --- cp/parser.c (revision 174656) +++ cp/parser.c (working copy) @@ -23187,7 +23187,7 @@ cp_parser_objc_at_property_declaration (cp_parser break; } cp_lexer_consume_token (parser->lexer); /* eat the = */ - if (cp_lexer_next_token_is_not (parser->lexer, CPP_NAME)) + if (!cp_parser_objc_selector_p (cp_lexer_peek_token (parser->lexer)->type)) { cp_parser_error (parser, "expected identifier"); syntax_error = true; @@ -23196,10 +23196,12 @@ cp_parser_objc_at_property_declaration (cp_parser if (keyword == RID_SETTER) { if (property_setter_ident != NULL_TREE) - cp_parser_error (parser, "the % attribute may only be specified once"); + { + cp_parser_error (parser, "the % attribute may only be specified once"); + cp_lexer_consume_token (parser->lexer); + } else - property_setter_ident = cp_lexer_peek_token (parser->lexer)->u.value; - cp_lexer_consume_token (parser->lexer); + property_setter_ident = cp_parser_objc_selector (parser); if (cp_lexer_next_token_is_not (parser->lexer, CPP_COLON)) cp_parser_error (parser, "setter name must terminate with %<:%>"); else @@ -23208,10 +23210,12 @@ cp_parser_objc_at_property_declaration (cp_parser else { if (property_getter_ident != NULL_TREE) - cp_parser_error (parser, "the % attribute may only be specified once"); + { + cp_parser_error (parser, "the % attribute may only be specified once"); + cp_lexer_consume_token (parser->lexer); + } else - property_getter_ident = cp_lexer_peek_token (parser->lexer)->u.value; - cp_lexer_consume_token (parser->lexer); + property_getter_ident = cp_parser_objc_selector (parser); } break; default:
Re: objc/objc++: switch all testcases to Modern Objective-C runtime API
> I checked on i686-darwin9 with both m32 and m32/abi=1 the only difference I > see is the XPASSes > for m64 torture/forward-1.m for gnu runtime. That is very comforting; I have committed the (revised) patch. Thanks a lot for your help testing and reviewing. :-) > I will try to test on darwin8 during the week - but time v. limited. I expect there will be a few issues with darwin8; it's all supposed to work there, but software never works until you test it, and I haven't tested it. ;-) If you try, please send me the logs of the failures and I'll fix them. Thanks
objc/objc++: fix most testsuite failures on darwin8
This patch (prepared by me and Iain) fixes almost all failures of the testsuite on Darwin 8 caused by the large testsuite changes I committed yesterday. The patch fixes all the failures but 2. These two require a different small fix that is being developed/tested and will be submitted separately. Thanks Iain for the help! :-) OK to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 174760) +++ ChangeLog (working copy) @@ -1,3 +1,10 @@ +2011-06-07 Nicola Pero + Iain Sandoe + + * objc-obj-c++-shared/TestsuiteObject.h ([-free]): Return 'id'. + * objc-obj-c++-shared/TestsuiteObject.m ([-free]): Return 'id'. + Added cast. + 2011-06-07 Rainer Orth gcc/testsuite: Index: objc-obj-c++-shared/TestsuiteObject.h === --- objc-obj-c++-shared/TestsuiteObject.h (revision 174760) +++ objc-obj-c++-shared/TestsuiteObject.h (working copy) @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see + (id) new; + (id) alloc; - (id) init; -- (void) free; +- (id) free; /* Auxiliary methods. */ + (Class) class; Index: objc-obj-c++-shared/TestsuiteObject.m === --- objc-obj-c++-shared/TestsuiteObject.m (revision 174760) +++ objc-obj-c++-shared/TestsuiteObject.m (working copy) @@ -41,9 +41,14 @@ along with GCC; see the file COPYING3. If not see { return self; } -- (void) free +/* We return 'id' to have the same signature as [Object -free] in + older runtimes and avoid warnings about conflicting signatures. */ +- (id) free { - object_dispose (self); + /* Cast 'self' to 'id' because the NeXT runtime in darwin8 (Apple + Mac OS X 10.4) declares object_dispose to take an "Object *" + argument. */ + return object_dispose ((id)self); } + (Class) class {
Re: objc/objc++: fix most testsuite failures on darwin8
This patch (written with Iain) fixes all the testsuite failiures on Darwin8. It includes the previous one. OK to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 174760) +++ ChangeLog (working copy) @@ -1,3 +1,18 @@ +2011-06-07 Nicola Pero + Iain Sandoe + + * objc-obj-c++-shared/runtime.h (protocol_getMethodDescription): + Added code to deal with the case when [Protocol + -descriptionForInstanceMethod:] or [Protocol + -descriptionForClassMethod:] returns NULL. + +2011-06-07 Nicola Pero + Iain Sandoe + + * objc-obj-c++-shared/TestsuiteObject.h ([-free]): Return 'id'. + * objc-obj-c++-shared/TestsuiteObject.m ([-free]): Return 'id'. + Added cast. + 2011-06-07 Rainer Orth gcc/testsuite: Index: objc-obj-c++-shared/TestsuiteObject.h === --- objc-obj-c++-shared/TestsuiteObject.h (revision 174761) +++ objc-obj-c++-shared/TestsuiteObject.h (working copy) @@ -35,7 +35,7 @@ along with GCC; see the file COPYING3. If not see + (id) new; + (id) alloc; - (id) init; -- (void) free; +- (id) free; /* Auxiliary methods. */ + (Class) class; Index: objc-obj-c++-shared/runtime.h === --- objc-obj-c++-shared/runtime.h (revision 174761) +++ objc-obj-c++-shared/runtime.h (working copy) @@ -93,14 +93,16 @@ struct objc_method_description protocol_getMethodD struct objc_method_description result; if (instanceMethod) -{ - tmp = [protocol descriptionForInstanceMethod: selector]; - result = *tmp; -} +tmp = [protocol descriptionForInstanceMethod: selector]; else +tmp = [protocol descriptionForClassMethod: selector]; + + if (tmp) +result = *tmp; + else { - tmp = [protocol descriptionForClassMethod: selector]; - result = *tmp; + result.name = (SEL)0; + result.types = (char *)0; } return result; Index: objc-obj-c++-shared/TestsuiteObject.m === --- objc-obj-c++-shared/TestsuiteObject.m (revision 174761) +++ objc-obj-c++-shared/TestsuiteObject.m (working copy) @@ -41,9 +41,14 @@ along with GCC; see the file COPYING3. If not see { return self; } -- (void) free +/* We return 'id' to have the same signature as [Object -free] in + older runtimes and avoid warnings about conflicting signatures. */ +- (id) free { - object_dispose (self); + /* Cast 'self' to 'id' because the NeXT runtime in darwin8 (Apple + Mac OS X 10.4) declares object_dispose to take an "Object *" + argument. */ + return object_dispose ((id)self); } + (Class) class {
libobjc: remove unused code (patch 1)
bclass_list = CLASSOF (impostor); - -/* Set impostor to have no sibling classes. */ -impostor->sibling_class = 0; -CLASSOF (impostor)->sibling_class = 0; - } - - /* Check relationship of impostor and super_class is kept. */ - assert (impostor->super_class == super_class); - assert (CLASSOF (impostor)->super_class == CLASSOF (super_class)); - - /* This is how to update the lookup table. Regardless of what the - keys of the hashtable is, change all values that are superclass - into impostor. */ - - objc_mutex_lock (__objc_runtime_mutex); - - class_table_replace (super_class, impostor); - - objc_mutex_unlock (__objc_runtime_mutex); - - /* Next, we update the dispatch tables... */ - __objc_update_dispatch_table_for_class (CLASSOF (impostor)); - __objc_update_dispatch_table_for_class (impostor); - - return impostor; -} Index: ChangeLog === --- ChangeLog (revision 174766) +++ ChangeLog (working copy) @@ -1,5 +1,13 @@ 2011-06-07 Nicola Pero + * class.c (objc_next_class): Removed. + (class_pose_as): Removed. + (CLASSOF): Removed. + (class_table_replace): Removed. + (objc_lookup_class): Removed. + +2011-06-07 Nicola Pero + Removed the Traditional Objective-C runtime public API. * Makefile.in (OBJC_DEPRECATED_H): Variable removed. (install-headers): Do not create the objc/deprecated directory and
libobjc: Remove unused code (patch 2)
Removed more code in libobjc that is no longer used anywhere. Committed to trunk. Thanks Index: encoding.c === --- encoding.c (revision 174766) +++ encoding.c (working copy) @@ -993,22 +993,6 @@ method_getNumberOfArguments (struct objc_method *m } } -int -method_get_number_of_arguments (struct objc_method *mth) -{ - return method_getNumberOfArguments (mth); -} - -/* Return the size of the argument block needed on the stack to invoke - the method MTH. This may be zero, if all arguments are passed in - registers. */ -int -method_get_sizeof_arguments (struct objc_method *mth) -{ - const char *type = objc_skip_typespec (mth->method_types); - return atoi (type); -} - unsigned objc_get_type_qualifiers (const char *type) { Index: ChangeLog === --- ChangeLog (revision 174767) +++ ChangeLog (working copy) @@ -1,5 +1,10 @@ 2011-06-07 Nicola Pero + * encoding.c (method_get_number_of_arguments): Removed. + (method_get_sizeof_arguments): Removed. + +2011-06-07 Nicola Pero + * class.c (objc_next_class): Removed. (class_pose_as): Removed. (CLASSOF): Removed.
libobjc: Remove unused code (patch 3)
uot;objc-private/error.h" -/* __USE_FIXED_PROTOTYPES__ used to be required to get prototypes for - malloc, free, etc. on some platforms. It is unclear if we still - need it, but it can't hurt. */ -#define __USE_FIXED_PROTOTYPES__ #include #include #include Index: objects.c === --- objects.c (revision 174766) +++ objects.c (working copy) @@ -67,12 +67,6 @@ class_createInstance (Class class, size_t extraByt /* Traditional GNU Objective-C Runtime API. */ id -class_create_instance (Class class) -{ - return class_createInstance (class, 0); -} - -id object_copy (id object, size_t extraBytes) { if ((object != nil) && CLS_ISCLASS (object->class_pointer)) @@ -122,4 +116,3 @@ object_setClass (id object, Class class_) return old_class; } } - Index: ChangeLog === --- ChangeLog (revision 174768) +++ ChangeLog (working copy) @@ -1,5 +1,21 @@ 2011-06-07 Nicola Pero + * objc-private/module-abi-8.h (class_get_instance_size): Removed. + * objects.c (class_create_instance): Removed. + * error.c (__USE_FIXED_PROTOTYPES__): Removed. + * gc.c (__objc_generate_gc_type_description): Use + class_getInstanceSize() instead of class_get_instance_size(). + * selector.c (sel_types_match): Made static. + (sel_get_typed_uid): Removed. + (sel_get_any_typed_uid): Removed. + (sel_get_name): Removed. + (sel_get_type): Removed. + (sel_register_name): Removed. + (sel_register_typed_name): Removed. + (sel_get_uid): Removed. + +2011-06-07 Nicola Pero + * encoding.c (method_get_number_of_arguments): Removed. (method_get_sizeof_arguments): Removed. Index: gc.c === --- gc.c(revision 174766) +++ gc.c(working copy) @@ -304,7 +304,7 @@ __objc_generate_gc_type_description (Class class) /* The number of bits in the mask is the size of an instance in bytes divided by the size of a pointer. */ - bits_no = (ROUND (class_get_instance_size (class), sizeof (void *)) + bits_no = (ROUND (class_getInstanceSize (class), sizeof (void *)) / sizeof (void *)); size = ROUND (bits_no, BITS_PER_WORD) / BITS_PER_WORD; mask = objc_atomic_malloc (size * sizeof (int));
libobjc: Remove unused code (patch 4)
Another cleanup patch. Committed to trunk. Thanks Index: sendmsg.c === --- sendmsg.c (revision 174766) +++ sendmsg.c (working copy) @@ -62,7 +62,9 @@ see the files COPYING3 and COPYING.RUNTIME respect #define INVISIBLE_STRUCT_RETURN 0 #endif -/* The uninstalled dispatch table. */ +/* The uninstalled dispatch table. If a class' dispatch table points + to __objc_uninstalled_dtable then that means it needs its dispatch + table to be installed. */ struct sarray *__objc_uninstalled_dtable = 0; /* !T:MUTEX */ /* Two hooks for method forwarding. If either is set, it is invoked to @@ -469,9 +471,6 @@ objc_msg_lookup_super (struct objc_super *super, S return (IMP)nil_method; } -struct objc_method * -class_get_instance_method (Class class, SEL op); - void __objc_init_dispatch_tables () { @@ -645,18 +644,6 @@ class_add_method_list (Class class, struct objc_me } struct objc_method * -class_get_instance_method (Class class, SEL op) -{ - return search_for_method_in_hierarchy (class, op); -} - -struct objc_method * -class_get_class_method (Class class, SEL op) -{ - return search_for_method_in_hierarchy (class, op); -} - -struct objc_method * class_getInstanceMethod (Class class_, SEL selector) { struct objc_method *m; @@ -1001,15 +988,6 @@ __objc_print_dtable_stats (void) objc_mutex_unlock (__objc_runtime_mutex); } -/* Returns the uninstalled dispatch table indicator. If a class' - dispatch table points to __objc_uninstalled_dtable then that means - it needs its dispatch table to be installed. */ -struct sarray * -objc_get_uninstalled_dtable (void) -{ - return __objc_uninstalled_dtable; -} - static cache_ptr prepared_dtable_table = 0; /* This function is called by: objc_msg_lookup, get_imp and Index: ChangeLog === --- ChangeLog (revision 174773) +++ ChangeLog (working copy) @@ -1,5 +1,11 @@ 2011-06-07 Nicola Pero + * sendmsg.c (class_get_instance_method): Removed. + (class_get_class_method): Removed. + (objc_get_uninstalled_dtable): Removed. + +2011-06-07 Nicola Pero + * objc-private/module-abi-8.h (class_get_instance_size): Removed. * objects.c (class_create_instance): Removed. * error.c (__USE_FIXED_PROTOTYPES__): Removed.
libobjc: updated some comments
Committed to trunk. Thanks Index: objc-private/selector.h === --- objc-private/selector.h (revision 174789) +++ objc-private/selector.h (working copy) @@ -28,16 +28,15 @@ see the files COPYING3 and COPYING.RUNTIME respect /* Private runtime functions that may go away or be rewritten or replaced. */ -/* -** Definition of a selector. Selectors themselves are not unique, but -** the sel_id is a unique identifier. -*/ +/* Definition of a selector. Selectors themselves are not unique, but + the sel_id is a unique identifier. */ struct objc_selector { void *sel_id; const char *sel_types; }; +/* An inline, fast version of sel_isEqual(). */ inline static BOOL sel_eq (SEL s1, SEL s2) { Index: ChangeLog === --- ChangeLog (revision 174789) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-06-08 Nicola Pero + + * objc/README: Updated. + * objc-private/selector.h: Updated comments. + 2011-06-07 Nicola Pero * sendmsg.c (class_get_instance_method): Removed. Index: objc/README === --- objc/README (revision 174789) +++ objc/README (working copy) @@ -1,13 +1,2 @@ This directory contains the public headers that are installed when libobjc is installed. - -Deprecated parts of the API should be moved into objc/deprecated and -then included by public headers until they are finally removed. For -example, if objc-api.h contains an _objc_unexpected_exception variable -which is then deprecated, it should be moved into a header in -objc/deprecated. This header is then included into objc-api.h. - -The result is that all the deprecated parts of the API are clearly -separated in objc/deprecated, while objc/ retains only the current public -API. -
Re: libobjc: Remove Traditional Objective-C runtime API
>> This patch completes the removal of the public part of the >> Traditional Objective-C runtime API from libobjc. >> >> From now on, the only supported API is the "Modern" API. :-) > > If you are removing exported functions from libobjc.so, you should > bump VERSION= in libobjc/configure.ac. Yes, sure ... shall I do that now ? I'm not done with changes yet. ;-) I suppose we'll bump VERSION only once between 4.6.0 and 4.7.0 ? Or do we want to keep bumping it at every change ? Thanks
Re: libobjc: Remove Traditional Objective-C runtime API
>>> This patch completes the removal of the public part of the >>> Traditional Objective-C runtime API from libobjc. >>> >>> From now on, the only supported API is the "Modern" API. :-) >> >> If you are removing exported functions from libobjc.so, you should >> bump VERSION= in libobjc/configure.ac. > > Yes, sure ... shall I do that now ? I'm not done with changes yet. ;-) But - you're right that we should bump it, so I bumped it :-) I suppose we could bump it again when we get into phase 3, when we're finished with the changes. Thanks Index: configure === --- configure (revision 174797) +++ configure (working copy) @@ -2274,7 +2274,7 @@ # We need the following definitions because AC_PROG_LIBTOOL relies on them PACKAGE=libobjc # Version is pulled out to make it a bit easier to change using sed. -VERSION=3:0:0 +VERSION=4:0:0 # This works around the fact that libtool configuration may change LD Index: configure.ac === --- configure.ac(revision 174797) +++ configure.ac(working copy) @@ -27,7 +27,7 @@ # We need the following definitions because AC_PROG_LIBTOOL relies on them PACKAGE=libobjc # Version is pulled out to make it a bit easier to change using sed. -VERSION=3:0:0 +VERSION=4:0:0 AC_SUBST(VERSION) # This works around the fact that libtool configuration may change LD Index: ChangeLog === --- ChangeLog (revision 174797) +++ ChangeLog (working copy) @@ -1,5 +1,10 @@ 2011-06-08 Nicola Pero + * configure.ac (VERSION): Bumped to 4:0:0. + * configure (VERSION): Likewise. + +2011-06-08 Nicola Pero + * objc/README: Updated. * objc-private/selector.h: Updated comments.
Re: libobjc: Remove Traditional Objective-C runtime API
I also bumped the API version #define marker. Committed to trunk. Thanks Index: ChangeLog === --- ChangeLog (revision 174798) +++ ChangeLog (working copy) @@ -1,5 +1,9 @@ 2011-06-08 Nicola Pero + * objc/objc.h (__GNU_LIBOBJC__): Bumped to 20110608. + +2011-06-08 Nicola Pero + * configure.ac (VERSION): Bumped to 4:0:0. * configure (VERSION): Likewise. Index: objc/objc.h === --- objc/objc.h (revision 174797) +++ objc/objc.h (working copy) @@ -43,7 +43,7 @@ release). This macro is only defined starting with the GNU Objective-C Runtime shipped with GCC 4.6.0. If it is not defined, it is either an older version of the runtime, or another runtime. */ -#define __GNU_LIBOBJC__ 20100911 +#define __GNU_LIBOBJC__ 20110608 /* Definition of the boolean type.
Re: libobjc: Remove Traditional Objective-C runtime API
> No. The next number is for the next release, and ideally, we want to sit on > it for another 10 years or so. We offer no compatibility before the RM says, > done with the release. Up until then, you can twiddle, after that, no more > changes to the abi, though, you can bug fix it. Sounds good. That was my original understanding - one ABI version per release. For GCC 4.6.0 we bumped the version number after the end of phase 1, which made sense to me, so I was expecting we'd do the same for GCC 4.7.0. But, as Jakub seemed to urge me to bump the version number right now, I got confused about whether there was an expectation of more than one bump per release; maybe to distinguish snapshots from one another or something like that ? Anyhow, we have done the bumping well in advance of the 4.7.0 release and we all seem to agree on what we should be doing (one bump per release), so it's all good. ;-) Thanks
ObjC/ObjC++/testsuite: Remove unused method_get_* functions from next-encode-assist files
This patch removes a number of functions from the ObjC/ObjC++ testsuite next-encode-assist files which are never used in the testsuite ... and will never be, since they have been removed from the GNU runtime. ;-) The next-encode-assist provides a compatible implementation for the NeXT runtime of some special GNU runtime functions. There is obviously no point in providing an implementation of functions that have been removed and are never used. OK to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 174812) +++ ChangeLog (working copy) @@ -1,3 +1,21 @@ +2011-06-08 Nicola Pero + + * objc-obj-c++-shared/objc-test-suite-next-encode-assist.h + (PMETH, arglist_t): Removed. + (method_get_number_of_arguments): Removed. + (method_get_nth_argument): Removed. + (method_get_first_argument): Removed. + (method_get_next_argument): Removed. + (method_get_sizeof_arguments): Removed. + * objc-obj-c++-shared/objc-test-suite-next-encode-assist-impl.h + (PMETH): Removed. + (method_get_number_of_arguments): Removed. + (method_get_nth_argument): Removed. + (method_get_first_argument): Removed. + (method_get_next_argument): Removed. + (method_get_sizeof_arguments): Removed. + * objc-obj-c++-shared/objc-test-suite-types.h (PMETH): Removed. + 2011-06-08 Rainer Orth PR middle-end/21953 Index: objc-obj-c++-shared/objc-test-suite-next-encode-assist-impl.h === --- objc-obj-c++-shared/objc-test-suite-next-encode-assist-impl.h (revision 174812) +++ objc-obj-c++-shared/objc-test-suite-next-encode-assist-impl.h (working copy) @@ -7,10 +7,8 @@ #include "next-abi.h" #ifdef NEXT_OBJC_USE_NEW_INTERFACE #include -typedef void * PMETH; #else #include -typedef struct objc_method * PMETH; #endif /* */ @@ -486,136 +484,7 @@ objc_skip_argspec (const char *type) type = objc_skip_offset (type); return type; } -/* - Return the number of arguments that the method MTH expects. - Note that all methods need two implicit arguments `self' and - `_cmd'. -*/ -int -method_get_number_of_arguments (PMETH mth) -{ - int i = 0; -#ifdef NEXT_OBJC_USE_NEW_INTERFACE - const char *type = method_getTypeEncoding((Method)mth); -#else - const char *type = mth->method_types; -#endif - while (*type) -{ - type = objc_skip_argspec (type); - i += 1; -} - return i - 1; -} -/* - Return the size of the argument block needed on the stack to invoke - the method MTH. This may be zero, if all arguments are passed in - registers. -*/ - -int -method_get_sizeof_arguments (PMETH mth) -{ -#ifdef NEXT_OBJC_USE_NEW_INTERFACE - const char *type = objc_skip_typespec (method_getTypeEncoding((Method)mth)); -#else - const char *type = objc_skip_typespec (mth->method_types); -#endif - return atoi (type); -} - -/* - Return a pointer to the next argument of ARGFRAME. type points to - the last argument. Typical use of this look like: - - { -char *datum, *type; -for (datum = method_get_first_argument (method, argframe, &type); - datum; datum = method_get_next_argument (argframe, &type)) - { -unsigned flags = objc_get_type_qualifiers (type); -type = objc_skip_type_qualifiers (type); - if (*type != _C_PTR) - [portal encodeData: datum ofType: type]; - else - { - if ((flags & _F_IN) == _F_IN) - [portal encodeData: *(char **) datum ofType: ++type]; - } - } - } -*/ - -char * -method_get_next_argument (arglist_t argframe, const char **type) -{ - const char *t = objc_skip_argspec (*type); - - if (*t == '\0') -return 0; - - *type = t; - t = objc_skip_typespec (t); - - if (*t == '+') -return argframe->arg_regs + atoi (++t); - else -return argframe->arg_ptr + atoi (t); -} - -/* - Return a pointer to the value of the first argument of the method - described in M with the given argumentframe ARGFRAME. The type - is returned in TYPE. type must be passed to successive calls of - method_get_next_argument. -*/ -char * -method_get_first_argument (PMETH m, - arglist_t argframe, - const char **type) -{ -#ifdef NEXT_OBJC_USE_NEW_INTERFACE - *type = method_getTypeEncoding((Method)m); -#else - *type = m->method_types; -#endif - - return method_get_next_argument (argframe, type); -} - -/* - Return a pointer to the ARGth argument of the method - M from the frame ARGFRAME. The type of the argument - is returned in the value-result argument TYPE -*/ - -char * -method_get_nth_argument (PMETH m, -arglist_t argframe, int arg, -const char **type) -{ -#ifdef NEXT_OBJC_USE_NEW_INTERFACE -
libobjc: updated documentation for removal of traditional API
This patch (trivially) updates the libobjc documentation to state that the Traditional Objective-C runtime API is no longer available. Committed to trunk. Thanks Index: ChangeLog === --- ChangeLog (revision 174821) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-06-09 Nicola Pero + + * doc/objc.texi (Traditional GNU Objective-C runtime API): + Updated. + 2011-06-08 Alexandre Oliva * tree-flow-inline.h (op_iter_init): Reject GIMPLE_PHI stmts. Index: doc/objc.texi === --- doc/objc.texi (revision 174821) +++ doc/objc.texi (working copy) @@ -121,25 +121,9 @@ different naming convention, such as @code{class_g API). Software using this API includes the file @file{objc/objc-api.h} where it is declared. -The traditional API is deprecated but it is still supported in this -release of the runtime; you can access it as usual by including -@file{objc/objc-api.h}. +Starting with GCC 4.7.0, the traditional GNU runtime API is no longer +available. -If you are using the traditional API you are urged to upgrade your -software to use the modern API because the traditional API requires -access to private runtime internals to do anything serious with it; -for this reason, there is no guarantee that future releases of the GNU -Objective-C runtime library will be able to provide a fully compatible -@file{objc/objc-api.h} as the private runtime internals change. It is -expected that the next release will hide a number of runtime internals -making the traditional API nominally supported but fairly useless -beyond very simple use cases. - -Finally, you can not include both @file{objc/objc-api.h} and -@file{objc/runtime.h} at the same time. The traditional and modern -APIs unfortunately have some conflicting declarations (such as the one -for @code{Method}) and can not be used at the same time. - @c = @node Executing code before main @section @code{+load}: Executing code before main
Patch: speed up compiler a little bit by optimizing lookup_attribute() and is_attribute_p()
This patch speeds up the C/C++/ObjC/ObjC++ compiler a little bit by optimizing lookup_attribute() and is_attribute_p(). The main change is that these functions are now inline. Benchmarking the C compiler (--enable-checking=release) compiling postgresql from source shows that total compilation times are reduced by about 0.4% with this patch (saving about 1 second over an average compilation time of 167 seconds). Benchmarking the C++ compiler compiling gold from source shows a similar speedup (about 0.5%). Not a huge speedup, but a real one. The original version of the patch was meant to speed up the Objective-C compiler and used preprocessor macros and some hacks to get a similar performance benefit in an uglier way. I prefer this new version because inline functions make the code neat and easy to read/understand, while providing similar performance benefits. The patch contains the following changes: * a tiny tweak in attribs.c to avoid looking up the attribute specs for the "naked" attribute for each and every function. If the function has no attributes whatsoever, the lookup is pointless. * a tiny tweak in tree.c to speed up attribute_list_equal() which is almost always called with two identical pointers. * inling of lookup_attribute() and is_attribute_p(). Most of the speedup (at least for the C/ObjC compiler, I haven't really studied the C++ one; it's probably the same) comes from the inling of lookup_attribute(). The reason inlining these functions is a winner is not just because we save a function call each time they are used, but also because the inlining allows further optimizations to be applied; in particular, the first argument (the attribute name) is almost always a fixed string (eg, lookup_attribute ("visibility", attrs)) and inlining allows the compiler to optimize the strlen() of the first argument. In the case of lookup_attribute(), the attribute list argument is also almost always NULL; before this patch, even with a NULL attribute argument, you'd still perform at least the function call to lookup_attribute() and then the strlen() of the first argument. With this patch, if the attribute list argument is NULL and the first argument is a string constant, which is the most likely case, nothing (expensive) should usually happen. * changes to lookup_attribute(), is_attribute_p() and remove_attribute() to require the first const char* argument to be in the form "text", disallowing the form "__text__" (the form "__text__" is still allowed in the attribute list; changing that is another simplification I'd like to make, but requires another wave of work). The only place in the compiler where the form "__text__" was required was inside tree.c, precisely inside functions that are comparing/merging attribute lists. There I replaced lookup_attribute() with a new static lookup_ident_attribute() which closely matches what is required there. I couldn't find any other place in the compiler where the form "__text__" would be required for the first argument, so it seemed pointless to allow it (particularly as, with the inlining, it would now bloat the code). I did document this change, and added asserts to catch cases that may have been missed (and, of course, it all still bootstraps with checking enabled, and works fine for me after the change). I also added an assert in attribs.c where attribute specs are registered to make sure that the names do not start with "_". * some tidyups in tree.c (in particular, the removal of is_attribute_with_length_p(), and the addition of lookup_ident_attribute(), which are internal details, consequences of the changes above). OK to commit ? Thanks PS: The next steps would be: - move all the "attribute list" functions from tree.h/tree.c (ie, lookup_attribute(), remove_attribute(), merge_attributes(), etc) into a separate .h/.c file ? Presumably attribs.h/attribs.c ? - see if we can manage to normalize attributes (eg, from '__text__' to 'text') when storing them in attribute lists; this would simplify/speedup the lookup_attribute() inline call. I expect that would result in faster compilation, but obviously would need to benchmark. I'll submit these as separate patches if I work on them; this one is big enough. PS2: While doing benchmarks, I accidentally benchmarked an older trunk and couldn't but notice that compiling gold with the C++ compiler regressed, in terms of performance, by 1.5% from 2011-05-19 to 2011-06-20. Index: ChangeLog ======= --- ChangeLog (revision 173917) +++ ChangeLog (working copy) @@ -1,3 +1,24 @@ +2011-06-19 Nicola Pero + + * attribs.c (registe
Re: Patch: speed up compiler a little bit by optimizing lookup_attribute() and is_attribute_p()
>> This patch speeds up the C/C++/ObjC/ObjC++ compiler a little bit by >> optimizing >> lookup_attribute() and is_attribute_p(). The main change is that these >> functions >> are now inline. > > I don't think this is a good idea. Can you explain why ? You never do in your response :-) I'm guessing it's because you think the inline functions are too big and that's counter-productive ? > For this case I'd factor out the NULL attribute list check into an > inline function and keeping the non-NULL attribute list pieces out-of-line. Ok ... so is this what you'd like - the common, hot case in the inline function, and the less common, cold case in the out-of-line one ? :-) That makes sense - I'll try that out tonight (it takes a few hours to run all the benchmarks). ;-) > Does it work for all languages? And yes, I agree it would be nice to > canonicalize to the form without _s even in the attribute lists itself. > Or go one step further - do not store an identifier but an enum as we > in fact only ever insert known attributes into the list (which should > be a VEC instead, possibly even sorted to allow binary search). Sure ... one step at a time. :-) Thanks
Re: Patch: speed up compiler a little bit by optimizing lookup_attribute() and is_attribute_p()
Dimitrious I didn't realize you were working on this. Your patch is indeed very similar. :-) Can I go ahead and rewrite mine following Richard's suggestions (which would make it even more similar to yours), and add your name to the ChangeLog entry too ? Thanks On 21 Jun 2011, at 13:20, Dimitrios Apostolou wrote: > FWIW I think that most of the speedup is due to inlining lookup_attribute(). > I got almost the same by applying only the attached very simple patch, since > strlen() was called too often (according to the profile at [1]). I used the > always_inline attribute to avoid using a macro. > > I was going to send it together with some other changes I'm trying and after > proper measurements. Anyway, better late than ever. Thanks to Christophe > Jaillet (CC'd) for pointing it to me. > > > Thanks, > Dimitris > > > [1] http://gcc.gnu.org/wiki/OptimisingGCC > > > > > On Tue, 21 Jun 2011, Richard Guenther wrote: > >> On Tue, Jun 21, 2011 at 12:17 PM, Nicola Pero >> wrote: >>>>> This patch speeds up the C/C++/ObjC/ObjC++ compiler a little bit by >>>>> optimizing >>>>> lookup_attribute() and is_attribute_p(). The main change is that these >>>>> functions >>>>> are now inline. >>>> >>>> I don't think this is a good idea. >>> >>> Can you explain why ? You never do in your response :-) >>> >>> I'm guessing it's because you think the inline functions are too big and >>> that's >>> counter-productive ? >> >> Yes. >> >>>> For this case I'd factor out the NULL attribute list check into an >>>> inline function and keeping the non-NULL attribute list pieces out-of-line. >>> >>> Ok ... so is this what you'd like - the common, hot case in the inline >>> function, >>> and the less common, cold case in the out-of-line one ? :-) >> >> Right. >> >>> That makes sense - I'll try that out tonight (it takes a few hours to run >>> all >>> the benchmarks). ;-) >> >> Thanks. >> >>> >>>> Does it work for all languages? And yes, I agree it would be nice to >>>> canonicalize to the form without _s even in the attribute lists itself. >>>> Or go one step further - do not store an identifier but an enum as we >>>> in fact only ever insert known attributes into the list (which should >>>> be a VEC instead, possibly even sorted to allow binary search). >>> >>> Sure ... one step at a time. :-) >> >> Of course ;) >> >> Richard. >> >>> Thanks >>> >>> >
Re: Patch: speed up compiler a little bit by optimizing lookup_attribute() and is_attribute_p()
trlen() before calling the out-of-line implementation. !In most cases attr_name is a string constant, and the compiler !will optimize the strlen() away. */ ! return private_lookup_attribute (attr_name, strlen (attr_name), list); ! } ! /* This function is a private implementation detail of !is_attribute_p() and you should never call it directly. */ ! extern bool private_is_attribute_p (const char *, size_t, const_tree); ! ! /* Given an identifier node IDENT and a string ATTR_NAME, return true !if the identifier node is a valid attribute name for the string. !ATTR_NAME must be in the form 'text' (not '__text__'). IDENT could !be the identifier for 'text' or for '__text__'. */ ! static inline bool ! is_attribute_p (const char *attr_name, const_tree ident) ! { ! gcc_checking_assert (attr_name[0] != '_'); ! /* Do the strlen() before calling the out-of-line implementation. ! In most cases attr_name is a string constant, and the compiler ! will optimize the strlen() away. */ ! return private_is_attribute_p (attr_name, strlen (attr_name), ident); ! } /* Remove any instances of attribute ATTR_NAME in LIST and return the !modified list. ATTR_NAME must be in the form 'text' (not !'__text__'). */ extern tree remove_attribute (const char *, tree); Index: ChangeLog === *** ChangeLog (revision 175269) --- ChangeLog (working copy) *** *** 1,3 --- 1,32 + 2011-06-21 Nicola Pero + + * attribs.c (register_attribute): Added assert to check that all + attribute specs are registered with a name that is not empty and + does not start with '_'. + (decl_attributes): Avoid the lookup of the "naked" attribute spec + if the function has no attributes. + * tree.c (is_attribute_with_length_p): Removed. + (is_attribute_p): Removed. + (private_is_attribute_p): New. + (private_lookup_attribute): New. + (lookup_attribute): Removed. + (lookup_ident_attribute): New. + (remove_attribute): Require the first argument to be in the form + 'text', not '__text__'. Updated asserts. + (merge_attributes): Use lookup_ident_attributes instead of + lookup_attribute. + (merge_dllimport_decl_attributes): Use remove_attribute. + (attribute_list_contained): Likewise. + (attribute_list_equal): Immediately return 1 if the arguments are + identical pointers. + * tree.h (is_attribute_p): Made inline. Return a 'bool', not an + 'int'. Require the first argument to be in the form 'text', not + '__text__'. Require the second argument to be an identifier. + (lookup_attribute): Made inline. Require the first argument to be + in the form 'text', not '__text__'. + (private_is_attribute_p, private_lookup_attribute): New. + Updated comments. + 2011-06-21 Georg-Johann Lay PR target/33049
Rename attribs.c to attributes.c
This patch renames attribs.c to attributes.c. I can only imagine the short "attribs.c" name was picked many years ago due to filename restrictions on certain systems ? Nowadays, it seems that we already have plenty of long filenames inside GCC, so there is no reason to use cryptic, newbie-unfriendly, shortened names for files. ;-) Bootstrapped with c,c++,objc,obj-c++,lto,java,fortran,ada,go on Linux i686. OK to commit ? Thanks In gcc/: 2011-06-22 Nicola Pero * attribs.c: Renamed to attributes.c. * Makefile.in: Changed all occurrences of attribs.c and attribs.o to attributes.c and attributes.o. * langhooks.h: Updated comments to refer to attributes.c instead of attribs.c. * plugin.h: Likewise. * tree.h: Likewise. In gcc/ada/: 2011-06-22 Nicola Pero * gcc-interface/Make-lang.in (ADA_BACKEND): Renamed attribs.o to attributes.o. In gcc/cp/: 2011-06-22 Nicola Pero * Make-lang.in (CXX_C_OBJS): Renamed attribs.o to attributes.o. In gcc/fortran/: 2011-06-22 Nicola Pero * Make-lang.in (f951$(exeext)): Replaced attribs.o with attributes.o. In gcc/go/: 2011-06-22 Nicola Pero * Make-lang.in (go1$(exeext)): Rename attribs.o to attributes.o. In gcc/java/: 2011-06-22 Nicola Pero * Make-lang.in (jc1$(exeext)): Renamed attribs.o to attributes.o. In gcc/lto/: 2011-06-22 Nicola Pero * Make-lang.in (LTO_OBJS): Renamed attribs.o to attributes.o Index: gcc/attribs.c === --- gcc/attribs.c (revision 175285) +++ gcc/attribs.c (working copy) @@ -1,485 +0,0 @@ -/* Functions dealing with attribute handling, used by most front ends. - Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, - 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010 - Free Software Foundation, Inc. - -This file is part of GCC. - -GCC is free software; you can redistribute it and/or modify it under -the terms of the GNU General Public License as published by the Free -Software Foundation; either version 3, or (at your option) any later -version. - -GCC is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or -FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -for more details. - -You should have received a copy of the GNU General Public License -along with GCC; see the file COPYING3. If not see -<http://www.gnu.org/licenses/>. */ - -#include "config.h" -#include "system.h" -#include "coretypes.h" -#include "tm.h" -#include "tree.h" -#include "flags.h" -#include "diagnostic-core.h" -#include "ggc.h" -#include "tm_p.h" -#include "cpplib.h" -#include "target.h" -#include "langhooks.h" -#include "hashtab.h" -#include "plugin.h" - -static void init_attributes (void); - -/* Table of the tables of attributes (common, language, format, machine) - searched. */ -static const struct attribute_spec *attribute_tables[4]; - -/* Hashtable mapping names (represented as substrings) to attribute specs. */ -static htab_t attribute_hash; - -/* Substring representation. */ - -struct substring -{ - const char *str; - int length; -}; - -static bool attributes_initialized = false; - -/* Default empty table of attributes. */ - -static const struct attribute_spec empty_attribute_table[] = -{ - { NULL, 0, 0, false, false, false, NULL, false } -}; - -/* Return base name of the attribute. Ie '__attr__' is turned into 'attr'. - To avoid need for copying, we simply return length of the string. */ - -static void -extract_attribute_substring (struct substring *str) -{ - if (str->length > 4 && str->str[0] == '_' && str->str[1] == '_' - && str->str[str->length - 1] == '_' && str->str[str->length - 2] == '_') -{ - str->length -= 4; - str->str += 2; -} -} - -/* Simple hash function to avoid need to scan whole string. */ - -static inline hashval_t -substring_hash (const char *str, int l) -{ - return str[0] + str[l - 1] * 256 + l * 65536; -} - -/* Used for attribute_hash. */ - -static hashval_t -hash_attr (const void *p) -{ - const struct attribute_spec *const spec = (const struct attribute_spec *) p; - const int l = strlen (spec->name); - - return substring_hash (spec->name, l); -} - -/* Used for attribute_hash. */ - -static int -eq_attr (const void *p, const void *q) -{ - const struct attribute_spec *const spec = (const struct attribute_spec *) p; - const struct substring *const str = (const struct substring *) q; - - return (!strncmp (spec->name, str->str, str->length) && !spec->name[str->
Re: Rename attribs.c to attributes.c
> Huh, I see no reason for this rename. It'll just make patches across > releases harder. Sure. But any change will make "patches across releases harder" ... does it mean we can't make any changes - not even in phase 1 ? :-( The reason I'd like to change the name is that "attribs.c" is meaningless. I never realized it contained code to deal with attributes until I opened the file and read the code inside. I always thought it contained some sort of mysterious internal GCC data structure or pass. Isn't that a good enough reason to rename it ? :-) Anyhow, if you want to keep the ugly name as it is, let's keep it that way. My next step was going to be to add an "attributes.h" file, moving into it the attributes functions (lookup_attribute(), is_attribute_p(), merge_attributes(), etc) from tree.h (and moving the corresponding implementations into attributes.c). The idea was to eventually have all the code dealing with attribute lists in these two files, so that it's easy to change the internal representation. And, there are few files actually accessing or manipulating attributes; only these files would include attributes.h, while the other ones - which include tree.h - wouldn't include or depend on the attribute functions. Can I go ahead with this or is it a waste of time as the patch will be rejected ? Presumably the new header file would need to be named "attribs.h", and I can't name it "attributes.h" ? Ouch. Thanks
ObjC: hide encoding obstacks inside objc-encoding.c
This Objective-C patch does an obvious cleanup of the encoding code internal API, by hiding the obstacks used to create the encoding strings inside objc-encoding.c. This provides a cleaner, simpler API, and improves code modularity. In practice, the patch makes the following changes: * have objc-act.c use the new objc_encoding_init() instead of setting up the obstacks directly; * improve encode_field_decl() to take only the field_decl as argument, and return the encoding string as identifier instead of requiring callers to access and manipulate the obstacks directly. * consequent cleanups, including removing dependency of various files from obstack.h. Ok to commit ? Thanks Index: objc/objc-encoding.c === --- objc/objc-encoding.c(revision 176090) +++ objc/objc-encoding.c(working copy) @@ -53,18 +53,24 @@ along with GCC; see the file COPYING3. If not see /* Set up for use of obstacks. */ #include "obstack.h" -/* This obstack is used to accumulate the encoding of a data type. - TODO: Make this static. */ -struct obstack util_obstack; +/* This obstack is used to accumulate the encoding of a data type. */ +static struct obstack util_obstack; /* This points to the beginning of obstack contents, so we can free - the whole contents. TODO: Make this static. */ -char *util_firstobj; + the whole contents. */ +static char *util_firstobj; +void objc_encoding_init (void) +{ + gcc_obstack_init (&util_obstack); + util_firstobj = (char *) obstack_finish (&util_obstack); +} + int generating_instance_variables = 0; static void encode_type_qualifiers (tree); static void encode_type (tree, int, int); +static void encode_field (tree field_decl, int curtype, int format); static tree objc_method_parm_type (tree type) @@ -470,7 +476,7 @@ encode_aggregate_fields (tree type, bool pointed_t obstack_1grow (&util_obstack, '"'); } - encode_field_decl (field, curtype, format); + encode_field (field, curtype, format); } } @@ -802,8 +808,8 @@ encode_gnu_bitfield (int position, tree type, int obstack_grow (&util_obstack, buffer, strlen (buffer)); } -void -encode_field_decl (tree field_decl, int curtype, int format) +static void +encode_field (tree field_decl, int curtype, int format) { #ifdef OBJCPLUS /* C++ static members, and things that are not fields at all, @@ -828,6 +834,25 @@ encode_gnu_bitfield (int position, tree type, int encode_type (TREE_TYPE (field_decl), curtype, format); } +tree +encode_field_decl (tree field_decl) +{ + tree result; + + encode_field (field_decl, + obstack_object_size (&util_obstack), + OBJC_ENCODE_DONT_INLINE_DEFS); + + /* Null terminate string. */ + obstack_1grow (&util_obstack, 0); + + /* Get identifier for the string. */ + result = get_identifier (XOBFINISH (&util_obstack, char *)); + obstack_free (&util_obstack, util_firstobj); + + return result; +} + /* This routine encodes the attribute of the input PROPERTY according to following formula: Index: objc/ChangeLog === --- objc/ChangeLog (revision 176090) +++ objc/ChangeLog (working copy) @@ -1,3 +1,30 @@ +2011-07-10 Nicola Pero + + * objc-encoding.h (obstack.h): Do not include. + (util_obstack, util_firstobj): Do not declare. + (encode_field_decl): Updated prototype to return a tree and take a + single tree argument. Updated comments. + * objc-encoding.c (util_obstack, util_firstobj): Made static. + (objc_encoding_init): New. + (encode_field_decl): Existing function renamed to encode_field and + made static. New encode_field_decl wrapper function added. + (encode_aggregate_fields): Update call to encode_field_decl to + call encode_field. + * objc-next-runtime-abi-02.c (obstack.h): Do not include. + (util_obstack, util_firstobj): Do not declare. + (build_v2_ivar_list_initializer): Updated call to + encode_field_decl. + * objc-runtime-shared-support.c (obstack.h): Do not include. + (util_obstack, util_firstobj): Do not declare. + (build_ivar_list_initializer): Updated call to encode_field_decl. + * objc-act.c (objc_init): Use objc_encoding_init. + * Make-lang.in (objc/objc-runtime-shared-support.o): Do not depend + on OBSTACK_H. + (objc/objc-gnu-runtime-abi-01.o): Likewise. + (objc/objc-next-runtime-abi-01.o): Likewise. + (objc/objc-next-runtime-abi-02.o): Likewise. + (objc/objc-act.o): Likewise. + 2011-07-04 Nicola Pero Refactored encoding code into objc-encoding.h and objc-encoding.c. Index: objc/objc-encoding.h === --- objc/objc-encoding.h(revis
ObjC: avoid creating temporary nodes just to compare method signatures
This patch fixes another inefficiency in the Objective-C compiler. When it was comparing method signatures, it would copy all the argument types into some temporary node chains, and then compare these copies. The copies are then thrown away. It all seems really pointless (since you can just access the argument types and compare them directly, as this patch does), but the inefficiency was hidden by the usage of get_arg_type_list() which looked like a very innocent and professionally looking API, while it does a very expensive copy of everything into a newly allocated chain of nodes. This patch saves about 10k node allocations when compiling a file that includes the Objective-C GNUstep system frameworks. With -fsyntax-only, that gives about a 0.5% speedup. Ok to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 172328) +++ ChangeLog (working copy) @@ -1,5 +1,12 @@ 2011-04-12 Nicola Pero + * objc-act.c (comp_proto_with_proto): Do not create and use + inefficient temporary argument lists. Compare the arguments + directly. (match_proto_with_proto): Removed; incorporated into + comp_proto_with_proto (). + +2011-04-12 Nicola Pero + * objc-act.c (printable_ivar_name): New. (add_instance_variable): Call printable_ivar_name() when an error message needs to be printed. Do not prepare the instance variable Index: objc-act.c === --- objc-act.c (revision 172328) +++ objc-act.c (working copy) @@ -147,7 +147,6 @@ static void objc_gen_property_data (tree, tree); static void objc_synthesize_getter (tree, tree, tree); static void objc_synthesize_setter (tree, tree, tree); static char *objc_build_property_setter_name (tree); -static int match_proto_with_proto (tree, tree, int); static tree lookup_property (tree, tree); static tree lookup_property_in_list (tree, tree); static tree lookup_property_in_protocol_list (tree, tree); @@ -4836,13 +4835,13 @@ objc_method_decl (enum tree_code opcode) return opcode == INSTANCE_METHOD_DECL || opcode == CLASS_METHOD_DECL; } -/* Used by `build_objc_method_call' and `comp_proto_with_proto'. Return - an argument list for method METH. CONTEXT is either METHOD_DEF or - METHOD_REF, saying whether we are trying to define a method or call - one. SUPERFLAG says this is for a send to super; this makes a - difference for the NeXT calling sequence in which the lookup and - the method call are done together. If METH is null, user-defined - arguments (i.e., beyond self and _cmd) shall be represented by `...'. */ +/* Used by `build_objc_method_call'. Return an argument list for + method METH. CONTEXT is either METHOD_DEF or METHOD_REF, saying + whether we are trying to define a method or call one. SUPERFLAG + says this is for a send to super; this makes a difference for the + NeXT calling sequence in which the lookup and the method call are + done together. If METH is null, user-defined arguments (i.e., + beyond self and _cmd) shall be represented by `...'. */ tree get_arg_type_list (tree meth, int context, int superflag) @@ -8241,19 +8240,13 @@ objc_types_share_size_and_alignment (tree type1, t static int comp_proto_with_proto (tree proto1, tree proto2, int strict) { + tree type1, type2; + /* The following test is needed in case there are hashing collisions. */ if (METHOD_SEL_NAME (proto1) != METHOD_SEL_NAME (proto2)) return 0; - return match_proto_with_proto (proto1, proto2, strict); -} - -static int -match_proto_with_proto (tree proto1, tree proto2, int strict) -{ - tree type1, type2; - /* Compare return types. */ type1 = TREE_VALUE (TREE_TYPE (proto1)); type2 = TREE_VALUE (TREE_TYPE (proto2)); @@ -8263,19 +8256,75 @@ comp_proto_with_proto (tree proto1, tree proto2, i return 0; /* Compare argument types. */ - for (type1 = get_arg_type_list (proto1, METHOD_REF, 0), - type2 = get_arg_type_list (proto2, METHOD_REF, 0); - type1 && type2; - type1 = TREE_CHAIN (type1), type2 = TREE_CHAIN (type2)) -{ - if (!objc_types_are_equivalent (TREE_VALUE (type1), TREE_VALUE (type2)) - && (strict - || !objc_types_share_size_and_alignment (TREE_VALUE (type1), - TREE_VALUE (type2 - return 0; -} - return (!type1 && !type2); + /* The first argument (objc_object_type) is always the same, no need + to compare. */ + + /* The second argument (objc_selector_type) is always the same, no + need to compare. */ + + /* Compare the other arguments. */ + { +tree arg1, arg2; + +/* Compare METHOD_SEL_ARGS. */ +for (arg1 = METHOD_SEL_ARGS (proto1), arg2 = METHOD_SEL_ARGS (proto2); +arg1 && arg2; +
ObjC: get rid of temporary tree list when compiling a method
This fixes another small inefficiency in the Objective-C compiler. When a method invocation is found, and the parser calls objc_build_method_expr() to compile it, it used to invoke it as in objc_build_message_expr (build_tree_list (rec, args)); this (trivial) patch removes the need to create the temporary tree list, so that the call becomes objc_build_message_expr (rec, args); it's also easier to understand, not just more efficient. The speedup is tiny, as it saves just one allocation per method invocation. It's more about cleaning up the codebase and migrating it from Lisp to C. Ok to commit ? Thanks Index: c-family/c-objc.h === --- c-family/c-objc.h (revision 172328) +++ c-family/c-objc.h (working copy) @@ -53,7 +53,7 @@ extern tree objc_is_id (tree); extern void objc_declare_alias (tree, tree); extern void objc_declare_class (tree); extern void objc_declare_protocols (tree, tree); -extern tree objc_build_message_expr (tree); +extern tree objc_build_message_expr (tree, tree); extern tree objc_finish_message_expr (tree, tree, tree, tree*); extern tree objc_build_selector_expr (location_t, tree); extern tree objc_build_protocol_expr (tree); Index: ChangeLog === --- ChangeLog (revision 172334) +++ ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-04-12 Nicola Pero + + * c-objc.h (objc_build_message_expr): Updated prototype. + * stub-objc.c (objc_build_message_expr): Likewise. + 2011-04-12 Martin Jambor * c-gimplify.c (c_genericize): Call cgraph_get_create_node instead Index: c-family/stub-objc.c === --- c-family/stub-objc.c(revision 172328) +++ c-family/stub-objc.c(working copy) @@ -258,7 +258,7 @@ objc_build_selector_expr (location_t ARG_UNUSED (l } tree -objc_build_message_expr (tree ARG_UNUSED (expr)) +objc_build_message_expr (tree ARG_UNUSED (receiver), tree ARG_UNUSED (args)) { return 0; } Index: objc/ChangeLog === --- objc/ChangeLog (revision 172328) +++ objc/ChangeLog (working copy) @@ -1,5 +1,11 @@ 2011-04-12 Nicola Pero + * objc-act.c (objc_build_message_expr): Accept two arguments + instead of one so that callers can simply pass the arguments + without having to create a temporary chain to hold them. + +2011-04-12 Nicola Pero + * objc-act.c (printable_ivar_name): New. (add_instance_variable): Call printable_ivar_name() when an error message needs to be printed. Do not prepare the instance variable Index: objc/objc-act.c === --- objc/objc-act.c (revision 172328) +++ objc/objc-act.c (working copy) @@ -5027,14 +5027,13 @@ objc_message_selector (void) (*((*)())_msgSuper)(receiver, selTransTbl[n], ...); */ tree -objc_build_message_expr (tree mess) +objc_build_message_expr (tree receiver, tree message_args) { - tree receiver = TREE_PURPOSE (mess); tree sel_name; #ifdef OBJCPLUS - tree args = TREE_PURPOSE (TREE_VALUE (mess)); + tree args = TREE_PURPOSE (message_args); #else - tree args = TREE_VALUE (mess); + tree args = message_args; #endif tree method_params = NULL_TREE; @@ -5058,7 +5057,7 @@ tree /* Build the parameter list to give to the method. */ if (TREE_CODE (args) == TREE_LIST) #ifdef OBJCPLUS -method_params = chainon (args, TREE_VALUE (TREE_VALUE (mess))); +method_params = chainon (args, TREE_VALUE (message_args)); #else { tree chain = args, prev = NULL_TREE; Index: ChangeLog === --- ChangeLog (revision 172328) +++ ChangeLog (working copy) @@ -1,5 +1,11 @@ 2011-04-12 Nicola Pero + * c-parser.c (c_parser_initelt): Updated call to + objc_build_message_expr. + (c_parser_postfix_expression): Likewise. + +2011-04-12 Nicola Pero + * c-parser.c (c_lex_one_token): Rewritten conditional used when compiling Objective-C to be more efficient. Index: cp/ChangeLog === --- cp/ChangeLog(revision 172328) +++ cp/ChangeLog(working copy) @@ -1,3 +1,8 @@ +2011-04-12 Nicola Pero + + * parser.c (cp_parser_objc_message_expression): Updated call + to objc_build_message_expr. + 2011-04-12 Martin Jambor * class.c (cp_fold_obj_type_ref): Call cgraph_get_node instead of Index: cp/parser.c === --- cp/parser.c (revision 172328) +++ cp/parser.c (working copy) @@ -21289,7 +21289,7 @@ cp_parser_objc_message_expression (cp_parser* pars messageargs = cp_parser_objc_message_args (parser); cp_parser_requi
ObjC: another tiny performance tidyup
This saves a few thousands strlen() calls per compilation by reusing the length of selector strings instead of calculating it again. Ok to commit ? Thanks PS: I'll come back to hashtables later, as they do deserve some discussion. I want to get all the other obvious tiny changes in first. Index: ChangeLog === --- ChangeLog (revision 172338) +++ ChangeLog (working copy) @@ -1,5 +1,10 @@ 2011-04-12 Nicola Pero + * objc-act.c (build_keyword_selector): Use get_identifier_with_length + instead of get_identifier. + +2011-04-12 Nicola Pero + * objc-act.c (objc_build_message_expr): Accept two arguments instead of one so that callers can simply pass the arguments without having to create a temporary chain to hold them. Index: objc-act.c === --- objc-act.c (revision 172338) +++ objc-act.c (working copy) @@ -4668,7 +4668,7 @@ build_keyword_selector (tree selector) strcat (buf, ":"); } - return get_identifier (buf); + return get_identifier_with_length (buf, len); } /* Used for declarations and definitions. */
ObjC: remove temporary tree list used when calling objc_declare_class()
This patch removes another case of temporary tree chains from the ObjC compiler. When the parser finds a @class NSArray; declaration, it would call objc_declare_class() passing as argument a temporary tree list containing the identifier. This tree list is created, used for the function call, then discarded. Btw, this made some sense when you have a list with multiple identifiers, as in @class NSArray, NSString; as they are all passed in the same linked list. it is still cleaner and more efficient to call objc_declare_class() for each identifier, as opposed to creating a temporary tree list, populating it with the identifiers, then calling objc_declare_class() which then iterates over the temporary tree list to read the identifiers, and then the list gets thrown away. The patch speeds things up but the effect is very small; the GNUstep system headers do contain about 800 @class declarations or so, so the patch typically saves something like 1k allocations or so when compiling a file. That is probably a 0.05% speedup (order of magnitude). But we get rid of a the tree list. :-) The ObjC++ parser needed a bit of changes, but while changing it I also made the ObjC++ parsing code almost identical to the ObjC one, which simplifies maintenance. Ok to commit ? Thanks Index: c-family/ChangeLog === --- c-family/ChangeLog (revision 172360) +++ c-family/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2011-04-13 Nicola Pero + + * stub-objc.c (objc_declare_class): Updated argument name. + 2011-04-12 Nathan Froyd * c-common.h (c_common_init_ts): Declare. Index: c-family/stub-objc.c === --- c-family/stub-objc.c(revision 172360) +++ c-family/stub-objc.c(working copy) @@ -110,7 +110,7 @@ objc_declare_alias (tree ARG_UNUSED (alias), tree } void -objc_declare_class (tree ARG_UNUSED (list)) +objc_declare_class (tree ARG_UNUSED (identifier)) { } Index: objc/ChangeLog === --- objc/ChangeLog (revision 172360) +++ objc/ChangeLog (working copy) @@ -1,5 +1,12 @@ 2011-04-13 Nicola Pero + * objc-act.c (objc_declare_class): Changed to take a single + identifier as argument instead of a tree list. This means callers + don't have to build temporary tree lists to call this function. + (synth_module_prologue): Updated calls to objc_declare_class. + +2011-04-13 Nicola Pero + * objc-act.c (build_keyword_selector): Use get_identifier_with_length instead of get_identifier. Index: objc/objc-act.c === --- objc/objc-act.c (revision 172360) +++ objc/objc-act.c (working copy) @@ -2953,7 +2953,7 @@ synth_module_prologue (void) /* Forward-declare '@interface Protocol'. */ type = get_identifier (PROTOCOL_OBJECT_CLASS_NAME); - objc_declare_class (tree_cons (NULL_TREE, type, NULL_TREE)); + objc_declare_class (type); objc_protocol_type = build_pointer_type (xref_tag (RECORD_TYPE, type)); /* Declare receiver type used for dispatching messages to 'super'. */ @@ -2985,7 +2985,7 @@ synth_module_prologue (void) if (!constant_string_class_name) constant_string_class_name = runtime.default_constant_string_class_name; constant_string_id = get_identifier (constant_string_class_name); - objc_declare_class (tree_cons (NULL_TREE, constant_string_id, NULL_TREE)); + objc_declare_class (constant_string_id); /* Pre-build the following entities - for speed/convenience. */ self_id = get_identifier ("self"); @@ -3360,48 +3360,42 @@ objc_declare_alias (tree alias_ident, tree class_i } void -objc_declare_class (tree ident_list) +objc_declare_class (tree identifier) { - tree list; #ifdef OBJCPLUS if (current_namespace != global_namespace) { error ("Objective-C declarations may only appear in global scope"); } #endif /* OBJCPLUS */ - for (list = ident_list; list; list = TREE_CHAIN (list)) + if (! objc_is_class_name (ident)) { - tree ident = TREE_VALUE (list); - - if (! objc_is_class_name (ident)) + tree record = lookup_name (ident), type = record; + + if (record) { - tree record = lookup_name (ident), type = record; - - if (record) + if (TREE_CODE (record) == TYPE_DECL) + type = DECL_ORIGINAL_TYPE (record) + ? DECL_ORIGINAL_TYPE (record) + : TREE_TYPE (record); + + if (!TYPE_HAS_OBJC_INFO (type) + || !TYPE_OBJC_INTERFACE (type)) { - if (TREE_CODE (record) == TYPE_DECL) - type = DECL_ORIGINAL_TYPE (record) - ? DECL_ORIGINAL_TYPE (record) -
ObjC: remove temporary tree list used when calling objc_declare_protocols()
This patch cleans up objc_declare_protocols() to avoid having to create temporary tree chains just to perform the function call (in the same way as my other patch cleaned up objc_declare_class()). Ok to commit ? Thanks PS: This patch has no measurable effect on compilation speed in my tests because the GNUstep codebase almost never uses the protocol forward-declaration syntax "@protocol X;". Another codebase that use it extensively may see some tiny benefit. Index: gcc/c-family/c-objc.h === --- gcc/c-family/c-objc.h (revision 172399) +++ gcc/c-family/c-objc.h (working copy) @@ -52,7 +52,7 @@ extern int objc_is_public (tree, tree); extern tree objc_is_id (tree); extern void objc_declare_alias (tree, tree); extern void objc_declare_class (tree); -extern void objc_declare_protocols (tree, tree); +extern void objc_declare_protocol (tree, tree); extern tree objc_build_message_expr (tree, tree); extern tree objc_finish_message_expr (tree, tree, tree, tree*); extern tree objc_build_selector_expr (location_t, tree); Index: gcc/c-family/ChangeLog === --- gcc/c-family/ChangeLog (revision 172399) +++ gcc/c-family/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2011-04-13 Nicola Pero + + * stub-objc.c (objc_declare_protocols): Renamed to + objc_declare_protocol. + * c-objc.h: Likewise. + 2011-04-12 Nathan Froyd * c-common.h (c_common_init_ts): Declare. Index: gcc/c-family/stub-objc.c === --- gcc/c-family/stub-objc.c(revision 172399) +++ gcc/c-family/stub-objc.c(working copy) @@ -115,7 +115,7 @@ objc_declare_class (tree ARG_UNUSED (list)) } void -objc_declare_protocols (tree ARG_UNUSED (list), tree ARG_UNUSED (attributes)) +objc_declare_protocol (tree ARG_UNUSED (name), tree ARG_UNUSED (attributes)) { } Index: gcc/objc/ChangeLog === --- gcc/objc/ChangeLog (revision 172399) +++ gcc/objc/ChangeLog (working copy) @@ -1,5 +1,12 @@ 2011-04-13 Nicola Pero + * objc-act.c (objc_declare_protocols): Renamed to + objc_declare_protocol. Changed first argument to be an identifier + instead of a tree chain of identifiers, so that callers don't have + to create a temporary tree chain. + +2011-04-13 Nicola Pero + * objc-act.c (build_keyword_selector): Use get_identifier_with_length instead of get_identifier. Index: gcc/objc/objc-act.c === --- gcc/objc/objc-act.c (revision 172399) +++ gcc/objc/objc-act.c (working copy) @@ -7869,9 +7869,8 @@ lookup_protocol (tree ident, bool warn_if_deprecat they are already declared or defined, the function has no effect. */ void -objc_declare_protocols (tree names, tree attributes) +objc_declare_protocol (tree name, tree attributes) { - tree list; bool deprecated = false; #ifdef OBJCPLUS @@ -7896,29 +7895,25 @@ void } } - for (list = names; list; list = TREE_CHAIN (list)) + if (lookup_protocol (name, /* warn if deprecated */ false, + /* definition_required */ false) == NULL_TREE) { - tree name = TREE_VALUE (list); - - if (lookup_protocol (name, /* warn if deprecated */ false, - /* definition_required */ false) == NULL_TREE) + tree protocol = make_node (PROTOCOL_INTERFACE_TYPE); + + TYPE_LANG_SLOT_1 (protocol) + = make_tree_vec (PROTOCOL_LANG_SLOT_ELTS); + PROTOCOL_NAME (protocol) = name; + PROTOCOL_LIST (protocol) = NULL_TREE; + add_protocol (protocol); + PROTOCOL_DEFINED (protocol) = 0; + PROTOCOL_FORWARD_DECL (protocol) = NULL_TREE; + + if (attributes) { - tree protocol = make_node (PROTOCOL_INTERFACE_TYPE); - - TYPE_LANG_SLOT_1 (protocol) - = make_tree_vec (PROTOCOL_LANG_SLOT_ELTS); - PROTOCOL_NAME (protocol) = name; - PROTOCOL_LIST (protocol) = NULL_TREE; - add_protocol (protocol); - PROTOCOL_DEFINED (protocol) = 0; - PROTOCOL_FORWARD_DECL (protocol) = NULL_TREE; - - if (attributes) - { - TYPE_ATTRIBUTES (protocol) = attributes; - if (deprecated) - TREE_DEPRECATED (protocol) = 1; - } + /* TODO: Do we need to store the attributes here ? */ + TYPE_ATTRIBUTES (protocol) = attributes; + if (deprecated) + TREE_DEPRECATED (protocol) = 1; } } } Index: gcc/ChangeLog === --- gcc/ChangeLog (revision 172399) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-04-13 Nicola Pero + + * c-parser.c (c_parser_objc_prot
RE: [build] Allow building libobjc_gc on Tru64 UNIX, Darwin
> I recently tried to build with --enable-libobjc-gc. While this worked > out of the box on Solaris, I ran intro trouble on both Tru64 UNIX and > Darwin. > > [...] > > The following patch fixes both issues. [...] > > Ok for mainline if both pass? Yes. [and by the way, I think you're fixing PR libobjc/32037 in the process. :-)] > Btw., it would be considerably easier if --enable-libobjc-gc could be > enabled automatically if boehm-gc is configured. Yes. > Besides, it seems that libobjc_gc isn't tested anywhere. Yes. Thanks!
ObjC: rewritten checks for duplicate instance variables (for improved speed and improved error messages)
This patch rewrites the check for duplicate instance variables done by the Objective-C (and Objective-C++) compiler. The new code has many advantages: * it avoids copying all the instance variables into a temporary tree chain in the way that the all code was doing (according to some notes from benchmarks and profiling I did a few months ago, this should save about 5k allocations per compilation when compiling a typical ObjC GNUstep file, giving an approx 0.25% order of magnitude speedup with -fsyntax-only); * it provides better error messages by providing the informative message "previous declaration of ..." when a duplicate declaration is found; * it avoids producing duplicate errors if a class with duplicate instance variables is subclassed. The existing code always built a copy of the full list of instance variables for the class (including superclass ones) and then would look for duplicates. This means if you have a class with a duplicate, and subclass it 10 times, you'll get the same error message 11 times! The new code avoids this mistake, which also reduces the number of checks required (for the standard case without a hashtable, I'll explain in a minute). * it removes the special, ad-hoc field duplicate check implementation for ObjC++ and has it use the same code as the ObjC codebase. The new code does the checks for duplicates directly, by just iterating and comparing, unless the number of checks to do is very large, in which case it falls back to a hashtable. This is similar to what the C code does for structs, but here the check is more specific as we are only checking the instance variables in the current class against the other instance variables in the class and the superclass, so it's all more specific and optimized for the situation. Updated existing testcases (to check for the new "previous declaration of ..." messages), and added more testcases. Ok to commit ? Thanks Index: c-family/c-objc.h === --- c-family/c-objc.h (revision 172444) +++ c-family/c-objc.h (working copy) @@ -62,7 +62,7 @@ extern tree objc_build_string_object (tree); extern tree objc_get_protocol_qualified_type (tree, tree); extern tree objc_get_class_reference (tree); extern tree objc_get_class_ivars (tree); -extern tree objc_get_interface_ivars (tree); +extern bool objc_detect_field_duplicates (bool); extern void objc_start_class_interface (tree, tree, tree, tree); extern void objc_start_category_interface (tree, tree, tree, tree); extern void objc_start_protocol (tree, tree, tree); Index: c-family/ChangeLog === --- c-family/ChangeLog (revision 172444) +++ c-family/ChangeLog (working copy) @@ -1,3 +1,9 @@ +2011-04-15 Nicola Pero + + * c-objc.h (objc_get_interface_ivars): Removed. + (objc_detect_field_duplicates): New. + * stub-objc.c: Likewise. + 2011-04-14 Nicola Pero * stub-objc.c (objc_declare_protocols): Renamed to Index: c-family/stub-objc.c === --- c-family/stub-objc.c(revision 172444) +++ c-family/stub-objc.c(working copy) @@ -275,10 +275,10 @@ objc_get_class_reference (tree ARG_UNUSED (name)) return 0; } -tree -objc_get_interface_ivars (tree ARG_UNUSED (fieldlist)) +bool +objc_detect_field_duplicates (bool ARG_UNUSED (check_superclasses_only)) { - return 0; + return false; } tree Index: objc/ChangeLog === --- objc/ChangeLog (revision 172444) +++ objc/ChangeLog (working copy) @@ -1,3 +1,10 @@ +2011-04-15 Nicola Pero + + * objc-act.c (objc_get_interface_ivars): Removed. + (objc_detect_field_duplicates): New. + (hash_instance_variable): New. + (eq_instance_variable): New. + 2011-04-14 Nicola Pero * objc-act.c (objc_declare_protocols): Renamed to Index: objc/objc-act.c === --- objc/objc-act.c (revision 172444) +++ objc/objc-act.c (working copy) @@ -3813,6 +3813,8 @@ lookup_interface (tree ident) } } + + /* Implement @defs () within struct bodies. */ tree @@ -3829,19 +3831,242 @@ objc_get_class_ivars (tree class_name) return error_mark_node; } + +/* Functions used by the hashtable for field duplicates in + objc_detect_field_duplicates(). Ideally, we'd use a standard + key-value dictionary hashtable , and store as keys the field names, + and as values the actual declarations (used to print nice error + messages with the locations). But, the hashtable we are using only + allows us to store keys in the hashtable, without values (it looks + more like a set). So, we store the DECLs, but define equality as + DECLs having th
ObjC: get rid of another unnecessary, temporary copy of instance variables
This patch for the Objective-C compiler gets rid of another case where we'd create a temporary tree chain with a copy of all the instance variables of a class just to do a simple check on them. The check is the one to check the scope of the instance variable that is being accessed; without this patch, the check requires copying all the instance variables for the class on a temporary tree chain. With this patch, the check is done (as you'd expect) on the instance variables themselves, without copying them. This is obviously faster; on the other hand, the typical GNUstep-based ObjC file has classes with few instance variables (maybe 10 or 20) and only accesses instance variables up to a few hundred times per file, so the speedup is only of the order of 0.1% to 0.2% even with -fsyntax-only. Of course, in unusual cases (ie, classes with many instance variables, and a big file accessing instance variables lots of times) the speedup may be bigger. Ok to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 172511) +++ ChangeLog (working copy) @@ -1,5 +1,10 @@ 2011-04-15 Nicola Pero + * objc-act.c (ivar_of_class): New. + (objc_is_public): Use ivar_of_class. + +2011-04-15 Nicola Pero + * objc-act.c (objc_get_interface_ivars): Removed. (objc_detect_field_duplicates): New. (hash_instance_variable): New. Index: objc-act.c === --- objc-act.c (revision 172511) +++ objc-act.c (working copy) @@ -6367,6 +6367,35 @@ is_private (tree decl) DECL_NAME (decl))); } +/* Searches all the instance variables of 'klass' and of its + superclasses for an instance variable whose name (identifier) is + 'ivar_name_ident'. Return the declaration (DECL) of the instance + variable, if found, or NULL_TREE, if not found. */ +static inline tree +ivar_of_class (tree klass, tree ivar_name_ident) +{ + /* First, look up the ivar in CLASS_RAW_IVARS. */ + tree decl_chain = CLASS_RAW_IVARS (klass); + + for ( ; decl_chain; decl_chain = DECL_CHAIN (decl_chain)) +if (DECL_NAME (decl_chain) == ivar_name_ident) + return decl_chain; + + /* If not found, search up the class hierarchy. */ + while (CLASS_SUPER_NAME (klass)) +{ + klass = lookup_interface (CLASS_SUPER_NAME (klass)); + + decl_chain = CLASS_RAW_IVARS (klass); + + for ( ; decl_chain; decl_chain = DECL_CHAIN (decl_chain)) + if (DECL_NAME (decl_chain) == ivar_name_ident) + return decl_chain; +} + + return NULL_TREE; +} + /* We have an instance variable reference;, check to see if it is public. */ int @@ -6397,7 +6426,7 @@ objc_is_public (tree expr, tree identifier) return 0; } - if ((decl = is_ivar (get_class_ivars (klass, true), identifier))) + if ((decl = ivar_of_class (klass, identifier))) { if (TREE_PUBLIC (decl)) return 1;
Fix gengtype-state string hashtable
While reading GCC code, I noticed that in gengtype-state.c the equality function in a string hashtable is set to strcmp. But that returns 0 (ie, false for hashtable.c) when the strings are equal! I can't see how that hashtable would ever work. Do we have any tests for gengtype-state ? Am I missing something ? :-) Else, Ok to commit the following patch ? Thanks Index: gengtype-state.c === --- gengtype-state.c(revision 172522) +++ gengtype-state.c(working copy) @@ -2385,7 +2385,16 @@ equals_type_number (const void *ty1, const void *t return type1->state_number == type2->state_number; } +static int +string_eq (const void *a, const void *b) +{ + const char *a0 = (const char *)a; + const char *b0 = (const char *)b; + return (strcmp (a0, b0) == 0); +} + + /* The function reading the state, called by main from gengtype.c. */ void read_state (const char *path) @@ -2408,7 +2417,7 @@ read_state (const char *path) state_seen_types = htab_create (2017, hash_type_number, equals_type_number, NULL); state_ident_tab = -htab_create (4027, htab_hash_string, (htab_eq) strcmp, NULL); +htab_create (4027, htab_hash_string, string_eq, NULL); read_state_version (version_string); read_state_srcdir (); read_state_languages (); Index: ChangeLog === --- ChangeLog (revision 172522) +++ ChangeLog (working copy) @@ -1,3 +1,9 @@ +2011-04-17 Nicola Pero + + * gengtype-state.c (string_eq): New. + (read_state): Use string_eq instead of strcmp when creating the + state_ident_tab. + 2011-04-15 Pat Haugen * config/rs6000/rs6000.c (call_ABI_of_interest): Call
(build) Patch to fix cp/cfns.gperf building issues
This patch fixes a building annoyance that I had when building on a new machine (an x86_64 gnu/linux box). The building failed. It was down to two problems: * due to how I got a copy of the GCC source code on the machine, the timestamp of each source file was the timestamp of when it was copied to the machine (ie, a random timestamp from the point of view of the building system). This caused the build system to decide that $(srcdir)/cp/cfns.h needed to be rebuilt from $(srcdir)/cp/cfns.gperf (it didn't, obviously; the source code was trunk with no changes). * when the automated rebuild failed because gperf was not there, it also created an empty cp/cfns.h, basically corrupting my source tree. Further attempts to rebuild (with or without gperf) would then fail due to a missing definition of "libc_name_p" (because cp/cfns.h now existed, and was newer than cp/cfns.gperf, it wouldn't be rebuilt, and I was stuck with the empty cp/cfns.h). Searching on the internet, I found that a number of people got stuck at this stage and couldn't finish their build. So, rather than just manually fixing my source tree, I'm posting a patch that will remove the problems at the root. This patch fixes both problems, making the build more robust: * it only rebuilds cp/cfns.h when a specific command ("make rebuild-cp-cfns") is used. According to the ChangeLogs, cp/cfns.gperf was edited about 5 times in 10 years, so it does not seem unreasonable to require developers/maintainers to use an explicit command to rebuild cp/cfns.h from cp/cfns.gperf for the once-every-two-years occasion when it is changed. I documented the process clearly in cfns.gperf itself. This makes the build more robust for end users, who are not bugged by timestamp issues in the source tree causing unexpected rebuilds or complications requiring gperf. In general, I personally feel that the building system should not depend on the relative timestamps of source files unless it's doing something in "maintainer mode" where it's being explicitly asked to rebuild one source file from the other. The average user who downloads the GCC source code to build it should not be expected to keep the timestamps of each source file religiously unchanged! Timestamps may change as the source code is moved around by users and the building system should not have a problem with that. * it fails gracefully when the rebuild is triggered and gperf is not available. Instead of creating en empty cp/cfns.h file, it creates no file at all, so that if you then install gperf, it will rebuild cp/cfns.h correctly, and if you don't, you'll keep getting the error the gperf is not available (not an error about libc_name_p not being defined), which is the correct one. Ok to commit ? Thanks Index: cfns.gperf === --- cfns.gperf (revision 172858) +++ cfns.gperf (working copy) @@ -15,7 +15,18 @@ for more details. You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see -<http://www.gnu.org/licenses/>. */ +<http://www.gnu.org/licenses/>. + +You need to use gperf to generate cfns.h from cfns.gperf. This is +the process: + + have a GCC source/build tree already checked out + edit cfns.gperf + cd $(buildir)/gcc + make rebuild-cp-cfns + +Alternatively, just look into cp/Make-lang.in and run the gperf +command in the rebuild-cp-cfns rule manually. */ #ifdef __GNUC__ __inline #endif Index: Make-lang.in === --- Make-lang.in(revision 172858) +++ Make-lang.in(working copy) @@ -104,11 +104,19 @@ cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $ +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \ $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS) -# Special build rules. -$(srcdir)/cp/cfns.h: $(srcdir)/cp/cfns.gperf +# Special build rule. This is a maintainer rule, that needs to be +# invoked manually (as in "cd $(builddir)/gcc; make rebuild-cp-cfns") +# to rebuild cfns.h from cfns.gperf any time that cfns.gperf is +# edited. We don't trigger it automatically when +# $(srcdir)/cp/cfns.gperf is newer than $(srcdir)/cp/cfns.h because we +# don't want to depend on users getting the source code with +# particular timestamps. +rebuild-cp-cfns: gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L ANSI-C \ - $(srcdir)/cp/cfns.gperf > $(srcdir)/cp/cfns.h + $(srcdir)/cp/cfns.gperf --output-file $(srcdir)/cp/cfns.h +.PHONY: rebuild-cp-cfns + #^L # Build hooks: Index: ChangeLog ======= --- ChangeLog (revision 172858) +++ ChangeLog (working copy) @@ -1,3 +1,13 @
Re: (build) Patch to fix cp/cfns.gperf building issues
> We have a --enable-maintainer-mode configure option. Thanks - I had missed that option. It's an excellent suggestion - here is a new patch that uses it. :-) Ok to commit ? Thanks PS: Regarding how I detect --enable-maintainer-mode in this new patch, cp/Make-lang.in is used at it is, without going through configure, so I can't use @MAINT@ in it. I can't use MAINT either, because it's always empty. I added a FIXME as the intention in the code was probably different. I could actually fix MAINT to end up being exactly '#' when --disable-maintainer-mode is used, but why would we want that ? It would be a literal value, which you can't use to comment out bits of code in the same way as you can with @MAINT@. Of course, people may still try, and waste time trying to figure out why it doesn't work. It just doesn't make sense; you can't comment out make code by putting a variable with a value of '#' in front of something. If you ask me, I'd just remove the MAINT variable altogether - it's a bad idea and would/will confuse people. I added a new readable variable instead, ENABLE_MAINTAINER_RULES, which is 'true' or empty, so you can do ifeq ($(ENABLE_MAINTAINER_RULES), true) ... maintainer rules ... endif which is readable, expressive, simple and robust. Index: ChangeLog === --- ChangeLog (revision 172860) +++ ChangeLog (working copy) @@ -1,3 +1,7 @@ +2011-04-22 Nicola Pero + + * Makefile.in (ENABLE_MAINTAINER_RULES): New. + 2011-04-22 Jakub Jelinek PR c/48716 Index: cp/Make-lang.in === --- cp/Make-lang.in (revision 172860) +++ cp/Make-lang.in (working copy) @@ -104,10 +104,15 @@ cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $ +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \ $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS) -# Special build rules. +ifeq ($(ENABLE_MAINTAINER_RULES), true) +# Special build rule. This is a maintainer rule, that is only +# available when GCC is configured with --enable-maintainer-mode. In +# other cases, it is not available to avoid triggering rebuilds if a +# user has the source checked out with unusual timestamps. $(srcdir)/cp/cfns.h: $(srcdir)/cp/cfns.gperf gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L ANSI-C \ - $(srcdir)/cp/cfns.gperf > $(srcdir)/cp/cfns.h + $(srcdir)/cp/cfns.gperf --output-file $(srcdir)/cp/cfns.h +endif #^L # Build hooks: Index: cp/ChangeLog === --- cp/ChangeLog(revision 172860) +++ cp/ChangeLog(working copy) @@ -1,3 +1,10 @@ +2011-04-23 Nicola Pero + + * Make-lang.in ($(srcdir)/cp/cfns.h): Enable the rule only in + maintainer mode. Use the --output-file option of gperf instead of + > to prevent creating an empty cp/cfns.h when gperf is not + available. + 2011-04-20 Jason Merrill * semantics.c (finish_compound_literal): Don't put an array Index: Makefile.in === --- Makefile.in (revision 172860) +++ Makefile.in (working copy) @@ -165,8 +165,19 @@ C_STRICT_WARN = @c_strict_warn@ NOCOMMON_FLAG = @nocommon_flag@ # This is set by --disable-maintainer-mode (default) to "#" +# FIXME: 'MAINT' will always be set to an empty string, no matter if +# --disable-maintainer-mode is used or not. This is because the +# following will expand to "MAINT := " in maintainer mode, and to +# "MAINT := #" in non-maintainer mode, but because '#' starts a comment, +# they mean exactly the same thing for make. MAINT := @MAINT@ +# The following provides the variable ENABLE_MAINTAINER_RULES that can +# be used in language Make-lang.in makefile fragments to enable +# maintainer rules. So, ENABLE_MAINTAINER_RULES is 'true' in +# maintainer mode, and '' otherwise. +@MAINT@ ENABLE_MAINTAINER_RULES = true + # These are set by --enable-checking=valgrind. RUN_GEN = @valgrind_command@ VALGRIND_DRIVER_DEFINES = @valgrind_path_defines@
Re: (build) Patch to fix cp/cfns.gperf building issues
> Additionally, > > contrib/gcc_update --touch > > can be used to to fix the time stamps until such time as someone changes the > gperf rule to be under maintainer mode. Thanks Mike, good to know. :-) > So, only the dependency should go away under a maintainer rules, as in the > below, not the entire rule. What is the reason to keep the rule without the dependency ? Is it so that even with --disable-maintainer-mode you can force the file to be recreated by manually deleting it ? That would make sense ... it sounds like a good idea, so here is yet another refinement of the patch with that refinement added too :-) Ok to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 172860) +++ ChangeLog (working copy) @@ -1,3 +1,7 @@ +2011-04-22 Nicola Pero + + * Makefile.in (ENABLE_MAINTAINER_RULES): New. + 2011-04-22 Jakub Jelinek PR c/48716 Index: cp/Make-lang.in === --- cp/Make-lang.in (revision 172860) +++ cp/Make-lang.in (working copy) @@ -104,10 +104,20 @@ cc1plus$(exeext): $(CXX_OBJS) cc1plus-checksum.o $ +$(LINKER) $(ALL_LINKERFLAGS) $(LDFLAGS) -o $@ \ $(CXX_OBJS) cc1plus-checksum.o $(BACKEND) $(LIBS) $(BACKENDLIBS) -# Special build rules. +ifeq ($(ENABLE_MAINTAINER_RULES), true) +# Special build rule. This is a maintainer rule, that is only +# available when GCC is configured with --enable-maintainer-mode. In +# other cases, it is not available to avoid triggering rebuilds if a +# user has the source checked out with unusual timestamps. $(srcdir)/cp/cfns.h: $(srcdir)/cp/cfns.gperf +else +# We keep the rule so that you can still force a rebuild, even if you +# didn't configure GCC with --enable-maintainer-mode, by manually +# deleting the $(srcdir)/cp/cfns.h file. +$(srcdir)/cp/cfns.h: +endif gperf -o -C -E -k '1-6,$$' -j1 -D -N 'libc_name_p' -L ANSI-C \ - $(srcdir)/cp/cfns.gperf > $(srcdir)/cp/cfns.h + $(srcdir)/cp/cfns.gperf --output-file $(srcdir)/cp/cfns.h #^L # Build hooks: Index: cp/ChangeLog === --- cp/ChangeLog(revision 172860) +++ cp/ChangeLog (working copy) @@ -1,3 +1,11 @@ +2011-04-23 Nicola Pero , + Mike Stump + + * Make-lang.in ($(srcdir)/cp/cfns.h): Enable the dependency only + in maintainer mode. Use the --output-file option of gperf instead + of > to prevent creating an empty cp/cfns.h when gperf is not + available. + 2011-04-20 Jason Merrill * semantics.c (finish_compound_literal): Don't put an array Index: Makefile.in === --- Makefile.in (revision 172860) +++ Makefile.in (working copy) @@ -165,8 +165,19 @@ C_STRICT_WARN = @c_strict_warn@ NOCOMMON_FLAG = @nocommon_flag@ # This is set by --disable-maintainer-mode (default) to "#" +# FIXME: 'MAINT' will always be set to an empty string, no matter if +# --disable-maintainer-mode is used or not. This is because the +# following will expand to "MAINT := " in maintainer mode, and to +# "MAINT := #" in non-maintainer mode, but because '#' starts a comment, +# they mean exactly the same thing for make. MAINT := @MAINT@ +# The following provides the variable ENABLE_MAINTAINER_RULES that can +# be used in language Make-lang.in makefile fragments to enable +# maintainer rules. So, ENABLE_MAINTAINER_RULES is 'true' in +# maintainer mode, and '' otherwise. +@MAINT@ ENABLE_MAINTAINER_RULES = true + # These are set by --enable-checking=valgrind. RUN_GEN = @valgrind_command@ VALGRIND_DRIVER_DEFINES = @valgrind_path_defines@
Re: (build) Patch to fix cp/cfns.gperf building issues
>> Ok? > > Ping? PS: For the maintainer who will (eventually) review this patch, the latest version, tested and with all the comments and contributions from Joseph and Mike merged in, is -- http://gcc.gnu.org/ml/gcc-patches/2011-04/msg01930.html So, that's the one to review.
Re: (build) Patch to fix cp/cfns.gperf building issues
Alexandre thanks for the review :-) > -pedantic review: how about outputting to a temporary file (say > cp/cfns.hT) and only renaming to the intended name on success, so that, > if gperf crashes or we reboot part-way through it, we don't end up with > a partially-generated file that will seem to be up to date? It's a good suggestion. On the other hand, now that the rule is maintainer-only, and considering it's used once every few years, I wouldn't personally want to spend more time on it. ;-) Thanks
Re: [patch libiberty include gcc]: PR debug/28047 DWARF output_file_names should really understand DOS pathnames
Can I ask for some clarifications on this patch (applied on 2011-02-28) ? This patch changed the equality function in a hashtable that holds file names, making for example "/" and "\" identical entries on MS-DOS, but it didn't change the hash function, meaning "/" and "\" are now identical hashtable entries on MS-DOS, but with a *different* hash. How can that work ? Lookups for "/" will look in the slot for that hash, which is not the slot for "\", because "\" has a different hash. So, unless there is collision, "/" will never even be compared to "\", and the patch (which changed the comparison function, but not the hash function) would have almost always no effect as it is. What am I missing ? I don't have an MS-DOS machine to test on; I was just reading the code and wondering, so I may well be missing something important. ;-) How was the patch tested ? Is there a testcase ? Thanks
Patch: New GTY ((atomic)) option
This patch adds a new GTY option, "atomic", which is similar to the identical option you have with Boehm GC and which can be used with pointers to inform the GC/PCH machinery that they point to an area of memory that contains no pointers (and hence needs no scanning). The reason for adding this option is that, without it, it seems to be (surprisingly) impossible to write code that keeps a GC pointer to a plain array of C stuff such as integers. In my case, I was experimenting with hash tables that can automatically cache hash values. So I needed a plain C array to store the cached hash values, but found that it is currently unsupported by GC/PCH! :-( That is, at the moment you can't have a struct such as the following one -- struct GTY(()) my_struct { ... unsigned int * some_ints; size_t count; ... }; because gengtype rejects it with the error "field `(*x).some_ints' is pointer to unimplemented type". This patch basically implements it, but at this stage requires you to explicitly tell gengtype that the pointer is atomic (and that is safe for gengtype to ignore the memory it points to). So, the following now works as expected -- struct GTY(()) my_struct { ... unsigned int * GTY((atomic)) some_ints; size_t count; ... }; A next, nice step would be to have gengtype automatically mark as "atomic" any pointers that gengtype can safely determine point to an area of memory that never contains any pointers. But that's slightly more complicated (eg, currently gengtype makes no difference between "unsigned int" and "void", hence "unsigned int *" and "void *" would be treated the same, while you'd want the first one to be automatically marked as atomic, and the second one to generate an error as gengtype has no way to determine if it's atomic or not - unless it's explicitly marked as atomic of course), so for now I haven't implemented it; it could be a follow-up patch (even after implementing it, the explicit "atomic" option would remain useful for "void *" pointers and such like, so it's a good starting point). Btw, there are a few existing pointers in GCC that could be marked as atomic, for example the field "su" of struct function in function.h. The advantage of marking them as atomic would be a slight speedup of the GC marking by saving a function call each time one of these structs is being walked; I suspect that alone wouldn't make any visibile difference in practice, but I haven't done any profiling or benchmarking to know for sure. I have done some testing of this patch, and I want to do some more before I commit. If anyone has good ideas on how to perform throughout testing, they are welcome. :-) Ok to commit ? Thanks PS: This patch does not include support for marking root/global variables with "atomic" (neither manually nor automatically); only fields in a struct. That would be useful too, but I'm leaving it for yet another patch. 2011-05-16 Nicola Pero * gengtype.c (walk_type): Implemented "atomic" GTY option. * doc/gty.texi (GTY Options): Document "atomic" GTY option. Index: doc/gty.texi === --- doc/gty.texi(revision 173768) +++ doc/gty.texi(working copy) @@ -383,6 +383,42 @@ could be calculated as follows: size_t size = sizeof (struct sorted_fields_type) + n * sizeof (tree); @end smallexample +@findex atomic +@item atomic + +The @code{atomic} option can only be used with pointers. It informs +the GC machinery that the memory that the pointer points to does not +contain any pointers, and hence it should be treated by the GC and PCH +machinery as an ``atomic'' block of memory that does not need to be +examined. In particular, the machinery will not scan that memory for +pointers to mark them as reachable (when marking pointers for GC) or +to relocate them (when writing a PCH file). + +The @code{atomic} option must be used with great care, because all +sorts of problem can occur if used incorrectly, that is, if the memory +the pointer points to does actually contain a pointer. + +Here is an example of how to use it: +@smallexample +struct GTY(()) my_struct @{ + int number_of_elements; + unsigned int GTY ((atomic)) * elements; +@}; +@end smallexample +In this case, @code{elements} is a pointer under GC, and the memory it +points to needs to be allocated using the Garbage Collector, and will +be freed automatically by the Garbage Collector when it is no longer +referenced. But the memory that the pointer points to is an array of +@code{unsigned int} elements, and the GC does not need, and indeed +must not, try to scan it to find pointers to mark or relocate, which +is why it is marked with the @code{atomic} option. + +Note that, currently, global
Re: Patch: New GTY ((atomic)) option
>>> This patch adds a new GTY option, "atomic", which is similar to the >>> identical option you have with Boehm GC >>> and which can be used with pointers to inform the GC/PCH machinery that >>> they point to an area of memory that >> [...] >>> This patch basically implements it, but at this stage requires you to >>> explicitly tell gengtype that the >>> pointer is atomic (and that is safe for gengtype to ignore the memory it >>> points to). >> >> then should you not name the attribute "ignore"? > > Or even the existing attribute "skip"? "skip" is different. With "skip", the pointer is completely ignored by GC/PCH. In this case, we don't want to skip the pointer; we want the pointer itself to be managed by GC/PCH, but the memory *it points to* to not be scanned for pointers. ;-) In the example I gave, struct GTY(()) my_struct { ... unsigned int * GTY((atomic)) some_ints; size_t count; ... }; you'd allocate "some_ints" using, for example, ggc_alloc_atomic_stat(), which already exists in the GC (even if at the moment there seems to be no particular support for atomic allocation other than the name of that function, which allocates memory in the same way as for non-atomic allocation), and which would put the pointer under control of the GC; so it is freed when the GC decides that it is no longer referenced; you don't free it manually. That is different from "skip", which would make then pointer simply invisible to GC (you'd allocate it using malloc()), and you'd have to free it manually (or to never free it). In practice, when the GC is doing its marking pass, and is marking a structure of type "my_struct", if the "some_ints" pointer has the option "skip", the GC would not mark it at all; it's ignored. The option "atomic" would cause the GC to mark the pointer but ignore what it points to. The default behaviour is yet different; it is to examine the memory it points to, mark any pointers in there, and then mark the pointer itself too. But because gengtype does not know, at the moment, how to examine unsigned ints (you don't examine them, because the pointer is atomic!), it will print a error saying that the pointer type is uninmplemented, and abort (a further step, after introducing the "atomic" option, would be to have the GC automatically mark such pointers as atomic, as explained in the original post). To clarify, I didn't invent the word "atomic" - AFAIK it is the standard GC naming convention for memory that contains no pointers. It's the name used for this in Boehm GC (the most popular C/C++ GC), where the function is called GC_MALLOC_ATOMIC(), and it is also the name for it in the GCC GC, presumably, since there already is a function "ggc_alloc_atomic_stat()" which presumably is meant to allocate atomic memory (hard to say in the absence of documentation and given that the implementation is identical to the other memory allocation at the moment, but it's a safe guess). What is the problem with "atomic" ? I guess you find it confusing because it makes you think of "atomic access" to memory ? You are right that there is that potential for confusion. :-( We could rename it, but then we'd want to rename the GCC ggc_alloc_atomic_stat() function too, and I'm not entirely sure it would make anything clearer ... as "atomic" is the standard word for that. I think the best we can do is provide good documentation. So, I guess what I take from your comments is that I should update the documentation in my patch to include a short discussion of how "atomic" differs from "skip", since it doesn't seem to be that obvious for people. :-) But please let me know if I'm missing something. Thanks
Re: Patch: New GTY ((atomic)) option
> Yes why can't you use vec(int,gc)? Can you use that in libiberty ? I thought it was a GCC-only thing ? Thanks
Re: Patch: New GTY ((atomic)) option
>> * gengtype.c (walk_type): Implemented "atomic" GTY option. >> * doc/gty.texi (GTY Options): Document "atomic" GTY option. > > The patch is OK, with difference between "skip" and "atomic" options > documented. (Can be done as a follow-up patch). Thanks for the quick review. Here's an updated patch with revised documentation. Ok to go ? Thanks Index: gcc/doc/gty.texi === --- gcc/doc/gty.texi(revision 173917) +++ gcc/doc/gty.texi(working copy) @@ -383,6 +383,51 @@ size_t size = sizeof (struct sorted_fields_type) + n * sizeof (tree); @end smallexample +@findex atomic +@item atomic + +The @code{atomic} option can only be used with pointers. It informs +the GC machinery that the memory that the pointer points to does not +contain any pointers, and hence it should be treated by the GC and PCH +machinery as an ``atomic'' block of memory that does not need to be +examined when scanning memory for pointers. In particular, the +machinery will not scan that memory for pointers to mark them as +reachable (when marking pointers for GC) or to relocate them (when +writing a PCH file). + +The @code{atomic} option differs from the @code{skip} option. +@code{atomic} keeps the memory under Garbage Collection, but makes the +GC ignore the contents of the memory. @code{skip} is more drastic in +that it causes the pointer and the memory to be completely ignored by +the Garbage Collector. So, memory marked as @code{atomic} is +automatically freed when no longer reachable, while memory marked as +@code{skip} is not. + +The @code{atomic} option must be used with great care, because all +sorts of problem can occur if used incorrectly, that is, if the memory +the pointer points to does actually contain a pointer. + +Here is an example of how to use it: +@smallexample +struct GTY(()) my_struct @{ + int number_of_elements; + unsigned int GTY ((atomic)) * elements; +@}; +@end smallexample +In this case, @code{elements} is a pointer under GC, and the memory it +points to needs to be allocated using the Garbage Collector, and will +be freed automatically by the Garbage Collector when it is no longer +referenced. But the memory that the pointer points to is an array of +@code{unsigned int} elements, and the GC must not try to scan it to +find pointers to mark or relocate, which is why it is marked with the +@code{atomic} option. + +Note that, currently, global variables can not be marked with +@code{atomic}; only fields of a struct can. This is a known +limitation. It would be useful to be able to mark global pointers +with @code{atomic} to make the PCH machinery aware of them so that +they are saved and restored correctly to PCH files. + @findex special @item special ("@var{name}") Index: gcc/gengtype.c === --- gcc/gengtype.c (revision 173917) +++ gcc/gengtype.c (working copy) @@ -2386,6 +2386,7 @@ int maybe_undef_p = 0; int use_param_num = -1; int use_params_p = 0; + int atomic_p = 0; options_p oo; const struct nested_ptr_data *nested_ptr_d = NULL; @@ -2415,6 +2416,8 @@ ; else if (strcmp (oo->name, "skip") == 0) ; +else if (strcmp (oo->name, "atomic") == 0) + atomic_p = 1; else if (strcmp (oo->name, "default") == 0) ; else if (strcmp (oo->name, "param_is") == 0) @@ -2480,6 +2483,12 @@ return; } + if (atomic_p && (t->kind != TYPE_POINTER)) +{ + error_at_line (d->line, "field `%s' has invalid option `atomic'\n", d->val); + return; +} + switch (t->kind) { case TYPE_SCALAR: @@ -2495,6 +2504,25 @@ break; } + /* If a pointer type is marked as "atomic", we process the + field itself, but we don't walk the data that they point to. + + There are two main cases where we walk types: to mark + pointers that are reachable, and to relocate pointers when + writing a PCH file. In both cases, an atomic pointer is + itself marked or relocated, but the memory that it points + to is left untouched. In the case of PCH, that memory will + be read/written unchanged to the PCH file. */ + if (atomic_p) + { + oprintf (d->of, "%*sif (%s != NULL) {\n", d->indent, "", d->val); + d->indent += 2; + d->process_field (t, d); + d->indent -= 2; + oprintf (d->of, "%*s}\n", d->indent, ""); + break; + } + if (!length) { if (!UNION_OR_STRUCT_P (t->u.p) Index: gcc/ChangeLog
Re: Patch: New GTY ((atomic)) option
> However, did you check that the atomic qualifier is correctly written & > re-read in the state (I believe you did, otherwise it probably won't > work). This is needed for plugins using it, or using atomic qualified > fields of existing (or future) structures. Yes. String options are written as they are, no particular changes are needed. ;-) I'd like to show you a testcase, but, as you discuss in your other email, we can't really write GTY testcases at this stage. So here is a walked tour of how to test the new atomic option -- * apply the GTY ((atomic)) patch (obviously) * add the "GTY ((atomic))" option to field 'su' of struct 'function' in function.h (that field is atomic, so you can mark it "atomic" and it should work) * rebuild everything from scratch (bootstrap the compiler) * gtype.state now contains, some time after (!pair "su", the lines (!srcfileloc "function.h" 516) (!options (!option atomic string "") ) btw, we should probably improve gtype.state; indentation would be nice :-) ... * gtype-desc.c now contains void gt_ggc_mx_function (void *x_p) { struct function * const x = (struct function *)x_p; if (ggc_test_and_set_mark (x)) { gt_ggc_m_9eh_status ((*x).eh); gt_ggc_m_18control_flow_graph ((*x).cfg); gt_ggc_m_12gimple_seq_d ((*x).gimple_body); gt_ggc_m_9gimple_df ((*x).gimple_df); gt_ggc_m_5loops ((*x).x_current_loops); if ((*x).su != NULL) { ggc_mark ((*x).su); } gt_ggc_m_9tree_node ((*x).decl); gt_ggc_m_9tree_node ((*x).static_chain_decl); gt_ggc_m_9tree_node ((*x).nonlocal_goto_save_area); gt_ggc_m_11VEC_tree_gc ((*x).local_decls); gt_ggc_m_16machine_function ((*x).machine); gt_ggc_m_17language_function ((*x).language); gt_ggc_m_P9tree_node4htab ((*x).used_types_hash); } } as you notice, the "su" field is only marked, but not followed. Normally that same marking function would be void gt_ggc_mx_function (void *x_p) { struct function * const x = (struct function *)x_p; if (ggc_test_and_set_mark (x)) { gt_ggc_m_9eh_status ((*x).eh); gt_ggc_m_18control_flow_graph ((*x).cfg); gt_ggc_m_12gimple_seq_d ((*x).gimple_body); gt_ggc_m_9gimple_df ((*x).gimple_df); gt_ggc_m_5loops ((*x).x_current_loops); gt_ggc_m_11stack_usage ((*x).su); gt_ggc_m_9tree_node ((*x).decl); gt_ggc_m_9tree_node ((*x).static_chain_decl); gt_ggc_m_9tree_node ((*x).nonlocal_goto_save_area); gt_ggc_m_11VEC_tree_gc ((*x).local_decls); gt_ggc_m_16machine_function ((*x).machine); gt_ggc_m_17language_function ((*x).language); gt_ggc_m_P9tree_node4htab ((*x).used_types_hash); } } which would call the gt_ggc_mx_stack_usage() function, which does nothing but mark the pointer in this case (since the field actually is atomic), but would in other cases mark the children as well. So, in this case marking the field as "atomic" results in a small optimization when doing the GC marking stage. In other cases, when gengtype doesn't know how to inspect the memory pointed to (eg, "unsigned int *"), then it would make it possible to use GC for the pointer. PCH traversing is similar. To test that the GC marking actually works, I mostly bootstrap the compiler first, then test compiling a few testcases using --param ggc-min-expand=0 --param ggc-min-heapsize=0. This is by no means a full test; if you or Laurynas have any suggestions on how to test better, they'd be welcome. :-) Thanks
Re: ObjC/ObjC++: Fix property encoding on Apple
With your patch and Dominique's change both the objc and obj-c++ testsuites pass without regressions at -m32/-m64. Updating the objc/c++ testcase is obvious if everyone is on the same page. :-) Yes. Thanks a lot to Jack and Dominique for the helpful review/ testing. :-) I committed the testcases after updating the ObjC++ testcase to use the same "machinery" as the ObjC one. Sorry it took me so long. Thanks
Re: ObjC/ObjC++: Fix property encoding on Apple
With your patch and Dominique's change both the objc and obj-c++ testsuites pass without regressions at -m32/-m64. Updating the objc/c++ testcase is obvious if everyone is on the same page. :-) Yes. Thanks a lot to Jack and Dominique for the helpful review/ testing. :-) I committed the testcases after updating the ObjC++ testcase to use the same "machinery" as the ObjC one. Sorry it took me so long. Thanks
Re: ObjC/ObjC++: Fix property encoding on Apple
On 4 Mar 2011, at 16:41, Dominique Dhumieres wrote: Nicola, obj-c++.dg/property/property-encoding-1.mm fails to compile with: [...] You need to use the right C++ incantations, [...] Apologies. I now did the obvious changes that should make it work in both the ObjC and ObjC++ testsuites, and committed them as obvious. Please let me know if it still doesn't work! Thanks Index: ChangeLog === --- ChangeLog (revision 170682) +++ ChangeLog (working copy) @@ -1,5 +1,10 @@ 2011-03-04 Nicola Pero + * objc.dg/property/property-encoding-1.m: Tidied up testcase. + * obj-c++.dg/property/property-encoding-1.mm: Likewise. + +2011-03-04 Nicola Pero + * objc.dg/gnu-api-2-property.m: Added tests for property_getName() and property_getAttributes() if __OBJC2__. * obj-c++.dg/gnu-api-2-property.mm: Likewise. Index: objc.dg/property/property-encoding-1.m === --- objc.dg/property/property-encoding-1.m (revision 170682) +++ objc.dg/property/property-encoding-1.m (working copy) @@ -89,22 +89,21 @@ void error (objc_property_t p) } /* Concatenate 3 strings and return the result. */ -char *concat (char *a, char *b, char *c) +char *concat (const char *a, const char *b, const char *c) { /* We happily leak memory here. This is a test. */ - char *x = malloc (sizeof (char) * 128); + char *x = (char *)malloc (sizeof (char) * 128); snprintf (x, 128, "%s%s%s", a, b, c); return x; } #endif -int main(int argc, void **args) +int main (void) { #ifdef __OBJC2__ Class c = objc_getClass ("MySubClass"); objc_property_t p; - const char *expected_result; p = class_getProperty (c, "char_property"); /* Usually we expect "Tc,Vchar_property", but if a char is of Index: obj-c++.dg/property/property-encoding-1.mm === --- obj-c++.dg/property/property-encoding-1.mm (revision 170682) +++ obj-c++.dg/property/property-encoding-1.mm (working copy) @@ -89,22 +89,21 @@ void error (objc_property_t p) } /* Concatenate 3 strings and return the result. */ -char *concat (char *a, char *b, char *c) +char *concat (const char *a, const char *b, const char *c) { /* We happily leak memory here. This is a test. */ - char *x = malloc (sizeof (char) * 128); + char *x = (char *)malloc (sizeof (char) * 128); snprintf (x, 128, "%s%s%s", a, b, c); return x; } #endif -int main(int argc, char **args) +int main (void) { #ifdef __OBJC2__ Class c = objc_getClass ("MySubClass"); objc_property_t p; - const char *expected_result; p = class_getProperty (c, "char_property"); /* Usually we expect "Tc,Vchar_property", but if a char is of
RE: [objc++] RFH: PR 48167 gengtype failure (issue4291054)
> The Obj-C++ FE is kind of weird as it shares files from cp/ and objc/, > so I'm missing some other connection I need to make to fix this. > > Any ideas? As far as I can see, the problem is that header files (such as cp/parser.h) generate GC stuff that gets put into gtype-{lang}.h, where {lang} is determined by looking at the directory where the file is (eg, if it's in the cp/ directory, then {lang} is cp) ... unless you override this with a custom hardcoded rule in gengtype.c. It seems that all files that are shared between ObjC or C++ and ObjC++ have custom hardcoded rules in gengtype.c. The cp/parser.h file you added didn't, and without it, every time it is processed, the results are stored in gtype-cp.h even if the file is processed for ObjC++. :-( This all looks ugly. Anyhow, until someone refactors everything, the following patch fixes ObjC++ bootstrap in trunk by processing cp/parser.h in the same way as the other C++ headers are processed. :-) Ok to commit ? Thanks Index: gcc/gengtype.c === --- gcc/gengtype.c (revision 171155) +++ gcc/gengtype.c (working copy) @@ -1761,6 +1761,12 @@ matters, so change with extreme care! */ struct file_rule_st files_rules[] = { + /* The general rule assumes that files in subdirectories belong to a + particular front-end, and files not in subdirectories are shared. + The following rules deal with exceptions - files that are in + subdirectories and yet are shared, and files that are top-level, + but are not shared. */ + /* the c-family/ source directory is special. */ { DIR_PREFIX_REGEX "c-family/([[:alnum:]_-]*)\\.c$", REG_EXTENDED, NULL_REGEX, @@ -1792,7 +1798,12 @@ REG_EXTENDED, NULL_REGEX, "gt-cp-name-lookup.h", "cp/name-lookup.c", NULL_FRULACT }, - /* objc/objc-act.h fives gt-objc-objc-act.h for objc/objc-act.c ! */ + /* cp/parser.h gives gt-cp-parser.h for cp/parser.c ! */ + { DIR_PREFIX_REGEX "cp/parser\\.h$", +REG_EXTENDED, NULL_REGEX, +"gt-cp-parser.h", "cp/parser.c", NULL_FRULACT }, + + /* objc/objc-act.h gives gt-objc-objc-act.h for objc/objc-act.c ! */ { DIR_PREFIX_REGEX "objc/objc-act\\.h$", REG_EXTENDED, NULL_REGEX, "gt-objc-objc-act.h", "objc/objc-act.c", NULL_FRULACT }, Index: gcc/ChangeLog === --- gcc/ChangeLog (revision 171155) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2011-03-18 Nicola Pero + + * gengtype.c (files_rules): Added rule for cp/parser.h. + 2011-03-18 Maxim Kuvyrkov PR rtl-optimization/48170 Index: gcc/objcp/Make-lang.in === --- gcc/objcp/Make-lang.in (revision 171155) +++ gcc/objcp/Make-lang.in (working copy) @@ -45,7 +45,7 @@ .PHONY: obj-c++ START_HDRS = $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(CXX_TREE_H) \ - langhooks.h c-family/c-objc.h objc/objc-act.h + $(CXX_PARSER_H) $(CXX_PRETTY_PRINT_H) langhooks.h c-family/c-objc.h objc/objc-act.h # Use maximal warnings for this front end. Also, make ObjC and C++ # headers accessible. @@ -78,7 +78,7 @@ objcp/objcp-lang.o : objcp/objcp-lang.c $(START_HDRS) \ $(C_COMMON_H) $(LANGHOOKS_DEF_H) cp/cp-objcp-common.h \ - $(TARGET_H) gtype-objcp.h + $(TARGET_H) gtype-objcp.h objcp/objcp-decl.o : objcp/objcp-decl.c \ $(CONFIG_H) $(SYSTEM_H) coretypes.h $(TM_H) $(TREE_H) $(CXX_TREE_H) \ Index: gcc/objcp/ChangeLog === --- gcc/objcp/ChangeLog (revision 171155) +++ gcc/objcp/ChangeLog (working copy) @@ -1,3 +1,11 @@ +2011-03-17 Nicola Pero + + * Make-lang.in (START_HDRS): Added CXX_PARSER_H and + CXX_PRETTY_PRINT_H. + * config-lang.in (gtfiles): Added cp/parser.h and reorganized list + so that it is more obvious that it is identical to the C++ one + with the addition of some files at the end. + 2011-03-06 Joseph Myers * lang-specs.h: Match -save-temps* instead of -save-temps. Index: gcc/objcp/config-lang.in === --- gcc/objcp/config-lang.in(revision 171155) +++ gcc/objcp/config-lang.in(working copy) @@ -37,5 +37,14 @@ lang_requires="objc c++" subdir_requires="objc cp" -gtfiles="\$(srcdir)/objc/objc-act.h \$(srcdir)/objc/objc-act.c \$(srcdir)/objc/objc-runtime-shared-support.c \$(srcdir)/objc/objc-gnu-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-01.c \$(srcdir)/objc/objc-next-runtime-abi-02.c \$(srcdir)/cp/call.c \$(srcdir)/cp/class.c \$(srcdir)/cp/cp-tree.h \$(srcdir)/cp/decl.c \$(srcdir)/cp/decl2.c \$(srcdir)/cp/mangle.c \$(srcdir)/cp/method.c \$(srcdir)/cp/name-lookup.h \$(
Re: [objc++] RFH: PR 48167 gengtype failure (issue4291054)
>> + /* cp/parser.h gives gt-cp-parser.h for cp/parser.c ! */ >> + { DIR_PREFIX_REGEX "cp/parser\\.h$", >> + REG_EXTENDED, NULL_REGEX, >> + "gt-cp-parser.h", "cp/parser.c", NULL_FRULACT }, > > But cp/parser.c also gets its own gt-cp-parser.h. Won't they > conflict? Doesn't this mean that cp/parser.h should be renamed to > something else? (say cp/cp-parser.h). My understanding is that, with that rule, GC generated code from cp-parser.h will end up into gt-cp-parser.h, together with the code generated from cp-parser.c. gengtype basically runs once for all files, so has no problem putting GC generated code from multiple input files into the same output file. In practical terms, cp/decl.c and cp/decl.h (or cp/name-lookup.c and cp/name-lookup.h) are in a similar situation, and work fine with similar gengtype.c rules. :-) Thanks
ObjC: some minor optimizations
This patch removes some very minor inefficiencies in the ObjC compiler code. Ok to commit ? Thanks Index: gcc/objc/ChangeLog === --- gcc/objc/ChangeLog (revision 172239) +++ gcc/objc/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-04-10 Nicola Pero + + * objc-act.c (objc_is_class_name, objc_is_id): For efficiency, + avoid calling identifier_global_value() multiple times. + 2011-04-06 Joseph Myers * objc-act.c: Include c-target.h instead of target.h. Index: gcc/objc/objc-act.c === --- gcc/objc/objc-act.c (revision 172239) +++ gcc/objc/objc-act.c (working copy) @@ -3411,9 +3411,13 @@ objc_is_class_name (tree ident) { hash target; - if (ident && TREE_CODE (ident) == IDENTIFIER_NODE - && identifier_global_value (ident)) -ident = identifier_global_value (ident); + if (ident && TREE_CODE (ident) == IDENTIFIER_NODE) +{ + tree t = identifier_global_value (ident); + if (t) + ident = t; +} + while (ident && TREE_CODE (ident) == TYPE_DECL && DECL_ORIGINAL_TYPE (ident)) ident = OBJC_TYPE_NAME (DECL_ORIGINAL_TYPE (ident)); @@ -3453,9 +3457,12 @@ objc_is_class_name (tree ident) tree objc_is_id (tree type) { - if (type && TREE_CODE (type) == IDENTIFIER_NODE - && identifier_global_value (type)) -type = identifier_global_value (type); + if (type && TREE_CODE (type) == IDENTIFIER_NODE) +{ + tree t = identifier_global_value (type); + if (t) + type = t; +} if (type && TREE_CODE (type) == TYPE_DECL) type = TREE_TYPE (type); Index: gcc/ChangeLog === --- gcc/ChangeLog (revision 172239) +++ gcc/ChangeLog (working copy) @@ -1,3 +1,8 @@ +2011-04-10 Nicola Pero + + * c-parser.c (c_lex_one_token): Rewritten conditional used when + compiling Objective-C to be more efficient. + 2011-04-09 Anatoly Sokolov * expr.c (expand_expr_real_1): Use add_to_hard_reg_set function Index: gcc/c-parser.c === --- gcc/c-parser.c (revision 172239) +++ gcc/c-parser.c (working copy) @@ -334,8 +334,7 @@ c_lex_one_token (c_parser *parser, c_token *token) variables and typedefs, and hence are shadowed by local declarations. */ if (objc_interface_decl - && (global_bindings_p () - || (!objc_force_identifier && !decl))) +&& (!objc_force_identifier || global_bindings_p ())) { token->value = objc_interface_decl; token->id_kind = C_ID_CLASSNAME;
ObjC: do not prepare instance variables for output unless there is an actual error message to print
This is another very small optimization. Whenever the ObjC compiler found an instance variable, it was preparing it for printing it in error messages. Of course, in the typical ObjC compilation run with Foundation and AppKit the compiler will see about 1.5k instance variables, none of which will generate any error message (in most cases), so this patch changes the compiler to only do the work for pretty printing when there is an actual error message to print. The speedup is tiny. Ok to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 172254) +++ ChangeLog (working copy) @@ -1,3 +1,10 @@ +2011-04-11 Nicola Pero + + * objc-act.c (printable_ivar_name): New. + (add_instance_variable): Call printable_ivar_name() when an error + message needs to be printed. Do not prepare the instance variable + for printing unless there is an actual error. + 2011-04-06 Joseph Myers * objc-act.c: Include c-target.h instead of target.h. Index: objc-act.c === --- objc-act.c (revision 172254) +++ objc-act.c (working copy) @@ -5974,6 +5974,17 @@ flexible_array_type_p (tree type) } #endif +/* Produce a printable version of an ivar name. This is only used + inside add_instance_variable. */ +static const char * +printable_ivar_name (tree field_decl) +{ + if (DECL_NAME (field_decl)) +return identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (field_decl))); + else +return _(""); +} + /* Called after parsing each instance variable declaration. Necessary to preserve typedefs and implement public/private... @@ -5984,15 +5995,12 @@ add_instance_variable (tree klass, objc_ivar_visib tree field_decl) { tree field_type = TREE_TYPE (field_decl); - const char *ivar_name = DECL_NAME (field_decl) - ? identifier_to_locale (IDENTIFIER_POINTER (DECL_NAME (field_decl))) - : _(""); #ifdef OBJCPLUS if (TREE_CODE (field_type) == REFERENCE_TYPE) { error ("illegal reference type specified for instance variable %qs", -ivar_name); +printable_ivar_name (field_decl)); /* Return class as is without adding this ivar. */ return klass; } @@ -6002,7 +6010,8 @@ add_instance_variable (tree klass, objc_ivar_visib || TYPE_SIZE (field_type) == error_mark_node) /* 'type[0]' is allowed, but 'type[]' is not! */ { - error ("instance variable %qs has unknown size", ivar_name); + error ("instance variable %qs has unknown size", +printable_ivar_name (field_decl)); /* Return class as is without adding this ivar. */ return klass; } @@ -6022,7 +6031,8 @@ add_instance_variable (tree klass, objc_ivar_visib to calculate the offset of the next instance variable. */ if (flexible_array_type_p (field_type)) { - error ("instance variable %qs uses flexible array member", ivar_name); + error ("instance variable %qs uses flexible array member", +printable_ivar_name (field_decl)); /* Return class as is without adding this ivar. */ return klass; } @@ -6069,7 +6079,7 @@ add_instance_variable (tree klass, objc_ivar_visib error ("type %qE has virtual member functions", type_name); error ("illegal aggregate type %qE specified " "for instance variable %qs", -type_name, ivar_name); +type_name, printable_ivar_name (field_decl)); /* Return class as is without adding this ivar. */ return klass; }
ObjC: interface hashtable rewritten for speed and simplicity
This patch rewrites the ObjC interface hashtable for speed, saving in excess of 100k function calls per typical compilation run in my benchmarks. I did extensively benchmark this solution (and other solutions) while developing it a few months ago. trunk has changed substantially in the meanwhile, so those results do not necessarily apply, and I now just want to get the changes into trunk without having to rebenchmark everything, but to give an idea, I'd expect this change to speed up the compiler by about 1% to 2% when compiling real code with -fsyntax-only in release mode. Anyhow, the new data structure is really simple and obvious, it is exactly designed for the task, it is (clearly) lot more efficient as all the function calls that used to be required to do anything are gone, and the hashtable size has been tuned. Ok to commit ? Thanks Index: ChangeLog === --- ChangeLog (revision 172255) +++ ChangeLog (working copy) @@ -1,3 +1,15 @@ +2011-04-11 Nicola Pero + + Rewritten the hashtable holding interfaces for speed. + * objc-act.h (INTERFACE_HASHTABLE_SIZE, interface_hashtable_entry, + interface_hash, interface_hashtable): New. + (interface_chain, OCTI_INF_CHAIN): Removed. + * objc-act.c (interface_tuple, interface_htab, hash_interface, + eq_interface): Removed. + (lookup_interface): Rewritten. + (add_class): Renamed to add_interface, reimplemented. + (interface_hashtable): New. + 2011-04-06 Joseph Myers * objc-act.c: Include c-target.h instead of target.h. Index: objc-act.c === --- objc-act.c (revision 172255) +++ objc-act.c (working copy) @@ -187,7 +187,11 @@ static hash hash_lookup (hash *, tree); static tree lookup_method (tree, tree); static tree lookup_method_static (tree, tree, int); -static tree add_class (tree, tree); +/* Hashtable with all the interfaces. You can look things up in it by + using lookup_interface(). */ +interface_hash *interface_hashtable = 0; +static void add_interface (tree, tree); + static void add_category (tree, tree); static inline tree lookup_category (tree, tree); @@ -3764,27 +3768,6 @@ objc_generate_write_barrier (tree lhs, enum tree_c return result; } -struct GTY(()) interface_tuple { - tree id; - tree class_name; -}; - -static GTY ((param_is (struct interface_tuple))) htab_t interface_htab; - -static hashval_t -hash_interface (const void *p) -{ - const struct interface_tuple *d = (const struct interface_tuple *) p; - return IDENTIFIER_HASH_VALUE (d->id); -} - -static int -eq_interface (const void *p1, const void *p2) -{ - const struct interface_tuple *d = (const struct interface_tuple *) p1; - return d->id == p2; -} - tree lookup_interface (tree ident) { @@ -3797,19 +3780,19 @@ lookup_interface (tree ident) return NULL_TREE; { -struct interface_tuple **slot; -tree i = NULL_TREE; +interface_hash target; + +target = interface_hashtable[IDENTIFIER_HASH_VALUE (ident) % INTERFACE_HASHTABLE_SIZE]; -if (interface_htab) +while (target) { - slot = (struct interface_tuple **) - htab_find_slot_with_hash (interface_htab, ident, - IDENTIFIER_HASH_VALUE (ident), - NO_INSERT); - if (slot && *slot) - i = (*slot)->class_name; + if (ident == target->ident) + return target->class_name; + + target = target->next; } -return i; + +return NULL_TREE; } } @@ -5507,6 +5490,8 @@ hash_init (void) ivar_offset_hash_list = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE); + interface_hashtable = ggc_alloc_cleared_vec_interface_hash (INTERFACE_HASHTABLE_SIZE); + /* Initialize the hash table used to hold the constant string objects. */ string_htab = htab_create_ggc (31, string_hash, string_eq, NULL); @@ -5878,29 +5863,16 @@ objc_add_method (tree klass, tree method, int is_c return method; } -static tree -add_class (tree class_name, tree name) +static void +add_interface (tree class_name, tree name) { - struct interface_tuple **slot; - - /* Put interfaces on list in reverse order. */ - TREE_CHAIN (class_name) = interface_chain; - interface_chain = class_name; - - if (interface_htab == NULL) -interface_htab = htab_create_ggc (31, hash_interface, eq_interface, NULL); - slot = (struct interface_tuple **) -htab_find_slot_with_hash (interface_htab, name, - IDENTIFIER_HASH_VALUE (name), - INSERT); - if (!*slot) -{ - *slot = ggc_alloc_cleared_interface_tuple (); - (*slot)->id = name; -} - (*slot)->class_name = class_name; - - return interface_chain; + int slot = IDENTIFIER_HASH_VALUE (name) % INTERFACE_HA