[v3,17/19] Make the completion API completely opaque.
Commit Message
There are no revisions in this version.
--
Now that the completion API is passing around a structure holding
its internal data, there is no need to expose any of this data and
other settings to other modules.
This patch removes global access to max_completions and
introduces a new API function, get_maximum_completions (void), which
other modules may use to query the current completion maximum.
The API will be expanded as necessary in subsequent patches.
gdb/ChangeLog
* cli/cli-cmds.c (complete_command): Use get_maximum_completions
instead of accessing the global max_completions.
* completer.c (max_completions): Move definition earlier and
make static.
(get_maximum_completions): New function.
(throw_max_completions_reached_error): Add comment.
* completer.h (max_completions): Remove declaration.
(get_maximum_completions): New declaration.
---
gdb/cli/cli-cmds.c | 4 ++--
gdb/completer.c | 22 +++++++++++++++++-----
gdb/completer.h | 8 ++++----
3 files changed, 23 insertions(+), 11 deletions(-)
Comments
Keith Seitz <keiths@redhat.com> writes:
> There are no revisions in this version.
>
> --
>
> Now that the completion API is passing around a structure holding
> its internal data, there is no need to expose any of this data and
> other settings to other modules.
>
> This patch removes global access to max_completions and
> introduces a new API function, get_maximum_completions (void), which
> other modules may use to query the current completion maximum.
>
> The API will be expanded as necessary in subsequent patches.
>
> gdb/ChangeLog
>
> * cli/cli-cmds.c (complete_command): Use get_maximum_completions
> instead of accessing the global max_completions.
> * completer.c (max_completions): Move definition earlier and
> make static.
> (get_maximum_completions): New function.
> (throw_max_completions_reached_error): Add comment.
> * completer.h (max_completions): Remove declaration.
> (get_maximum_completions): New declaration.
IIUC, we generally don't export accessors for parameters,
we just export the parameter. But I don't know if that's
a hard and fast rule.
It'd be nice if grep max_completions found both
the variable and the function.
Ok with that change.
@@ -248,7 +248,7 @@ complete_command (char *arg, int from_tty)
dont_repeat ();
- if (max_completions == 0)
+ if (get_maximum_completions () == 0)
{
/* Only print this for non-mi frontends. An MI frontend may not
be able to handle this. */
@@ -307,7 +307,7 @@ complete_command (char *arg, int from_tty)
xfree (prev);
VEC_free (char_ptr, completions);
- if (size == max_completions)
+ if (size == get_maximum_completions ())
{
/* ARG_PREFIX and POINT are included in the output so that emacs
will include the message in the output. */
@@ -43,6 +43,13 @@
#include "completer.h"
+/* Maximum number of candidates to consider before the completer
+ bails by throwing MAX_COMPLETIONS_REACHED_ERROR. Negative values
+ disable limiting. */
+
+#define DEFAULT_MAX_COMPLETIONS 200
+static int max_completions = DEFAULT_MAX_COMPLETIONS;
+
/* Prototypes for local functions. */
static
char *line_completion_function (const char *text, int matches,
@@ -813,11 +820,6 @@ complete_line_internal (struct completer_data *cdata,
return list;
}
-/* See completer.h. */
-
-#define DEFAULT_MAX_COMPLETIONS 200
-int max_completions = DEFAULT_MAX_COMPLETIONS;
-
/* Allocate a new completer data structure. */
static struct completer_data *
@@ -907,6 +909,14 @@ completer_strdup (const char *match, const char *text, const char *word)
/* See completer.h. */
+int
+get_maximum_completions (void)
+{
+ return max_completions;
+}
+
+/* See completer.h. */
+
enum add_completion_status
add_completion (struct completer_data *cdata, VEC (char_ptr) **result,
const char *match, const char *text, const char *word)
@@ -934,6 +944,8 @@ add_completion (struct completer_data *cdata, VEC (char_ptr) **result,
return ADD_COMPLETION_OK;
}
+/* See completer.h. */
+
void
throw_max_completions_reached_error (void)
{
@@ -126,11 +126,11 @@ extern const char *skip_quoted_chars (const char *, const char *,
extern const char *skip_quoted (const char *);
-/* Maximum number of candidates to consider before the completer
- bails by throwing MAX_COMPLETIONS_REACHED_ERROR. Negative values
- disable limiting. */
+/* Get the maximum number of completions that are permitted before the
+ completer throws a MAX_COMPLETIONS_REACHED_ERROR. Negative values
+ mean completion limiting is entirely disabled. */
-extern int max_completions;
+extern int get_maximum_completions (void);
/* Return values for add_completion. */