From: René Scharfe Date: Tue, 12 Nov 2019 18:37:23 GMT Subject: Re: coccinelle: adjustments for array.cocci? Message-ID: <5189f847-1af1-f050-6c72-576a977f6f12@web.de> In-Reply-To: <50c77cdc-2b2d-16c8-b413-5eb6a2bae749@web.de> Am 12.11.19 um 16:08 schrieb Markus Elfring: > Hello, > > I would like to comment implementation details from > the commit 177fbab747da4f58cb2a8ce010b3515c86dd67c9 ("coccinelle: use COPY_ARRAY for copying arrays"). > > > Do you find the following code variant (for the semantic patch language) also useful? > > memcpy( > ( ptr, E, n * > - sizeof(*(ptr)) > + sizeof(T) > | arr, E, n * > - sizeof(*(arr)) > + sizeof(T) > | E, ptr, n * > - sizeof(*(ptr)) > + sizeof(T) > | E, arr, n * > - sizeof(*(arr)) > + sizeof(T) > ) > ) This reduces duplication in the semantic patch, which is nice. I think I tried something like that at the time, but found that it failed to produce some of the cases in 921d49be86 ("use COPY_ARRAY for copying arrays", 2019-06-15) for some reason. > How do you think about the following SmPL code variant? > > -memcpy > +COPY_ARRAY > ( > ( dst_ptr > | dst_arr > ) > , > ( src_ptr > | src_arr > ) > , > - (n) * sizeof(T) > + n > ) This eliminates duplication in the semantic patch, which is good. It messes up the indentation of n in some of the cases in 921d49be86 ("use COPY_ARRAY for copying arrays", 2019-06-15), though. Hmm, but that can be cured by duplicating the comma: - , (n) * sizeof(T) + , n René