Bug 1523996 - part 3 - factor out reading/writing sentinels; r=Alex_Gaynor
authorNathan Froyd <froydnj@gmail.com>
Wed, 06 Mar 2019 13:59:43 +0000
changeset 520541 1746c87bdd261f2254909bb25d0c15091ec1e545
parent 520540 5a1bb4076f8fd77e616fa54dbd85812285ef303f
child 520542 90d17458ca5425d50a0d58ad59ec227a3458890e
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersAlex_Gaynor
bugs1523996
milestone67.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1523996 - part 3 - factor out reading/writing sentinels; r=Alex_Gaynor We're going to read and write sentinels slightly differently for bulk-writing adjacent fields, so let's factor out some reusable code for doing so. Differential Revision: https://phabricator.services.mozilla.com/D21999
ipc/ipdl/ipdl/lower.py
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -1851,16 +1851,38 @@ class _ParamTraits():
         return ifstmt
 
     @classmethod
     def fatalError(cls, reason):
         return StmtExpr(ExprCall(ExprSelect(cls.actor, '->', 'FatalError'),
                                  args=[ExprLiteral.String(reason)]))
 
     @classmethod
+    def writeSentinel(cls, msgvar, sentinelKey):
+        return [
+            Whitespace('// Sentinel = ' + repr(sentinelKey) + '\n', indent=True),
+            StmtExpr(ExprCall(ExprSelect(msgvar, '->', 'WriteSentinel'),
+                              args=[ExprLiteral.Int(hashfunc(sentinelKey))]))
+        ]
+
+    @classmethod
+    def readSentinel(cls, msgvar, itervar, sentinelKey, sentinelFail):
+        # Read the sentinel
+        assert sentinelKey
+        read = ExprCall(ExprSelect(msgvar, '->', 'ReadSentinel'),
+                        args=[itervar, ExprLiteral.Int(hashfunc(sentinelKey))])
+        ifsentinel = StmtIf(ExprNot(read))
+        ifsentinel.addifstmts(sentinelFail)
+
+        return [
+            Whitespace('// Sentinel = ' + repr(sentinelKey) + '\n', indent=True),
+            ifsentinel,
+        ]
+
+    @classmethod
     def write(cls, var, msgvar, actor, ipdltype=None):
         # WARNING: This doesn't set AutoForActor for you, make sure this is
         # only called when the actor is already correctly set.
         if ipdltype and _cxxTypeNeedsMoveForSend(ipdltype):
             var = ExprMove(var)
         return ExprCall(ExprVar('WriteIPDLParam'), args=[msgvar, actor, var])
 
     @classmethod
@@ -1869,20 +1891,18 @@ class _ParamTraits():
         block = Block()
 
         # Assert we aren't serializing a null non-nullable actor
         if ipdltype and ipdltype.isIPDL() and ipdltype.isActor() and not ipdltype.nullable:
             block.addstmt(_abortIfFalse(var, 'NULL actor value passed to non-nullable param'))
 
         block.addstmts([
             StmtExpr(cls.write(var, msgvar, actor, ipdltype)),
-            Whitespace('// Sentinel = ' + repr(sentinelKey) + '\n', indent=True),
-            StmtExpr(ExprCall(ExprSelect(msgvar, '->', 'WriteSentinel'),
-                              args=[ExprLiteral.Int(hashfunc(sentinelKey))]))
         ])
+        block.addstmts(cls.writeSentinel(msgvar, sentinelKey))
         return block
 
     @classmethod
     def checkedRead(cls, ipdltype, var,
                     msgvar, itervar, errfn,
                     paramtype, sentinelKey,
                     errfnSentinel, actor):
         block = Block()
@@ -1896,25 +1916,18 @@ class _ParamTraits():
         block.addstmt(ifbad)
 
         # Check if we got a null non-nullable actor
         if ipdltype and ipdltype.isIPDL() and ipdltype.isActor() and not ipdltype.nullable:
             ifnull = StmtIf(ExprNot(ExprDeref(var)))
             ifnull.addifstmts(errfn(*paramtype))
             block.addstmt(ifnull)
 
-        # Read the sentinel
-        assert sentinelKey
-        block.addstmt(Whitespace('// Sentinel = ' + repr(sentinelKey) + '\n',
-                                 indent=True))
-        read = ExprCall(ExprSelect(msgvar, '->', 'ReadSentinel'),
-                        args=[itervar, ExprLiteral.Int(hashfunc(sentinelKey))])
-        ifsentinel = StmtIf(ExprNot(read))
-        ifsentinel.addifstmts(errfnSentinel(*paramtype))
-        block.addstmt(ifsentinel)
+        block.addstmts(cls.readSentinel(msgvar, itervar, sentinelKey,
+                                        errfnSentinel(*paramtype)))
 
         return block
 
     # Helper wrapper for checkedRead for use within _ParamTraits
     @classmethod
     def _checkedRead(cls, ipdltype, var, sentinelKey, what):
         def errfn(msg):
             return [cls.fatalError(msg), StmtReturn.FALSE]