mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 13:51:41 +00:00
Bug 1345897 - Use a separate error function for sentinel errors. r=kanru
Using a separate error function will distinguish mismatched sentinels from other errors, such as array length problems. MozReview-Commit-ID: Gl8swNhqLns --HG-- extra : rebase_source : 494759b105086c6c26f3ac53fb644bbf51c12800
This commit is contained in:
parent
91a4a0b1a5
commit
50ab94e943
@ -347,12 +347,20 @@ UnionTypeReadError(const char* aUnionName)
|
||||
NS_RUNTIMEABORT(message.get());
|
||||
}
|
||||
|
||||
void ArrayLengthReadError(const char* aElementName)
|
||||
void
|
||||
ArrayLengthReadError(const char* aElementName)
|
||||
{
|
||||
nsPrintfCString message("error deserializing length of %s[]", aElementName);
|
||||
NS_RUNTIMEABORT(message.get());
|
||||
}
|
||||
|
||||
void
|
||||
SentinelReadError(const char* aClassName)
|
||||
{
|
||||
nsPrintfCString message("incorrect sentinel when reading %s", aClassName);
|
||||
NS_RUNTIMEABORT(message.get());
|
||||
}
|
||||
|
||||
void
|
||||
TableToArray(const nsTHashtable<nsPtrHashKey<void>>& aTable,
|
||||
nsTArray<void*>& aArray)
|
||||
|
@ -489,6 +489,9 @@ UnionTypeReadError(const char* aUnionName);
|
||||
MOZ_NEVER_INLINE void
|
||||
ArrayLengthReadError(const char* aElementName);
|
||||
|
||||
MOZ_NEVER_INLINE void
|
||||
SentinelReadError(const char* aElementName);
|
||||
|
||||
struct PrivateIPDLInterface {};
|
||||
|
||||
nsresult
|
||||
|
@ -406,6 +406,11 @@ def _unionTypeReadError(unionname):
|
||||
ExprCall(ExprVar('mozilla::ipc::UnionTypeReadError'),
|
||||
args=[ ExprLiteral.String(unionname) ]))
|
||||
|
||||
def _sentinelReadError(classname):
|
||||
return StmtExpr(
|
||||
ExprCall(ExprVar('mozilla::ipc::SentinelReadError'),
|
||||
args=[ ExprLiteral.String(classname) ]))
|
||||
|
||||
def _killProcess(pid):
|
||||
return ExprCall(
|
||||
ExprVar('base::KillProcess'),
|
||||
@ -467,6 +472,11 @@ def errfnArrayLength(elementname):
|
||||
def errfnUnionType(unionname):
|
||||
return [ _unionTypeReadError(unionname), StmtReturn.FALSE ]
|
||||
|
||||
def errfnSentinel(rvalue=ExprLiteral.FALSE):
|
||||
def inner(msg):
|
||||
return [ _sentinelReadError(msg), StmtReturn(rvalue) ]
|
||||
return inner
|
||||
|
||||
def _destroyMethod():
|
||||
return ExprVar('ActorDestroy')
|
||||
|
||||
@ -3381,7 +3391,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
self.checkedRead(eltipdltype, ExprAddrOf(ExprIndex(elemsvar, ivar)),
|
||||
msgvar, itervar, errfnRead,
|
||||
'\'' + eltipdltype.name() + '[i]\'',
|
||||
sentinelKey=arraytype.name()))
|
||||
sentinelKey=arraytype.name(),
|
||||
errfnSentinel=errfnSentinel()))
|
||||
appendstmt = StmtDecl(Decl(directtype, elemsvar.name),
|
||||
init=ExprCall(ExprSelect(favar, '.', 'AppendElements'),
|
||||
args=[ lenvar ]))
|
||||
@ -3391,7 +3402,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
self.checkedRead(None, ExprAddrOf(lenvar),
|
||||
msgvar, itervar, errfnArrayLength,
|
||||
[ arraytype.name() ],
|
||||
sentinelKey=('length', arraytype.name())),
|
||||
sentinelKey=('length', arraytype.name()),
|
||||
errfnSentinel=errfnSentinel()),
|
||||
Whitespace.NL,
|
||||
appendstmt,
|
||||
forread,
|
||||
@ -3526,7 +3538,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
writefield = self.checkedWrite(f.ipdltype, get('.', f), msgvar, sentinelKey=f.basename)
|
||||
readfield = self.checkedRead(f.ipdltype,
|
||||
ExprAddrOf(get('->', f)),
|
||||
msgvar, itervar, errfnRead, desc, sentinelKey=f.basename)
|
||||
msgvar, itervar, errfnRead, desc,
|
||||
sentinelKey=f.basename, errfnSentinel=errfnSentinel())
|
||||
if f.special and f.side != self.side:
|
||||
writefield = Whitespace(
|
||||
"// skipping actor field that's meaningless on this side\n", indent=1)
|
||||
@ -3590,7 +3603,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
c.ipdltype,
|
||||
ExprAddrOf(ExprCall(ExprSelect(var, '->',
|
||||
c.getTypeName()))),
|
||||
msgvar, itervar, errfnRead, 'Union type', sentinelKey=origenum),
|
||||
msgvar, itervar, errfnRead, 'Union type',
|
||||
sentinelKey=origenum, errfnSentinel=errfnSentinel()),
|
||||
StmtReturn(ExprLiteral.TRUE)
|
||||
])
|
||||
|
||||
@ -3619,7 +3633,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
self.checkedRead(
|
||||
None, ExprAddrOf(typevar), msgvar, itervar, errfnUnionType,
|
||||
[ uniontype.name() ],
|
||||
sentinelKey=uniontype.name()),
|
||||
sentinelKey=uniontype.name(), errfnSentinel=errfnSentinel()),
|
||||
Whitespace.NL,
|
||||
readswitch,
|
||||
])
|
||||
@ -3786,7 +3800,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
def errfnCleanupCtor(msg):
|
||||
return self.failCtorIf(md, ExprLiteral.TRUE)
|
||||
stmts = self.deserializeReply(
|
||||
md, ExprAddrOf(replyvar), self.side, errfnCleanupCtor)
|
||||
md, ExprAddrOf(replyvar), self.side,
|
||||
errfnCleanupCtor, errfnSentinel(ExprLiteral.NULL))
|
||||
method.addstmts(stmts + [ StmtReturn(actor.var()) ])
|
||||
|
||||
return method
|
||||
@ -3893,7 +3908,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
+ sendstmts)
|
||||
|
||||
destmts = self.deserializeReply(
|
||||
md, ExprAddrOf(replyvar), self.side, errfnSend, actorvar)
|
||||
md, ExprAddrOf(replyvar), self.side, errfnSend,
|
||||
errfnSentinel(), actorvar)
|
||||
ifsendok = StmtIf(ExprLiteral.FALSE)
|
||||
ifsendok.addifstmts(destmts)
|
||||
ifsendok.addifstmts([ Whitespace.NL,
|
||||
@ -3956,7 +3972,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
failif.addifstmt(StmtReturn.FALSE)
|
||||
|
||||
desstmts = self.deserializeReply(
|
||||
md, ExprAddrOf(replyvar), self.side, errfnSend)
|
||||
md, ExprAddrOf(replyvar), self.side, errfnSend, errfnSentinel())
|
||||
|
||||
method.addstmts(
|
||||
serstmts
|
||||
@ -3979,7 +3995,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
actorvar = md.actorDecl().var()
|
||||
actorhandle = self.handlevar
|
||||
|
||||
stmts = self.deserializeMessage(md, self.side, errfnRecv)
|
||||
stmts = self.deserializeMessage(md, self.side, errfnRecv,
|
||||
errfnSent=errfnSentinel(_Result.ValuError))
|
||||
|
||||
idvar, saveIdStmts = self.saveActorId(md)
|
||||
case.addstmts(
|
||||
@ -4009,7 +4026,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
lbl = CaseLabel(md.pqMsgId())
|
||||
case = StmtBlock()
|
||||
|
||||
stmts = self.deserializeMessage(md, self.side, errfnRecv)
|
||||
stmts = self.deserializeMessage(md, self.side, errfnRecv,
|
||||
errfnSent=errfnSentinel(_Result.ValuError))
|
||||
|
||||
idvar, saveIdStmts = self.saveActorId(md)
|
||||
case.addstmts(
|
||||
@ -4035,7 +4053,8 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
lbl = CaseLabel(md.pqMsgId())
|
||||
case = StmtBlock()
|
||||
|
||||
stmts = self.deserializeMessage(md, self.side, errfn=errfnRecv)
|
||||
stmts = self.deserializeMessage(md, self.side, errfn=errfnRecv,
|
||||
errfnSent=errfnSentinel(_Result.ValuError))
|
||||
|
||||
idvar, saveIdStmts = self.saveActorId(md)
|
||||
case.addstmts(
|
||||
@ -4162,7 +4181,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
return stmts + [ Whitespace.NL ]
|
||||
|
||||
|
||||
def deserializeMessage(self, md, side, errfn):
|
||||
def deserializeMessage(self, md, side, errfn, errfnSent):
|
||||
msgvar = self.msgvar
|
||||
itervar = self.itervar
|
||||
msgexpr = ExprAddrOf(msgvar)
|
||||
@ -4187,7 +4206,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
reads = [ self.checkedRead(None, ExprAddrOf(handlevar), msgexpr,
|
||||
ExprAddrOf(self.itervar),
|
||||
errfn, "'%s'" % handletype.name,
|
||||
sentinelKey='actor') ]
|
||||
sentinelKey='actor', errfnSentinel=errfnSent) ]
|
||||
start = 1
|
||||
|
||||
stmts.extend((
|
||||
@ -4200,14 +4219,14 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
+ reads + [ self.checkedRead(p.ipdltype, ExprAddrOf(p.var()),
|
||||
msgexpr, ExprAddrOf(itervar),
|
||||
errfn, "'%s'" % p.bareType(side).name,
|
||||
sentinelKey=p.name)
|
||||
sentinelKey=p.name, errfnSentinel=errfnSent)
|
||||
for p in md.params[start:] ]
|
||||
+ [ self.endRead(msgvar, itervar) ]))
|
||||
|
||||
return stmts
|
||||
|
||||
|
||||
def deserializeReply(self, md, replyexpr, side, errfn, actor=None):
|
||||
def deserializeReply(self, md, replyexpr, side, errfn, errfnSentinel, actor=None):
|
||||
stmts = [ Whitespace.NL,
|
||||
self.logMessage(md, replyexpr,
|
||||
'Received reply ', actor, receiving=True) ]
|
||||
@ -4224,7 +4243,7 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
ExprAddrOf(self.replyvar),
|
||||
ExprAddrOf(self.itervar),
|
||||
errfn, "'%s'" % r.bareType(side).name,
|
||||
sentinelKey=r.name)
|
||||
sentinelKey=r.name, errfnSentinel=errfnSentinel)
|
||||
for r in md.returns ]
|
||||
+ [ self.endRead(self.replyvar, itervar) ])
|
||||
|
||||
@ -4368,12 +4387,14 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
args=[ ExprVar(msgid),
|
||||
ExprAddrOf(stateexpr) ])) ]
|
||||
|
||||
def checkedRead(self, ipdltype, expr, msgexpr, iterexpr, errfn, paramtype, sentinelKey, sentinel=True):
|
||||
def checkedRead(self, ipdltype, expr, msgexpr, iterexpr, errfn, paramtype, sentinelKey, errfnSentinel, sentinel=True):
|
||||
ifbad = StmtIf(ExprNot(self.read(ipdltype, expr, msgexpr, iterexpr)))
|
||||
if isinstance(paramtype, list):
|
||||
errorcall = errfn(*paramtype)
|
||||
senterrorcall = errfnSentinel(*paramtype)
|
||||
else:
|
||||
errorcall = errfn('Error deserializing ' + paramtype)
|
||||
senterrorcall = errfnSentinel('Error deserializing ' + paramtype)
|
||||
ifbad.addifstmts(errorcall)
|
||||
|
||||
block = Block()
|
||||
@ -4381,12 +4402,11 @@ class _GenerateProtocolActorCode(ipdl.ast.Visitor):
|
||||
|
||||
if sentinel:
|
||||
assert sentinelKey
|
||||
|
||||
block.addstmt(Whitespace('// Sentinel = ' + repr(sentinelKey) + '\n', indent=1))
|
||||
read = ExprCall(ExprSelect(msgexpr, '->', 'ReadSentinel'),
|
||||
args=[ iterexpr, ExprLiteral.Int(hashfunc(sentinelKey)) ])
|
||||
ifsentinel = StmtIf(ExprNot(read))
|
||||
ifsentinel.addifstmts(errorcall)
|
||||
ifsentinel.addifstmts(senterrorcall)
|
||||
block.addstmt(ifsentinel)
|
||||
|
||||
return block
|
||||
|
Loading…
Reference in New Issue
Block a user