Re: [PATCH] libtracefs: An API to set the filtering of functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



>We are happy to have you working with us.
>
>I asked because the API you happened to pick is probably the most
>complex one to implement compared to some of the other APIs listed in the
>bugzilla, which is why I asked if you planned on doing anything with it, as
>it is also one of the more crucial APIs to get right.

At first I thought, my work will be done, if I write to that file, but
complexity
increased gradually, but let me try, since i have started i will finish this.

>So yes, let's go with "const char **" as we want to show that the
>strings will not be modified, and have "const char ***" for errs.

okay then i will change the errors declaration alone.

Thanks
sameer.

On Sat, Mar 6, 2021 at 8:35 PM Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> On Sat, 6 Mar 2021 07:25:18 +0530
> Sameeruddin Shaik <sameeruddin.shaik8@xxxxxxxxx> wrote:
>
> > 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
> > 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};
>
> OK, my apologies, I see the issue that you are having, and you are
> correct.
>
> Because newer compiles will warn if you pass "char **" to a
> "const char * const *" parameter. Because it assumes that the two types
> are different, even when they shouldn't be. I'm not sure why the
> compiler wont let you pass in a char ** to a const char * const *, but
> it does indeed make them different.
>
> Even though there's ways to always pass strings via this logic, (you
> can create a "const char **" array and assign it to the dynamic one,
> and pass that in just fine). I looked at other prototypes, and see that
> the common method is.
>
>  const char **
>
> A couple do the "const char * const *" but they look to be special
> cases.
>
> So yes, let's go with "const char **" as we want to show that the
> strings will not be modified, and have "const char ***" for errs.
>
> Thanks!
>
> -- Steve



[Index of Archives]     [Linux USB Development]     [Linux USB Development]     [Linux Audio Users]     [Yosemite Hiking]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux