mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-06 07:15:30 -04:00
grid: reflow: qsort_r() is not portable
Replace with qsort() + global variable. Not thread safe!
This commit is contained in:
parent
aa1f589e3f
commit
8d1b724056
1 changed files with 15 additions and 11 deletions
26
grid.c
26
grid.c
|
|
@ -385,25 +385,27 @@ _line_wrap(struct grid *old_grid, struct row **new_grid, struct row *row,
|
||||||
return new_row;
|
return new_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct tp_cmp_ctx {
|
static struct {
|
||||||
int scrollback_start;
|
int scrollback_start;
|
||||||
int rows;
|
int rows;
|
||||||
};
|
} tp_cmp_ctx;
|
||||||
|
|
||||||
static int
|
static int
|
||||||
tp_cmp(const void *_a, const void *_b, void *_arg)
|
tp_cmp(const void *_a, const void *_b)
|
||||||
{
|
{
|
||||||
const struct coord *a = *(const struct coord **)_a;
|
const struct coord *a = *(const struct coord **)_a;
|
||||||
const struct coord *b = *(const struct coord **)_b;
|
const struct coord *b = *(const struct coord **)_b;
|
||||||
const struct tp_cmp_ctx *ctx = _arg;
|
|
||||||
|
|
||||||
int a_row = (a->row - ctx->scrollback_start + ctx->rows) & (ctx->rows - 1);
|
int scrollback_start = tp_cmp_ctx.scrollback_start;
|
||||||
int b_row = (b->row - ctx->scrollback_start + ctx->rows) & (ctx->rows - 1);
|
int num_rows = tp_cmp_ctx.rows;
|
||||||
|
|
||||||
|
int a_row = (a->row - scrollback_start + num_rows) & (num_rows - 1);
|
||||||
|
int b_row = (b->row - scrollback_start + num_rows) & (num_rows - 1);
|
||||||
|
|
||||||
xassert(a_row >= 0);
|
xassert(a_row >= 0);
|
||||||
xassert(a_row < ctx->rows || ctx->rows == 0);
|
xassert(a_row < num_rows || num_rows == 0);
|
||||||
xassert(b_row >= 0);
|
xassert(b_row >= 0);
|
||||||
xassert(b_row < ctx->rows || ctx->rows == 0);
|
xassert(b_row < num_rows || num_rows == 0);
|
||||||
|
|
||||||
if (a_row < b_row)
|
if (a_row < b_row)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
@ -486,9 +488,11 @@ grid_resize_and_reflow(
|
||||||
if (!view_follows)
|
if (!view_follows)
|
||||||
tracking_points[tracking_points_count + 2] = &viewport;
|
tracking_points[tracking_points_count + 2] = &viewport;
|
||||||
|
|
||||||
qsort_r(
|
/* Not thread safe! */
|
||||||
tracking_points, tp_count - 1, sizeof(tracking_points[0]), &tp_cmp,
|
tp_cmp_ctx.scrollback_start = offset;
|
||||||
&(struct tp_cmp_ctx){.scrollback_start = offset, .rows = old_rows});
|
tp_cmp_ctx.rows = old_rows;
|
||||||
|
qsort(
|
||||||
|
tracking_points, tp_count - 1, sizeof(tracking_points[0]), &tp_cmp);
|
||||||
|
|
||||||
/* NULL terminate */
|
/* NULL terminate */
|
||||||
struct coord terminator = {-1, -1};
|
struct coord terminator = {-1, -1};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue