From: Yudi Yang <jy103@rice.edu>
To: Julia Lawall <julia.lawall@inria.fr>
Cc: cocci@inria.fr
Subject: Re: [cocci] Match and print size of allocation
Date: Sat, 15 Apr 2023 01:13:28 -0500 [thread overview]
Message-ID: <da277553-d798-4dd0-a0bb-f641f41a16bf@Spark> (raw)
[-- Attachment #1: Type: text/plain, Size: 1481 bytes --]
Hello Julia,
Thank you for your answer! I have modified my code:
@@
expression E, SIZE, N;
statement S;
@@
(
E = malloc(SIZE);
+ printf("%d", SIZE);
|
E = calloc(N, SIZE);
+ printf("%d", (N) * (SIZE));
)
However, it cannot match initializations and if-statements.
I am not quite understanding your "malloc(SIZE)@S" solution.
Could you point on how to use the it, or perhaps some related links?
Thank you,
Yudi
> On Apr 15, Reiwa 5, at 12:43 AM, Julia Lawall <julia.lawall@inria.fr> wrote:
>
>
>
> On Fri, 14 Apr 2023, Yudi Yang wrote:
>
> > Hello,
> >
> > I would like to match the size of allocation, I am wondering if I write the following:
> >
> > @print@
> > expression N, SIZE;
> > @@
> >
> > (
> > malloc(SIZE);
>
> Code doesn't usually contain just malloc(...); because then the return
> value would be thrown away. You can write x = malloc(SIZE); for an
> expression metavariable x. If malloc can be used in other contexts, eg an
> if header, then you can write malloc(SIZE)@S where S is a statement
> metavariable. I think that that will allow the printf to be added after
> the innermost statement containing the call to malloc.
>
> julia
>
> > |
> > calloc(N, SIZE);
> > )
> > + printf(“Allocation: %d\n", (N) * (SIZE));
> >
> > I am not sure if I could set the default value for N in the malloc case, or is there anything I should do to make it correct.
> >
> > Best, Yudi
> >
> >
[-- Attachment #2: Type: text/html, Size: 4221 bytes --]
next reply other threads:[~2023-04-15 7:23 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-15 6:13 Yudi Yang [this message]
2023-04-15 7:31 ` [cocci] Match and print size of allocation Julia Lawall
2023-04-15 16:40 ` Yudi Yang
2023-04-15 16:53 ` Julia Lawall
2023-04-17 17:48 ` Yudi Yang
[not found] ` <alpine.DEB.2.22.394.2304172139580.2883@hadrien>
2023-04-17 23:26 ` Yudi Yang
[not found] <eccc2924-6657-4776-84f1-3d8413904cf2@Spark>
2023-04-14 22:36 ` Yudi Yang
2023-04-15 5:40 ` Julia Lawall
2023-04-15 5:42 ` 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:
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=da277553-d798-4dd0-a0bb-f641f41a16bf@Spark \
--to=jy103@rice.edu \
--cc=cocci@inria.fr \
--cc=julia.lawall@inria.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).