From 816a89c1b5f24ffecab94181091d3fb8d834f054 Mon Sep 17 00:00:00 2001 From: Nathan Goldbaum Date: Wed, 14 Dec 2022 12:46:56 -0700 Subject: [PATCH] acquire GIL for error condition in unicode to ascii cast --- asciidtype/asciidtype/src/casts.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/asciidtype/asciidtype/src/casts.c b/asciidtype/asciidtype/src/casts.c index dc504b9a..8b4acfab 100644 --- a/asciidtype/asciidtype/src/casts.c +++ b/asciidtype/asciidtype/src/casts.c @@ -135,9 +135,12 @@ unicode_to_ascii(PyArrayMethod_Context *context, char *const data[], for (int i = 0; i < copy_size; i++) { Py_UCS4 c = ((Py_UCS4 *)in)[i]; if (c > 127) { + PyGILState_STATE gstate; + gstate = PyGILState_Ensure(); PyErr_SetString( PyExc_TypeError, "Can only store ASCII text in a ASCIIDType array."); + PyGILState_Release(gstate); return -1; } // UCS4 character is ascii, so casting to Py_UCS1 does not truncate