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

Incorrect generated serialization code for multi-dimensional arrays that use typedef #4453

Open
sonndinh opened this issue Jan 31, 2024 · 2 comments

Comments

@sonndinh
Copy link
Member

This assumes XCDR2 is used; XCDR1 has not been inspected. Example IDL:

// Currently: A delimiter is added to the outer dim.
// Expected: No delimiter for the whole array.
typedef long PrimArray[2];
struct PrimTypedefStruct {
  PrimArray arr[2];
};

struct A {
  long l;
};

// Currently: One delimiter for the outer dim, one for each element in the inner dim.
// Expected: Only 1 delimiter for the whole array.
typedef A Array[2];
struct TypedefStruct {
  Array arr[2];
};

First, the spec is not clear as to whether an alias type is respected or flattened when used as the element type of an array. Consider the first example. If PrimArray is resolved to long[2], arr would have type long[2][2] and thus has no delimiter. If PrimArray alias type is considered as the base type of arr, arr would have a delimiter since PrimArray is not primitive. The second example is similar.

The team agreed that aliases should be flattened for serialization since alias is typically treated transparently and shouldn't have an impact on serialization otherwise one could make serialization of basically the same type arbitrarily large by adding multiple typedefs for its members or elements. So this assumes flattening alias types is the correct approach for the rest of the report.

Second, opendds_idl currently doesn't flatten the alias types when encountering multi-dimensional arrays as in the example IDL above. In particular, for the first example, a delimiter is added while there should be no delimiter. In the second example, there is a delimiter for the outer dimension and one delimiter for each element of type Array while there should be only one delimiter for the whole array.

Multi-dimensional arrays of primitive or non-primitive element types without aliasing seem to be handled correctly, for example

// No delimiter is added to the array.
struct PrimMDimStruct {
  long arr[2][2];
};

// There is 1 delimiter for the outer dim since the element is non-primitive.
struct MultiDimStruct {
  A arr[2][2];
};

Single-dimensional arrays also seem to be handled correctly even when using aliases.

@mitza-oci
Copy link
Member

"Table 6 – Alias types" from the spec may be a helpful piece of the puzzle as to what the spec actually requires.
Based on this I would say that the spec does indicate (perhaps not clearly) that typedef can't change the encoding.

@sonndinh
Copy link
Member Author

"Table 6 – Alias types" from the spec may be a helpful piece of the puzzle as to what the spec actually requires. Based on this I would say that the spec does indicate (perhaps not clearly) that typedef can't change the encoding.

Yeah, the second paragraph implies that. Okay, that's more clear now.

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

2 participants