Release GIL during entity replacement

This commit is contained in:
Kovid Goyal 2024-09-13 13:16:40 +05:30
parent 55c2ad77ce
commit 6f00feb3cb
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -157,7 +157,10 @@ replace_all_entities(PyObject *self, PyObject *const *args, Py_ssize_t nargs) {
if (nargs > 1) keep_xml_entities = PyObject_IsTrue(args[1]); if (nargs > 1) keep_xml_entities = PyObject_IsTrue(args[1]);
char *output = malloc(input_sz + 1); char *output = malloc(input_sz + 1);
if (!output) { return PyErr_NoMemory(); } if (!output) { return PyErr_NoMemory(); }
size_t output_sz = replace(input, input_sz, output, keep_xml_entities); size_t output_sz;
Py_BEGIN_ALLOW_THREADS
output_sz = replace(input, input_sz, output, keep_xml_entities);
Py_END_ALLOW_THREADS
PyObject *retval; PyObject *retval;
if (PyErr_Occurred()) retval = NULL; if (PyErr_Occurred()) retval = NULL;
else if (!output_sz) retval = Py_NewRef(args[0]); else if (!output_sz) retval = Py_NewRef(args[0]);