Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python: Erroneous transmission of non-8-byte-aligned unions within structs #175

Open
fabiandiewald opened this issue Mar 7, 2022 · 0 comments

Comments

@fabiandiewald
Copy link

Hello,

the issue is related to Python API.

Assuming a union
enum Kind { ONE, TWO };
union ExampleUnion switch(Kind) { case ONE: double foo; case TWO: float bar; };

inside a structure
struct NoIssueStruct { double some8ByteVal; ExampleUnion unionData; };

everything is fine. E.g. publishing
Published NoIssueStruct using foo: some8ByteVal: 42.0, unionData: ExampleUnion(discrimitator=Kind.ONE, foo=3.1415)
Published NoIssueStruct using bar: some8ByteVal: 42.0, unionData: ExampleUnion(discrimitator=Kind.TWO, bar=3.1415)
leads at receiver side to
Content of NoIssueExample some8ByteVal: 42.0, unionData: ExampleUnion(discrimitator=Kind.ONE, foo=3.1415)
Content of NoIssueExample some8ByteVal: 42.0, unionData: ExampleUnion(discrimitator=Kind.TWO, bar=3.1414999961853027)

If the union is not 8 byte aligned, like in e.g.
struct AnotherExampleStruct { float some4ByteVal; ExampleUnion unionData; };

data of the union is not received correctly by a subscriber. Sending side:
Published AnotherExampleStruct using foo: some4ByteVal: 42.0, unionData: ExampleUnion(discrimitator=Kind.ONE, foo=3.1415)
Published AnotherExampleStruct using bar: some4ByteVal: 42.0, unionData: ExampleUnion(discrimitator=Kind.TWO, bar=3.1415)

is received as
Content of AnotherExample some4ByteVal: 42.0, unionData: ExampleUnion(discrimitator=Kind.ONE, foo=3.141498565673828)
Content of AnotherExample some4ByteVal: 42.0, unionData: ExampleUnion(discrimitator=Kind.ONE, foo=0.0)

Full example code:
alignmentIssue.zip

It seems proper 8 byte alignment is done for the union itself (in _calc_union_formats inside ddsutil.py), but aligning properly when the unions are within structs fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant