Fix API changes in EventLoop

This commit is contained in:
Jason Paryani 2013-12-04 11:42:57 -08:00
parent cfc11e4a8a
commit bb3121d3ae
4 changed files with 30 additions and 29 deletions

View file

@ -9,7 +9,7 @@
cimport cython
cimport capnp_cpp as capnp
cimport schema_cpp
from capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, fixMaybe, getEnumString, SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, ObjectPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, new_client, new_server, server_to_client, Request, Response, RemotePromise, convert_to_pypromise, UnixEventLoop, PyPromise, VoidPromise, CallContext, PyRestorer, RpcSystem, makeRpcServer, makeRpcClient, makeRpcClientWithRestorer, restoreHelper, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream_wrapFd, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, reraise_kj_exception
from capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, fixMaybe, getEnumString, SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, ObjectPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, new_client, new_server, server_to_client, Request, Response, RemotePromise, convert_to_pypromise, UnixEventLoop, PyPromise, VoidPromise, CallContext, PyRestorer, RpcSystem, makeRpcServer, makeRpcClient, makeRpcClientWithRestorer, restoreHelper, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, reraise_kj_exception
from schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
from cython.operator cimport dereference as deref
@ -488,7 +488,7 @@ cdef class _DynamicListBuilder:
cpdef adopt(self, index, _DynamicOrphan orphan):
"""A method for adopting Cap'n Proto orphans
Don't use this method unless you know what you're doing. Orphans are useful for dynamically allocating objects for an unkown sized list.
Don't use this method unless you know what you're doing. Orphans are useful for dynamically allocating objects for an unknown sized list.
:type index: int
:param index: The index of the element in the list to replace with the newly adopted object
@ -989,7 +989,7 @@ cdef class _DynamicStructBuilder:
cpdef adopt(self, field, _DynamicOrphan orphan):
"""A method for adopting Cap'n Proto orphans
Don't use this method unless you know what you're doing. Orphans are useful for dynamically allocating objects for an unkown sized list.
Don't use this method unless you know what you're doing. Orphans are useful for dynamically allocating objects for an unknown sized list.
:type field: str
:param field: The field name in the struct
@ -1164,20 +1164,22 @@ cdef class _DynamicObjectBuilder:
return _DynamicStructBuilder()._init(self.thisptr.getAs(s.thisptr), self._parent)
cdef class _EventLoop:
cdef UnixEventLoop * thisptr
cdef Own[capnp.AsyncIoProvider] thisptr
def __init__(self):
self._init()
cdef _init(self) except +reraise_kj_exception:
self.thisptr = new UnixEventLoop()
self.thisptr = capnp.setupIoEventLoop()
def __dealloc__(self):
self.remove()
cdef Own[AsyncIoStream] wrapSocketFd(self, int fd):
return deref(self.thisptr).wrapSocketFd(fd)
cpdef remove(self) except +reraise_kj_exception:
del self.thisptr
self.thisptr = NULL
# def __dealloc__(self):
# self.remove()
# cpdef remove(self) except +reraise_kj_exception:
# self.thisptr = NULL
# cpdef evalLater(self, func):
# Py_INCREF(func)
@ -1211,13 +1213,7 @@ cdef class _EventLoop:
# Py_INCREF(error_func)
# return Promise()._init(capnp.there(self.thisptr, deref(promise.thisptr), <PyObject *>func, <PyObject *>error_func))
DEFAULT_EVENT_LOOP = _EventLoop()
def remove_event_loop():
global DEFAULT_EVENT_LOOP
DEFAULT_EVENT_LOOP.remove()
DEFAULT_EVENT_LOOP = None
cdef _EventLoop C_DEFAULT_EVENT_LOOP = _EventLoop()
cdef class _CallContext:
cdef CallContext * thisptr
@ -1612,7 +1608,10 @@ cdef class _FdAsyncIoStream:
cdef Own[AsyncIoStream] thisptr
def __init__(self, int fd):
self.thisptr = AsyncIoStream_wrapFd(fd)
self._init(fd)
cdef _init(self, int fd) except +reraise_kj_exception:
self.thisptr = C_DEFAULT_EVENT_LOOP.wrapSocketFd(fd)
cdef class PromiseFulfillerPair:
cdef Own[C_PromiseFulfillerPair] thisptr
@ -2091,7 +2090,7 @@ cdef class _MessageBuilder:
cpdef new_orphan(self, schema) except +reraise_kj_exception:
"""A method for instantiating Cap'n Proto orphans
Don't use this method unless you know what you're doing. Orphans are useful for dynamically allocating objects for an unkown sized list, ie::
Don't use this method unless you know what you're doing. Orphans are useful for dynamically allocating objects for an unknown sized list, ie::
addressbook = capnp.load('addressbook.capnp')
m = capnp._MallocMessageBuilder()

View file

@ -59,8 +59,11 @@ cdef extern from "kj/array.h" namespace " ::kj":
cdef extern from "kj/async-io.h" namespace " ::kj":
cdef cppclass AsyncIoStream:
pass
Own[AsyncIoStream] AsyncIoStream_wrapFd" ::kj::AsyncIoStream::wrapFd"(int)
cdef cppclass AsyncIoProvider:
# Own[AsyncInputStream] wrapInputFd(int)
# Own[AsyncOutputStream] wrapOutputFd(int)
Own[AsyncIoStream] wrapSocketFd(int)
Own[AsyncIoProvider] setupIoEventLoop()
cdef extern from "capnp/schema.h" namespace " ::capnp":
cdef cppclass Schema:
@ -343,7 +346,7 @@ cdef extern from "capnp/schema-parser.h" namespace " ::capnp":
ParsedSchema getNested(char * name) except +reraise_kj_exception
cdef cppclass SchemaParser:
SchemaParser()
ParsedSchema parseDiskFile(char * displayName, char * diskPath, ArrayPtr[StringPtr] importPath) except +reraise_kj_exception
ParsedSchema parseDiskFile(char * displayName, char * diskPath, ArrayPtr[StringPtr] importPath)
cdef extern from "capnp/orphan.h" namespace " ::capnp":
cdef cppclass DynamicOrphan" ::capnp::Orphan< ::capnp::DynamicValue>":

View file

@ -32,4 +32,9 @@ def example_simple_rpc():
assert response.x == '125'
example_simple_rpc()
# example_simple_rpc()
capnp.load('test.capnp')
for i in range(100):
capnp.load('test.capnp')
capnp.load('test.capnp')

View file

@ -34,9 +34,3 @@ def test_simple_rpc(capability):
response = remote.wait()
assert response.x == '125'
def test_custom_event_loop(capability):
capnp.remove_event_loop()
capnp.DEFAULT_EVENT_LOOP = capnp._EventLoop()
test_simple_rpc(capability)