Bug 1245241 - part 3 - remove unused AdoptShmem from IPDL. r=billm
authorLee Salzman <lsalzman@mozilla.com>
Thu, 18 Feb 2016 10:56:15 -0500
changeset 331905 48fa8a92f9364a82985021ae1dfe940de09dd898
parent 331904 7c656da2e681a2321c9fb2c7b9aa36b03446f89a
child 331906 94f9bb9e325342ef86c534a14a651060d76bd8b4
push id11113
push userrjesup@wgate.com
push dateThu, 18 Feb 2016 19:00:12 +0000
reviewersbillm
bugs1245241
milestone47.0a1
Bug 1245241 - part 3 - remove unused AdoptShmem from IPDL. r=billm
ipc/glue/ProtocolUtils.h
ipc/glue/Shmem.h
ipc/ipdl/ipdl/lower.py
--- a/ipc/glue/ProtocolUtils.h
+++ b/ipc/glue/ProtocolUtils.h
@@ -168,17 +168,16 @@ public:
     virtual int32_t Register(ListenerT*) = 0;
     virtual int32_t RegisterID(ListenerT*, int32_t) = 0;
     virtual ListenerT* Lookup(int32_t) = 0;
     virtual void Unregister(int32_t) = 0;
     virtual void RemoveManagee(int32_t, ListenerT*) = 0;
 
     virtual Shmem::SharedMemory* CreateSharedMemory(
         size_t, SharedMemory::SharedMemoryType, bool, int32_t*) = 0;
-    virtual bool AdoptSharedMemory(Shmem::SharedMemory*, int32_t*) = 0;
     virtual Shmem::SharedMemory* LookupSharedMemory(int32_t) = 0;
     virtual bool IsTrackingSharedMemory(Shmem::SharedMemory*) = 0;
     virtual bool DestroySharedMemory(Shmem&) = 0;
 
     // XXX odd ducks, acknowledged
     virtual ProcessId OtherPid() const = 0;
     virtual MessageChannel* GetIPCChannel() = 0;
 
