Refactor layout of pxd files

This commit is contained in:
Jason Paryani 2013-12-08 17:27:59 -08:00
parent 8aa258ff73
commit cff551c774
13 changed files with 66 additions and 16 deletions

0
capnp/__init__.pxd Normal file
View file

View file

@ -7,11 +7,16 @@
# cython: embedsignature = True
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, AnyPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, new_client, new_server, server_to_client, Request, Response, RemotePromise, convert_to_pypromise, 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 .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, 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, AnyPointer as C_DynamicObject, DynamicCapability as C_DynamicCapability, new_client, new_server, server_to_client, Request, Response, RemotePromise, convert_to_pypromise, PyPromise, VoidPromise, CallContext, PyRestorer, RpcSystem, makeRpcServer, makeRpcClient, restoreHelper, Capability as C_Capability, TwoPartyVatNetwork as C_TwoPartyVatNetwork, Side, AsyncIoStream, Own, makeTwoPartyVatNetwork, PromiseFulfillerPair as C_PromiseFulfillerPair, copyPromiseFulfillerPair, newPromiseAndFulfiller, reraise_kj_exception
from .capnp.includes.schema_cpp cimport Node as C_Node, EnumNode as C_EnumNode
from .capnp.helpers.helpers cimport makeRpcClientWithRestorer
from cython.operator cimport dereference as deref
from cpython.ref cimport PyObject, Py_INCREF, Py_DECREF

View file

View file

@ -0,0 +1,11 @@
#ifdef __GNUC__
#if __clang__
#if __cplusplus >= 201103L && !__has_include(<initializer_list>)
#warning "Your compiler supports C++11 but your C++ standard library does not. If your system has libc++ installed (as should be the case on e.g. Mac OSX), try adding -stdlib=libc++ to your CFLAGS (ignore the other warning that says to use CXXFLAGS)."
#endif
#endif
#endif
#include "capnp/dynamic.h"
static_assert(CAPNP_VERSION >= 3000, "Version of Cap'n Proto C++ Library is too old. Please upgrade to a version >= 0.3 and then re-install this python library");

View file

