On Mon, Jun 19, 2017 at 08:37:32PM +0700, Nikolay Marchuk wrote: > On 19.06.2017 11:08, Eugene Syromiatnikov wrote: > >> + if (!strncmp(name, str, len)) { > > Not sure whether strncmp is better than strcmp here, since this function > > is not called with user-supplied str at all. > > > > Or, do you expect that these will work with user-supplied strings in the > > future? > > > > BTW, personally, I don't think that this needs to be string-keyed. > > Something as simple as > > > > enum filter_type_name { > > FILTER_TYPE_syscall, > > FILTER_TYPE_fd, > > }; > > > > #define FILTER_TYPE(name) \ > > [FILTER_TYPE_ ## name] = { \ > > .parse_filter = parse_ ## name ## _filter, \ > > .run_filter = run_ ## name ## _filter, \ > > ._free_priv_data = free_ ## name ## _filter, \ > > } > > > > static const struct filter_type { > > void* (*parse_filter)(const char *, const char *const); > > bool (*run_filter)(struct tcb *, void *); > > void (*_free_priv_data)(void *); > > } filter_types[] = { > > FILTER_TYPE(syscall), > > FILTER_TYPE(fd), > > }; > > > > struct filter * > > add_filter_to_array(struct filter **filters, unsigned int *nfilters, > > enum filter_type_name name) > > { > > *filters = xreallocarray(*filters, ++(*nfilters), > > sizeof(struct filter)); > > struct filter *filter = &((*filters)[*nfilters - 1]); > > filter->type = filters[name]; > > return filter; > > } > > > > [...] > > > > #define create_filter(a, t) actual_create_filter(a, FILTER_TYPE_ ## t) > > > > [...] > > > > create_filter(action, fd); > > > > should also suffice. > I am going to use string-keyed filters and actions for new filtering > language parsing and enum is not sufficient.
I'm not sure I follow this; how could it be that enum is not sufficient? -- ldv
signature.asc
Description: PGP signature
------------------------------------------------------------------------------ Check out the vibrant tech community on one of the world's most engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________ Strace-devel mailing list Strace-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/strace-devel