Coccinelle archive on
 help / color / Atom feed
From: Thomas Adam <>
Subject: [Cocci] Using cocci to mangle function arguments
Date: Sun, 17 May 2020 01:16:46 +0100
Message-ID: <20200517001646.gtobyv6jea5bugfr@debian> (raw)

Hi all,

I have a situation where I'm trying to use Coccinelle to both rename one
function to another, and at the same time modify the number of arguments.

I have a function called:

    func_old(ERR, "func_name", "%s message", charstring);

Which is therefore variadic.  In terms of argument ordering func_old() takes:

  1.  log-level type
  2.  the calling function
  3.  A variadic string

I'm wanting to replace func_old() with func_new() such that it looks like

    func_new("%s: %s message", __func__, charstring);

Hence, func_new() reduces the number of arguments to just one -- a format
string, and variadic arguments.

My question is how would I go about trying to get coccinelle to help me
translate this?  Is this even possible?  I have tried:

expression O1, O2, O3

- func_old(O1, O2, O3, ...);

But I don't know how to convert what would be O2 to '__func__'.  When calling
func_new(), there is no explicit O2 parameter from func_old(), it should be
part of the format string, hence:

+ func_new("%s: ...", __func__, O3);

I suspect I might be stretching coccinelle's abilities in trying to craft new
parameters, but I thought I'd ask.

Apologies if this is convoluted.  If I can help answer any additional
questions, or if something's not clear, let me know.


Cocci mailing list

             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17  0:16 Thomas Adam [this message]
2020-05-17  8:07 ` Julia Lawall

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200517001646.gtobyv6jea5bugfr@debian \ \ \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Coccinelle archive on

Archives are clonable:
	git clone --mirror cocci/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 cocci cocci/ \
	public-inbox-index cocci

Example config snippet for mirrors

Newsgroup available over NNTP:

AGPL code for this site: git clone