Move exported functions used in capabilityHelper.h from extern "C" to api.

Signed-off-by: Keith Rothman <537074+litghost@users.noreply.github.com>
This commit is contained in:
Keith Rothman
2020-02-28 16:58:26 -08:00
parent e0d3618aa6
commit dbc9debbbf
7 changed files with 215 additions and 172 deletions

View File

@@ -2,7 +2,7 @@
from capnp.includes cimport capnp_cpp as capnp
from capnp.includes cimport schema_cpp
from capnp.includes.capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, EnumSchema as C_EnumSchema, ListSchema as C_ListSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, 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, PyPromise, VoidPromise, CallContext, RpcSystem, makeRpcServerBootstrap, makeRpcClient, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, PyArray, DynamicStruct_Builder, TwoWayPipe
from capnp.includes.capnp_cpp cimport Schema as C_Schema, StructSchema as C_StructSchema, InterfaceSchema as C_InterfaceSchema, EnumSchema as C_EnumSchema, ListSchema as C_ListSchema, DynamicStruct as C_DynamicStruct, DynamicValue as C_DynamicValue, Type as C_Type, DynamicList as C_DynamicList, 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, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, PyArray, DynamicStruct_Builder, TwoWayPipe
from capnp.includes.schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
from capnp.includes.types cimport *
from capnp.helpers.non_circular cimport reraise_kj_exception
@@ -130,6 +130,15 @@ cdef class _DynamicListBuilder:
cpdef init(self, index, size)
cdef class _MessageBuilder:
cdef schema_cpp.MessageBuilder * thisptr
cpdef init_root(self, schema)
cpdef get_root(self, schema) except +reraise_kj_exception
cpdef get_root_as_any(self) except +reraise_kj_exception
cpdef set_root(self, value) except +reraise_kj_exception
cpdef get_segments_for_output(self) except +reraise_kj_exception
cpdef new_orphan(self, schema) except +reraise_kj_exception
cdef to_python_reader(C_DynamicValue.Reader self, object parent)
cdef to_python_builder(C_DynamicValue.Builder self, object parent)
cdef _to_dict(msg, bint verbose, bint ordered)
@@ -137,3 +146,13 @@ cdef _from_list(_DynamicListBuilder msg, list d)
cdef _from_tuple(_DynamicListBuilder msg, tuple d)
cdef _setDynamicFieldWithField(DynamicStruct_Builder thisptr, _StructSchemaField field, value, parent)
cdef _setDynamicFieldStatic(DynamicStruct_Builder thisptr, field, value, parent)
cdef api object wrap_dynamic_struct_reader(Response & r) with gil
cdef api PyObject * wrap_remote_call(PyObject * func, Response & r) except * with gil
cdef api Promise[void] * call_server_method(PyObject * _server, char * _method_name, CallContext & _context) except * with gil
cdef api convert_array_pyobject(PyArray & arr) with gil
cdef api Promise[PyObject*] * extract_promise(object obj) with gil
cdef api RemotePromise * extract_remote_promise(object obj) with gil
cdef api object wrap_kj_exception(capnp.Exception & exception) with gil
cdef api object wrap_kj_exception_for_reraise(capnp.Exception & exception) with gil
cdef api object get_exception_info(object exc_type, object exc_obj, object exc_tb) with gil

View File

@@ -9,8 +9,8 @@
cimport cython
from capnp.helpers.helpers cimport AsyncIoStreamReadHelper
from capnp.includes.capnp_cpp cimport AsyncIoStream, WaitScope
from capnp.helpers.helpers cimport AsyncIoStreamReadHelper, init_capnp_api
from capnp.includes.capnp_cpp cimport AsyncIoStream, WaitScope, PyPromise, VoidPromise
from libc.stdlib cimport malloc, free
from libc.string cimport memcpy
@@ -48,10 +48,10 @@ def deregister_all_types():
_type_registry = {}
# By making it public, we'll be able to call it from capabilityHelper.h
cdef public object wrap_dynamic_struct_reader(Response & r) with gil:
cdef api object wrap_dynamic_struct_reader(Response & r) with gil:
return _Response()._init_childptr(new Response(moveResponse(r)), None)
cdef public PyObject * wrap_remote_call(PyObject * func, Response & r) except * with gil:
cdef api PyObject * wrap_remote_call(PyObject * func, Response & r) except * with gil:
response = _Response()._init_childptr(new Response(moveResponse(r)), None)
func_obj = <object>func
@@ -62,7 +62,7 @@ cdef public PyObject * wrap_remote_call(PyObject * func, Response & r) except *
cdef _find_field_order(struct_node):
return [f.name for f in sorted(struct_node.fields, key=_attrgetter('codeOrder'))]
cdef public VoidPromise * call_server_method(PyObject * _server, char * _method_name, CallContext & _context) except * with gil:
cdef api VoidPromise * call_server_method(PyObject * _server, char * _method_name, CallContext & _context) except * with gil:
server = <object>_server
method_name = <object>_method_name
@@ -117,10 +117,10 @@ cdef public VoidPromise * call_server_method(PyObject * _server, char * _method_
return NULL
cdef public convert_array_pyobject(PyArray & arr) with gil:
cdef api convert_array_pyobject(PyArray & arr) with gil:
return [<object>arr[i] for i in range(arr.size())]
cdef public PyPromise * extract_promise(object obj) with gil:
cdef api PyPromise * extract_promise(object obj) with gil:
if type(obj) is _Promise:
promise = <_Promise>obj
@@ -131,7 +131,7 @@ cdef public PyPromise * extract_promise(object obj) with gil:
return NULL
cdef public RemotePromise * extract_remote_promise(object obj) with gil:
cdef api RemotePromise * extract_remote_promise(object obj) with gil:
if type(obj) is _RemotePromise:
promise = <_RemotePromise>obj
promise.is_consumed = True
@@ -235,20 +235,20 @@ class KjException(Exception):
return AttributeError(message)
return self
cdef public object wrap_kj_exception(capnp.Exception & exception) with gil:
cdef api object wrap_kj_exception(capnp.Exception & exception) with gil:
PyErr_Clear()
wrapper = _KjExceptionWrapper()._init(exception)
ret = KjException(wrapper=wrapper)
return ret
cdef public object wrap_kj_exception_for_reraise(capnp.Exception & exception) with gil:
cdef api object wrap_kj_exception_for_reraise(capnp.Exception & exception) with gil:
wrapper = _KjExceptionWrapper()._init(exception)
ret = KjException(wrapper=wrapper)
return ret
cdef public object get_exception_info(object exc_type, object exc_obj, object exc_tb) with gil:
cdef api object get_exception_info(object exc_type, object exc_obj, object exc_tb) with gil:
try:
return (exc_tb.tb_frame.f_code.co_filename.encode(), exc_tb.tb_lineno, (repr(exc_type) + ':' + str(exc_obj)).encode())
except:
@@ -3250,7 +3250,6 @@ cdef class _MessageBuilder:
.. warning:: Don't ever instantiate this class directly. It is only used for inheritance.
"""
cdef schema_cpp.MessageBuilder * thisptr
def __dealloc__(self):
del self.thisptr
@@ -4080,3 +4079,7 @@ def remove_import_hook():
if _importer is not None:
_sys.meta_path.remove(_importer)
_importer = None
def _init_capnp_api():
""" Initialize static function pointers for cdef api functions. """
init_capnp_api()