--- a/ipc/glue/Shmem.h
+++ b/ipc/glue/Shmem.h
@@ -120,23 +120,17 @@ public:
     mData = aRhs.mData;
     mSize = aRhs.mSize;
     mId = aRhs.mId;
     return *this;
   }
 
   bool operator==(const Shmem& aRhs) const
   {
-    // need to compare IDs because of AdoptShmem(); two Shmems might
-    // refer to the same segment but with different IDs for different
-    // protocol trees.  (NB: it's possible for this method to
-    // spuriously return true if AdoptShmem() gives the same ID for
-    // two protocol trees, but I don't think that can cause any
-    // problems since the Shmems really would be indistinguishable.)
-    return mSegment == aRhs.mSegment && mId == aRhs.mId;
+    return mSegment == aRhs.mSegment;
   }
 
   // Returns whether this Shmem is writable by you, and thus whether you can
   // transfer writability to another actor.
   bool
   IsWritable() const
   {
     return mSegment != nullptr;
--- a/ipc/ipdl/ipdl/lower.py
+++ b/ipc/ipdl/ipdl/lower.py
@@ -1115,19 +1115,16 @@ class Protocol(ipdl.ast.Protocol):
         return ExprVar('Unregister')
 
     def removeManageeMethod(self):
         return ExprVar('RemoveManagee')
 
     def createSharedMemory(self):
         return ExprVar('CreateSharedMemory')
 
-    def adoptSharedMemory(self):
-        return ExprVar('AdoptSharedMemory')
-
     def lookupSharedMemory(self):
         return ExprVar('LookupSharedMemory')
 
     def isTrackingSharedMemory(self):
         return ExprVar('IsTrackingSharedMemory')
 
     def destroySharedMemory(self):
         return ExprVar('DestroySharedMemory')
@@ -3669,22 +3666,16 @@ class _GenerateProtocolActorCode(ipdl.as
         createshmem = MethodDefn(MethodDecl(
             p.createSharedMemory().name,
             ret=_rawShmemType(ptr=1),
             params=[ Decl(Type.SIZE, sizevar.name),
                      Decl(_shmemTypeType(), typevar.name),
                      Decl(Type.BOOL, unsafevar.name),
                      Decl(_shmemIdType(ptr=1), idvar.name) ],
             virtual=1))
-        adoptshmem = MethodDefn(MethodDecl(
-            p.adoptSharedMemory().name,
-            ret=Type.BOOL,
-            params=[ Decl(_rawShmemType(ptr=1), rawvar.name),
-                     Decl(_shmemIdType(ptr=1), idvar.name) ],
-            virtual=1))
         lookupshmem = MethodDefn(MethodDecl(
             p.lookupSharedMemory().name,
             ret=_rawShmemType(ptr=1),
             params=[ Decl(_shmemIdType(), idvar.name) ],
             virtual=1))
         destroyshmem = MethodDefn(MethodDecl(
             p.destroySharedMemory().name,
             ret=Type.BOOL,
@@ -3791,58 +3782,16 @@ class _GenerateProtocolActorCode(ipdl.as
                 StmtDecl(Decl(_rawShmemType(ptr=1), rawsegmentvar.name),
                          init=_refptrGet(rawvar)),
                 StmtExpr(ExprCall(
                     ExprSelect(p.shmemMapVar(), '.', 'AddWithID'),
                     args=[ _refptrTake(_refptrForget(rawvar)), ExprDeref(idvar) ])),
                 StmtReturn(rawsegmentvar)
             ])
 
-            # SharedMemory* AdoptSharedMemory(SharedMemory*, id_t*):
-            #   Shmem s(seg, [nextshmemid]);
-            #   Message descriptor;
-            #   if (!s->ShareTo(subprocess, mId, descriptor) ||
-            #       !Send(descriptor))
-            #     return false;
-            #   mShmemMap.Add(seg, id);
-            #   seg->AddRef();
-            #   return true;
-
-            # XXX this is close to the same code as above, could be
-            # refactored
-            descriptorvar = ExprVar('descriptor')
-            adoptshmem.addstmts([
-                StmtDecl(
-                    Decl(_shmemType(), shmemvar.name),
-                    initargs=[ _shmemBackstagePass(),
-                               rawvar,
-                               p.nextShmemIdExpr(self.side) ]),
-                StmtDecl(Decl(Type('Message', ptr=1), descriptorvar.name),
-                         init=_shmemShareTo(shmemvar,
-                                            p.callOtherPid(),
-                                            p.routingId()))
-            ])
-            failif = StmtIf(ExprNot(descriptorvar))
-            failif.addifstmt(StmtReturn.FALSE)
-            adoptshmem.addstmt(failif)
-
-            failif = StmtIf(ExprNot(ExprCall(
-                ExprSelect(p.channelVar(), p.channelSel(), 'Send'),
-                args=[ descriptorvar ])))
-            adoptshmem.addstmt(failif)
-
-            adoptshmem.addstmts([
-                StmtExpr(ExprAssn(ExprDeref(idvar), _shmemId(shmemvar))),
-                StmtExpr(ExprCall(
-                    ExprSelect(p.shmemMapVar(), '.', 'AddWithID'),
-                    args=[ rawvar, ExprDeref(idvar) ])),
-                StmtExpr(ExprCall(ExprSelect(rawvar, '->', 'AddRef'))),
-                StmtReturn.TRUE
-            ])
-
             # SharedMemory* Lookup(id)
             lookupshmem.addstmt(StmtReturn(ExprCall(
                 ExprSelect(p.shmemMapVar(), '.', 'Lookup'),
                 args=[ idvar ])))
 
             # bool IsTrackingSharedMemory(mem)
             istracking.addstmt(StmtReturn(ExprCall(
                 ExprSelect(p.shmemMapVar(), '.', 'HasData'),
@@ -3931,19 +3880,16 @@ class _GenerateProtocolActorCode(ipdl.as
                 ExprSelect(p.managerVar(), '->', p.lookupIDMethod().name),
                 [ idvar ])))
             unregister.addstmt(StmtReturn(ExprCall(
                 ExprSelect(p.managerVar(), '->', p.unregisterMethod().name),
                 [ idvar ])))
             createshmem.addstmt(StmtReturn(ExprCall(
                 ExprSelect(p.managerVar(), '->', p.createSharedMemory().name),
                 [ sizevar, typevar, unsafevar, idvar ])))
-            adoptshmem.addstmt(StmtReturn(ExprCall(
-                ExprSelect(p.managerVar(), '->', p.adoptSharedMemory().name),
-                [ rawvar, idvar ])))
             lookupshmem.addstmt(StmtReturn(ExprCall(
                 ExprSelect(p.managerVar(), '->', p.lookupSharedMemory().name),
                 [ idvar ])))
             istracking.addstmt(StmtReturn(ExprCall(
                 ExprSelect(p.managerVar(), '->',
                            p.isTrackingSharedMemory().name),
                 [ rawvar ])))
             destroyshmem.addstmt(StmtReturn(ExprCall(
@@ -4086,17 +4032,16 @@ class _GenerateProtocolActorCode(ipdl.as
             removemanagee.addstmt(switchontype)
 
         return [ register,
                  registerid,
                  lookup,
                  unregister,
                  removemanagee,
                  createshmem,
-                 adoptshmem,
                  lookupshmem,
                  istracking,
                  destroyshmem,
                  otherpid,
                  getchannel,
                  clonemanagees,
                  cloneprotocol,
                  Whitespace.NL ]
@@ -4149,62 +4094,16 @@ class _GenerateProtocolActorCode(ipdl.as
             return method
 
         # bool AllocShmem(size_t size, Type type, Shmem* outmem):
         allocShmem = allocShmemMethod('AllocShmem', False)
 
         # bool AllocUnsafeShmem(size_t size, Type type, Shmem* outmem):
         allocUnsafeShmem = allocShmemMethod('AllocUnsafeShmem', True)
 
-        # bool AdoptShmem(Shmem& aMem, Shmem* aOutmem):
-        #   SharedMemory* rawmem = aMem.Segment();
-        #   if (!rawmem || IsTrackingSharedMemory(rawmem)) {
-        #     NS_WARNING("bad Shmem"); // or NS_RUNTIMEABORT on child side
-        #     return false;
-        #   }
-        #   id_t id
-        #   if (!AdoptSharedMemory(rawmem, &id))
-        #     return false
-        #   *aOutmem = Shmem(rawmem, id);
-        #   return true;
-        adoptShmem = MethodDefn(MethodDecl(
-            'AdoptShmem',
-            params=[ Decl(_shmemType(const=1, ref=1), memvar.name),
-                     Decl(_shmemType(ptr=1), outmemvar.name) ],
-            ret=Type.BOOL))
-
-        adoptShmem.addstmt(StmtDecl(Decl(_rawShmemType(ptr=1), rawvar.name),
-                                    init=_shmemSegment(memvar)))
-        ifbad = StmtIf(ExprBinary(
-            ExprNot(rawvar), '||',
-            ExprCall(ExprVar('IsTrackingSharedMemory'), args=[ rawvar ])))
-        badShmemActions = []
-        if (self.side == 'child'):
-            badShmemActions.append(_runtimeAbort('bad Shmem'));
-        else:
-            badShmemActions.append(_printWarningMessage('bad Shmem'));
-        badShmemActions.append(StmtReturn.FALSE);
-        ifbad.addifstmts(badShmemActions)
-
-        adoptShmem.addstmt(ifbad)
-
-        ifadoptfails = StmtIf(ExprNot(ExprCall(
-            p.adoptSharedMemory(), args=[ rawvar, ExprAddrOf(idvar) ])))
-        ifadoptfails.addifstmt(StmtReturn.FALSE)
-
-        adoptShmem.addstmts([
-            Whitespace.NL,
-            StmtDecl(Decl(_shmemIdType(), idvar.name)),
-            ifadoptfails,
-            Whitespace.NL,
-            StmtExpr(ExprAssn(ExprDeref(outmemvar),
-                              _shmemCtor(rawvar, idvar))),
-            StmtReturn.TRUE
-        ])
-
         # bool DeallocShmem(Shmem& mem):
         #   bool ok = DestroySharedMemory(mem);
         ##ifdef DEBUG
         #   if (!ok) {
         #     NS_WARNING("bad Shmem"); // or NS_RUNTIMEABORT on child side
         #     return false;
         #   }
         ##endif // DEBUG
@@ -4212,16 +4111,22 @@ class _GenerateProtocolActorCode(ipdl.as
         #   return ok;
         deallocShmem = MethodDefn(MethodDecl(
             'DeallocShmem',
             params=[ Decl(_shmemType(ref=1), memvar.name) ],
             ret=Type.BOOL))
         okvar = ExprVar('ok')
 
         ifbad = StmtIf(ExprNot(okvar))
+        badShmemActions = []
+        if (self.side == 'child'):
+            badShmemActions.append(_runtimeAbort('bad Shmem'));
+        else:
+            badShmemActions.append(_printWarningMessage('bad Shmem'));
+        badShmemActions.append(StmtReturn.FALSE);
         ifbad.addifstmts(badShmemActions)
 
         deallocShmem.addstmts([
             StmtDecl(Decl(Type.BOOL, okvar.name),
                      init=ExprCall(p.destroySharedMemory(),
                                    args=[ memvar ])),
             CppDirective('ifdef', 'DEBUG'),
             ifbad,
@@ -4230,18 +4135,16 @@ class _GenerateProtocolActorCode(ipdl.as
             StmtReturn(okvar)
         ])
 
         return [ Whitespace('// Methods for managing shmem\n', indent=1),
                  allocShmem,
                  Whitespace.NL,
                  allocUnsafeShmem,
                  Whitespace.NL,
-                 adoptShmem,
-                 Whitespace.NL,
                  deallocShmem,
                  Whitespace.NL ]
 
     def genShmemCreatedHandler(self):
         p = self.protocol
         assert p.decl.type.isToplevel()
 
         case = StmtBlock()