All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Sameeruddin Shaik <sameeruddin.shaik8@gmail.com>
Cc: Tzvetomir Stoyanov <tz.stoyanov@gmail.com>,
	Linux Trace Devel <linux-trace-devel@vger.kernel.org>
Subject: Re: [PATCH] libtracefs: An API to set the filtering of functions
Date: Fri, 5 Mar 2021 22:39:12 -0500	[thread overview]
Message-ID: <20210305223912.58f4e86c@rorschach.local.home> (raw)
In-Reply-To: <CAK7tX=aASGnr+zyAc+Y_oeqPwOdkwkstJUvypUS=yqNmenCy_Q@mail.gmail.com>

On Sat, 6 Mar 2021 07:25:18 +0530
Sameeruddin Shaik <sameeruddin.shaik8@gmail.com> wrote:

> hi steve,
> 
> i have one doubt.
> >Note, @filters should be of type: const char * const * filters,  as not
> >only is filters pointing to constant strings, the array itself will not be
> >modified.  
> 
> what If the user wants to capture the filters at run time like below ?
> let's say
> 
>   filters = malloc(sizeof(char *));
>         if (!filters)
>                 return 1;
>         printf("please enter the input filters count\n");
>         scanf("%d", &fil_count);
>         while(i < fil_count) {
>                 scanf("%s", buf);
>                 slen = strlen(buf);
>                 if (!slen)
>                         return 1;
>                 filters[i] = calloc(1, slen);
>                 strncpy(filters[i++], buf, slen);
>         }
> at that time, this declaration will be problematic right?, because we
> are trying to modify

No it wont. You can assign const pointers to dynamic pointers, but not
the other way around. It's a way to show that the function you are
calling wont do anything with the array you pass to it.

> the read-only memory. Are we expecting the user to supply filters at
> compile time like below?
> const char * const *filters = {"kvm_pmu_reset", "kvm_pmu_init",
> "dir_item_err", NULL};

No, as explained above.

> 
> Tzvetomir & steve,
> >Since a triple pointer is difficult to manage in the code, you could have:
> >
> >       const char **e = NULL;
> >
> >
> >               if (errs) {
> >                        e = realloc(sizeof(*e), j + 1);
> >                        e[j++] = filters[i];
> >               }
> >
> >Then at the end:
> >
> >       if (errs)
> >                *errs = e;  
> i have a concern here
> when a double pointer is doing our work here without any overhead, why
> we want to make it a triple pointer?

What overhead? A string is a pointer, an array of strings is a double
pointer, and passing in the address to an array of strings so you can
modify that array is a triple pointer, and that's exactly what you need
for errs.

This is basic C coding, nothing special here.

I'm curious to why you picked this particular API to implement. Is
there something you are planning on using this for?

-- Steve

  reply	other threads:[~2021-03-06  3:39 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-06 11:20 [PATCH] libtracefs: An API to set the filtering of functions Sameeruddin shaik
2021-03-05 12:20 ` Tzvetomir Stoyanov
2021-03-05 14:39   ` Steven Rostedt
2021-03-05 14:54     ` Steven Rostedt
2021-03-06  1:55       ` Sameeruddin Shaik
2021-03-06  3:39         ` Steven Rostedt [this message]
2021-03-06  4:29           ` Sameeruddin Shaik
2021-03-06  5:19             ` Steven Rostedt
2021-03-06 15:05         ` Steven Rostedt
2021-03-08 23:53           ` Sameeruddin Shaik
  -- strict thread matches above, loose matches on Subject: below --
2021-03-10 16:21 Sameeruddin shaik
2021-03-10  5:28 ` Tzvetomir Stoyanov
2021-03-10 16:51 ` Sameeruddin Shaik
2021-03-10  5:28   ` Tzvetomir Stoyanov
2021-03-02 17:15 Sameeruddin shaik
2021-03-01 18:17 ` Steven Rostedt
2021-03-02  4:21   ` Tzvetomir Stoyanov
2021-03-02  5:14     ` Sameeruddin Shaik
2021-03-02 13:15       ` Steven Rostedt
2021-03-03  1:16   ` Sameeruddin Shaik
2021-03-02  1:28     ` Steven Rostedt
2021-03-04  8:59       ` Tzvetomir Stoyanov
2021-03-04  9:43         ` Sameeruddin Shaik

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=20210305223912.58f4e86c@rorschach.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=sameeruddin.shaik8@gmail.com \
    --cc=tz.stoyanov@gmail.com \
    /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.