Skip to content

Commit

Permalink
Fix compilation with recent Cython 3.x versions (#415)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danieldk authored Apr 24, 2024
1 parent dccca69 commit ba6bf82
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion spacy_transformers/align.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

0 comments on commit ba6bf82

Please sign in to comment.