Skip to content

Commit ce5a75d

Browse files
committed
xdrgen: XDR width for union types
Not yet complete. The tool doesn't do any math yet. Thus, even though the maximum XDR width of a union is the width of the union enumerator plus the width of its largest arm, we're using the sum of all the elements of the union for the moment. This means that buffer size requirements are overestimated, and that the generated maxsize macro cannot yet be used for determining data element alignment in the XDR buffer. Signed-off-by: Chuck Lever <[email protected]>
1 parent 447dc1e commit ce5a75d

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

tools/net/sunrpc/xdrgen/xdr_ast.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,35 @@ class _XdrUnion(_XdrAst):
450450
cases: List[_XdrCaseSpec]
451451
default: _XdrDeclaration
452452

453+
def max_width(self) -> int:
454+
"""Return width of type in XDR_UNITS"""
455+
max_width = 0
456+
for case in self.cases:
457+
if case.arm.max_width() > max_width:
458+
max_width = case.arm.max_width()
459+
if self.default:
460+
if self.default.arm.max_width() > max_width:
461+
max_width = self.default.arm.max_width()
462+
return 1 + max_width
463+
464+
def symbolic_width(self) -> List:
465+
"""Return list containing XDR width of type's components"""
466+
max_width = 0
467+
for case in self.cases:
468+
if case.arm.max_width() > max_width:
469+
max_width = case.arm.max_width()
470+
width = case.arm.symbolic_width()
471+
if self.default:
472+
if self.default.arm.max_width() > max_width:
473+
max_width = self.default.arm.max_width()
474+
width = self.default.arm.symbolic_width()
475+
return symbolic_widths[self.discriminant.name] + width
476+
453477
def __post_init__(self):
454478
structs.add(self.name)
455479
pass_by_reference.add(self.name)
480+
max_widths[self.name] = self.max_width()
481+
symbolic_widths[self.name] = self.symbolic_width()
456482

457483

458484
@dataclass

0 commit comments

Comments
 (0)