From 83d610c116c0778d5c05cb0dfa42766532f178a3 Mon Sep 17 00:00:00 2001 From: Lasse Blaauwbroek Date: Sun, 11 Jun 2023 03:50:54 +0200 Subject: [PATCH] Remove some more c++ helper functions --- capnp/helpers/capabilityHelper.h | 11 ----------- capnp/helpers/non_circular.pxd | 2 -- capnp/includes/capnp_cpp.pxd | 9 ++++++--- capnp/lib/capnp.pxd | 2 +- capnp/lib/capnp.pyx | 13 ++++++++----- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/capnp/helpers/capabilityHelper.h b/capnp/helpers/capabilityHelper.h index 7113baa..d1d270a 100644 --- a/capnp/helpers/capabilityHelper.h +++ b/capnp/helpers/capabilityHelper.h @@ -89,17 +89,6 @@ public: capnp::CallContext< capnp::DynamicStruct, capnp::DynamicStruct> context); }; -inline capnp::DynamicCapability::Client new_client(capnp::InterfaceSchema & schema, PyObject * server) { - return capnp::DynamicCapability::Client(kj::heap(schema, server)); -} -inline capnp::DynamicValue::Reader new_server(capnp::InterfaceSchema & schema, PyObject * server) { - return capnp::DynamicValue::Reader(kj::heap(schema, server)); -} - -inline capnp::Capability::Client server_to_client(capnp::InterfaceSchema & schema, PyObject * server) { - return kj::heap(schema, server); -} - class PyAsyncIoStream: public kj::AsyncIoStream { public: kj::Own protocol; diff --git a/capnp/helpers/non_circular.pxd b/capnp/helpers/non_circular.pxd index a14e910..164a569 100644 --- a/capnp/helpers/non_circular.pxd +++ b/capnp/helpers/non_circular.pxd @@ -2,8 +2,6 @@ from cpython.ref cimport PyObject from libcpp cimport bool cdef extern from "capnp/helpers/capabilityHelper.h": - cppclass PythonInterfaceDynamicImpl: - PythonInterfaceDynamicImpl(PyObject *) void reraise_kj_exception() cdef cppclass PyRefCounter: PyRefCounter(PyObject *) diff --git a/capnp/includes/capnp_cpp.pxd b/capnp/includes/capnp_cpp.pxd index a34967c..8428987 100644 --- a/capnp/includes/capnp_cpp.pxd +++ b/capnp/includes/capnp_cpp.pxd @@ -5,7 +5,7 @@ cdef extern from "capnp/helpers/checkCompiler.h": from libcpp cimport bool from capnp.helpers.non_circular cimport ( - PythonInterfaceDynamicImpl, reraise_kj_exception, PyRefCounter, + reraise_kj_exception, PyRefCounter, ) from capnp.includes.schema_cpp cimport ( Node, Data, StructNode, EnumNode, InterfaceNode, MessageBuilder, MessageReader, ReaderOptions, @@ -296,6 +296,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp": cppclass Client nogil: Client() Client(Client&) + Client(Own[PythonInterfaceDynamicImpl]) Client upcast(InterfaceSchema requestedSchema) DynamicCapability.Client castAs"castAs< ::capnp::DynamicCapability>"(InterfaceSchema) InterfaceSchema getSchema() @@ -326,7 +327,7 @@ cdef extern from "capnp/rpc-twoparty.h" namespace " ::capnp": TwoPartyVatNetwork(EventLoop &, AsyncIoStream& stream, Side, ReaderOptions) VoidPromise onDisconnect() VoidPromise onDrained() - RpcSystem makeRpcServerBootstrap"makeRpcServer"(TwoPartyVatNetwork&, Capability.Client) nogil + RpcSystem makeRpcServer(TwoPartyVatNetwork&, Capability.Client) nogil RpcSystem makeRpcClient(TwoPartyVatNetwork&) nogil cdef extern from "capnp/dynamic.h" namespace " ::capnp": @@ -410,7 +411,7 @@ cdef extern from "capnp/dynamic.h" namespace " ::capnp": Reader(DynamicEnum value) Reader(DynamicStruct.Reader& value) Reader(DynamicCapability.Client& value) - Reader(PythonInterfaceDynamicImpl& value) + Reader(Own[PythonInterfaceDynamicImpl] value) Reader(AnyPointer.Reader& value) Type getType() int64_t asInt"as"() @@ -497,6 +498,8 @@ cdef extern from "capnp/helpers/capabilityHelper.h": void rejectVoidDisconnected(VoidPromiseFulfiller& fulfiller, StringPtr message) Exception makeException(StringPtr message) PyPromise tryReadMessage(AsyncIoStream& stream, ReaderOptions opts) + cppclass PythonInterfaceDynamicImpl: + PythonInterfaceDynamicImpl(InterfaceSchema&, PyObject *) cdef extern from "capnp/serialize-async.h" namespace " ::capnp": VoidPromise writeMessage(AsyncIoStream& output, MessageBuilder& builder) diff --git a/capnp/lib/capnp.pxd b/capnp/lib/capnp.pxd index d131a66..aed34d1 100644 --- a/capnp/lib/capnp.pxd +++ b/capnp/lib/capnp.pxd @@ -9,7 +9,7 @@ from capnp.includes.capnp_cpp cimport ( SchemaParser as C_SchemaParser, ParsedSchema as C_ParsedSchema, VOID, ArrayPtr, StringPtr, String, StringTree, DynamicOrphan as C_DynamicOrphan, AnyPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, Request, Response, RemotePromise, Promise, - CallContext, RpcSystem, makeRpcServerBootstrap, makeRpcClient, Capability as C_Capability, + CallContext, RpcSystem, makeRpcServer, makeRpcClient, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, DynamicStruct_Builder, PyRefCounter, PyAsyncIoStream ) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 0de1829..887e43e 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -10,7 +10,7 @@ cimport cython # noqa: E402 from capnp.helpers.helpers cimport init_capnp_api -from capnp.includes.capnp_cpp cimport AsyncIoStream, WaitScope, PyPromise, VoidPromise, EventPort, EventLoop, Canceler, PyAsyncIoStream, PromiseFulfiller, VoidPromiseFulfiller, tryReadMessage, writeMessage, makeException +from capnp.includes.capnp_cpp cimport AsyncIoStream, WaitScope, PyPromise, VoidPromise, EventPort, EventLoop, Canceler, PyAsyncIoStream, PromiseFulfiller, VoidPromiseFulfiller, tryReadMessage, writeMessage, makeException, PythonInterfaceDynamicImpl from capnp.includes.schema_cpp cimport (MessageReader,) from cpython cimport array, Py_buffer, PyObject_CheckBuffer, memoryview, buffer @@ -702,7 +702,7 @@ cdef C_DynamicValue.Reader _extract_dynamic_client(_DynamicCapabilityClient valu cdef C_DynamicValue.Reader _extract_dynamic_server(object value): cdef _InterfaceSchema schema = value.schema - return helpers.new_server(schema.thisptr, value) + return C_DynamicValue.Reader(capnp.heap[PythonInterfaceDynamicImpl](schema.thisptr, value)) cdef C_DynamicValue.Reader _extract_dynamic_enum(_DynamicEnum value): @@ -2056,7 +2056,8 @@ cdef class _DynamicCapabilityClient: else: s = schema - self.thisptr = helpers.new_client(s.thisptr, server) + self.thisptr = C_DynamicCapability.Client( + capnp.heap[PythonInterfaceDynamicImpl](s.thisptr, server)) self._parent = server return self @@ -2250,8 +2251,10 @@ cdef class TwoPartyServer: raise ValueError(f"Argument socket should be a AsyncIoStream, was {type(socket)}") cdef _InterfaceSchema schema = bootstrap.schema - self.thisptr = capnp.heap[RpcSystem](makeRpcServerBootstrap( - deref(self._network.thisptr), helpers.server_to_client(schema.thisptr, bootstrap))) + self.thisptr = capnp.heap[RpcSystem](makeRpcServer( + deref(self._network.thisptr), + C_DynamicCapability.Client(capnp.heap[PythonInterfaceDynamicImpl]( + schema.thisptr, bootstrap)))) cpdef bootstrap(self) except +reraise_kj_exception: return _CapabilityClient()._init(helpers.bootstrapHelperServer(deref(self.thisptr)), self)