Skip to content

Commit

Permalink
Dynamically allocated parser state should be 64 byte aligned as well
Browse files Browse the repository at this point in the history
  • Loading branch information
kovidgoyal committed Jan 14, 2024
1 parent d6d474e commit 4621e9e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions kitty/vt-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,10 @@ typedef struct ParsedCSI {
} ParsedCSI;

typedef struct PS {
alignas(BUF_EXTRA) UTF8Decoder utf8_decoder;

id_type window_id;

UTF8Decoder utf8_decoder;
VTEState vte_state;
ParsedCSI csi;

Expand Down Expand Up @@ -1532,9 +1533,18 @@ alloc_vt_parser(id_type window_id) {
Parser *self = (Parser*)Parser_Type.tp_alloc(&Parser_Type, 1);
if (self != NULL) {
int ret;
self->state = calloc(1, sizeof(PS));
self->state = aligned_alloc(BUF_EXTRA, sizeof(self->state[0]));
if (!self->state) { Py_CLEAR(self); PyErr_NoMemory(); return NULL; }
memset(self->state, 0, sizeof(self->state[0]));
PS *state = (PS*)self->state;
if ((intptr_t)state->utf8_decoder.output % BUF_EXTRA != 0) {
Py_CLEAR(self); PyErr_SetString(PyExc_TypeError, "UTF8Decoder is not aligned");
return NULL;
}
if ((intptr_t)state->buf % BUF_EXTRA != 0) {
Py_CLEAR(self); PyErr_SetString(PyExc_TypeError, "PS->buf is not aligned");
return NULL;
}
if ((ret = pthread_mutex_init(&state->lock, NULL)) != 0) {
Py_CLEAR(self); PyErr_Format(PyExc_RuntimeError, "Failed to create Parser lock mutex: %s", strerror(ret));
return NULL;
Expand Down

0 comments on commit 4621e9e

Please sign in to comment.