# HG changeset patch # User Nika Layzell # Date 1519343914 18000 # Thu Feb 22 18:58:34 2018 -0500 # Node ID df74e15398ad0132f2506109e1619cdd40ac31ea # Parent 73a096b8506cf27035aa89c2a517a64188715b62 Bug 1440511 - Part 11: Switch to calling IPDLParamTraits directly when pickling and unpickling messages, r=froydnj MozReview-Commit-ID: 1t4oIp5JWcU diff --git a/ipc/ipdl/ipdl/lower.py b/ipc/ipdl/ipdl/lower.py --- a/ipc/ipdl/ipdl/lower.py +++ b/ipc/ipdl/ipdl/lower.py @@ -4818,24 +4818,25 @@ class _GenerateProtocolActorCode(ipdl.as def unregisterActor(self): return [ StmtExpr(ExprCall(self.protocol.unregisterMethod(), args=[ _actorId() ])) ] def makeMessage(self, md, errfn, fromActor=None): msgvar = self.msgvar routingId = self.protocol.routingId(fromActor) - this = None + this = ExprVar.THIS if md.decl.type.isDtor(): this = md.actorDecl().var() stmts = ([ StmtDecl(Decl(Type('IPC::Message', ptr=1), msgvar.name), init=ExprCall(ExprVar(md.pqMsgCtorFunc()), args=[ routingId ])) ] + [ Whitespace.NL ] - + [ self.checkedWrite(p.ipdltype, p.var(), msgvar, sentinelKey=p.name, this=this) + + [ _ParamTraits.checkedWrite(p.ipdltype, p.var(), msgvar, + sentinelKey=p.name, actor=this) for p in md.params ] + [ Whitespace.NL ] + self.setMessageFlags(md, msgvar)) return msgvar, stmts def makeResolver(self, md, errfn, routingId): if routingId is None: @@ -4883,21 +4884,21 @@ class _GenerateProtocolActorCode(ipdl.as + [ StmtDecl(Decl(Type.BOOL, resolve.name), init=ExprLiteral.TRUE) ] + [ StmtDecl(Decl(p.bareType(self.side), p.var().name)) for p in md.returns ] + [ StmtExpr(ExprAssn(destructexpr, ExprMove(ExprVar('aParam')))), StmtDecl(Decl(Type('IPC::Message', ptr=1), self.replyvar.name), init=ExprCall(ExprVar(md.pqReplyCtorFunc()), args=[ routingId ])) ] - + [ self.checkedWrite(None, resolve, self.replyvar, - sentinelKey=resolve.name) ] - + [ self.checkedWrite(r.ipdltype, r.var(), self.replyvar, - sentinelKey=r.name) - for r in md.returns ]) + + [ _ParamTraits.checkedWrite(None, resolve, self.replyvar, + sentinelKey=resolve.name, actor=selfvar) ] + + [ _ParamTraits.checkedWrite(r.ipdltype, r.var(), self.replyvar, + sentinelKey=r.name, actor=selfvar) + for r in md.returns ]) resolverfn.addstmts(sendmsg) makeresolver = [ Whitespace.NL, StmtDecl(Decl(Type.INT32, seqno.name), init=ExprCall(ExprSelect(self.msgvar, '.', 'seqno'))), StmtDecl(Decl(Type('WeakPtr', T=ExprVar(self.clsname)), selfvar.name), init=ExprVar.THIS), @@ -4914,17 +4915,18 @@ class _GenerateProtocolActorCode(ipdl.as if md.decl.type.isAsync() and md.decl.type.hasReply(): return [ ] replyvar = self.replyvar return ( [ StmtExpr(ExprAssn( replyvar, ExprCall(ExprVar(md.pqReplyCtorFunc()), args=[ routingId ]))), Whitespace.NL ] - + [ self.checkedWrite(r.ipdltype, r.var(), replyvar, sentinelKey=r.name) + + [ _ParamTraits.checkedWrite(r.ipdltype, r.var(), replyvar, + sentinelKey=r.name, actor=ExprVar.THIS) for r in md.returns ] + self.setMessageFlags(md, replyvar) + [ self.logMessage(md, replyvar, 'Sending reply ') ]) def genVerifyMessage(self, verify, params, errfn, msgsrcVar): stmts = [ ] if not verify: return stmts @@ -4945,22 +4947,23 @@ class _GenerateProtocolActorCode(ipdl.as # PickleIterator msgverifyIter__(msgverify__); [ StmtDecl(Decl(_iterType(ptr=0), itervar.name), initargs=[ msgvar ]) ] # declare varCopy for each variable to deserialize. + [ StmtDecl(Decl(p.bareType(side), p.var().name + 'Copy')) for p in params ] + [ Whitespace.NL ] # checked Read(&(varCopy), &(msgverify__), &(msgverifyIter__)) - + [ self.checkedRead(p.ipdltype, - ExprAddrOf(ExprVar(p.var().name + 'Copy')), - msgexpr, ExprAddrOf(itervar), - errfn, p.bareType(side).name, - sentinelKey=p.name, - errfnSentinel=errfnSentinel()) + + [ _ParamTraits.checkedRead(p.ipdltype, + ExprAddrOf(ExprVar(p.var().name + 'Copy')), + msgexpr, ExprAddrOf(itervar), + errfn, p.bareType(side).name, + sentinelKey=p.name, + errfnSentinel=errfnSentinel(), + actor=ExprVar.THIS) for p in params ] + [ self.endRead(msgvar, itervar) ] # Move the message back to its source before sending. + [ StmtExpr(ExprAssn(ExprDeref(msgsrcVar), ExprMove(msgvar))) ] )) return stmts @@ -4992,54 +4995,58 @@ class _GenerateProtocolActorCode(ipdl.as start, decls, reads = 0, [], [] if isctor: # return the raw actor handle so that its ID can be used # to construct the "real" actor handlevar = self.handlevar handletype = Type('ActorHandle') decls = [ StmtDecl(Decl(handletype, handlevar.name)) ] - reads = [ self.checkedRead(None, ExprAddrOf(handlevar), msgexpr, - ExprAddrOf(self.itervar), - errfn, "'%s'" % handletype.name, - sentinelKey='actor', errfnSentinel=errfnSent) ] + reads = [ _ParamTraits.checkedRead(None, ExprAddrOf(handlevar), msgexpr, + ExprAddrOf(self.itervar), + errfn, "'%s'" % handletype.name, + sentinelKey='actor', errfnSentinel=errfnSent, + actor=ExprVar.THIS) ] start = 1 stmts.extend(( [ StmtDecl(Decl(_iterType(ptr=0), self.itervar.name), initargs=[ msgvar ]) ] + decls + [ StmtDecl(Decl(p.bareType(side), p.var().name)) for p in md.params ] + [ Whitespace.NL ] - + reads + [ self.checkedRead(p.ipdltype, ExprAddrOf(p.var()), - msgexpr, ExprAddrOf(itervar), - errfn, "'%s'" % p.bareType(side).name, - sentinelKey=p.name, errfnSentinel=errfnSent) + + reads + [ _ParamTraits.checkedRead(p.ipdltype, ExprAddrOf(p.var()), + msgexpr, ExprAddrOf(itervar), + errfn, "'%s'" % p.bareType(side).name, + sentinelKey=p.name, errfnSentinel=errfnSent, + actor=ExprVar.THIS) for p in md.params[start:] ] + [ self.endRead(msgvar, itervar) ])) return stmts def deserializeAsyncReply(self, md, side, errfn, errfnSent): msgvar = self.msgvar itervar = self.itervar msgexpr = ExprAddrOf(msgvar) isctor = md.decl.type.isCtor() resolve = ExprVar('resolve__') reason = ExprVar('reason__') desresolve = [ StmtDecl(Decl(Type.BOOL, resolve.name)), - self.checkedRead(None, ExprAddrOf(resolve), msgexpr, - ExprAddrOf(itervar), - errfn, "'%s'" % resolve.name, - sentinelKey=resolve.name, errfnSentinel=errfnSent) ] + _ParamTraits.checkedRead(None, ExprAddrOf(resolve), msgexpr, + ExprAddrOf(itervar), + errfn, "'%s'" % resolve.name, + sentinelKey=resolve.name, errfnSentinel=errfnSent, + actor=ExprVar.THIS) ] desrej = [ StmtDecl(Decl(_ResponseRejectReason.Type(), reason.name)), - self.checkedRead(None, ExprAddrOf(reason), msgexpr, - ExprAddrOf(itervar), - errfn, "'%s'" % reason.name, - sentinelKey=reason.name, errfnSentinel=errfnSent), + _ParamTraits.checkedRead(None, ExprAddrOf(reason), msgexpr, + ExprAddrOf(itervar), + errfn, "'%s'" % reason.name, + sentinelKey=reason.name, errfnSentinel=errfnSent, + actor=ExprVar.THIS), self.endRead(msgvar, itervar) ] prologue = ([ self.logMessage(md, msgexpr, 'Received ', receiving=True), self.profilerLabel(md), Whitespace.NL ]) @@ -5052,30 +5059,32 @@ class _GenerateProtocolActorCode(ipdl.as start, decls, reads = 0, [], [] if isctor: # return the raw actor handle so that its ID can be used # to construct the "real" actor handlevar = self.handlevar handletype = Type('ActorHandle') decls = [ StmtDecl(Decl(handletype, handlevar.name)) ] - reads = [ self.checkedRead(None, ExprAddrOf(handlevar), msgexpr, - ExprAddrOf(itervar), - errfn, "'%s'" % handletype.name, - sentinelKey='actor', errfnSentinel=errfnSent) ] + reads = [ _ParamTraits.checkedRead(None, ExprAddrOf(handlevar), msgexpr, + ExprAddrOf(itervar), + errfn, "'%s'" % handletype.name, + sentinelKey='actor', errfnSentinel=errfnSent, + actor=ExprVar.THIS) ] start = 1 stmts = ( decls + [ StmtDecl(Decl(p.bareType(side), p.var().name)) for p in md.returns ] + [ Whitespace.NL ] - + reads + [ self.checkedRead(p.ipdltype, ExprAddrOf(p.var()), - msgexpr, ExprAddrOf(itervar), - errfn, "'%s'" % p.bareType(side).name, - sentinelKey=p.name, errfnSentinel=errfnSent) + + reads + [ _ParamTraits.checkedRead(p.ipdltype, ExprAddrOf(p.var()), + msgexpr, ExprAddrOf(itervar), + errfn, "'%s'" % p.bareType(side).name, + sentinelKey=p.name, errfnSentinel=errfnSent, + actor=ExprVar.THIS) for p in md.returns[start:] ] + [ self.endRead(msgvar, itervar) ]) return resolve, reason, prologue, desrej, stmts def deserializeReply(self, md, replyexpr, side, errfn, errfnSentinel, actor=None, decls=False): stmts = [ Whitespace.NL, self.logMessage(md, replyexpr, @@ -5089,21 +5098,22 @@ class _GenerateProtocolActorCode(ipdl.as declstmts = [ StmtDecl(Decl(p.bareType(side), p.var().name)) for p in md.returns ] stmts.extend( [ Whitespace.NL, StmtDecl(Decl(_iterType(ptr=0), itervar.name), initargs= [ self.replyvar ]) ] + declstmts + [ Whitespace.NL ] - + [ self.checkedRead(r.ipdltype, r.var(), - ExprAddrOf(self.replyvar), - ExprAddrOf(self.itervar), - errfn, "'%s'" % r.bareType(side).name, - sentinelKey=r.name, errfnSentinel=errfnSentinel) + + [ _ParamTraits.checkedRead(r.ipdltype, r.var(), + ExprAddrOf(self.replyvar), + ExprAddrOf(self.itervar), + errfn, "'%s'" % r.bareType(side).name, + sentinelKey=r.name, errfnSentinel=errfnSentinel, + actor=ExprVar.THIS) for r in md.returns ] + [ self.endRead(self.replyvar, itervar) ]) return stmts def sendAsync(self, md, msgexpr, actor=None): sendok = ExprVar('sendok__') resolvefn = ExprVar('aResolve')