From: Khushal Chitturi <kc9282016@gmail.com>
To: chuck.lever@oracle.com, jlayton@kernel.org
Cc: neil@brown.name, okorniev@redhat.com, Dai.Ngo@oracle.com,
tom@talpey.com, linux-nfs@vger.kernel.org,
linux-kernel@vger.kernel.org,
Khushal Chitturi <kc9282016@gmail.com>
Subject: [PATCH] xdrgen: Handle typedef void types
Date: Wed, 12 Nov 2025 02:27:38 +0530 [thread overview]
Message-ID: <20251111205738.4574-1-kc9282016@gmail.com> (raw)
This patch Handle typedef void in XDR Generator. Previously, such
declarations triggered a NotImplementedError in typedef.py.
This change adds handling for _XdrVoid AST nodes within the
typedef generator. When an XDR includes a typedef void,
the generator now recognizes _XdrVoid nodes and emits the
respective C typedefs and associated functions. New Jinja2
templates were introduced for encoder, decoder, declaration,
definition, and maxsize generation. The XDR grammar was
updated so that void typedefs can be parsed properly
Tested by running xdrgen on tests/test.x containing a typedef void
declaration. The tool now runs and produces the encoder, decoder,
and typedef outputs across source, definitions, and declarations.
Signed-off-by: Khushal Chitturi <kc9282016@gmail.com>
---
tools/net/sunrpc/xdrgen/generators/typedef.py | 12 ++++++++----
tools/net/sunrpc/xdrgen/grammars/xdr.lark | 2 +-
.../xdrgen/templates/C/typedef/declaration/void.j2 | 2 ++
.../xdrgen/templates/C/typedef/decoder/void.j2 | 6 ++++++
.../xdrgen/templates/C/typedef/definition/void.j2 | 2 ++
.../xdrgen/templates/C/typedef/encoder/void.j2 | 6 ++++++
.../xdrgen/templates/C/typedef/maxsize/void.j2 | 2 ++
7 files changed, 27 insertions(+), 5 deletions(-)
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/declaration/void.j2
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/void.j2
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/definition/void.j2
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/encoder/void.j2
create mode 100644 tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/void.j2
diff --git a/tools/net/sunrpc/xdrgen/generators/typedef.py b/tools/net/sunrpc/xdrgen/generators/typedef.py
index fab72e9d6915..f49ae26c4830 100644
--- a/tools/net/sunrpc/xdrgen/generators/typedef.py
+++ b/tools/net/sunrpc/xdrgen/generators/typedef.py
@@ -58,7 +58,8 @@ def emit_typedef_declaration(environment: Environment, node: _XdrDeclaration) ->
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
- raise NotImplementedError("<void> typedef not yet implemented")
+ template = get_jinja2_template(environment, "declaration", node.template)
+ print(template.render(name=node.name))
else:
raise NotImplementedError("typedef: type not recognized")
@@ -104,7 +105,8 @@ def emit_type_definition(environment: Environment, node: _XdrDeclaration) -> Non
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
- raise NotImplementedError("<void> typedef not yet implemented")
+ template = get_jinja2_template(environment, "definition", node.template)
+ print(template.render(name=node.name))
else:
raise NotImplementedError("typedef: type not recognized")
@@ -165,7 +167,8 @@ def emit_typedef_decoder(environment: Environment, node: _XdrDeclaration) -> Non
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
- raise NotImplementedError("<void> typedef not yet implemented")
+ template = get_jinja2_template(environment, "decoder", node.template)
+ print(template.render(name=node.name))
else:
raise NotImplementedError("typedef: type not recognized")
@@ -225,7 +228,8 @@ def emit_typedef_encoder(environment: Environment, node: _XdrDeclaration) -> Non
elif isinstance(node, _XdrOptionalData):
raise NotImplementedError("<optional_data> typedef not yet implemented")
elif isinstance(node, _XdrVoid):
- raise NotImplementedError("<void> typedef not yet implemented")
+ template = get_jinja2_template(environment, "encoder", node.template)
+ print(template.render(name=node.name))
else:
raise NotImplementedError("typedef: type not recognized")
diff --git a/tools/net/sunrpc/xdrgen/grammars/xdr.lark b/tools/net/sunrpc/xdrgen/grammars/xdr.lark
index 7c2c1b8c86d1..d8c5f7130d83 100644
--- a/tools/net/sunrpc/xdrgen/grammars/xdr.lark
+++ b/tools/net/sunrpc/xdrgen/grammars/xdr.lark
@@ -8,7 +8,7 @@ declaration : "opaque" identifier "[" value "]" -> fixed_
| type_specifier identifier "<" [ value ] ">" -> variable_length_array
| type_specifier "*" identifier -> optional_data
| type_specifier identifier -> basic
- | "void" -> void
+ | "void" [identifier] -> void
value : decimal_constant
| hexadecimal_constant
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/declaration/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/declaration/void.j2
new file mode 100644
index 000000000000..22c5226ee526
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/declaration/void.j2
@@ -0,0 +1,2 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+typedef void {{ name }};
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/void.j2
new file mode 100644
index 000000000000..ed9e2455b36f
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/decoder/void.j2
@@ -0,0 +1,6 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+static inline bool
+xdrgen_decode_{{ name }}(struct xdr_stream *xdr, void *ptr)
+{
+ return true;
+}
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/definition/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/definition/void.j2
new file mode 100644
index 000000000000..22c5226ee526
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/definition/void.j2
@@ -0,0 +1,2 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+typedef void {{ name }};
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/encoder/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/encoder/void.j2
new file mode 100644
index 000000000000..47d48af81546
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/encoder/void.j2
@@ -0,0 +1,6 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+static inline bool
+xdrgen_encode_{{ name }}(struct xdr_stream *xdr, const void *ptr)
+{
+ return true;
+}
diff --git a/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/void.j2 b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/void.j2
new file mode 100644
index 000000000000..129374200ad0
--- /dev/null
+++ b/tools/net/sunrpc/xdrgen/templates/C/typedef/maxsize/void.j2
@@ -0,0 +1,2 @@
+{# SPDX-License-Identifier: GPL-2.0 #}
+#define {{ macro }} 0
--
2.51.2
next reply other threads:[~2025-11-11 20:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-11 20:57 Khushal Chitturi [this message]
2025-11-11 22:57 ` [PATCH] xdrgen: Handle typedef void types 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=20251111205738.4574-1-kc9282016@gmail.com \
--to=kc9282016@gmail.com \
--cc=Dai.Ngo@oracle.com \
--cc=chuck.lever@oracle.com \
--cc=jlayton@kernel.org \
--cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).