From f7e93b554106527a4fc299a314adada65dbf672a Mon Sep 17 00:00:00 2001 From: Chris Dearman Date: Wed, 8 Aug 2012 15:10:03 -0400 Subject: [PATCH] Bug 779013 - Align the mValue union in IPDL-generated code. r=cjones --- ipc/ipdl/ipdl/cxx/ast.py | 16 ++++++++++++++-- ipc/ipdl/ipdl/lower.py | 4 +++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/ipc/ipdl/ipdl/cxx/ast.py b/ipc/ipdl/ipdl/cxx/ast.py index 90c87e9d0a9..1698e2932b7 100644 --- a/ipc/ipdl/ipdl/cxx/ast.py +++ b/ipc/ipdl/ipdl/cxx/ast.py @@ -358,9 +358,21 @@ class TypeUnion(Node): Node.__init__(self) self.name = name self.components = [ ] # [ Decl ] + # Expr -- evaluates to a constant value representing + # the maximum alignment of all types in the union + self.alignment = None - def addComponent(self, type, name): - self.components.append(Decl(type, name)) + def addComponent(self, c): + self.components.append(Decl(c.unionType(), c.name)) + alignme = ExprCall(ExprVar('MOZ_ALIGNOF'), [ c.internalType() ]) + if self.alignment: + self.alignment = ExprCall(ExprVar('PR_MAX'), [ alignme, self.alignment ]) + else: + self.alignment = alignme + + def addAlignment(self): + if self.alignment: + self.components.append(Decl(Type('mozilla::AlignedElem', T=self.alignment), '__align')) class Typedef(Node): def __init__(self, fromtype, totypename): diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py index 1fa87ec0fa1..84c9c39e142 100644 --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -2098,7 +2098,9 @@ def _generateCxxUnion(ud): # the C++ union the discunion use for storage valueunion = TypeUnion(valuetype.name) for c in ud.components: - valueunion.addComponent(c.unionType(), c.name) + valueunion.addComponent(c); + valueunion.addAlignment(); + cls.addstmts([ StmtDecl(Decl(valueunion,'')), Whitespace.NL ])