From aafec2281e70e47baa6f3d0fe5f1b11897f993e8 Mon Sep 17 00:00:00 2001 From: Lasse Blaauwbroek Date: Tue, 31 Oct 2023 09:37:03 +0100 Subject: [PATCH] Make `reraise_kj_exception` available to downstream I'm using Pycapnp in a project, where we compile `.capnp` files directly to Cython instead of using the dynamic interface (for speed). For this, we need access to the `reraise_kj_exception` C function defined by Pycapnp. This is not possible, because Cython does not automatically make this function available to downstream users. My previous solution, in #301, was rather flawed. The file `capabilityHelper.cpp`, where `reraise_kj_exception` is defined, was bundled into the distribution, so that this file could be included in downstream libraries. This turns out to be a terrible idea, because it redefines a bunch of other things like `ReadPromiseAdapter`. For reasons not entirely clear to me, this leads to segmentation faults. This PR revers #301. Instead, in this PR I've made `reraise_kj_exception` a Cython-level function, that can be used by downstream libraries. The C-level variant has been renamed to `c_reraise_kj_exception`. --- capnp/helpers/capabilityHelper.cpp | 2 +- capnp/helpers/capabilityHelper.h | 2 +- capnp/helpers/helpers.pxd | 2 +- capnp/helpers/non_circular.pxd | 2 +- capnp/includes/capnp_cpp.pxd | 2 +- capnp/includes/schema_cpp.pxd | 2 +- capnp/lib/capnp.pxd | 2 +- capnp/lib/capnp.pyx | 4 ++++ setup.py | 1 - 9 files changed, 11 insertions(+), 8 deletions(-) diff --git a/capnp/helpers/capabilityHelper.cpp b/capnp/helpers/capabilityHelper.cpp index 98cf950..455adc2 100644 --- a/capnp/helpers/capabilityHelper.cpp +++ b/capnp/helpers/capabilityHelper.cpp @@ -6,7 +6,7 @@ return stealPyRef(wrap_dynamic_struct_reader(response)); } ); } -void reraise_kj_exception() { +void c_reraise_kj_exception() { GILAcquire gil; try { if (PyErr_Occurred()) diff --git a/capnp/helpers/capabilityHelper.h b/capnp/helpers/capabilityHelper.h index 3aabbba..fc98b70 100644 --- a/capnp/helpers/capabilityHelper.h +++ b/capnp/helpers/capabilityHelper.h @@ -63,7 +63,7 @@ inline ::kj::Promise> convert_to_pypromise(kj::Promise