@ -1,8 +1,6 @@
#include "kj/common.h"
#include <stdexcept>
static_assert(CAPNP_VERSION >= 3000, "Version of Cap'n Proto C++ Library is too old. Please upgrade to a version >= 0.3 and then re-install this python library");
template<typename T>
T fixMaybe(::kj::Maybe<T> val) {
KJ_IF_MAYBE(new_val, val) {

29
capnp/helpers/helpers.pxd Normal file
View file

@ -0,0 +1,29 @@
from .capnp.includes.capnp_cpp cimport Maybe, DynamicStruct, Request, PyPromise, VoidPromise, RemotePromise, DynamicCapability, InterfaceSchema, EnumSchema, StructSchema, DynamicValue, Capability, RpcSystem, MessageBuilder, MessageReader, TwoPartyVatNetwork
from non_circular cimport reraise_kj_exception
from cpython.ref cimport PyObject
cdef extern from "helpers/fixMaybe.h":
EnumSchema.Enumerant fixMaybe(Maybe[EnumSchema.Enumerant]) except +reraise_kj_exception
char * getEnumString(DynamicStruct.Reader val)
char * getEnumString(DynamicStruct.Builder val)
char * getEnumString(Request val)
cdef extern from "helpers/capabilityHelper.h":
# PyPromise evalLater(EventLoop &, PyObject * func)
# PyPromise there(EventLoop & loop, PyPromise & promise, PyObject * func, PyObject * error_func)
PyPromise then(PyPromise & promise, PyObject * func, PyObject * error_func)
VoidPromise then(RemotePromise & promise, PyObject * func, PyObject * error_func)
PyPromise then(VoidPromise & promise, PyObject * func, PyObject * error_func)
DynamicCapability.Client new_client(InterfaceSchema&, PyObject *)
DynamicValue.Reader new_server(InterfaceSchema&, PyObject *)
Capability.Client server_to_client(InterfaceSchema&, PyObject *)
PyPromise convert_to_pypromise(RemotePromise&)
cdef extern from "helpers/rpcHelper.h":
cdef cppclass PyRestorer:
PyRestorer(PyObject *, StructSchema&)
Capability.Client restoreHelper(RpcSystem&, MessageBuilder&)
Capability.Client restoreHelper(RpcSystem&, MessageReader&)
RpcSystem makeRpcClientWithRestorer(TwoPartyVatNetwork&, PyRestorer&)

View file

@ -0,0 +1,8 @@
from cpython.ref cimport PyObject
cdef extern from "helpers/capabilityHelper.h":
cppclass PythonInterfaceDynamicImpl:
PythonInterfaceDynamicImpl(PyObject *)
cdef extern from "helpers/capabilityHelper.h":
void reraise_kj_exception()

View file

View file

@ -1,7 +1,11 @@
# schema.capnp.cpp.pyx
# distutils: language = c++
# distutils: extra_compile_args = --std=c++11
cdef extern from "helpers/checkCompiler.h":
pass
from schema_cpp cimport Node, Data, StructNode, EnumNode, InterfaceNode, MessageBuilder, MessageReader
from .capnp.helpers.non_circular cimport PythonInterfaceDynamicImpl, reraise_kj_exception
from cpython.ref cimport PyObject
from libc.stdint cimport *
@ -17,9 +21,6 @@ cdef extern from "kj/async.h" namespace " ::kj":
ctypedef Promise[PyObject *] PyPromise
ctypedef Promise[void] VoidPromise
cdef extern from "capabilityHelper.h":
void reraise_kj_exception()
cdef extern from "capnp/common.h" namespace " ::capnp":
enum Void:
VOID " ::capnp::VOID"
@ -252,26 +253,24 @@ cdef extern from "capnp/any.h" namespace " ::capnp":
Builder(Builder)
DynamicStruct.Builder getAs"getAs< ::capnp::DynamicStruct>"(StructSchema)
cdef extern from "fixMaybe.h":
cdef extern from "helpers/fixMaybe.h":
EnumSchema.Enumerant fixMaybe(Maybe[EnumSchema.Enumerant]) except +reraise_kj_exception
char * getEnumString(DynamicStruct.Reader val)
char * getEnumString(DynamicStruct.Builder val)
char * getEnumString(Request val)
cdef extern from "capabilityHelper.h":
cdef extern from "helpers/capabilityHelper.h":
# PyPromise evalLater(EventLoop &, PyObject * func)
# PyPromise there(EventLoop & loop, PyPromise & promise, PyObject * func, PyObject * error_func)
PyPromise then(PyPromise & promise, PyObject * func, PyObject * error_func)
VoidPromise then(RemotePromise & promise, PyObject * func, PyObject * error_func)
PyPromise then(VoidPromise & promise, PyObject * func, PyObject * error_func)
cppclass PythonInterfaceDynamicImpl:
PythonInterfaceDynamicImpl(PyObject *)
DynamicCapability.Client new_client(InterfaceSchema&, PyObject *)
DynamicValueForward.Reader new_server(InterfaceSchema&, PyObject *)
Capability.Client server_to_client(InterfaceSchema&, PyObject *)
PyPromise convert_to_pypromise(RemotePromise&)
cdef extern from "rpcHelper.h":
cdef extern from "helpers/rpcHelper.h":
cdef cppclass PyRestorer:
PyRestorer(PyObject *, StructSchema&)
Capability.Client restoreHelper(RpcSystem&, MessageBuilder&)

View file

@ -718,7 +718,7 @@ cdef extern from "kj/array.h" namespace " ::kj":
word* begin()
size_t size()
cdef extern from "capabilityHelper.h":
cdef extern from "helpers/capabilityHelper.h":
void reraise_kj_exception()
cdef extern from "kj/array.h" namespace " ::kj":

View file

@ -48,7 +48,7 @@ setup(
name="pycapnp",
packages=["capnp"],
version=VERSION,
package_data={'capnp': ['*.pxd', '*.pyx', '*.h']},
package_data={'capnp': ['*.pxd', '*.pyx', '*.h', 'helpers/*.pxd', 'helpers/*.h', 'includes/*.pxd']},
ext_modules=cythonize('capnp/*.pyx', language="c++"),
install_requires=[
'cython > 0.19',