All of lore.kernel.org
 help / color / mirror / Atom feed
From: John Snow <jsnow@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, peter.maydell@linaro.org, armbru@redhat.com
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH v2] add macro file for coccinelle
Date: Tue, 8 Sep 2015 13:30:25 -0400	[thread overview]
Message-ID: <55EF1B31.6070504@redhat.com> (raw)
In-Reply-To: <1441621264-23812-1-git-send-email-pbonzini@redhat.com>



On 09/07/2015 06:21 AM, Paolo Bonzini wrote:
> Coccinelle chokes on some idioms from compiler.h and queue.h.
> Extract those in a macro file, to be used with "--macro-file
> scripts/cocci-macro-file.h".
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  scripts/cocci-macro-file.h | 119 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 119 insertions(+)
>  create mode 100644 scripts/cocci-macro-file.h
> 
> diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h
> new file mode 100644
> index 0000000..eceb4be
> --- /dev/null
> +++ b/scripts/cocci-macro-file.h
> @@ -0,0 +1,119 @@
> +/* Macro file for Coccinelle
> + *
> + * Copyright (C) 2015 Red Hat, Inc.
> + *
> + * Authors:
> + *  Paolo Bonzini <pbonzini@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or, at your
> + * option, any later version.  See the COPYING file in the top-level directory.
> + */
> +
> +/* Coccinelle only does limited parsing of headers, and chokes on some idioms
> + * defined in compiler.h and queue.h.  Macros that Coccinelle must know about
> + * in order to parse .c files must be in a separate macro file---which is
> + * exactly what you're staring at now.
> + *
> + * To use this file, add the "--macro-file scripts/cocci-macro-file.h" to the
> + * Coccinelle command line.
> + */
> +
> +/* From qemu/compiler.h */
> +#define QEMU_GNUC_PREREQ(maj, min) 1
> +#define QEMU_NORETURN __attribute__ ((__noreturn__))
> +#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
> +#define QEMU_SENTINEL __attribute__((sentinel))
> +#define QEMU_ARTIFICIAL __attribute__((always_inline, artificial))
> +#define QEMU_PACKED __attribute__((gcc_struct, packed))
> +
> +#define cat(x,y) x ## y
> +#define cat2(x,y) cat(x,y)
> +#define QEMU_BUILD_BUG_ON(x) \
> +    typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
> +
> +#define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
> +
> +#define xglue(x, y) x ## y
> +#define glue(x, y) xglue(x, y)
> +#define stringify(s)	tostring(s)
> +#define tostring(s)	#s
> +
> +#define typeof_field(type, field) typeof(((type *)0)->field)
> +#define type_check(t1,t2) ((t1*)0 - (t2*)0)
> +
> +/* From qemu/queue.h */
> +
> +#define QLIST_HEAD(name, type)                                          \
> +struct name {                                                           \
> +        struct type *lh_first;  /* first element */                     \
> +}
> +
> +#define QLIST_HEAD_INITIALIZER(head)                                    \
> +        { NULL }
> +
> +#define QLIST_ENTRY(type)                                               \
> +struct {                                                                \
> +        struct type *le_next;   /* next element */                      \
> +        struct type **le_prev;  /* address of previous next element */  \
> +}
> +
> +/*
> + * Singly-linked List definitions.
> + */
> +#define QSLIST_HEAD(name, type)                                          \
> +struct name {                                                           \
> +        struct type *slh_first; /* first element */                     \
> +}
> +
> +#define QSLIST_HEAD_INITIALIZER(head)                                    \
> +        { NULL }
> +
> +#define QSLIST_ENTRY(type)                                               \
> +struct {                                                                \
> +        struct type *sle_next;  /* next element */                      \
> +}
> +
> +/*
> + * Simple queue definitions.
> + */
> +#define QSIMPLEQ_HEAD(name, type)                                       \
> +struct name {                                                           \
> +    struct type *sqh_first;    /* first element */                      \
> +    struct type **sqh_last;    /* addr of last next element */          \
> +}
> +
> +#define QSIMPLEQ_HEAD_INITIALIZER(head)                                 \
> +    { NULL, &(head).sqh_first }
> +
> +#define QSIMPLEQ_ENTRY(type)                                            \
> +struct {                                                                \
> +    struct type *sqe_next;    /* next element */                        \
> +}
> +
> +/*
> + * Tail queue definitions.
> + */
> +#define Q_TAILQ_HEAD(name, type, qual)                                  \
> +struct name {                                                           \
> +        qual type *tqh_first;           /* first element */             \
> +        qual type *qual *tqh_last;      /* addr of last next element */ \
> +}
> +#define QTAILQ_HEAD(name, type)                                         \
> +struct name {                                                           \
> +        type *tqh_first;      /* first element */                       \
> +        type **tqh_last;      /* addr of last next element */           \
> +}
> +
> +#define QTAILQ_HEAD_INITIALIZER(head)                                   \
> +        { NULL, &(head).tqh_first }
> +
> +#define Q_TAILQ_ENTRY(type, qual)                                       \
> +struct {                                                                \
> +        qual type *tqe_next;            /* next element */              \
> +        qual type *qual *tqe_prev;      /* address of previous next element */\
> +}
> +#define QTAILQ_ENTRY(type)                                              \
> +struct {                                                                \
> +        type *tqe_next;       /* next element */                        \
> +        type **tqe_prev;      /* address of previous next element */    \
> +}
> 

