diff --git a/kitty/history.c b/kitty/history.c index 05398fc59..5a9b9c1e8 100644 --- a/kitty/history.c +++ b/kitty/history.c @@ -463,7 +463,7 @@ as_text(HistoryBuf *self, PyObject *args) { GetLineWrapper glw = {.self=self}; glw.line.xnum = self->xnum; ANSIBuf output = {0}; - PyObject *ans = as_text_generic(args, &glw, get_line_wrapper, self->count, self->xnum, &output); + PyObject *ans = as_text_generic(args, &glw, get_line_wrapper, self->count, &output); free(output.buf); return ans; } diff --git a/kitty/line-buf.c b/kitty/line-buf.c index a5f46ff77..1a2cb4904 100644 --- a/kitty/line-buf.c +++ b/kitty/line-buf.c @@ -442,7 +442,7 @@ get_line(void *x, int y) { static PyObject* as_text(LineBuf *self, PyObject *args) { ANSIBuf output = {0}; - PyObject* ans = as_text_generic(args, self, get_line, self->ynum, self->xnum, &output); + PyObject* ans = as_text_generic(args, self, get_line, self->ynum, &output); free(output.buf); return ans; } diff --git a/kitty/line.c b/kitty/line.c index bf9ddf8eb..932f967f4 100644 --- a/kitty/line.c +++ b/kitty/line.c @@ -762,21 +762,16 @@ mark_text_in_line(PyObject *marker, Line *line) { } PyObject* -as_text_generic(PyObject *args, void *container, get_line_func get_line, index_type lines, index_type columns, ANSIBuf *ansibuf) { +as_text_generic(PyObject *args, void *container, get_line_func get_line, index_type lines, ANSIBuf *ansibuf) { PyObject *callback; int as_ansi = 0, insert_wrap_markers = 0; if (!PyArg_ParseTuple(args, "O|pp", &callback, &as_ansi, &insert_wrap_markers)) return NULL; PyObject *ret = NULL, *t = NULL; - Py_UCS4 *buf = NULL; PyObject *nl = PyUnicode_FromString("\n"); PyObject *cr = PyUnicode_FromString("\r"); PyObject *sgr_reset = PyUnicode_FromString("\x1b[m"); const GPUCell *prev_cell = NULL; if (nl == NULL || cr == NULL) goto end; - if (as_ansi) { - buf = malloc(sizeof(Py_UCS4) * columns * 100); - if (buf == NULL) { PyErr_NoMemory(); goto end; } - } for (index_type y = 0; y < lines; y++) { Line *line = get_line(container, y); if (!line->continued && y > 0) { @@ -811,7 +806,7 @@ as_text_generic(PyObject *args, void *container, get_line_func get_line, index_t } } end: - Py_CLEAR(nl); Py_CLEAR(cr); Py_CLEAR(sgr_reset); free(buf); + Py_CLEAR(nl); Py_CLEAR(cr); Py_CLEAR(sgr_reset); if (PyErr_Occurred()) return NULL; Py_RETURN_NONE; } diff --git a/kitty/lineops.h b/kitty/lineops.h index 3cd4b9cfc..5f350d283 100644 --- a/kitty/lineops.h +++ b/kitty/lineops.h @@ -110,4 +110,4 @@ void historybuf_refresh_sprite_positions(HistoryBuf *self); void historybuf_clear(HistoryBuf *self); void mark_text_in_line(PyObject *marker, Line *line); bool line_has_mark(Line *, attrs_type mark); -PyObject* as_text_generic(PyObject *args, void *container, get_line_func get_line, index_type lines, index_type columns, ANSIBuf *ansibuf); +PyObject* as_text_generic(PyObject *args, void *container, get_line_func get_line, index_type lines, ANSIBuf *ansibuf); diff --git a/kitty/screen.c b/kitty/screen.c index 767702f9b..a7fa9888f 100644 --- a/kitty/screen.c +++ b/kitty/screen.c @@ -2030,17 +2030,17 @@ static Line* get_range_line(void *x, int y) { return range_line_(x, y); } static PyObject* as_text(Screen *self, PyObject *args) { - return as_text_generic(args, self, get_visual_line, self->lines, self->columns, &self->as_ansi_buf); + return as_text_generic(args, self, get_visual_line, self->lines, &self->as_ansi_buf); } static PyObject* as_text_non_visual(Screen *self, PyObject *args) { - return as_text_generic(args, self, get_range_line, self->lines, self->columns, &self->as_ansi_buf); + return as_text_generic(args, self, get_range_line, self->lines, &self->as_ansi_buf); } static inline PyObject* as_text_generic_wrapper(Screen *self, PyObject *args, get_line_func get_line) { - return as_text_generic(args, self, get_line, self->lines, self->columns, &self->as_ansi_buf); + return as_text_generic(args, self, get_line, self->lines, &self->as_ansi_buf); } static PyObject*