diff --git a/kitty/freetype.c b/kitty/freetype.c index 7c6ed9a19..933308377 100644 --- a/kitty/freetype.c +++ b/kitty/freetype.c @@ -63,9 +63,7 @@ new(PyTypeObject *type, PyObject *args, PyObject UNUSED *kwds) { self = (Face *)type->tp_alloc(type, 0); if (self != NULL) { - Py_BEGIN_ALLOW_THREADS; error = FT_New_Face(library, path, index, &(self->face)); - Py_END_ALLOW_THREADS; if(error) { set_freetype_error("Failed to load face, with error:", error); Py_CLEAR(self); return NULL; } #define CPY(n) self->n = self->face->n; CPY(units_per_EM); CPY(ascender); CPY(descender); CPY(height); CPY(max_advance_width); CPY(max_advance_height); CPY(underline_position); CPY(underline_thickness); @@ -88,9 +86,7 @@ set_char_size(Face *self, PyObject *args) { unsigned int xdpi, ydpi; int error; if (!PyArg_ParseTuple(args, "llII", &char_width, &char_height, &xdpi, &ydpi)) return NULL; - Py_BEGIN_ALLOW_THREADS; error = FT_Set_Char_Size(self->face, char_width, char_height, xdpi, ydpi); - Py_END_ALLOW_THREADS; if (error) { set_freetype_error("Failed to set char size, with error:", error); Py_CLEAR(self); return NULL; } Py_RETURN_NONE; } @@ -107,9 +103,7 @@ load_char(Face *self, PyObject *args) { if (hintstyle >= 3) flags |= FT_LOAD_TARGET_NORMAL; else if (0 < hintstyle && hintstyle < 3) flags |= FT_LOAD_TARGET_LIGHT; } else flags |= FT_LOAD_NO_HINTING; - Py_BEGIN_ALLOW_THREADS; error = FT_Load_Glyph(self->face, glyph_index, flags); - Py_END_ALLOW_THREADS; if (error) { set_freetype_error("Failed to load glyph, with error:", error); Py_CLEAR(self); return NULL; } Py_RETURN_NONE; } @@ -120,9 +114,7 @@ get_char_index(Face *self, PyObject *args) { int code; unsigned int ans; if (!PyArg_ParseTuple(args, "C", &code)) return NULL; - Py_BEGIN_ALLOW_THREADS; ans = FT_Get_Char_Index(self->face, code); - Py_END_ALLOW_THREADS; return Py_BuildValue("I", ans); } diff --git a/kitty/gl.h b/kitty/gl.h index 382d0ceb9..fcf964033 100644 --- a/kitty/gl.h +++ b/kitty/gl.h @@ -194,9 +194,7 @@ GetString(PyObject UNUSED *self, PyObject *val) { static PyObject* Clear(PyObject UNUSED *self, PyObject *val) { unsigned long m = PyLong_AsUnsignedLong(val); - Py_BEGIN_ALLOW_THREADS; glClear((GLbitfield)m); - Py_END_ALLOW_THREADS; CHECK_ERROR; Py_RETURN_NONE; } @@ -206,9 +204,7 @@ DrawArrays(PyObject UNUSED *self, PyObject *args) { int mode, first; unsigned int count; if (!PyArg_ParseTuple(args, "iiI", &mode, &first, &count)) return NULL; - Py_BEGIN_ALLOW_THREADS; glDrawArrays(mode, first, count); - Py_END_ALLOW_THREADS; CHECK_ERROR; Py_RETURN_NONE; } @@ -219,9 +215,7 @@ MultiDrawArrays(PyObject UNUSED *self, PyObject *args) { unsigned int draw_count; PyObject *a, *b; if (!PyArg_ParseTuple(args, "iO!O!I", &mode, &PyLong_Type, &a, &PyLong_Type, &b, &draw_count)) return NULL; - Py_BEGIN_ALLOW_THREADS; glMultiDrawArrays(mode, PyLong_AsVoidPtr(a), PyLong_AsVoidPtr(b), draw_count); - Py_END_ALLOW_THREADS; CHECK_ERROR; Py_RETURN_NONE; } @@ -231,9 +225,7 @@ DrawArraysInstanced(PyObject UNUSED *self, PyObject *args) { int mode, first; unsigned int count, primcount; if (!PyArg_ParseTuple(args, "iiII", &mode, &first, &count, &primcount)) return NULL; - Py_BEGIN_ALLOW_THREADS; glDrawArraysInstanced(mode, first, count, primcount); - Py_END_ALLOW_THREADS; CHECK_ERROR; Py_RETURN_NONE; } @@ -522,9 +514,7 @@ TexStorage3D(PyObject UNUSED *self, PyObject *args) { int target, fmt; unsigned int levels, width, height, depth; if (!PyArg_ParseTuple(args, "iIiIII", &target, &levels, &fmt, &width, &height, &depth)) return NULL; - Py_BEGIN_ALLOW_THREADS; glTexStorage3D(target, levels, fmt, width, height, depth); - Py_END_ALLOW_THREADS; CHECK_ERROR; Py_RETURN_NONE; } @@ -548,9 +538,7 @@ CopyImageSubData(PyObject UNUSED *self, PyObject *args) { &dest, &dest_target, &dest_level, &destX, &destY, &destZ, &width, &height, &depth )) return NULL; - Py_BEGIN_ALLOW_THREADS; glCopyImageSubData(src, src_target, src_level, srcX, srcY, srcZ, dest, dest_target, dest_level, destX, destY, destZ, width, height, depth); - Py_END_ALLOW_THREADS; CHECK_ERROR; Py_RETURN_NONE; } @@ -564,14 +552,12 @@ copy_image_sub_data(PyObject UNUSED *self, PyObject *args) { uint8_t *src = (uint8_t*)PyMem_Malloc(5 * width * height * num_levels); if (src == NULL) return PyErr_NoMemory(); uint8_t *dest = src + (4 * width * height * num_levels); - Py_BEGIN_ALLOW_THREADS; glBindTexture(GL_TEXTURE_2D_ARRAY, src_target); glGetTexImage(GL_TEXTURE_2D_ARRAY, 0, GL_RGBA, GL_UNSIGNED_BYTE, src); glBindTexture(GL_TEXTURE_2D_ARRAY, dest_target); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); for(unsigned int i = 0; i < width * height * num_levels; i++) dest[i] = src[4*i]; glTexSubImage3D(GL_TEXTURE_2D_ARRAY, 0, 0, 0, 0, width, height, num_levels, GL_RED, GL_UNSIGNED_BYTE, dest); - Py_END_ALLOW_THREADS; PyMem_Free(src); Py_RETURN_NONE; } @@ -584,9 +570,7 @@ TexSubImage3D(PyObject UNUSED *self, PyObject *args) { if (!PyArg_ParseTuple(args, "iiiiiIIIiiO!", &target, &level, &x, &y, &z, &width, &height, &depth, &fmt, &type, &PyLong_Type, &pixels)) return NULL; void *data = PyLong_AsVoidPtr(pixels); if (data == NULL) { PyErr_SetString(PyExc_TypeError, "Not a valid data pointer"); return NULL; } - Py_BEGIN_ALLOW_THREADS; glTexSubImage3D(target, level, x, y, z, width, height, depth, fmt, type, data); - Py_END_ALLOW_THREADS; CHECK_ERROR; Py_RETURN_NONE; } @@ -599,9 +583,7 @@ GetTexImage(PyObject UNUSED *self, PyObject *args) { if (!PyArg_ParseTuple(args, "iiiiO!", &target, &level, &fmt, &type, &PyLong_Type, &pixels)) return NULL; void *data = PyLong_AsVoidPtr(pixels); if (data == NULL) { PyErr_SetString(PyExc_TypeError, "Not a valid data pointer"); return NULL; } - Py_BEGIN_ALLOW_THREADS; glGetTexImage(target, level, fmt, type, data); - Py_END_ALLOW_THREADS; CHECK_ERROR; Py_RETURN_NONE; } @@ -615,9 +597,7 @@ GetBufferSubData(PyObject UNUSED *self, PyObject *args) { void *data = PyLong_AsVoidPtr(address); if (data == NULL) { PyErr_SetString(PyExc_TypeError, "Not a valid data pointer"); return NULL; } glBindBuffer(buftype, target); - Py_BEGIN_ALLOW_THREADS; glGetBufferSubData(buftype, offset, size, data); - Py_END_ALLOW_THREADS; CHECK_ERROR; glBindBuffer(buftype, 0); Py_RETURN_NONE; @@ -632,10 +612,8 @@ replace_or_create_buffer(PyObject UNUSED *self, PyObject *args) { void *data = PyLong_AsVoidPtr(address); if (data == NULL) { PyErr_SetString(PyExc_TypeError, "Not a valid data pointer"); return NULL; } glBindBuffer(buftype, target); - Py_BEGIN_ALLOW_THREADS; if (prev_sz == 0 || prev_sz != size) glBufferData(buftype, size, data, usage); else glBufferSubData(buftype, 0, size, data); - Py_END_ALLOW_THREADS; CHECK_ERROR; glBindBuffer(buftype, 0); Py_RETURN_NONE; diff --git a/kitty/glfw.c b/kitty/glfw.c index 8a30fa896..292947dff 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -169,10 +169,8 @@ glfw_wait_events(PyObject UNUSED *self, PyObject *args) { time = PyFloat_AsDouble(PyTuple_GET_ITEM(args, 0)); if (PyErr_Occurred()) PyErr_Clear(); } - Py_BEGIN_ALLOW_THREADS; if (time < 0) glfwWaitEvents(); else glfwWaitEventsTimeout(time); - Py_END_ALLOW_THREADS; Py_RETURN_NONE; } @@ -234,9 +232,7 @@ dealloc(Window* self) { static PyObject* swap_buffers(Window *self) { - Py_BEGIN_ALLOW_THREADS; glfwSwapBuffers(self->window); - Py_END_ALLOW_THREADS; Py_RETURN_NONE; } diff --git a/kitty/history.c b/kitty/history.c index 4ee6095ec..e669f18ca 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -223,11 +223,9 @@ HistoryBuf *alloc_historybuf(unsigned int lines, unsigned int columns) { void historybuf_rewrap(HistoryBuf *self, HistoryBuf *other) { // Fast path if (other->xnum == self->xnum && other->ynum == self->ynum) { - Py_BEGIN_ALLOW_THREADS; memcpy(other->buf, self->buf, sizeof(Cell) * self->xnum * self->ynum); memcpy(other->continued_map, self->continued_map, sizeof(bool) * self->ynum); other->count = self->count; other->start_of_data = self->start_of_data; - Py_END_ALLOW_THREADS; return; } other->count = 0; other->start_of_data = 0; diff --git a/kitty/line-buf.c b/kitty/line-buf.c index fde612e61..98001bd97 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -435,16 +435,13 @@ linebuf_rewrap(LineBuf *self, LineBuf *other, int *cursor_y_out, HistoryBuf *his // Fast path if (other->xnum == self->xnum && other->ynum == self->ynum) { - Py_BEGIN_ALLOW_THREADS; memcpy(other->line_map, self->line_map, sizeof(index_type) * self->ynum); memcpy(other->continued_map, self->continued_map, sizeof(bool) * self->ynum); memcpy(other->buf, self->buf, self->xnum * self->ynum * sizeof(Cell)); - Py_END_ALLOW_THREADS; return; } // Find the first line that contains some content - Py_BEGIN_ALLOW_THREADS; for (first = self->ynum - 1; true; first--) { Cell *cells = lineptr(self, first); for(i = 0; i < self->xnum; i++) { @@ -452,7 +449,6 @@ linebuf_rewrap(LineBuf *self, LineBuf *other, int *cursor_y_out, HistoryBuf *his } if (!is_empty || !first) break; } - Py_END_ALLOW_THREADS; if (first == 0) { *cursor_y_out = 0; return; } // All lines are empty diff --git a/kitty/rewrap.h b/kitty/rewrap.h index 6de30ffe4..fa830132a 100644 --- a/kitty/rewrap.h +++ b/kitty/rewrap.h @@ -51,7 +51,6 @@ static void rewrap_inner(BufType *src, BufType *dest, const index_type src_limit, HistoryBuf UNUSED *historybuf) { bool src_line_is_continued = false; index_type src_y = 0, src_x = 0, dest_x = 0, dest_y = 0, num = 0, src_x_limit = 0; - Py_BEGIN_ALLOW_THREADS; first_dest_line; do { @@ -73,5 +72,4 @@ rewrap_inner(BufType *src, BufType *dest, const index_type src_limit, HistoryBuf if (!src_line_is_continued && src_y < src_limit) { next_dest_line(false); dest_x = 0; } } while (src_y < src_limit); dest->line->ynum = dest_y; - Py_END_ALLOW_THREADS; }