Re: [PATCH] Tab completion for ALTER DATABASE … SET TABLESPACE

From: Andres Freund <andres(at)anarazel(dot)de>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Thomas Munro <thomas(dot)munro(at)enterprisedb(dot)com>, Arthur Zakirov <a(dot)zakirov(at)postgrespro(dot)ru>, Dagfinn Ilmari Mannsåker <ilmari(at)ilmari(dot)org>, Pg Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: [PATCH] Tab completion for ALTER DATABASE … SET TABLESPACE
Date: 2018-09-21 05:52:01
Message-ID: 20180921055201.3qwuv2ojhsxzt56u@alap3.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 2018-09-20 16:19:26 -0700, Andres Freund wrote:
> On 2018-09-20 19:03:16 -0400, Tom Lane wrote:
> > Andres Freund <andres(at)anarazel(dot)de> writes:
> > > On 2018-09-20 18:38:36 -0400, Tom Lane wrote:
> > >> hmmm ... but even with variadic, C's macro facility is so weak that
> > >> I'm not sure we can reimplement these with it. What would the
> > >> expansion look like?
> >
> > > There's a dirty hack to count arguments in vararg macros:
> > > https://groups.google.com/d/msg/comp.std.c/d-6Mj5Lko_s/5fW1bP6T3RIJ
> >
> > Doesn't seem to help for this case. What we really want is to expand
> > a given pattern once for each variadic argument, and I don't see how
> > to get there from here.
>
> Depends on whether your goal is to simplify *using* the macro, or the
> infrastructure for the macro. Afaict it should be relatively
> straightforward to use a, possibly simplified, macro like referenced
> above to have TailMatches(...), TailMatchesCS(...), Matches(...) that
> then expand to the current *N macros.
>
>
> > Although maybe I'm thinking too much inside-the-box. The expansion
> > doesn't necessarily have to be identical to the code the macros
> > generate today. In fact, that code is kinda bulky. I wonder if
> > we could go over to something involving a variadic function, or
> > maybe an array of string-pointer constants?
>
> Yea, that might be a way to simplify both the macros and the use of the
> macros. Assuming we have something like PP_NARG, ISTM it should be
> relatively straightforward to define something like
>
> #define Matches(...) CheckMatchesFor(PP_NARG(__VA_ARGS__), __VA_ARGS__)
>
> and then have a CheckMatchesFor() first check previous_words_count, and
> then just have a simple for loop through previous_words[] - afaict the
> number of arguments ought to suffice to make that possible?

Here's a very quick-and-dirty implementation of this approach. Some very
very brief testing seems to indicate it works, although I'm sure not
perfectly.

The current duplication of the new functions doing the actual checking
(like CheckMatchesFor(), CheckTailMatchesFor()) would probably need to
be reduced. But I don't want to invest actual time before we decide that
this could be something we'd actually want to pursue.

Greetings,

Andres Freund

Attachment Content-Type Size
varargify-tab-complete.diff text/x-diff 125.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Michael Paquier 2018-09-21 06:01:33 Re: Changing the setting of wal_sender_timeout per standby
Previous Message Tsunakawa, Takayuki 2018-09-21 05:37:42 RE: Changing the setting of wal_sender_timeout per standby