mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
Turn Event into a tagged union
If we ever need arbitrary data or more than very few bytes on `Events` we just have to add a `void *` field in the `data` union.
This commit is contained in:
parent
967fb1aca6
commit
c3cea30cb7
@ -12,7 +12,7 @@
|
|||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "misc2.h"
|
#include "misc2.h"
|
||||||
|
|
||||||
// event.data will be cleaned up after the event is processed
|
// event will be cleaned up after it gets processed
|
||||||
#define _destroy_event(x) // do nothing
|
#define _destroy_event(x) // do nothing
|
||||||
KLIST_INIT(Event, Event, _destroy_event)
|
KLIST_INIT(Event, Event, _destroy_event)
|
||||||
|
|
||||||
|
@ -10,7 +10,9 @@ typedef enum {
|
|||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
EventType type;
|
EventType type;
|
||||||
void *data;
|
union {
|
||||||
|
int signum;
|
||||||
|
} data;
|
||||||
} Event;
|
} Event;
|
||||||
|
|
||||||
void event_init(void);
|
void event_init(void);
|
||||||
|
@ -69,9 +69,7 @@ void signal_accept_deadly()
|
|||||||
|
|
||||||
void signal_handle(Event event)
|
void signal_handle(Event event)
|
||||||
{
|
{
|
||||||
int signum = *(int *)event.data;
|
int signum = event.data.signum;
|
||||||
|
|
||||||
free(event.data);
|
|
||||||
|
|
||||||
switch (signum) {
|
switch (signum) {
|
||||||
case SIGINT:
|
case SIGINT:
|
||||||
@ -157,8 +155,9 @@ static void signal_cb(uv_signal_t *handle, int signum)
|
|||||||
|
|
||||||
Event event = {
|
Event event = {
|
||||||
.type = kEventSignal,
|
.type = kEventSignal,
|
||||||
.data = xmalloc(sizeof(int))
|
.data = {
|
||||||
|
.signum = signum
|
||||||
|
}
|
||||||
};
|
};
|
||||||
*(int *)event.data = signum;
|
|
||||||
event_push(event);
|
event_push(event);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user