Having not used Coccinelle yet, what happens if any of these functions
become desynchronized ?


WARNING: multiple messages have this Message-ID (diff)
From: John Snow <jsnow@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: qemu-trivial@nongnu.org, peter.maydell@linaro.org, armbru@redhat.com
Subject: Re: [Qemu-devel] [PATCH v2] add macro file for coccinelle
Date: Tue, 8 Sep 2015 13:30:25 -0400	[thread overview]
Message-ID: <55EF1B31.6070504@redhat.com> (raw)
In-Reply-To: <1441621264-23812-1-git-send-email-pbonzini@redhat.com>



On 09/07/2015 06:21 AM, Paolo Bonzini wrote:
> Coccinelle chokes on some idioms from compiler.h and queue.h.
> Extract those in a macro file, to be used with "--macro-file
> scripts/cocci-macro-file.h".
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  scripts/cocci-macro-file.h | 119 +++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 119 insertions(+)
>  create mode 100644 scripts/cocci-macro-file.h
> 
> diff --git a/scripts/cocci-macro-file.h b/scripts/cocci-macro-file.h
> new file mode 100644
> index 0000000..eceb4be
> --- /dev/null
> +++ b/scripts/cocci-macro-file.h
> @@ -0,0 +1,119 @@
> +/* Macro file for Coccinelle
> + *
> + * Copyright (C) 2015 Red Hat, Inc.
> + *
> + * Authors:
> + *  Paolo Bonzini <pbonzini@redhat.com>
> + *
> + * This work is licensed under the terms of the GNU GPL, version 2 or, at your
> + * option, any later version.  See the COPYING file in the top-level directory.
> + */
> +
> +/* Coccinelle only does limited parsing of headers, and chokes on some idioms
> + * defined in compiler.h and queue.h.  Macros that Coccinelle must know about
> + * in order to parse .c files must be in a separate macro file---which is
> + * exactly what you're staring at now.
> + *
> + * To use this file, add the "--macro-file scripts/cocci-macro-file.h" to the
> + * Coccinelle command line.
> + */
> +
> +/* From qemu/compiler.h */
> +#define QEMU_GNUC_PREREQ(maj, min) 1
> +#define QEMU_NORETURN __attribute__ ((__noreturn__))
> +#define QEMU_WARN_UNUSED_RESULT __attribute__((warn_unused_result))
> +#define QEMU_SENTINEL __attribute__((sentinel))
> +#define QEMU_ARTIFICIAL __attribute__((always_inline, artificial))
> +#define QEMU_PACKED __attribute__((gcc_struct, packed))
> +
> +#define cat(x,y) x ## y
> +#define cat2(x,y) cat(x,y)
> +#define QEMU_BUILD_BUG_ON(x) \
> +    typedef char cat2(qemu_build_bug_on__,__LINE__)[(x)?-1:1] __attribute__((unused));
> +
> +#define GCC_FMT_ATTR(n, m) __attribute__((format(gnu_printf, n, m)))
> +
> +#define xglue(x, y) x ## y
> +#define glue(x, y) xglue(x, y)
> +#define stringify(s)	tostring(s)
> +#define tostring(s)	#s
> +
> +#define typeof_field(type, field) typeof(((type *)0)->field)
> +#define type_check(t1,t2) ((t1*)0 - (t2*)0)
> +
> +/* From qemu/queue.h */
> +
> +#define QLIST_HEAD(name, type)                                          \
> +struct name {                                                           \
> +        struct type *lh_first;  /* first element */                     \
> +}
> +
> +#define QLIST_HEAD_INITIALIZER(head)                                    \
> +        { NULL }
> +
> +#define QLIST_ENTRY(type)                                               \
> +struct {                                                                \
> +        struct type *le_next;   /* next element */                      \
> +        struct type **le_prev;  /* address of previous next element */  \
> +}
> +
> +/*
> + * Singly-linked List definitions.
> + */
> +#define QSLIST_HEAD(name, type)                                          \
> +struct name {                                                           \
> +        struct type *slh_first; /* first element */                     \
> +}
> +
> +#define QSLIST_HEAD_INITIALIZER(head)                                    \
> +        { NULL }
> +
> +#define QSLIST_ENTRY(type)                                               \
> +struct {                                                                \
> +        struct type *sle_next;  /* next element */                      \
> +}
> +
> +/*
> + * Simple queue definitions.
> + */
> +#define QSIMPLEQ_HEAD(name, type)                                       \
> +struct name {                                                           \
> +    struct type *sqh_first;    /* first element */                      \
> +    struct type **sqh_last;    /* addr of last next element */          \
> +}
> +
> +#define QSIMPLEQ_HEAD_INITIALIZER(head)                                 \
> +    { NULL, &(head).sqh_first }
> +
> +#define QSIMPLEQ_ENTRY(type)                                            \
> +struct {                                                                \
> +    struct type *sqe_next;    /* next element */                        \
> +}
> +
> +/*
> + * Tail queue definitions.
> + */
> +#define Q_TAILQ_HEAD(name, type, qual)                                  \
> +struct name {                                                           \
> +        qual type *tqh_first;           /* first element */             \
> +        qual type *qual *tqh_last;      /* addr of last next element */ \
> +}
> +#define QTAILQ_HEAD(name, type)                                         \
> +struct name {                                                           \
> +        type *tqh_first;      /* first element */                       \
> +        type **tqh_last;      /* addr of last next element */           \
> +}
> +
> +#define QTAILQ_HEAD_INITIALIZER(head)                                   \
> +        { NULL, &(head).tqh_first }
> +
> +#define Q_TAILQ_ENTRY(type, qual)                                       \
> +struct {                                                                \
> +        qual type *tqe_next;            /* next element */              \
> +        qual type *qual *tqe_prev;      /* address of previous next element */\
> +}
> +#define QTAILQ_ENTRY(type)                                              \
> +struct {                                                                \
> +        type *tqe_next;       /* next element */                        \
> +        type **tqe_prev;      /* address of previous next element */    \
> +}
> 

