agora inbox for pgsql-hackers@postgresql.org
help / color / mirror / Atom feedFrom: Nathan Bossart <nathandbossart@gmail.com>
To: Tom Lane <tgl@sss.pgh.pa.us>
Cc: Chao Li <li.evan.chao@gmail.com>
Cc: Rahila Syed <rahilasyed90@gmail.com>
Cc: Robert Haas <robertmhaas@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: pgindent versus struct members and typedefs
Date: Wed, 6 May 2026 11:13:21 -0500
Message-ID: <aftooa3UABE3AuZf@nathan> (raw)
In-Reply-To: <aftcOkcXCeFKmZbH@nathan>
References: <aS9hkwnkWf3dZIA_@nathan>
<347EA055-D626-414C-B10D-7E70041B9B55@gmail.com>
<509793.1764715875@sss.pgh.pa.us>
<afplW8DvRONDc1yl@nathan>
<729177.1778039019@sss.pgh.pa.us>
<aftTyjC_xWp-n30S@nathan>
<771696.1778079755@sss.pgh.pa.us>
<afta-6zVawsxlt1v@nathan>
<773076.1778080637@sss.pgh.pa.us>
<aftcOkcXCeFKmZbH@nathan>
On Wed, May 06, 2026 at 10:20:26AM -0500, Nathan Bossart wrote:
> Alright. I'll just prepare the patches and post them here for when that
> time comes, then.
Here's a new version of 0001 with a cleaned-up commit message. I've
omitted 0002, since it's just the result of running pgindent after apply
the first one.
--
nathan
From ca254e2440bdf5aeaf0574d133f35dab10d6b570 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathan@postgresql.org>
Date: Wed, 6 May 2026 11:02:22 -0500
Subject: [PATCH v2 1/1] pgindent: Fix spacing after != when member name
matches typedef.
When a struct member name matches a registered typedef, pgindent
removes the space after "!=" (and some other operators), like so:
entry->dsh.dsa_handle !=DSA_HANDLE_INVALID
The problem is that the related code in lexi.c sets last_u_d to
true before jumping to found_typename, causing the next operator to
be classified as unary and suppressing the following space. This
is correct for type names, but not for struct members. For
example, "Datum *x" needs "*" to be unary to suppress the space
before "x". To fix, only set last_u_d before jumping to
found_typename if the typedef name doesn't appear after "." or
"->".
Note that this does not bump INDENT_VERSION. We'll do that just
once after some other changes to pg_bsd_indent are committed.
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/aS9hkwnkWf3dZIA_%40nathan
---
src/tools/pg_bsd_indent/lexi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/tools/pg_bsd_indent/lexi.c b/src/tools/pg_bsd_indent/lexi.c
index 943bf7ce6b0..e846188d6f4 100644
--- a/src/tools/pg_bsd_indent/lexi.c
+++ b/src/tools/pg_bsd_indent/lexi.c
@@ -363,7 +363,8 @@ lexi(struct parser_state *state)
bsearch(s_token, typenames, typename_top + 1,
sizeof(typenames[0]), strcmp_type))) {
state->keyword = 4; /* a type name */
- state->last_u_d = true;
+ if (state->last_token != period && state->last_token != unary_op)
+ state->last_u_d = true;
goto found_typename;
}
} else { /* we have a keyword */
--
2.50.1 (Apple Git-155)
Attachments:
[text/plain] v2-0001-pgindent-Fix-spacing-after-when-member-name-match.patch (1.8K, ../aftooa3UABE3AuZf@nathan/2-v2-0001-pgindent-Fix-spacing-after-when-member-name-match.patch)
download | inline diff:
From ca254e2440bdf5aeaf0574d133f35dab10d6b570 Mon Sep 17 00:00:00 2001
From: Nathan Bossart <nathan@postgresql.org>
Date: Wed, 6 May 2026 11:02:22 -0500
Subject: [PATCH v2 1/1] pgindent: Fix spacing after != when member name
matches typedef.
When a struct member name matches a registered typedef, pgindent
removes the space after "!=" (and some other operators), like so:
entry->dsh.dsa_handle !=DSA_HANDLE_INVALID
The problem is that the related code in lexi.c sets last_u_d to
true before jumping to found_typename, causing the next operator to
be classified as unary and suppressing the following space. This
is correct for type names, but not for struct members. For
example, "Datum *x" needs "*" to be unary to suppress the space
before "x". To fix, only set last_u_d before jumping to
found_typename if the typedef name doesn't appear after "." or
"->".
Note that this does not bump INDENT_VERSION. We'll do that just
once after some other changes to pg_bsd_indent are committed.
Reviewed-by: Chao Li <li.evan.chao@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/aS9hkwnkWf3dZIA_%40nathan
---
src/tools/pg_bsd_indent/lexi.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/tools/pg_bsd_indent/lexi.c b/src/tools/pg_bsd_indent/lexi.c
index 943bf7ce6b0..e846188d6f4 100644
--- a/src/tools/pg_bsd_indent/lexi.c
+++ b/src/tools/pg_bsd_indent/lexi.c
@@ -363,7 +363,8 @@ lexi(struct parser_state *state)
bsearch(s_token, typenames, typename_top + 1,
sizeof(typenames[0]), strcmp_type))) {
state->keyword = 4; /* a type name */
- state->last_u_d = true;
+ if (state->last_token != period && state->last_token != unary_op)
+ state->last_u_d = true;
goto found_typename;
}
} else { /* we have a keyword */
--
2.50.1 (Apple Git-155)
view thread (22+ messages) latest in thread
Message-ID: <aftooa3UABE3AuZf@nathan>
Permalink: ../aftooa3UABE3AuZf@nathan/
Also on: postgresql.org/message-id/aftooa3UABE3AuZf@nathan
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: nathandbossart@gmail.com, tgl@sss.pgh.pa.us, li.evan.chao@gmail.com, rahilasyed90@gmail.com, robertmhaas@gmail.com, pgsql-hackers@lists.postgresql.org
Subject: Re: pgindent versus struct members and typedefs
In-Reply-To: <aftooa3UABE3AuZf@nathan>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox