Re: [PATCH 2/2] replace-object.c: remove the_repository from prepare_replace_object
- From
Stefan Beller <sbeller@google.com>
- Date
- May 10, 2018, 18:32 UTC
- Message-ID
- <CAGZ79kb_qLm2dBxDmH7-N9C9+oVArxehTC3RuM7ci292AuFmBQ@mail.gmail.com>
- In-Reply-To
- <da155b13-b915-edb7-9bf9-6bef900cdde9@gmail.com>
> Using `git grep` I see 230 instances of 'xmalloc' and 261 instances of > 'xcalloc'. After the Coccinelle transformation, these are down to 194 and > 190, respectively, because the rest allocate in the same line as the > definition. It's worth thinking about the macro pattern for those cases.
Thanks for reporting the coccinelle experiment!
As we follow a strict declare before code, and we do not know if further declarations make use of this already, e.g. given
struct foo *f = xmalloc(sizeof(*f));
struct bar b = &f->baz;we cannot split up the line declaring and assigning f, but the macro has to recreate the assignment upon declaration, for that we'd need to have something like
ALLOCATE_TYPE(type, name);
which over complicates things IMHO.
Maybe it is worth identifying the pattern where 'f' is not used in further declarations, such that we can make patches as
- struct foo *f = xmalloc(sizeof(*f));
+ struct foo *f;
struct baz b = &unrelated;
+
+ ALLOCATE(f);
+Thanks, Stefan