Linux NFS development
 help / color / mirror / Atom feed
From: Chuck Lever <cel@kernel.org>
To: NeilBrown <neil@brown.name>, Jeff Layton <jlayton@kernel.org>,
	Olga Kornievskaia <okorniev@redhat.com>,
	Dai Ngo <dai.ngo@oracle.com>, Tom Talpey <tom@talpey.com>
Cc: <linux-nfs@vger.kernel.org>
Subject: [PATCH v1 3/4] xdrgen: Register optional-data names only for typedefs
Date: Sat, 24 Oct 2026 21:46:15 -0400	[thread overview]
Message-ID: <20261025014616.22236-4-cel@kernel.org> (raw)
In-Reply-To: <20261025014616.22236-1-cel@kernel.org>

_XdrOptionalData adds its name to structs and to pass_by_reference
when it is constructed, and that name is the field name when the
declaration is a member of a struct or a union. Both sets are
otherwise keyed by type name: _XdrDefinedType consults structs to
emit a "struct" classifier, and the encoder templates consult
pass_by_reference to pass an argument by address. A field named
after a scalar typedef turns every later reference to that typedef
into a struct passed by reference, and the generated C does not
compile. No in-tree .x file declares such a field, so the generated
headers do not change.

Add the name only when the optional-data declaration is a typedef,
beside the width registration in _XdrTypedef.

Signed-off-by: Chuck Lever <cel@kernel.org>
---
 tools/net/sunrpc/xdrgen/xdr_ast.py | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/tools/net/sunrpc/xdrgen/xdr_ast.py b/tools/net/sunrpc/xdrgen/xdr_ast.py
index a3595aa40a57..6b012f0f7a42 100644
--- a/tools/net/sunrpc/xdrgen/xdr_ast.py
+++ b/tools/net/sunrpc/xdrgen/xdr_ast.py
@@ -284,10 +284,6 @@ class _XdrOptionalData(_XdrDeclaration):
         """Return list containing XDR width of type's components"""
         return ["XDR_bool"]
 
-    def __post_init__(self):
-        structs.add(self.name)
-        pass_by_reference.add(self.name)
-
 
 @dataclass
 class _XdrBasic(_XdrDeclaration):
@@ -440,6 +436,9 @@ class _XdrTypedef(_XdrAst):
     def __post_init__(self):
         if isinstance(self.declaration, (_XdrVariableLengthOpaque, _XdrString)):
             varlen_object_typedefs[self.declaration.name] = self.declaration.maxsize
+        if isinstance(self.declaration, _XdrOptionalData):
+            structs.add(self.declaration.name)
+            pass_by_reference.add(self.declaration.name)
         if isinstance(self.declaration, _XdrBasic):
             new_type = self.declaration
             if isinstance(new_type.spec, _XdrDefinedType):
-- 
2.56.0


  parent reply	other threads:[~2026-10-25 16:42 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-25  1:46 [PATCH v1 0/4] xdrgen fixes Chuck Lever
2026-10-25  1:46 ` [PATCH v1 1/4] xdrgen: Handle a union whose arms are all void Chuck Lever
2026-10-25  1:46 ` [PATCH v1 2/4] xdrgen: Key the width tables by type name only Chuck Lever
2026-10-25  1:46 ` Chuck Lever [this message]
2026-10-25  1:46 ` [PATCH v1 4/4] xdrgen: Take a union's numeric discriminant width from the declaration Chuck Lever

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=20261025014616.22236-4-cel@kernel.org \
    --to=cel@kernel.org \
    --cc=dai.ngo@oracle.com \
    --cc=jlayton@kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=neil@brown.name \
    --cc=okorniev@redhat.com \
    --cc=tom@talpey.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