Having not used Coccinelle yet, what happens if any of these functions
become desynchronized ?

  parent reply	other threads:[~2015-09-08 17:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-07 10:21 [Qemu-trivial] [PATCH v2] add macro file for coccinelle Paolo Bonzini
2015-09-07 10:21 ` [Qemu-devel] " Paolo Bonzini
2015-09-08 11:10 ` [Qemu-trivial] " Markus Armbruster
2015-09-08 11:10   ` Markus Armbruster
2015-09-08 12:44   ` [Qemu-trivial] " Paolo Bonzini
2015-09-08 12:44     ` Paolo Bonzini
2015-09-08 13:08     ` [Qemu-trivial] " Markus Armbruster
2015-09-08 13:08       ` Markus Armbruster
2015-09-08 13:31   ` [Qemu-trivial] " Marcel Apfelbaum
2015-09-08 13:31     ` [Qemu-devel] [Qemu-trivial] " Marcel Apfelbaum
2015-09-08 17:30 ` John Snow [this message]
2015-09-08 17:30   ` [Qemu-devel] " John Snow
2015-09-08 18:35   ` [Qemu-trivial] " Markus Armbruster
2015-09-08 18:35     ` Markus Armbruster
2015-09-09  9:51     ` [Qemu-trivial] " Paolo Bonzini
2015-09-09  9:51       ` Paolo Bonzini
2015-09-10 21:23       ` [Qemu-trivial] " John Snow
2015-09-10 21:23         ` John Snow
2015-09-15 17:55 ` [Qemu-trivial] " Michael Tokarev
2015-09-15 17:55   ` [Qemu-devel] " Michael Tokarev

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=55EF1B31.6070504@redhat.com \
    --to=jsnow@redhat.com \
    --cc=armbru@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.