Re: [PATCH 3/3 v2] Implement completion limiting

Doug Evans
2014-11-24T06:09:21Z

Gary Benson <gbenson@redhat.com> writes:
> This commit adds a new exception, TOO_MANY_COMPLETIONS_ERROR, to be
> thrown whenever the completer has generated too many possibilities to
> be useful. A new user-settable variable, "max_completions", is added
> to control this behaviour. A top-level completion limit is added to
> complete_line_internal, as the final check to ensure the user never
> sees too many completions. An additional limit is added to
> default_make_symbol_completion_list_break_on, to halt time-consuming
> symbol table expansions.
>
> gdb/ChangeLog:
>
> PR cli/9007
> PR cli/11920
> PR cli/15548
> * common/common-exceptions.h (enum errors)
> <TOO_MANY_COMPLETIONS_ERROR>: New value.
> * completer.h (completion_tracker_t): New typedef.
> (new_completion_tracker): New declaration.
> (make_cleanup_free_completion_tracker): Likewise.
> (maybe_limit_completions): Likewise.
> * completer.c [TUI]: Include tui/tui.h and tui/tui-io.h.
> (max_completions): New static variable.
> (new_completion_tracker): New function.
> (make_cleanup_free_completion_tracker): Likewise.
> (maybe_limit_completions): Likewise.
> (complete_line_internal): Do not generate any completions if
> max_completions = 0. Limit the number of completions if
> max_completions >= 0.
> (line_completion_function): Handle TOO_MANY_COMPLETIONS_ERROR.
> (_initialize_completer): New declaration and function.
> * symtab.c: Include completer.h.
> (completion_tracker): New static variable.
> (completion_list_add_name): Call maybe_limit_completions.
> (default_make_symbol_completion_list_break_on): Maintain
> completion_tracker across calls to completion_list_add_name.
> * NEWS (New Options): Mention set/show max-completions.

Hi.

I only skimmed this patch set.
I want to give it a more thorough look
once the patch has been updated to apply
to current HEAD.

Thanks very much for working on this!

> +void
> +maybe_limit_completions (completion_tracker_t tracker, char *name)
> +{
> + if (max_completions < 0)
> + return;
> +
> + if (tracker != NULL)
> + {
> + void **slot = htab_find_slot (tracker, name, INSERT);
> +
> + if (*slot != HTAB_EMPTY_ENTRY)
> + return;
> +
> + if (htab_elements (tracker) <= max_completions)
> + {
> + *slot = name;
> + return;
> + }
> + }
> +
> + throw_error (TOO_MANY_COMPLETIONS_ERROR,
> + _("Too many possibilities."));
> +}

This will throw an error if tracker == NULL.
Is that intended?