On 20.06.2017 08:42, Dmitry V. Levin wrote: > 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? This functions will be later used for parsing of user-supplied expression. If enum is used, I will need additional table to parse string to enum, because preprocessor wrapper will not work for user-supplied strings.
signature.asc
Description: OpenPGP digital 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