]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
xdrgen: Fix struct prefix for typedef types in program wrappers
authorChuck Lever <chuck.lever@oracle.com>
Mon, 8 Dec 2025 16:15:32 +0000 (11:15 -0500)
committerChuck Lever <chuck.lever@oracle.com>
Mon, 26 Jan 2026 15:10:58 +0000 (10:10 -0500)
The program templates for decoder/argument.j2 and encoder/result.j2
unconditionally add 'struct' prefix to all types. This is incorrect
when an RPC protocol specification lists a typedef'd basic type or
an enum as a procedure argument or result (e.g., NFSv2's fhandle or
stat), resulting in compiler errors when building generated C code.

Fixes: 4b132aacb076 ("tools: Add xdrgen")
Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
tools/net/sunrpc/xdrgen/generators/__init__.py
tools/net/sunrpc/xdrgen/templates/C/program/decoder/argument.j2
tools/net/sunrpc/xdrgen/templates/C/program/encoder/result.j2

index e22632cf38fbec3cc7186776c70303853a64f248..1d577a986c6cf83d4eef00d763af8d6b20b000d0 100644 (file)
@@ -6,7 +6,7 @@ from pathlib import Path
 from jinja2 import Environment, FileSystemLoader, Template
 
 from xdr_ast import _XdrAst, Specification, _RpcProgram, _XdrTypeSpecifier
-from xdr_ast import public_apis, pass_by_reference, get_header_name
+from xdr_ast import public_apis, pass_by_reference, structs, get_header_name
 from xdr_parse import get_xdr_annotate
 
 
@@ -25,6 +25,7 @@ def create_jinja2_environment(language: str, xdr_type: str) -> Environment:
             environment.globals["annotate"] = get_xdr_annotate()
             environment.globals["public_apis"] = public_apis
             environment.globals["pass_by_reference"] = pass_by_reference
+            environment.globals["structs"] = structs
             return environment
         case _:
             raise NotImplementedError("Language not supported")
index 0b1709cca0d4a4357f832a952c428d3a96091922..19b219dd276d3e2a95e1beb66ca7dafe1b6cc396 100644 (file)
@@ -14,7 +14,11 @@ bool {{ program }}_svc_decode_{{ argument }}(struct svc_rqst *rqstp, struct xdr_
 {% if argument == 'void' %}
        return xdrgen_decode_void(xdr);
 {% else %}
+{% if argument in structs %}
        struct {{ argument }} *argp = rqstp->rq_argp;
+{% else %}
+       {{ argument }} *argp = rqstp->rq_argp;
+{% endif %}
 
        return xdrgen_decode_{{ argument }}(xdr, argp);
 {% endif %}
index 6fc61a5d47b7f5f84a6e321834a997a103994995..746592cfda5628164f9e834bb272c707cf421982 100644 (file)
@@ -14,8 +14,14 @@ bool {{ program }}_svc_encode_{{ result }}(struct svc_rqst *rqstp, struct xdr_st
 {% if result == 'void' %}
        return xdrgen_encode_void(xdr);
 {% else %}
+{% if result in structs %}
        struct {{ result }} *resp = rqstp->rq_resp;
 
        return xdrgen_encode_{{ result }}(xdr, resp);
+{% else %}
+       {{ result }} *resp = rqstp->rq_resp;
+
+       return xdrgen_encode_{{ result }}(xdr, *resp);
+{% endif %}
 {% endif %}
 }