Bug 1024795, part 4 - Use a default value for initializing unions, except for nsTArray. r=bent

This restores the initialization behavior prior to bug 819791, except for the one case that bug requires.
This commit is contained in:
Andrew McCreight 2014-08-13 11:36:15 -07:00
parent 7805ea0edf
commit 4790cd3937
2 changed files with 9 additions and 3 deletions

View File

@ -291,6 +291,7 @@ class Type(Node):
def __init__(self, name, const=0,
ptr=0, ptrconst=0, ptrptr=0, ptrconstptr=0,
ref=0,
hasimplicitcopyctor=True,
T=None):
"""
To avoid getting fancy with recursive types, we limit the kinds
@ -315,6 +316,7 @@ Any type, naked or pointer, can be const (const T) or ref (T&).
self.ptrptr = ptrptr
self.ptrconstptr = ptrconstptr
self.ref = ref
self.hasimplicitcopyctor = hasimplicitcopyctor
self.T = T
# XXX could get serious here with recursive types, but shouldn't
# need that for this codegen

View File

@ -332,7 +332,7 @@ def _refptrTake(expr):
return ExprCall(ExprSelect(expr, '.', 'take'))
def _cxxArrayType(basetype, const=0, ref=0):
return Type('nsTArray', T=basetype, const=const, ref=ref)
return Type('nsTArray', T=basetype, const=const, ref=ref, hasimplicitcopyctor=False)
def _cxxFallibleArrayType(basetype, const=0, ref=0):
return Type('FallibleTArray', T=basetype, const=const, ref=ref)
@ -849,6 +849,11 @@ IPDL union type."""
return t
def defaultValue(self):
# Use the default constructor for any class that does not have an
# implicit copy constructor.
if not self.bareType().hasimplicitcopyctor:
return None
if self.ipdltype.isIPDL() and self.ipdltype.isActor():
return ExprLiteral.NULL
# XXX sneaky here, maybe need ExprCtor()?
@ -4692,8 +4697,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
tmpvar = ExprVar('tmp')
ct = c.bareType()
readcase.addstmts([
StmtDecl(Decl(ct, tmpvar.name),
init=c.defaultValue() if ct.ptr else None),
StmtDecl(Decl(ct, tmpvar.name), init=c.defaultValue()),
StmtExpr(ExprAssn(ExprDeref(var), tmpvar)),
StmtReturn(self.read(
c.ipdltype,