Skip to content

Conversation

peterhinson
Copy link
Contributor

Fixes two issues in generated Python code related to structures containing unencapsulated unions. To better illustrate:

Given an IDL with this structure, union and discriminator:

enum TypeExample {
  DESC_FLT,
  DESC_U32
}

union UnionExample {
  case DESC_FLT:
    float flt
  case DESC_U32:
    uint32 u32
}

struct StructExample {
  UnionExample value @discriminator(kind);
  TypeExample kind
}

erpcgen will produce this somewhat broken Python code in common.py:

# Structures data types declarations
class StructExample(object):
    def __init__(self, kind=None):
        # syntax error! value not defined
        self.value = value # UnionExample
        self.kind = kind # TypeExample

    def _read(self, codec):
        # syntax error - common not defined (already in common module)
        self.value, self.kind = common.UnionExample()._read(codec) 
        return self
  # ...

Output after this PR:

# Structures data types declarations
class StructExample(object):
    def __init__(self, value=None, kind=None):
        self.value = value # UnionExample
        self.kind = kind # TypeExample

    def _read(self, codec):
        self.value, self.kind = UnionExample()._read(codec)
        return self
  # ...

Copy link
Member

@Hadatko Hadatko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes looks good to me. I improved/fixed tests for this case

@Hadatko Hadatko mentioned this pull request Jan 8, 2022
@Hadatko Hadatko added this to the 1.8.3 milestone Jan 11, 2022
@MichalPrincNXP MichalPrincNXP merged commit ac7cbe7 into EmbeddedRPC:develop Jan 18, 2022
@MichalPrincNXP
Copy link
Member

Thank you for your effort!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

3 participants