From ba6bf8202662f59aa1862bd4c5dd6fd0119a3335 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20de=20Kok?= Date: Wed, 24 Apr 2024 17:06:50 +0200 Subject: [PATCH] Fix compilation with recent Cython 3.x versions (#415) Recent versions of Cython 3.x refuse to compile the `_get_span2wp_alignment` function because it always requires acquiring the GIL to check if any exceptions are raised. Change the function signature to return an `int`, so that `-1` can be used to signal that an exception occured. It's not safe to qualify the function `noexcept`, since some calls can throw an exception. --- spacy_transformers/align.pyx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spacy_transformers/align.pyx b/spacy_transformers/align.pyx index db2da08d..ed7856c2 100644 --- a/spacy_transformers/align.pyx +++ b/spacy_transformers/align.pyx @@ -239,7 +239,7 @@ def get_span2wp_from_offset_mapping(span, wp_char_offsets): return result -cdef void _get_span2wp_alignment( +cdef int _get_span2wp_alignment( vector[unordered_set_uint32_t_ptr]* alignment, int32_t[::1] char_to_sp_token, int char_to_sp_token_length, @@ -262,3 +262,4 @@ cdef void _get_span2wp_alignment( deref(alignment.at(token_i)).insert(wp_j) char_idx += 1 wp_j += 1 + return 0