From: Alex Riesen Date: Tue, 29 Jun 2010 08:33:51 GMT Subject: Re: [PATCH] string-list.h: Add STRING_LIST_INIT macro and make use of it. Message-ID: In-Reply-To: <7v4ogmcs1u.fsf@alter.siamese.dyndns.org> On Tue, Jun 29, 2010 at 07:43, Junio C Hamano wrote: >>> >>>    #define STRING_LIST_INIT(pleasedup) { NULL, 0, 0, (pleasedup) } >> >> This begs for using strdup(string-to-dup) in the macro argument, which >> will not compile with ancient compilers which don't allow code in an >> initializer. > > Err, one of us must be confused. > > I was suggesting to rewrite things like these, found in builtin/remote.c > (add and rm): > >        struct string_list track = { NULL, 0, 0, 0 }; >        struct string_list branches = { NULL, 0, 0, 1 }; > That must be me, again. Didn't bother to check the string_list definition and naively assumed the pleasedup was for an initialization string. I thought that depending on usage the caller may wish to either copy it or leave the string_list referncing the original. Which cannot be the case with string_list, indeed. BTW, now that I took a look at it... The iteration over string_list items looks a little overengineered. At least from the point of view of the existing users of the feature. Wouldn't a simple loop be just as simple to use (if not simplier) and faster (no uninlineable function calls and argument preparation and passing needed)? #define string_list_foreach(item,list) \ for (item = (list)->items; item < (list)->items + (list)->nr; ++item)