Coccinelle Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: wagi@monom.org (Daniel Wagner)
To: cocci@systeme.lip6.fr
Subject: [Cocci] gboolean -> bool conversion
Date: Wed, 17 Jul 2013 10:47:21 +0200	[thread overview]
Message-ID: <51E65A19.6010903@monom.org> (raw)
In-Reply-To: <alpine.DEB.2.02.1307161818580.2264@hadrien>

Hi Julia,

On 07/16/2013 06:22 PM, Julia Lawall wrote:
> On Tue, 16 Jul 2013, Daniel Wagner wrote:
>
>> Hi Julia,
>>
>> On 07/12/2013 09:00 AM, Julia Lawall wrote:
>>> @r@
>>> identifier f;
>>> parameter list[n] ps;
>>> identifier i;
>>> @@
>>>
>>> f(ps, gboolean i, ...) { ... }
>>>
>>> @@
>>> identifier r.f;
>>> expression list [r.n] es;
>>> @@
>>>
>>> f(es,
>>> (
>>> - FALSE
>>> + false
>>> |
>>> - TRUE
>>> + true
>>> )
>>>    ,...)
>>>
>>>
>>> I have not tested this, but it should work.  Write back if you have
>>> problems.
>>
>> This rule is a half success. The main problem stems from the fact, that a
>> function is declared in a header, e.g.
>>
>> 	void connman_foo(gboolean foo);
>>
>> and the caller just sees that and not the definition. If I understood
>> this correctly the 'f(ps, gboolean i, ...) { ... }' will not match.
>
> OK, you can make a rule that matches a prototype as well.

I am still struggling with creating a rule for a prototype. Rereading 
examples and documentation.

So I am only allowed to write a prototype (funproto, right?) in the 
declaration section (common_decl)? How do I write the rule?

(I am really bad not getting this done by myself.)

>> Another boolean transformation I do is with connman_bool_t to bool. Coccinelle
>> is kind of unhappy with this function:
>>
>> https://git.kernel.org/cgit/network/connman/connman.git/tree/vpn/vpn-agent.c#n38
>>
>> parse error
>>   = error in vpn/vpn-agent.c; set verbose_parsing for more info
>> badcount: 20
>> bad: #include "vpn.h"
>> bad:
>> bad: connman_bool_t vpn_agent_check_reply_has_dict(DBusMessage *reply)
>> bad: {
>> bad:    const char *signature = DBUS_TYPE_ARRAY_AS_STRING
>> BAD:!!!!!               DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
>> bad:            DBUS_TYPE_STRING_AS_STRING
>> bad:            DBUS_TYPE_VARIANT_AS_STRING
>> bad:            DBUS_DICT_ENTRY_END_CHAR_AS_STRING;
>> bad:
>> bad:    if (dbus_message_has_signature(reply, signature) == TRUE)
>> bad:            return TRUE;
>> bad:
>> bad:    connman_warn("Reply %s to %s from %s has wrong signature %s",
>> bad:                    signature,
>> bad:                    dbus_message_get_interface(reply),
>> bad:                    dbus_message_get_sender(reply),
>> bad:                    dbus_message_get_signature(reply));
>> bad:
>> bad:    return FALSE;
>> bad: }
>>
>> Is there a way to make the parser happy?
>
> Yes, you need to give some macro definitions.  Make a copy of standard.h,
> add what you need and give the name of the file with the option
> --macro-file-builtins.
>
> Concretely, you want to put the following definitions:
>
> #define DBUS_TYPE_ARRAY_AS_STRING 0
> #define DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
> #define DBUS_TYPE_STRING_AS_STRING
> #define DBUS_TYPE_VARIANT_AS_STRING
> #define DBUS_DICT_ENTRY_END_CHAR_AS_STRING

That would work in the example but it would not do it for

https://git.kernel.org/cgit/network/connman/connman.git/tree/plugins/vpn.c#n666

	const char *signature = DBUS_TYPE_ARRAY_AS_STRING
		DBUS_STRUCT_BEGIN_CHAR_AS_STRING
		DBUS_TYPE_OBJECT_PATH_AS_STRING
		DBUS_TYPE_ARRAY_AS_STRING
		DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
		DBUS_TYPE_STRING_AS_STRING
		DBUS_TYPE_VARIANT_AS_STRING
		DBUS_DICT_ENTRY_END_CHAR_AS_STRING
		DBUS_STRUCT_END_CHAR_AS_STRING;

So my solution was to pull in the dbus-protocol.h header which defines 
them as strings and everyting works fine.

cheers,
daniel

  reply	other threads:[~2013-07-17  8:47 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-11  8:17 [Cocci] gboolean -> bool conversion Daniel Wagner
2013-07-11  8:29 ` Julia Lawall
2013-07-11  9:07   ` Daniel Wagner
2013-07-11  9:57     ` Julia Lawall
2013-07-11  9:58     ` Daniel Wagner
2013-07-11 10:24       ` Julia Lawall
2013-07-11 11:17         ` Daniel Wagner
2013-07-11 12:17           ` Julia Lawall
2013-07-11 12:38             ` Daniel Wagner
2013-07-11 13:07               ` Julia Lawall
2013-07-12  6:55                 ` Daniel Wagner
2013-07-12  7:00                   ` Julia Lawall
2013-07-12  9:08                     ` Daniel Wagner
2013-07-16 14:21                     ` Daniel Wagner
2013-07-16 16:22                       ` Julia Lawall
2013-07-17  8:47                         ` Daniel Wagner [this message]
2013-07-17  9:01                           ` Julia Lawall
2013-07-17 14:58                             ` Daniel Wagner
2013-07-17 15:11                               ` Julia Lawall
2013-07-17 15:40                                 ` Daniel Wagner

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=51E65A19.6010903@monom.org \
    --to=wagi@monom.org \
    --cc=cocci@systeme.lip6.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox