From patchwork Mon May 4 19:18:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 6561 Received: (qmail 97758 invoked by alias); 4 May 2015 19:18:51 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 97544 invoked by uid 89); 4 May 2015 19:18:51 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL, BAYES_00, SPF_HELO_PASS, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 04 May 2015 19:18:50 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id t44JIlSs014609 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Mon, 4 May 2015 15:18:48 -0400 Received: from valrhona.uglyboxes.com (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t44JIlRx032509 for ; Mon, 4 May 2015 15:18:47 -0400 Subject: [PATCH v2 16/18] Make the completion API completely opaque. From: Keith Seitz To: gdb-patches@sourceware.org Date: Mon, 04 May 2015 12:18:47 -0700 Message-ID: <20150504191847.20434.36128.stgit@valrhona.uglyboxes.com> In-Reply-To: <20150504191734.20434.68053.stgit@valrhona.uglyboxes.com> References: <20150504191734.20434.68053.stgit@valrhona.uglyboxes.com> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-IsSubscribed: yes 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(-) diff --git a/gdb/cli/cli-cmds.c b/gdb/cli/cli-cmds.c index 2ec2dd3..a73a655 100644 --- a/gdb/cli/cli-cmds.c +++ b/gdb/cli/cli-cmds.c @@ -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. */ diff --git a/gdb/completer.c b/gdb/completer.c index 44dd7e7..9a7af74 100644 --- a/gdb/completer.c +++ b/gdb/completer.c @@ -42,6 +42,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, @@ -833,11 +840,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 * @@ -901,6 +903,14 @@ maybe_add_completion (struct completer_data *cdata, char *name) /* 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, char *name) @@ -927,6 +937,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) { diff --git a/gdb/completer.h b/gdb/completer.h index 8b20ca5..29ff2e9 100644 --- a/gdb/completer.h +++ b/gdb/completer.h @@ -122,11 +122,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. */