Skip to content
/ linux Public

Commit a3a05e5

Browse files
chuckleverSasha Levin
authored andcommitted
xdrgen: Fix struct prefix for typedef types in program wrappers
[ Upstream commit bf0fe9a ] 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: 4b132aa ("tools: Add xdrgen") Signed-off-by: Chuck Lever <chuck.lever@oracle.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 771ba4c commit a3a05e5

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

tools/net/sunrpc/xdrgen/generators/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from jinja2 import Environment, FileSystemLoader, Template
77

88
from xdr_ast import _XdrAst, Specification, _RpcProgram, _XdrTypeSpecifier
9-
from xdr_ast import public_apis, pass_by_reference, get_header_name
9+
from xdr_ast import public_apis, pass_by_reference, structs, get_header_name
1010
from xdr_parse import get_xdr_annotate
1111

1212

@@ -22,6 +22,7 @@ def create_jinja2_environment(language: str, xdr_type: str) -> Environment:
2222
environment.globals["annotate"] = get_xdr_annotate()
2323
environment.globals["public_apis"] = public_apis
2424
environment.globals["pass_by_reference"] = pass_by_reference
25+
environment.globals["structs"] = structs
2526
return environment
2627
case _:
2728
raise NotImplementedError("Language not supported")

tools/net/sunrpc/xdrgen/templates/C/program/decoder/argument.j2

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ bool {{ program }}_svc_decode_{{ argument }}(struct svc_rqst *rqstp, struct xdr_
1414
{% if argument == 'void' %}
1515
return xdrgen_decode_void(xdr);
1616
{% else %}
17+
{% if argument in structs %}
1718
struct {{ argument }} *argp = rqstp->rq_argp;
19+
{% else %}
20+
{{ argument }} *argp = rqstp->rq_argp;
21+
{% endif %}
1822

1923
return xdrgen_decode_{{ argument }}(xdr, argp);
2024
{% endif %}

tools/net/sunrpc/xdrgen/templates/C/program/encoder/result.j2

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,14 @@ bool {{ program }}_svc_encode_{{ result }}(struct svc_rqst *rqstp, struct xdr_st
1414
{% if result == 'void' %}
1515
return xdrgen_encode_void(xdr);
1616
{% else %}
17+
{% if result in structs %}
1718
struct {{ result }} *resp = rqstp->rq_resp;
1819

1920
return xdrgen_encode_{{ result }}(xdr, resp);
21+
{% else %}
22+
{{ result }} *resp = rqstp->rq_resp;
23+
24+
return xdrgen_encode_{{ result }}(xdr, *resp);
25+
{% endif %}
2026
{% endif %}
2127
}

0 commit comments

Comments
 (0)