Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Doug Evans <xdje42@gmail.com>
To: Sergio Durigan Junior <sergiodj@redhat.com>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] PR python/16699: GDB Python command completion with overriden complete vs. completer class
Date: Wed, 21 May 2014 07:48:00 -0000	[thread overview]
Message-ID: <m3mweb6096.fsf@sspiff.org> (raw)
In-Reply-To: <m3ha4jevbq.fsf@redhat.com> (Sergio Durigan Junior's message of	"Tue, 20 May 2014 23:09:45 -0300")

Sergio Durigan Junior <sergiodj@redhat.com> writes:
> [...]
> Thanks.  WDYT of the following patch?

Hi.

fwiw it's too bad the ability to plug in different completers isn't more,
I dunno, parameterized (couldn't pick a better term, apologies -
I thought of "object oriented" but that carries its own baggage).
Performing completion obviously involves specifying more than a just
single function (witness the comparison of the completer with specific
functions).

Plus it's more than specifying brkchars.
Witness code like this:

		      /* Many commands which want to complete on
			 file names accept several file names, as
			 in "run foo bar >>baz".  So we don't want
			 to complete the entire text after the
			 command, just the last word.  To this
			 end, we need to find the beginning of the
			 file name by starting at `word' and going
			 backwards.  */
		      for (p = word;
			   p > tmp_command
			     && strchr (gdb_completer_file_name_break_characters, p[-1]) == NULL;
			   p--)
			;

IWBN if a "completer" object described how to do all these three things.
Then the special case code for filename_completer (and location_completer)
in completer.c could disappear.  But maybe that's a patch for another day.


Regarding the hack of using a static local to pass data from
handle_brkchars to handle_completion, I know it's a hacky pragmatic
choice.  To get the reference counting right the code assumes that
if the handle_brkchars phase is done then the handle_completion
phase will be done too, right?  I wonder if a SIGINT could sneak in
there between the two passes (either today or tomorrow).
Maybe the code in cmdpy_completer_helper for handle_brkchars_p could
first check whether resultobj is already non-NULL, and decrement its
reference count before setting it to NULL?  And cmdpy_completer_helper
could be defined to return a borrowed reference to resultobj?
Dunno, just thinking out loud.
Something puzzles me though: If it's ok to cache the completion result from the
handle_brkchars pass to the handle_completion pass, why have two passes?
It feels like there must be a case where this caching of the result
in a static local from one pass to the next won't work.


Another question:
I noticed complete_command doesn't do this two-phase dance
of handle_brkchars followed by handle_completions.  Should it?
It just goes straight to handle_completions.
[Maybe that explains the difference from using TAB.  Dunno off hand.]
It seems like complete_command is trying to hand-code its own
handle_brkchars handling:

static void
complete_command (char *arg, int from_tty)
{
  int argpoint;
  char *point, *arg_prefix;
  VEC (char_ptr) *completions;

  dont_repeat ();

  if (arg == NULL)
    arg = "";
  argpoint = strlen (arg);

  /* complete_line assumes that its first argument is somewhere
     within, and except for filenames at the beginning of, the word to
     be completed.  The following crude imitation of readline's
     word-breaking tries to accomodate this.  */
  point = arg + argpoint;
  while (point > arg)
    {
      if (strchr (rl_completer_word_break_characters, point[-1]) != 0)
        break;
      point--;
    }

  arg_prefix = alloca (point - arg + 1);
  memcpy (arg_prefix, arg, point - arg);
  arg_prefix[point - arg] = 0;

  completions = complete_line (point, arg, argpoint);

  ...
}

TAB and the complete command should work identically of course,
but for your testcase, maybe you should test both just to verify
both work reasonably well (even if not identically).
Given that complete_command doesn't do the two phase dance,
does it work with your patch?
Maybe it does, but IWBN to confirm that.


  reply	other threads:[~2014-05-21  7:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-12 22:49 Sergio Durigan Junior
2014-03-22  2:54 ` Sergio Durigan Junior
2014-04-04 20:41   ` Sergio Durigan Junior
2014-04-10 16:27 ` Tom Tromey
2014-05-03  0:04   ` Sergio Durigan Junior
2014-05-20 19:12     ` Tom Tromey
2014-05-21  2:09       ` Sergio Durigan Junior
2014-05-21  7:48         ` Doug Evans [this message]
2014-07-01  0:59           ` Sergio Durigan Junior
2014-07-08 15:32             ` Jan Kratochvil
2014-07-08 18:17               ` Jan Kratochvil
2014-07-08 20:30               ` Sergio Durigan Junior
2014-08-19 23:02                 ` Sergio Durigan Junior
2014-09-02 16:31                   ` Sergio Durigan Junior
2014-09-03  4:03                     ` Doug Evans
2014-09-03 20:36                       ` Sergio Durigan Junior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m3mweb6096.fsf@sspiff.org \
    --to=xdje42@gmail.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox