Fix segfault by making TwoPartyClient's members immortal

This commit is contained in:
Jason Paryani
2013-12-10 23:29:21 -08:00
parent a17c76f593
commit 0e178de136
2 changed files with 12 additions and 9 deletions

View File

@@ -1559,11 +1559,12 @@ cdef class _CapabilityClient:
cdef class _Restorer: cdef class _Restorer:
cdef PyRestorer * thisptr cdef PyRestorer * thisptr
cdef public object restore cdef public object restore, _parent
def __init__(self, restore): def __init__(self, restore, parent=None):
self.thisptr = new PyRestorer(<PyObject*>self) self.thisptr = new PyRestorer(<PyObject*>self)
self.restore = restore self.restore = restore
self._parent = parent
def __dealloc__(self): def __dealloc__(self):
del self.thisptr del self.thisptr
@@ -1580,11 +1581,11 @@ cdef class _TwoPartyVatNetwork:
cdef _Restorer _convert_restorer(restorer): cdef _Restorer _convert_restorer(restorer):
if isinstance(restorer, _RestorerImpl): if isinstance(restorer, _RestorerImpl):
return _Restorer(restorer._restore) return _Restorer(restorer._restore, restorer)
elif type(restorer) is _Restorer: elif type(restorer) is _Restorer:
return restorer return restorer
elif hasattr(restorer, 'restore'): elif hasattr(restorer, 'restore'):
return _Restorer(restorer.restore) return _Restorer(restorer.restore, restorer)
elif callable(restorer): elif callable(restorer):
return _Restorer(restorer) return _Restorer(restorer)
else: else:
@@ -1605,7 +1606,11 @@ cdef class TwoPartyClient:
self.thisptr = new RpcSystem(makeRpcClient(deref(self.network.thisptr))) self.thisptr = new RpcSystem(makeRpcClient(deref(self.network.thisptr)))
else: else:
self.restorer = _convert_restorer(restorer) self.restorer = _convert_restorer(restorer)
Py_INCREF(self.restorer)
self.thisptr = new RpcSystem(makeRpcClientWithRestorer(deref(self.network.thisptr), deref(self.restorer.thisptr))) self.thisptr = new RpcSystem(makeRpcClientWithRestorer(deref(self.network.thisptr), deref(self.restorer.thisptr)))
Py_INCREF(self._stream)
Py_INCREF(self.stream)
Py_INCREF(self.network) # TODO: attach this to onDrained, also figure out what's leaking
def __dealloc__(self): def __dealloc__(self):
del self.thisptr del self.thisptr
@@ -1659,12 +1664,12 @@ cdef class TwoPartyServer:
def __init__(self, stream, restorer): def __init__(self, stream, restorer):
self._stream = stream self._stream = stream
self.stream = _FdAsyncIoStream(stream.fileno()) self.stream = _FdAsyncIoStream(stream.fileno())
Py_INCREF(self._stream)
Py_INCREF(self.stream) # TODO: attach this to onDrained, also figure out what's leaking
self.restorer = _convert_restorer(restorer) self.restorer = _convert_restorer(restorer)
self.network = _TwoPartyVatNetwork()._init(deref(self.stream.thisptr), capnp.SERVER) self.network = _TwoPartyVatNetwork()._init(deref(self.stream.thisptr), capnp.SERVER)
self.thisptr = new RpcSystem(makeRpcServer(deref(self.network.thisptr), deref(self.restorer.thisptr))) self.thisptr = new RpcSystem(makeRpcServer(deref(self.network.thisptr), deref(self.restorer.thisptr)))
Py_INCREF(self.restorer) # TODO: attach this to onDrained, also figure out what's leaking Py_INCREF(self._stream)
Py_INCREF(self.stream)
Py_INCREF(self.restorer)
Py_INCREF(self.network) # TODO: attach this to onDrained, also figure out what's leaking Py_INCREF(self.network) # TODO: attach this to onDrained, also figure out what's leaking
def __dealloc__(self): def __dealloc__(self):

View File

@@ -5,10 +5,8 @@ import argparse
import socket import socket
import random import random
import capnp import capnp
import traceback
import calculator_capnp import calculator_capnp
import rpc_capnp
def readValue(value): def readValue(value):
'''Helper function to asynchronously call read() on a Calculator::Value and '''Helper function to asynchronously call read() on a Calculator::Value and