mirror of
https://github.com/neovim/neovim.git
synced 2025-09-08 04:18:18 +00:00
*: Fix errors from new linter checks
This commit is contained in:
@@ -7,24 +7,24 @@
|
|||||||
|
|
||||||
#define HANDLE_INIT(name) name##_handles = pmap_new(uint64_t)()
|
#define HANDLE_INIT(name) name##_handles = pmap_new(uint64_t)()
|
||||||
|
|
||||||
#define HANDLE_IMPL(type, name) \
|
#define HANDLE_IMPL(type, name) \
|
||||||
static PMap(uint64_t) *name##_handles = NULL; \
|
static PMap(uint64_t) *name##_handles = NULL; \
|
||||||
\
|
\
|
||||||
type *handle_get_##name(uint64_t handle) \
|
type *handle_get_##name(uint64_t handle) \
|
||||||
{ \
|
{ \
|
||||||
return pmap_get(uint64_t)(name##_handles, handle); \
|
return pmap_get(uint64_t)(name##_handles, handle); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void handle_register_##name(type *name) \
|
void handle_register_##name(type *name) \
|
||||||
{ \
|
{ \
|
||||||
assert(!name->handle); \
|
assert(!name->handle); \
|
||||||
name->handle = next_handle++; \
|
name->handle = next_handle++; \
|
||||||
pmap_put(uint64_t)(name##_handles, name->handle, name); \
|
pmap_put(uint64_t)(name##_handles, name->handle, name); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void handle_unregister_##name(type *name) \
|
void handle_unregister_##name(type *name) \
|
||||||
{ \
|
{ \
|
||||||
pmap_del(uint64_t)(name##_handles, name->handle); \
|
pmap_del(uint64_t)(name##_handles, name->handle); \
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint64_t next_handle = 1;
|
static uint64_t next_handle = 1;
|
||||||
|
@@ -4,9 +4,9 @@
|
|||||||
#include "nvim/vim.h"
|
#include "nvim/vim.h"
|
||||||
#include "nvim/buffer_defs.h"
|
#include "nvim/buffer_defs.h"
|
||||||
|
|
||||||
#define HANDLE_DECLS(type, name) \
|
#define HANDLE_DECLS(type, name) \
|
||||||
type *handle_get_##name(uint64_t handle); \
|
type *handle_get_##name(uint64_t handle); \
|
||||||
void handle_register_##name(type *name); \
|
void handle_register_##name(type *name); \
|
||||||
void handle_unregister_##name(type *name);
|
void handle_unregister_##name(type *name);
|
||||||
|
|
||||||
HANDLE_DECLS(buf_T, buffer)
|
HANDLE_DECLS(buf_T, buffer)
|
||||||
|
@@ -8,63 +8,63 @@
|
|||||||
#include "nvim/memory.h"
|
#include "nvim/memory.h"
|
||||||
#include "nvim/lib/kvec.h"
|
#include "nvim/lib/kvec.h"
|
||||||
|
|
||||||
#define api_set_error(err, errtype, ...) \
|
#define api_set_error(err, errtype, ...) \
|
||||||
do { \
|
do { \
|
||||||
snprintf((err)->msg, \
|
snprintf((err)->msg, \
|
||||||
sizeof((err)->msg), \
|
sizeof((err)->msg), \
|
||||||
__VA_ARGS__); \
|
__VA_ARGS__); \
|
||||||
(err)->set = true; \
|
(err)->set = true; \
|
||||||
(err)->type = kErrorType##errtype; \
|
(err)->type = kErrorType##errtype; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define OBJECT_OBJ(o) o
|
#define OBJECT_OBJ(o) o
|
||||||
|
|
||||||
#define BOOLEAN_OBJ(b) ((Object) { \
|
#define BOOLEAN_OBJ(b) ((Object) { \
|
||||||
.type = kObjectTypeBoolean, \
|
.type = kObjectTypeBoolean, \
|
||||||
.data.boolean = b \
|
.data.boolean = b \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define INTEGER_OBJ(i) ((Object) { \
|
#define INTEGER_OBJ(i) ((Object) { \
|
||||||
.type = kObjectTypeInteger, \
|
.type = kObjectTypeInteger, \
|
||||||
.data.integer = i \
|
.data.integer = i \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define STRING_OBJ(s) ((Object) { \
|
#define STRING_OBJ(s) ((Object) { \
|
||||||
.type = kObjectTypeString, \
|
.type = kObjectTypeString, \
|
||||||
.data.string = s \
|
.data.string = s \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define BUFFER_OBJ(s) ((Object) { \
|
#define BUFFER_OBJ(s) ((Object) { \
|
||||||
.type = kObjectTypeBuffer, \
|
.type = kObjectTypeBuffer, \
|
||||||
.data.buffer = s \
|
.data.buffer = s \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define WINDOW_OBJ(s) ((Object) { \
|
#define WINDOW_OBJ(s) ((Object) { \
|
||||||
.type = kObjectTypeWindow, \
|
.type = kObjectTypeWindow, \
|
||||||
.data.window = s \
|
.data.window = s \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define TABPAGE_OBJ(s) ((Object) { \
|
#define TABPAGE_OBJ(s) ((Object) { \
|
||||||
.type = kObjectTypeTabpage, \
|
.type = kObjectTypeTabpage, \
|
||||||
.data.tabpage = s \
|
.data.tabpage = s \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define ARRAY_OBJ(a) ((Object) { \
|
#define ARRAY_OBJ(a) ((Object) { \
|
||||||
.type = kObjectTypeArray, \
|
.type = kObjectTypeArray, \
|
||||||
.data.array = a \
|
.data.array = a \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define DICTIONARY_OBJ(d) ((Object) { \
|
#define DICTIONARY_OBJ(d) ((Object) { \
|
||||||
.type = kObjectTypeDictionary, \
|
.type = kObjectTypeDictionary, \
|
||||||
.data.dictionary = d \
|
.data.dictionary = d \
|
||||||
})
|
})
|
||||||
|
|
||||||
#define NIL ((Object) {.type = kObjectTypeNil})
|
#define NIL ((Object) {.type = kObjectTypeNil})
|
||||||
|
|
||||||
#define PUT(dict, k, v) \
|
#define PUT(dict, k, v) \
|
||||||
kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v }))
|
kv_push(dict, ((KeyValuePair) { .key = cstr_to_string(k), .value = v }))
|
||||||
|
|
||||||
#define ADD(array, item) \
|
#define ADD(array, item) \
|
||||||
kv_push(array, item)
|
kv_push(array, item)
|
||||||
|
|
||||||
#define STATIC_CSTR_AS_STRING(s) ((String) {.data = s, .size = sizeof(s) - 1})
|
#define STATIC_CSTR_AS_STRING(s) ((String) {.data = s, .size = sizeof(s) - 1})
|
||||||
|
@@ -647,14 +647,14 @@ static void write_msg(String message, bool to_err)
|
|||||||
static size_t out_pos = 0, err_pos = 0;
|
static size_t out_pos = 0, err_pos = 0;
|
||||||
static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE];
|
static char out_line_buf[LINE_BUFFER_SIZE], err_line_buf[LINE_BUFFER_SIZE];
|
||||||
|
|
||||||
#define PUSH_CHAR(i, pos, line_buf, msg) \
|
#define PUSH_CHAR(i, pos, line_buf, msg) \
|
||||||
if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \
|
if (message.data[i] == NL || pos == LINE_BUFFER_SIZE - 1) { \
|
||||||
line_buf[pos] = NUL; \
|
line_buf[pos] = NUL; \
|
||||||
msg((uint8_t *)line_buf); \
|
msg((uint8_t *)line_buf); \
|
||||||
pos = 0; \
|
pos = 0; \
|
||||||
continue; \
|
continue; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
line_buf[pos++] = message.data[i];
|
line_buf[pos++] = message.data[i];
|
||||||
|
|
||||||
++no_wait_return;
|
++no_wait_return;
|
||||||
|
@@ -76,14 +76,14 @@ static inline void restore_win_for_buf(win_T *save_curwin,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define WITH_BUFFER(b, code) \
|
#define WITH_BUFFER(b, code) \
|
||||||
do { \
|
do { \
|
||||||
buf_T *save_curbuf = NULL; \
|
buf_T *save_curbuf = NULL; \
|
||||||
win_T *save_curwin = NULL; \
|
win_T *save_curwin = NULL; \
|
||||||
tabpage_T *save_curtab = NULL; \
|
tabpage_T *save_curtab = NULL; \
|
||||||
switch_to_win_for_buf(b, &save_curwin, &save_curtab, &save_curbuf); \
|
switch_to_win_for_buf(b, &save_curwin, &save_curtab, &save_curbuf); \
|
||||||
code; \
|
code; \
|
||||||
restore_win_for_buf(save_curwin, save_curtab, save_curbuf); \
|
restore_win_for_buf(save_curwin, save_curtab, save_curbuf); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22160,13 +22160,13 @@ typval_T eval_call_provider(char *provider, char *method, list_T *arguments)
|
|||||||
bool eval_has_provider(char *name)
|
bool eval_has_provider(char *name)
|
||||||
{
|
{
|
||||||
|
|
||||||
#define check_provider(name) \
|
#define check_provider(name) \
|
||||||
if (has_##name == -1) { \
|
if (has_##name == -1) { \
|
||||||
has_##name = !!find_func((uint8_t *)"provider#" #name "#Call"); \
|
has_##name = !!find_func((uint8_t *)"provider#" #name "#Call"); \
|
||||||
if (!has_##name) { \
|
if (!has_##name) { \
|
||||||
script_autoload((uint8_t *)"provider#" #name "#Call", false); \
|
script_autoload((uint8_t *)"provider#" #name "#Call", false); \
|
||||||
has_##name = !!find_func((uint8_t *)"provider#" #name "#Call"); \
|
has_##name = !!find_func((uint8_t *)"provider#" #name "#Call"); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
static int has_clipboard = -1, has_python = -1, has_python3 = -1;
|
static int has_clipboard = -1, has_python = -1, has_python3 = -1;
|
||||||
|
@@ -14,19 +14,19 @@ typedef struct message {
|
|||||||
} Event;
|
} Event;
|
||||||
typedef void(*event_scheduler)(Event event, void *data);
|
typedef void(*event_scheduler)(Event event, void *data);
|
||||||
|
|
||||||
#define VA_EVENT_INIT(event, p, h, a) \
|
#define VA_EVENT_INIT(event, p, h, a) \
|
||||||
do { \
|
do { \
|
||||||
assert(a <= EVENT_HANDLER_MAX_ARGC); \
|
assert(a <= EVENT_HANDLER_MAX_ARGC); \
|
||||||
(event)->priority = p; \
|
(event)->priority = p; \
|
||||||
(event)->handler = h; \
|
(event)->handler = h; \
|
||||||
if (a) { \
|
if (a) { \
|
||||||
va_list args; \
|
va_list args; \
|
||||||
va_start(args, a); \
|
va_start(args, a); \
|
||||||
for (int i = 0; i < a; i++) { \
|
for (int i = 0; i < a; i++) { \
|
||||||
(event)->argv[i] = va_arg(args, void *); \
|
(event)->argv[i] = va_arg(args, void *); \
|
||||||
} \
|
} \
|
||||||
va_end(args); \
|
va_end(args); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static inline Event event_create(int priority, argv_callback cb, int argc, ...)
|
static inline Event event_create(int priority, argv_callback cb, int argc, ...)
|
||||||
|
@@ -26,43 +26,43 @@ typedef struct loop {
|
|||||||
int recursive;
|
int recursive;
|
||||||
} Loop;
|
} Loop;
|
||||||
|
|
||||||
#define CREATE_EVENT(queue, handler, argc, ...) \
|
#define CREATE_EVENT(queue, handler, argc, ...) \
|
||||||
do { \
|
do { \
|
||||||
if (queue) { \
|
if (queue) { \
|
||||||
queue_put((queue), (handler), argc, __VA_ARGS__); \
|
queue_put((queue), (handler), argc, __VA_ARGS__); \
|
||||||
} else { \
|
} else { \
|
||||||
void *argv[argc] = {__VA_ARGS__}; \
|
void *argv[argc] = {__VA_ARGS__}; \
|
||||||
(handler)(argv); \
|
(handler)(argv); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
// Poll for events until a condition or timeout
|
// Poll for events until a condition or timeout
|
||||||
#define LOOP_PROCESS_EVENTS_UNTIL(loop, queue, timeout, condition) \
|
#define LOOP_PROCESS_EVENTS_UNTIL(loop, queue, timeout, condition) \
|
||||||
do { \
|
do { \
|
||||||
int remaining = timeout; \
|
int remaining = timeout; \
|
||||||
uint64_t before = (remaining > 0) ? os_hrtime() : 0; \
|
uint64_t before = (remaining > 0) ? os_hrtime() : 0; \
|
||||||
while (!(condition)) { \
|
while (!(condition)) { \
|
||||||
LOOP_PROCESS_EVENTS(loop, queue, remaining); \
|
LOOP_PROCESS_EVENTS(loop, queue, remaining); \
|
||||||
if (remaining == 0) { \
|
if (remaining == 0) { \
|
||||||
break; \
|
break; \
|
||||||
} else if (remaining > 0) { \
|
} else if (remaining > 0) { \
|
||||||
uint64_t now = os_hrtime(); \
|
uint64_t now = os_hrtime(); \
|
||||||
remaining -= (int) ((now - before) / 1000000); \
|
remaining -= (int) ((now - before) / 1000000); \
|
||||||
before = now; \
|
before = now; \
|
||||||
if (remaining <= 0) { \
|
if (remaining <= 0) { \
|
||||||
break; \
|
break; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define LOOP_PROCESS_EVENTS(loop, queue, timeout) \
|
#define LOOP_PROCESS_EVENTS(loop, queue, timeout) \
|
||||||
do { \
|
do { \
|
||||||
if (queue && !queue_empty(queue)) { \
|
if (queue && !queue_empty(queue)) { \
|
||||||
queue_process_events(queue); \
|
queue_process_events(queue); \
|
||||||
} else { \
|
} else { \
|
||||||
loop_poll_events(loop, timeout); \
|
loop_poll_events(loop, timeout); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -22,11 +22,11 @@
|
|||||||
#define TERM_TIMEOUT 1000000000
|
#define TERM_TIMEOUT 1000000000
|
||||||
#define KILL_TIMEOUT (TERM_TIMEOUT * 2)
|
#define KILL_TIMEOUT (TERM_TIMEOUT * 2)
|
||||||
|
|
||||||
#define CLOSE_PROC_STREAM(proc, stream) \
|
#define CLOSE_PROC_STREAM(proc, stream) \
|
||||||
do { \
|
do { \
|
||||||
if (proc->stream && !proc->stream->closed) { \
|
if (proc->stream && !proc->stream->closed) { \
|
||||||
stream_close(proc->stream, NULL); \
|
stream_close(proc->stream, NULL); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static bool process_is_tearing_down = false;
|
static bool process_is_tearing_down = false;
|
||||||
|
@@ -21,10 +21,10 @@ typedef struct growarray {
|
|||||||
|
|
||||||
#define GA_EMPTY(ga_ptr) ((ga_ptr)->ga_len <= 0)
|
#define GA_EMPTY(ga_ptr) ((ga_ptr)->ga_len <= 0)
|
||||||
|
|
||||||
#define GA_APPEND(item_type, gap, item) \
|
#define GA_APPEND(item_type, gap, item) \
|
||||||
do { \
|
do { \
|
||||||
ga_grow(gap, 1); \
|
ga_grow(gap, 1); \
|
||||||
((item_type *)(gap)->ga_data)[(gap)->ga_len++] = (item); \
|
((item_type *)(gap)->ga_data)[(gap)->ga_len++] = (item); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define GA_APPEND_VIA_PTR(item_type, gap) \
|
#define GA_APPEND_VIA_PTR(item_type, gap) \
|
||||||
@@ -49,16 +49,16 @@ static inline void *ga_append_via_ptr(garray_T *gap, size_t item_size)
|
|||||||
/// @param gap the garray to be freed
|
/// @param gap the garray to be freed
|
||||||
/// @param item_type type of the item in the garray
|
/// @param item_type type of the item in the garray
|
||||||
/// @param free_item_fn free function that takes (*item_type) as parameter
|
/// @param free_item_fn free function that takes (*item_type) as parameter
|
||||||
#define GA_DEEP_CLEAR(gap, item_type, free_item_fn) \
|
#define GA_DEEP_CLEAR(gap, item_type, free_item_fn) \
|
||||||
do { \
|
do { \
|
||||||
garray_T *_gap = (gap); \
|
garray_T *_gap = (gap); \
|
||||||
if (_gap->ga_data != NULL) { \
|
if (_gap->ga_data != NULL) { \
|
||||||
for (int i = 0; i < _gap->ga_len; i++) { \
|
for (int i = 0; i < _gap->ga_len; i++) { \
|
||||||
item_type *_item = &(((item_type *)_gap->ga_data)[i]); \
|
item_type *_item = &(((item_type *)_gap->ga_data)[i]); \
|
||||||
free_item_fn(_item); \
|
free_item_fn(_item); \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
ga_clear(_gap); \
|
ga_clear(_gap); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
#define FREE_PTR_PTR(ptr) xfree(*(ptr))
|
#define FREE_PTR_PTR(ptr) xfree(*(ptr))
|
||||||
|
@@ -33,35 +33,35 @@
|
|||||||
#include "nvim/func_attr.h"
|
#include "nvim/func_attr.h"
|
||||||
|
|
||||||
|
|
||||||
#define KMEMPOOL_INIT(name, kmptype_t, kmpfree_f) \
|
#define KMEMPOOL_INIT(name, kmptype_t, kmpfree_f) \
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
size_t cnt, n, max; \
|
size_t cnt, n, max; \
|
||||||
kmptype_t **buf; \
|
kmptype_t **buf; \
|
||||||
} kmp_##name##_t; \
|
} kmp_##name##_t; \
|
||||||
static inline kmp_##name##_t *kmp_init_##name(void) { \
|
static inline kmp_##name##_t *kmp_init_##name(void) { \
|
||||||
return xcalloc(1, sizeof(kmp_##name##_t)); \
|
return xcalloc(1, sizeof(kmp_##name##_t)); \
|
||||||
} \
|
} \
|
||||||
static inline void kmp_destroy_##name(kmp_##name##_t *mp) \
|
static inline void kmp_destroy_##name(kmp_##name##_t *mp) \
|
||||||
REAL_FATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
static inline void kmp_destroy_##name(kmp_##name##_t *mp) { \
|
static inline void kmp_destroy_##name(kmp_##name##_t *mp) { \
|
||||||
size_t k; \
|
size_t k; \
|
||||||
for (k = 0; k < mp->n; ++k) { \
|
for (k = 0; k < mp->n; ++k) { \
|
||||||
kmpfree_f(mp->buf[k]); xfree(mp->buf[k]); \
|
kmpfree_f(mp->buf[k]); xfree(mp->buf[k]); \
|
||||||
} \
|
} \
|
||||||
xfree(mp->buf); xfree(mp); \
|
xfree(mp->buf); xfree(mp); \
|
||||||
} \
|
} \
|
||||||
static inline kmptype_t *kmp_alloc_##name(kmp_##name##_t *mp) { \
|
static inline kmptype_t *kmp_alloc_##name(kmp_##name##_t *mp) { \
|
||||||
++mp->cnt; \
|
++mp->cnt; \
|
||||||
if (mp->n == 0) return xcalloc(1, sizeof(kmptype_t)); \
|
if (mp->n == 0) return xcalloc(1, sizeof(kmptype_t)); \
|
||||||
return mp->buf[--mp->n]; \
|
return mp->buf[--mp->n]; \
|
||||||
} \
|
} \
|
||||||
static inline void kmp_free_##name(kmp_##name##_t *mp, kmptype_t *p) { \
|
static inline void kmp_free_##name(kmp_##name##_t *mp, kmptype_t *p) { \
|
||||||
--mp->cnt; \
|
--mp->cnt; \
|
||||||
if (mp->n == mp->max) { \
|
if (mp->n == mp->max) { \
|
||||||
mp->max = mp->max? mp->max<<1 : 16; \
|
mp->max = mp->max? mp->max<<1 : 16; \
|
||||||
mp->buf = xrealloc(mp->buf, sizeof(kmptype_t *) * mp->max); \
|
mp->buf = xrealloc(mp->buf, sizeof(kmptype_t *) * mp->max); \
|
||||||
} \
|
} \
|
||||||
mp->buf[mp->n++] = p; \
|
mp->buf[mp->n++] = p; \
|
||||||
}
|
}
|
||||||
|
|
||||||
#define kmempool_t(name) kmp_##name##_t
|
#define kmempool_t(name) kmp_##name##_t
|
||||||
@@ -70,53 +70,53 @@
|
|||||||
#define kmp_alloc(name, mp) kmp_alloc_##name(mp)
|
#define kmp_alloc(name, mp) kmp_alloc_##name(mp)
|
||||||
#define kmp_free(name, mp, p) kmp_free_##name(mp, p)
|
#define kmp_free(name, mp, p) kmp_free_##name(mp, p)
|
||||||
|
|
||||||
#define KLIST_INIT(name, kltype_t, kmpfree_t) \
|
#define KLIST_INIT(name, kltype_t, kmpfree_t) \
|
||||||
struct __kl1_##name { \
|
struct __kl1_##name { \
|
||||||
kltype_t data; \
|
kltype_t data; \
|
||||||
struct __kl1_##name *next; \
|
struct __kl1_##name *next; \
|
||||||
}; \
|
}; \
|
||||||
typedef struct __kl1_##name kl1_##name; \
|
typedef struct __kl1_##name kl1_##name; \
|
||||||
KMEMPOOL_INIT(name, kl1_##name, kmpfree_t) \
|
KMEMPOOL_INIT(name, kl1_##name, kmpfree_t) \
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
kl1_##name *head, *tail; \
|
kl1_##name *head, *tail; \
|
||||||
kmp_##name##_t *mp; \
|
kmp_##name##_t *mp; \
|
||||||
size_t size; \
|
size_t size; \
|
||||||
} kl_##name##_t; \
|
} kl_##name##_t; \
|
||||||
static inline kl_##name##_t *kl_init_##name(void) { \
|
static inline kl_##name##_t *kl_init_##name(void) { \
|
||||||
kl_##name##_t *kl = xcalloc(1, sizeof(kl_##name##_t)); \
|
kl_##name##_t *kl = xcalloc(1, sizeof(kl_##name##_t)); \
|
||||||
kl->mp = kmp_init(name); \
|
kl->mp = kmp_init(name); \
|
||||||
kl->head = kl->tail = kmp_alloc(name, kl->mp); \
|
kl->head = kl->tail = kmp_alloc(name, kl->mp); \
|
||||||
kl->head->next = 0; \
|
kl->head->next = 0; \
|
||||||
return kl; \
|
return kl; \
|
||||||
} \
|
} \
|
||||||
static inline void kl_destroy_##name(kl_##name##_t *kl) \
|
static inline void kl_destroy_##name(kl_##name##_t *kl) \
|
||||||
REAL_FATTR_UNUSED; \
|
REAL_FATTR_UNUSED; \
|
||||||
static inline void kl_destroy_##name(kl_##name##_t *kl) { \
|
static inline void kl_destroy_##name(kl_##name##_t *kl) { \
|
||||||
kl1_##name *p; \
|
kl1_##name *p; \
|
||||||
for (p = kl->head; p != kl->tail; p = p->next) \
|
for (p = kl->head; p != kl->tail; p = p->next) \
|
||||||
kmp_free(name, kl->mp, p); \
|
kmp_free(name, kl->mp, p); \
|
||||||
kmp_free(name, kl->mp, p); \
|
kmp_free(name, kl->mp, p); \
|
||||||
kmp_destroy(name, kl->mp); \
|
kmp_destroy(name, kl->mp); \
|
||||||
xfree(kl); \
|
xfree(kl); \
|
||||||
} \
|
} \
|
||||||
static inline void kl_push_##name(kl_##name##_t *kl, kltype_t d) { \
|
static inline void kl_push_##name(kl_##name##_t *kl, kltype_t d) { \
|
||||||
kl1_##name *q, *p = kmp_alloc(name, kl->mp); \
|
kl1_##name *q, *p = kmp_alloc(name, kl->mp); \
|
||||||
q = kl->tail; p->next = 0; kl->tail->next = p; kl->tail = p; \
|
q = kl->tail; p->next = 0; kl->tail->next = p; kl->tail = p; \
|
||||||
++kl->size; \
|
++kl->size; \
|
||||||
q->data = d; \
|
q->data = d; \
|
||||||
} \
|
} \
|
||||||
static inline kltype_t kl_shift_at_##name(kl_##name##_t *kl, \
|
static inline kltype_t kl_shift_at_##name(kl_##name##_t *kl, \
|
||||||
kl1_##name **n) { \
|
kl1_##name **n) { \
|
||||||
assert((*n)->next); \
|
assert((*n)->next); \
|
||||||
kl1_##name *p; \
|
kl1_##name *p; \
|
||||||
--kl->size; \
|
--kl->size; \
|
||||||
p = *n; \
|
p = *n; \
|
||||||
*n = (*n)->next; \
|
*n = (*n)->next; \
|
||||||
if (p == kl->head) kl->head = *n; \
|
if (p == kl->head) kl->head = *n; \
|
||||||
kltype_t d = p->data; \
|
kltype_t d = p->data; \
|
||||||
kmp_free(name, kl->mp, p); \
|
kmp_free(name, kl->mp, p); \
|
||||||
return d; \
|
return d; \
|
||||||
} \
|
} \
|
||||||
|
|
||||||
|
|
||||||
#define kliter_t(name) kl1_##name
|
#define kliter_t(name) kl1_##name
|
||||||
|
@@ -25,7 +25,7 @@ typedef struct _queue {
|
|||||||
} QUEUE;
|
} QUEUE;
|
||||||
|
|
||||||
// Public macros.
|
// Public macros.
|
||||||
#define QUEUE_DATA(ptr, type, field) \
|
#define QUEUE_DATA(ptr, type, field) \
|
||||||
((type *)((char *)(ptr) - offsetof(type, field)))
|
((type *)((char *)(ptr) - offsetof(type, field)))
|
||||||
|
|
||||||
#define QUEUE_FOREACH(q, h) \
|
#define QUEUE_FOREACH(q, h) \
|
||||||
|
@@ -65,12 +65,12 @@
|
|||||||
/// @param TypeName Ring buffer type name. Actual type name will be
|
/// @param TypeName Ring buffer type name. Actual type name will be
|
||||||
/// `{TypeName}RingBuffer`.
|
/// `{TypeName}RingBuffer`.
|
||||||
/// @param RBType Type of the single ring buffer element.
|
/// @param RBType Type of the single ring buffer element.
|
||||||
#define RINGBUF_TYPEDEF(TypeName, RBType) \
|
#define RINGBUF_TYPEDEF(TypeName, RBType) \
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
RBType *buf; \
|
RBType *buf; \
|
||||||
RBType *next; \
|
RBType *next; \
|
||||||
RBType *first; \
|
RBType *first; \
|
||||||
RBType *buf_end; \
|
RBType *buf_end; \
|
||||||
} TypeName##RingBuffer;
|
} TypeName##RingBuffer;
|
||||||
|
|
||||||
/// Initialize a new ring buffer
|
/// Initialize a new ring buffer
|
||||||
@@ -84,198 +84,196 @@ typedef struct { \
|
|||||||
/// a macros like `#define RBFREE(item)` (to skip freeing).
|
/// a macros like `#define RBFREE(item)` (to skip freeing).
|
||||||
///
|
///
|
||||||
/// Intended function signature: `void *rbfree(RBType *)`;
|
/// Intended function signature: `void *rbfree(RBType *)`;
|
||||||
#define RINGBUF_INIT(TypeName, funcprefix, RBType, rbfree) \
|
#define RINGBUF_INIT(TypeName, funcprefix, RBType, rbfree) \
|
||||||
\
|
static inline TypeName##RingBuffer funcprefix##_rb_new(const size_t size) \
|
||||||
\
|
REAL_FATTR_WARN_UNUSED_RESULT; \
|
||||||
static inline TypeName##RingBuffer funcprefix##_rb_new(const size_t size) \
|
static inline TypeName##RingBuffer funcprefix##_rb_new(const size_t size) \
|
||||||
REAL_FATTR_WARN_UNUSED_RESULT; \
|
{ \
|
||||||
static inline TypeName##RingBuffer funcprefix##_rb_new(const size_t size) \
|
assert(size != 0); \
|
||||||
{ \
|
RBType *buf = xmalloc(size * sizeof(RBType)); \
|
||||||
assert(size != 0); \
|
return (TypeName##RingBuffer) { \
|
||||||
RBType *buf = xmalloc(size * sizeof(RBType)); \
|
.buf = buf, \
|
||||||
return (TypeName##RingBuffer) { \
|
.next = buf, \
|
||||||
.buf = buf, \
|
.first = NULL, \
|
||||||
.next = buf, \
|
.buf_end = buf + size - 1, \
|
||||||
.first = NULL, \
|
}; \
|
||||||
.buf_end = buf + size - 1, \
|
} \
|
||||||
}; \
|
\
|
||||||
} \
|
static inline void funcprefix##_rb_free(TypeName##RingBuffer *const rb) \
|
||||||
\
|
REAL_FATTR_UNUSED; \
|
||||||
static inline void funcprefix##_rb_free(TypeName##RingBuffer *const rb) \
|
static inline void funcprefix##_rb_free(TypeName##RingBuffer *const rb) \
|
||||||
REAL_FATTR_UNUSED; \
|
{ \
|
||||||
static inline void funcprefix##_rb_free(TypeName##RingBuffer *const rb) \
|
if (rb == NULL) { \
|
||||||
{ \
|
return; \
|
||||||
if (rb == NULL) { \
|
} \
|
||||||
return; \
|
RINGBUF_FORALL(rb, RBType, rbitem) { \
|
||||||
} \
|
rbfree(rbitem); \
|
||||||
RINGBUF_FORALL(rb, RBType, rbitem) { \
|
} \
|
||||||
rbfree(rbitem); \
|
xfree(rb->buf); \
|
||||||
} \
|
} \
|
||||||
xfree(rb->buf); \
|
\
|
||||||
} \
|
static inline void funcprefix##_rb_dealloc(TypeName##RingBuffer *const rb) \
|
||||||
\
|
REAL_FATTR_UNUSED; \
|
||||||
static inline void funcprefix##_rb_dealloc(TypeName##RingBuffer *const rb) \
|
static inline void funcprefix##_rb_dealloc(TypeName##RingBuffer *const rb) \
|
||||||
REAL_FATTR_UNUSED; \
|
{ \
|
||||||
static inline void funcprefix##_rb_dealloc(TypeName##RingBuffer *const rb) \
|
xfree(rb->buf); \
|
||||||
{ \
|
} \
|
||||||
xfree(rb->buf); \
|
\
|
||||||
} \
|
static inline void funcprefix##_rb_push(TypeName##RingBuffer *const rb, \
|
||||||
\
|
RBType item) \
|
||||||
static inline void funcprefix##_rb_push(TypeName##RingBuffer *const rb, \
|
REAL_FATTR_NONNULL_ARG(1); \
|
||||||
RBType item) \
|
static inline void funcprefix##_rb_push(TypeName##RingBuffer *const rb, \
|
||||||
REAL_FATTR_NONNULL_ARG(1); \
|
RBType item) \
|
||||||
static inline void funcprefix##_rb_push(TypeName##RingBuffer *const rb, \
|
{ \
|
||||||
RBType item) \
|
if (rb->next == rb->first) { \
|
||||||
{ \
|
rbfree(rb->first); \
|
||||||
if (rb->next == rb->first) { \
|
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
||||||
rbfree(rb->first); \
|
} else if (rb->first == NULL) { \
|
||||||
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
rb->first = rb->next; \
|
||||||
} else if (rb->first == NULL) { \
|
} \
|
||||||
rb->first = rb->next; \
|
*rb->next = item; \
|
||||||
} \
|
rb->next = _RINGBUF_NEXT(rb, rb->next); \
|
||||||
*rb->next = item; \
|
} \
|
||||||
rb->next = _RINGBUF_NEXT(rb, rb->next); \
|
\
|
||||||
} \
|
static inline ptrdiff_t funcprefix##_rb_find_idx( \
|
||||||
\
|
const TypeName##RingBuffer *const rb, const RBType *const item_p) \
|
||||||
static inline ptrdiff_t funcprefix##_rb_find_idx( \
|
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE REAL_FATTR_UNUSED; \
|
||||||
const TypeName##RingBuffer *const rb, const RBType *const item_p) \
|
static inline ptrdiff_t funcprefix##_rb_find_idx( \
|
||||||
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE REAL_FATTR_UNUSED; \
|
const TypeName##RingBuffer *const rb, const RBType *const item_p) \
|
||||||
static inline ptrdiff_t funcprefix##_rb_find_idx( \
|
{ \
|
||||||
const TypeName##RingBuffer *const rb, const RBType *const item_p) \
|
assert(rb->buf <= item_p); \
|
||||||
{ \
|
assert(rb->buf_end >= item_p); \
|
||||||
assert(rb->buf <= item_p); \
|
if (rb->first == NULL) { \
|
||||||
assert(rb->buf_end >= item_p); \
|
return -1; \
|
||||||
if (rb->first == NULL) { \
|
} else if (item_p >= rb->first) { \
|
||||||
return -1; \
|
return item_p - rb->first; \
|
||||||
} else if (item_p >= rb->first) { \
|
} else { \
|
||||||
return item_p - rb->first; \
|
return item_p - rb->buf + rb->buf_end - rb->first + 1; \
|
||||||
} else { \
|
} \
|
||||||
return item_p - rb->buf + rb->buf_end - rb->first + 1; \
|
} \
|
||||||
} \
|
\
|
||||||
} \
|
static inline size_t funcprefix##_rb_size( \
|
||||||
\
|
const TypeName##RingBuffer *const rb) \
|
||||||
static inline size_t funcprefix##_rb_size( \
|
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE; \
|
||||||
const TypeName##RingBuffer *const rb) \
|
static inline size_t funcprefix##_rb_size( \
|
||||||
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE; \
|
const TypeName##RingBuffer *const rb) \
|
||||||
static inline size_t funcprefix##_rb_size( \
|
{ \
|
||||||
const TypeName##RingBuffer *const rb) \
|
return (size_t) (rb->buf_end - rb->buf) + 1; \
|
||||||
{ \
|
} \
|
||||||
return (size_t) (rb->buf_end - rb->buf) + 1; \
|
\
|
||||||
} \
|
static inline size_t funcprefix##_rb_length( \
|
||||||
\
|
const TypeName##RingBuffer *const rb) \
|
||||||
static inline size_t funcprefix##_rb_length( \
|
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE; \
|
||||||
const TypeName##RingBuffer *const rb) \
|
static inline size_t funcprefix##_rb_length( \
|
||||||
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE; \
|
const TypeName##RingBuffer *const rb) \
|
||||||
static inline size_t funcprefix##_rb_length( \
|
{ \
|
||||||
const TypeName##RingBuffer *const rb) \
|
return _RINGBUF_LENGTH(rb); \
|
||||||
{ \
|
} \
|
||||||
return _RINGBUF_LENGTH(rb); \
|
\
|
||||||
} \
|
static inline RBType *funcprefix##_rb_idx_p( \
|
||||||
\
|
const TypeName##RingBuffer *const rb, const size_t idx) \
|
||||||
static inline RBType *funcprefix##_rb_idx_p( \
|
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE; \
|
||||||
const TypeName##RingBuffer *const rb, const size_t idx) \
|
static inline RBType *funcprefix##_rb_idx_p( \
|
||||||
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE; \
|
const TypeName##RingBuffer *const rb, const size_t idx) \
|
||||||
static inline RBType *funcprefix##_rb_idx_p( \
|
{ \
|
||||||
const TypeName##RingBuffer *const rb, const size_t idx) \
|
assert(idx <= funcprefix##_rb_size(rb)); \
|
||||||
{ \
|
assert(idx <= funcprefix##_rb_length(rb)); \
|
||||||
assert(idx <= funcprefix##_rb_size(rb)); \
|
if (rb->first + idx > rb->buf_end) { \
|
||||||
assert(idx <= funcprefix##_rb_length(rb)); \
|
return rb->buf + ((rb->first + idx) - (rb->buf_end + 1)); \
|
||||||
if (rb->first + idx > rb->buf_end) { \
|
} else { \
|
||||||
return rb->buf + ((rb->first + idx) - (rb->buf_end + 1)); \
|
return rb->first + idx; \
|
||||||
} else { \
|
} \
|
||||||
return rb->first + idx; \
|
} \
|
||||||
} \
|
\
|
||||||
} \
|
|
||||||
\
|
|
||||||
static inline RBType funcprefix##_rb_idx(const TypeName##RingBuffer *const rb, \
|
static inline RBType funcprefix##_rb_idx(const TypeName##RingBuffer *const rb, \
|
||||||
const size_t idx) \
|
const size_t idx) \
|
||||||
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE REAL_FATTR_UNUSED; \
|
REAL_FATTR_NONNULL_ALL REAL_FATTR_PURE REAL_FATTR_UNUSED; \
|
||||||
static inline RBType funcprefix##_rb_idx(const TypeName##RingBuffer *const rb, \
|
static inline RBType funcprefix##_rb_idx(const TypeName##RingBuffer *const rb, \
|
||||||
const size_t idx) \
|
const size_t idx) \
|
||||||
{ \
|
{ \
|
||||||
return *funcprefix##_rb_idx_p(rb, idx); \
|
return *funcprefix##_rb_idx_p(rb, idx); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void funcprefix##_rb_insert(TypeName##RingBuffer *const rb, \
|
static inline void funcprefix##_rb_insert(TypeName##RingBuffer *const rb, \
|
||||||
const size_t idx, \
|
const size_t idx, \
|
||||||
RBType item) \
|
RBType item) \
|
||||||
REAL_FATTR_NONNULL_ARG(1) REAL_FATTR_UNUSED; \
|
REAL_FATTR_NONNULL_ARG(1) REAL_FATTR_UNUSED; \
|
||||||
static inline void funcprefix##_rb_insert(TypeName##RingBuffer *const rb, \
|
static inline void funcprefix##_rb_insert(TypeName##RingBuffer *const rb, \
|
||||||
const size_t idx, \
|
const size_t idx, \
|
||||||
RBType item) \
|
RBType item) \
|
||||||
{ \
|
{ \
|
||||||
assert(idx <= funcprefix##_rb_size(rb)); \
|
assert(idx <= funcprefix##_rb_size(rb)); \
|
||||||
assert(idx <= funcprefix##_rb_length(rb)); \
|
assert(idx <= funcprefix##_rb_length(rb)); \
|
||||||
const size_t length = funcprefix##_rb_length(rb); \
|
const size_t length = funcprefix##_rb_length(rb); \
|
||||||
if (idx == length) { \
|
if (idx == length) { \
|
||||||
funcprefix##_rb_push(rb, item); \
|
funcprefix##_rb_push(rb, item); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
RBType *const insertpos = funcprefix##_rb_idx_p(rb, idx); \
|
RBType *const insertpos = funcprefix##_rb_idx_p(rb, idx); \
|
||||||
if (insertpos == rb->next) { \
|
if (insertpos == rb->next) { \
|
||||||
funcprefix##_rb_push(rb, item); \
|
funcprefix##_rb_push(rb, item); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
if (length == funcprefix##_rb_size(rb)) { \
|
if (length == funcprefix##_rb_size(rb)) { \
|
||||||
rbfree(rb->first); \
|
rbfree(rb->first); \
|
||||||
} \
|
} \
|
||||||
if (insertpos < rb->next) { \
|
if (insertpos < rb->next) { \
|
||||||
memmove(insertpos + 1, insertpos, \
|
memmove(insertpos + 1, insertpos, \
|
||||||
(size_t) ((uintptr_t) rb->next - (uintptr_t) insertpos)); \
|
(size_t) ((uintptr_t) rb->next - (uintptr_t) insertpos)); \
|
||||||
} else { \
|
} else { \
|
||||||
assert(insertpos > rb->first); \
|
assert(insertpos > rb->first); \
|
||||||
assert(rb->next <= rb->first); \
|
assert(rb->next <= rb->first); \
|
||||||
memmove(rb->buf + 1, rb->buf, \
|
memmove(rb->buf + 1, rb->buf, \
|
||||||
(size_t) ((uintptr_t) rb->next - (uintptr_t) rb->buf)); \
|
(size_t) ((uintptr_t) rb->next - (uintptr_t) rb->buf)); \
|
||||||
*rb->buf = *rb->buf_end; \
|
*rb->buf = *rb->buf_end; \
|
||||||
memmove(insertpos + 1, insertpos, \
|
memmove(insertpos + 1, insertpos, \
|
||||||
(size_t) ((uintptr_t) (rb->buf_end + 1) - (uintptr_t) insertpos)); \
|
(size_t) ((uintptr_t) (rb->buf_end + 1) - (uintptr_t) insertpos)); \
|
||||||
} \
|
} \
|
||||||
*insertpos = item; \
|
*insertpos = item; \
|
||||||
if (length == funcprefix##_rb_size(rb)) { \
|
if (length == funcprefix##_rb_size(rb)) { \
|
||||||
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
||||||
} \
|
} \
|
||||||
rb->next = _RINGBUF_NEXT(rb, rb->next); \
|
rb->next = _RINGBUF_NEXT(rb, rb->next); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
static inline void funcprefix##_rb_remove(TypeName##RingBuffer *const rb, \
|
static inline void funcprefix##_rb_remove(TypeName##RingBuffer *const rb, \
|
||||||
const size_t idx) \
|
const size_t idx) \
|
||||||
REAL_FATTR_NONNULL_ARG(1) REAL_FATTR_UNUSED; \
|
REAL_FATTR_NONNULL_ARG(1) REAL_FATTR_UNUSED; \
|
||||||
static inline void funcprefix##_rb_remove(TypeName##RingBuffer *const rb, \
|
static inline void funcprefix##_rb_remove(TypeName##RingBuffer *const rb, \
|
||||||
const size_t idx) \
|
const size_t idx) \
|
||||||
{ \
|
{ \
|
||||||
assert(idx < funcprefix##_rb_size(rb)); \
|
assert(idx < funcprefix##_rb_size(rb)); \
|
||||||
assert(idx < funcprefix##_rb_length(rb)); \
|
assert(idx < funcprefix##_rb_length(rb)); \
|
||||||
RBType *const rmpos = funcprefix##_rb_idx_p(rb, idx); \
|
RBType *const rmpos = funcprefix##_rb_idx_p(rb, idx); \
|
||||||
rbfree(rmpos); \
|
rbfree(rmpos); \
|
||||||
if (rmpos == rb->next - 1) { \
|
if (rmpos == rb->next - 1) { \
|
||||||
rb->next--; \
|
rb->next--; \
|
||||||
if (rb->first == rb->next) { \
|
if (rb->first == rb->next) { \
|
||||||
rb->first = NULL; \
|
rb->first = NULL; \
|
||||||
rb->next = rb->buf; \
|
rb->next = rb->buf; \
|
||||||
} \
|
} \
|
||||||
} else if (rmpos == rb->first) { \
|
} else if (rmpos == rb->first) { \
|
||||||
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
||||||
if (rb->first == rb->next) { \
|
if (rb->first == rb->next) { \
|
||||||
rb->first = NULL; \
|
rb->first = NULL; \
|
||||||
rb->next = rb->buf; \
|
rb->next = rb->buf; \
|
||||||
} \
|
} \
|
||||||
} else if (rb->first < rb->next || rb->next == rb->buf) { \
|
} else if (rb->first < rb->next || rb->next == rb->buf) { \
|
||||||
assert(rmpos > rb->first); \
|
assert(rmpos > rb->first); \
|
||||||
assert(rmpos <= _RINGBUF_PREV(rb, rb->next)); \
|
assert(rmpos <= _RINGBUF_PREV(rb, rb->next)); \
|
||||||
memmove(rb->first + 1, rb->first, \
|
memmove(rb->first + 1, rb->first, \
|
||||||
(size_t) ((uintptr_t) rmpos - (uintptr_t) rb->first)); \
|
(size_t) ((uintptr_t) rmpos - (uintptr_t) rb->first)); \
|
||||||
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
||||||
} else if (rmpos < rb->next) { \
|
} else if (rmpos < rb->next) { \
|
||||||
memmove(rmpos, rmpos + 1, \
|
memmove(rmpos, rmpos + 1, \
|
||||||
(size_t) ((uintptr_t) rb->next - (uintptr_t) rmpos)); \
|
(size_t) ((uintptr_t) rb->next - (uintptr_t) rmpos)); \
|
||||||
rb->next = _RINGBUF_PREV(rb, rb->next); \
|
rb->next = _RINGBUF_PREV(rb, rb->next); \
|
||||||
} else { \
|
} else { \
|
||||||
assert(rb->first < rb->buf_end); \
|
assert(rb->first < rb->buf_end); \
|
||||||
memmove(rb->first + 1, rb->first, \
|
memmove(rb->first + 1, rb->first, \
|
||||||
(size_t) ((uintptr_t) rmpos - (uintptr_t) rb->first)); \
|
(size_t) ((uintptr_t) rmpos - (uintptr_t) rb->first)); \
|
||||||
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
rb->first = _RINGBUF_NEXT(rb, rb->first); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // NVIM_LIB_RINGBUF_H
|
#endif // NVIM_LIB_RINGBUF_H
|
||||||
|
160
src/nvim/map.c
160
src/nvim/map.c
@@ -34,88 +34,88 @@
|
|||||||
#define INITIALIZER_DECLARE(T, U, ...) const U INITIALIZER(T, U) = __VA_ARGS__
|
#define INITIALIZER_DECLARE(T, U, ...) const U INITIALIZER(T, U) = __VA_ARGS__
|
||||||
#define DEFAULT_INITIALIZER {0}
|
#define DEFAULT_INITIALIZER {0}
|
||||||
|
|
||||||
#define MAP_IMPL(T, U, ...) \
|
#define MAP_IMPL(T, U, ...) \
|
||||||
INITIALIZER_DECLARE(T, U, __VA_ARGS__); \
|
INITIALIZER_DECLARE(T, U, __VA_ARGS__); \
|
||||||
__KHASH_IMPL(T##_##U##_map,, T, U, 1, T##_hash, T##_eq) \
|
__KHASH_IMPL(T##_##U##_map,, T, U, 1, T##_hash, T##_eq) \
|
||||||
\
|
\
|
||||||
Map(T, U) *map_##T##_##U##_new() \
|
Map(T, U) *map_##T##_##U##_new() \
|
||||||
{ \
|
{ \
|
||||||
Map(T, U) *rv = xmalloc(sizeof(Map(T, U))); \
|
Map(T, U) *rv = xmalloc(sizeof(Map(T, U))); \
|
||||||
rv->table = kh_init(T##_##U##_map); \
|
rv->table = kh_init(T##_##U##_map); \
|
||||||
return rv; \
|
return rv; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void map_##T##_##U##_free(Map(T, U) *map) \
|
void map_##T##_##U##_free(Map(T, U) *map) \
|
||||||
{ \
|
{ \
|
||||||
kh_destroy(T##_##U##_map, map->table); \
|
kh_destroy(T##_##U##_map, map->table); \
|
||||||
xfree(map); \
|
xfree(map); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
U map_##T##_##U##_get(Map(T, U) *map, T key) \
|
U map_##T##_##U##_get(Map(T, U) *map, T key) \
|
||||||
{ \
|
{ \
|
||||||
khiter_t k; \
|
khiter_t k; \
|
||||||
\
|
\
|
||||||
if ((k = kh_get(T##_##U##_map, map->table, key)) == kh_end(map->table)) { \
|
if ((k = kh_get(T##_##U##_map, map->table, key)) == kh_end(map->table)) { \
|
||||||
return INITIALIZER(T, U); \
|
return INITIALIZER(T, U); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return kh_val(map->table, k); \
|
return kh_val(map->table, k); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
bool map_##T##_##U##_has(Map(T, U) *map, T key) \
|
bool map_##T##_##U##_has(Map(T, U) *map, T key) \
|
||||||
{ \
|
{ \
|
||||||
return kh_get(T##_##U##_map, map->table, key) != kh_end(map->table); \
|
return kh_get(T##_##U##_map, map->table, key) != kh_end(map->table); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
U map_##T##_##U##_put(Map(T, U) *map, T key, U value) \
|
U map_##T##_##U##_put(Map(T, U) *map, T key, U value) \
|
||||||
{ \
|
{ \
|
||||||
int ret; \
|
int ret; \
|
||||||
U rv = INITIALIZER(T, U); \
|
U rv = INITIALIZER(T, U); \
|
||||||
khiter_t k = kh_put(T##_##U##_map, map->table, key, &ret); \
|
khiter_t k = kh_put(T##_##U##_map, map->table, key, &ret); \
|
||||||
\
|
\
|
||||||
if (!ret) { \
|
if (!ret) { \
|
||||||
rv = kh_val(map->table, k); \
|
rv = kh_val(map->table, k); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
kh_val(map->table, k) = value; \
|
kh_val(map->table, k) = value; \
|
||||||
return rv; \
|
return rv; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
U *map_##T##_##U##_ref(Map(T, U) *map, T key, bool put) \
|
U *map_##T##_##U##_ref(Map(T, U) *map, T key, bool put) \
|
||||||
{ \
|
{ \
|
||||||
int ret; \
|
int ret; \
|
||||||
khiter_t k; \
|
khiter_t k; \
|
||||||
if (put) { \
|
if (put) { \
|
||||||
k = kh_put(T##_##U##_map, map->table, key, &ret); \
|
k = kh_put(T##_##U##_map, map->table, key, &ret); \
|
||||||
if (ret) { \
|
if (ret) { \
|
||||||
kh_val(map->table, k) = INITIALIZER(T, U); \
|
kh_val(map->table, k) = INITIALIZER(T, U); \
|
||||||
} \
|
} \
|
||||||
} else { \
|
} else { \
|
||||||
k = kh_get(T##_##U##_map, map->table, key); \
|
k = kh_get(T##_##U##_map, map->table, key); \
|
||||||
if (k == kh_end(map->table)) { \
|
if (k == kh_end(map->table)) { \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return &kh_val(map->table, k); \
|
return &kh_val(map->table, k); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
U map_##T##_##U##_del(Map(T, U) *map, T key) \
|
U map_##T##_##U##_del(Map(T, U) *map, T key) \
|
||||||
{ \
|
{ \
|
||||||
U rv = INITIALIZER(T, U); \
|
U rv = INITIALIZER(T, U); \
|
||||||
khiter_t k; \
|
khiter_t k; \
|
||||||
\
|
\
|
||||||
if ((k = kh_get(T##_##U##_map, map->table, key)) != kh_end(map->table)) { \
|
if ((k = kh_get(T##_##U##_map, map->table, key)) != kh_end(map->table)) { \
|
||||||
rv = kh_val(map->table, k); \
|
rv = kh_val(map->table, k); \
|
||||||
kh_del(T##_##U##_map, map->table, k); \
|
kh_del(T##_##U##_map, map->table, k); \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
return rv; \
|
return rv; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void map_##T##_##U##_clear(Map(T, U) *map) \
|
void map_##T##_##U##_clear(Map(T, U) *map) \
|
||||||
{ \
|
{ \
|
||||||
kh_clear(T##_##U##_map, map->table); \
|
kh_clear(T##_##U##_map, map->table); \
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline khint_t String_hash(String s)
|
static inline khint_t String_hash(String s)
|
||||||
|
@@ -8,20 +8,20 @@
|
|||||||
#include "nvim/msgpack_rpc/defs.h"
|
#include "nvim/msgpack_rpc/defs.h"
|
||||||
#include "nvim/bufhl_defs.h"
|
#include "nvim/bufhl_defs.h"
|
||||||
|
|
||||||
#define MAP_DECLS(T, U) \
|
#define MAP_DECLS(T, U) \
|
||||||
KHASH_DECLARE(T##_##U##_map, T, U) \
|
KHASH_DECLARE(T##_##U##_map, T, U) \
|
||||||
\
|
\
|
||||||
typedef struct { \
|
typedef struct { \
|
||||||
khash_t(T##_##U##_map) *table; \
|
khash_t(T##_##U##_map) *table; \
|
||||||
} Map(T, U); \
|
} Map(T, U); \
|
||||||
\
|
\
|
||||||
Map(T, U) *map_##T##_##U##_new(void); \
|
Map(T, U) *map_##T##_##U##_new(void); \
|
||||||
void map_##T##_##U##_free(Map(T, U) *map); \
|
void map_##T##_##U##_free(Map(T, U) *map); \
|
||||||
U map_##T##_##U##_get(Map(T, U) *map, T key); \
|
U map_##T##_##U##_get(Map(T, U) *map, T key); \
|
||||||
bool map_##T##_##U##_has(Map(T, U) *map, T key); \
|
bool map_##T##_##U##_has(Map(T, U) *map, T key); \
|
||||||
U map_##T##_##U##_put(Map(T, U) *map, T key, U value); \
|
U map_##T##_##U##_put(Map(T, U) *map, T key, U value); \
|
||||||
U *map_##T##_##U##_ref(Map(T, U) *map, T key, bool put); \
|
U *map_##T##_##U##_ref(Map(T, U) *map, T key, bool put); \
|
||||||
U map_##T##_##U##_del(Map(T, U) *map, T key); \
|
U map_##T##_##U##_del(Map(T, U) *map, T key); \
|
||||||
void map_##T##_##U##_clear(Map(T, U) *map);
|
void map_##T##_##U##_clear(Map(T, U) *map);
|
||||||
|
|
||||||
MAP_DECLS(int, int)
|
MAP_DECLS(int, int)
|
||||||
|
@@ -1304,7 +1304,7 @@ int utfc_ptr2char(const char_u *p, int *pcc)
|
|||||||
*/
|
*/
|
||||||
int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen)
|
int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen)
|
||||||
{
|
{
|
||||||
#define IS_COMPOSING(s1, s2, s3) \
|
#define IS_COMPOSING(s1, s2, s3) \
|
||||||
(i == 0 ? UTF_COMPOSINGLIKE((s1), (s2)) : utf_iscomposing((s3)))
|
(i == 0 ? UTF_COMPOSINGLIKE((s1), (s2)) : utf_iscomposing((s3)))
|
||||||
|
|
||||||
assert(maxlen > 0);
|
assert(maxlen > 0);
|
||||||
|
@@ -18,39 +18,39 @@
|
|||||||
static msgpack_zone zone;
|
static msgpack_zone zone;
|
||||||
static msgpack_sbuffer sbuffer;
|
static msgpack_sbuffer sbuffer;
|
||||||
|
|
||||||
#define HANDLE_TYPE_CONVERSION_IMPL(t, lt) \
|
#define HANDLE_TYPE_CONVERSION_IMPL(t, lt) \
|
||||||
bool msgpack_rpc_to_##lt(msgpack_object *obj, t *arg) \
|
bool msgpack_rpc_to_##lt(msgpack_object *obj, t *arg) \
|
||||||
FUNC_ATTR_NONNULL_ALL \
|
FUNC_ATTR_NONNULL_ALL \
|
||||||
{ \
|
{ \
|
||||||
if (obj->type != MSGPACK_OBJECT_EXT \
|
if (obj->type != MSGPACK_OBJECT_EXT \
|
||||||
|| obj->via.ext.type != kObjectType##t) { \
|
|| obj->via.ext.type != kObjectType##t) { \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
msgpack_object data; \
|
msgpack_object data; \
|
||||||
msgpack_unpack_return ret = msgpack_unpack(obj->via.ext.ptr, \
|
msgpack_unpack_return ret = msgpack_unpack(obj->via.ext.ptr, \
|
||||||
obj->via.ext.size, \
|
obj->via.ext.size, \
|
||||||
NULL, \
|
NULL, \
|
||||||
&zone, \
|
&zone, \
|
||||||
&data); \
|
&data); \
|
||||||
\
|
\
|
||||||
if (ret != MSGPACK_UNPACK_SUCCESS) { \
|
if (ret != MSGPACK_UNPACK_SUCCESS) { \
|
||||||
return false; \
|
return false; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
*arg = data.via.u64; \
|
*arg = data.via.u64; \
|
||||||
return true; \
|
return true; \
|
||||||
} \
|
} \
|
||||||
\
|
\
|
||||||
void msgpack_rpc_from_##lt(t o, msgpack_packer *res) \
|
void msgpack_rpc_from_##lt(t o, msgpack_packer *res) \
|
||||||
FUNC_ATTR_NONNULL_ARG(2) \
|
FUNC_ATTR_NONNULL_ARG(2) \
|
||||||
{ \
|
{ \
|
||||||
msgpack_packer pac; \
|
msgpack_packer pac; \
|
||||||
msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \
|
msgpack_packer_init(&pac, &sbuffer, msgpack_sbuffer_write); \
|
||||||
msgpack_pack_uint64(&pac, o); \
|
msgpack_pack_uint64(&pac, o); \
|
||||||
msgpack_pack_ext(res, sbuffer.size, kObjectType##t); \
|
msgpack_pack_ext(res, sbuffer.size, kObjectType##t); \
|
||||||
msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \
|
msgpack_pack_ext_body(res, sbuffer.data, sbuffer.size); \
|
||||||
msgpack_sbuffer_clear(&sbuffer); \
|
msgpack_sbuffer_clear(&sbuffer); \
|
||||||
}
|
}
|
||||||
|
|
||||||
void msgpack_rpc_helpers_init(void)
|
void msgpack_rpc_helpers_init(void)
|
||||||
|
@@ -36,30 +36,30 @@
|
|||||||
//
|
//
|
||||||
// Note that the rbuffer_{produced,consumed} calls are necessary or these macros
|
// Note that the rbuffer_{produced,consumed} calls are necessary or these macros
|
||||||
// create infinite loops
|
// create infinite loops
|
||||||
#define RBUFFER_UNTIL_EMPTY(buf, rptr, rcnt) \
|
#define RBUFFER_UNTIL_EMPTY(buf, rptr, rcnt) \
|
||||||
for (size_t rcnt = 0, _r = 1; _r; _r = 0) \
|
for (size_t rcnt = 0, _r = 1; _r; _r = 0) \
|
||||||
for (char *rptr = rbuffer_read_ptr(buf, &rcnt); \
|
for (char *rptr = rbuffer_read_ptr(buf, &rcnt); \
|
||||||
buf->size; \
|
buf->size; \
|
||||||
rptr = rbuffer_read_ptr(buf, &rcnt))
|
rptr = rbuffer_read_ptr(buf, &rcnt))
|
||||||
|
|
||||||
#define RBUFFER_UNTIL_FULL(buf, wptr, wcnt) \
|
#define RBUFFER_UNTIL_FULL(buf, wptr, wcnt) \
|
||||||
for (size_t wcnt = 0, _r = 1; _r; _r = 0) \
|
for (size_t wcnt = 0, _r = 1; _r; _r = 0) \
|
||||||
for (char *wptr = rbuffer_write_ptr(buf, &wcnt); \
|
for (char *wptr = rbuffer_write_ptr(buf, &wcnt); \
|
||||||
rbuffer_space(buf); \
|
rbuffer_space(buf); \
|
||||||
wptr = rbuffer_write_ptr(buf, &wcnt))
|
wptr = rbuffer_write_ptr(buf, &wcnt))
|
||||||
|
|
||||||
|
|
||||||
// Iteration
|
// Iteration
|
||||||
#define RBUFFER_EACH(buf, c, i) \
|
#define RBUFFER_EACH(buf, c, i) \
|
||||||
for (size_t i = 0; i < buf->size; i = buf->size) \
|
for (size_t i = 0; i < buf->size; i = buf->size) \
|
||||||
for (char c = 0; \
|
for (char c = 0; \
|
||||||
i < buf->size ? ((int)(c = *rbuffer_get(buf, i))) || 1 : 0; \
|
i < buf->size ? ((int)(c = *rbuffer_get(buf, i))) || 1 : 0; \
|
||||||
i++)
|
i++)
|
||||||
|
|
||||||
#define RBUFFER_EACH_REVERSE(buf, c, i) \
|
#define RBUFFER_EACH_REVERSE(buf, c, i) \
|
||||||
for (size_t i = buf->size; i != SIZE_MAX; i = SIZE_MAX) \
|
for (size_t i = buf->size; i != SIZE_MAX; i = SIZE_MAX) \
|
||||||
for (char c = 0; \
|
for (char c = 0; \
|
||||||
i-- > 0 ? ((int)(c = *rbuffer_get(buf, i))) || 1 : 0; \
|
i-- > 0 ? ((int)(c = *rbuffer_get(buf, i))) || 1 : 0; \
|
||||||
)
|
)
|
||||||
|
|
||||||
typedef struct rbuffer RBuffer;
|
typedef struct rbuffer RBuffer;
|
||||||
|
@@ -358,11 +358,11 @@ static int nfa_ll_index = 0;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* helper functions used when doing re2post() ... regatom() parsing */
|
/* helper functions used when doing re2post() ... regatom() parsing */
|
||||||
#define EMIT(c) do { \
|
#define EMIT(c) do { \
|
||||||
if (post_ptr >= post_end) { \
|
if (post_ptr >= post_end) { \
|
||||||
realloc_post_list(); \
|
realloc_post_list(); \
|
||||||
} \
|
} \
|
||||||
*post_ptr++ = c; \
|
*post_ptr++ = c; \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -2892,12 +2892,12 @@ static nfa_state_T *post2nfa(int *postfix, int *end, int nfa_calc_size)
|
|||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
#define PUSH(s) st_push((s), &stackp, stack_end)
|
#define PUSH(s) st_push((s), &stackp, stack_end)
|
||||||
#define POP() st_pop(&stackp, stack); \
|
#define POP() st_pop(&stackp, stack); \
|
||||||
if (stackp < stack) \
|
if (stackp < stack) \
|
||||||
{ \
|
{ \
|
||||||
st_error(postfix, end, p); \
|
st_error(postfix, end, p); \
|
||||||
xfree(stack); \
|
xfree(stack); \
|
||||||
return NULL; \
|
return NULL; \
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nfa_calc_size == FALSE) {
|
if (nfa_calc_size == FALSE) {
|
||||||
@@ -4904,10 +4904,10 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
|
|||||||
} else
|
} else
|
||||||
addstate(thislist, start, m, NULL, 0);
|
addstate(thislist, start, m, NULL, 0);
|
||||||
|
|
||||||
#define ADD_STATE_IF_MATCH(state) \
|
#define ADD_STATE_IF_MATCH(state) \
|
||||||
if (result) { \
|
if (result) { \
|
||||||
add_state = state->out; \
|
add_state = state->out; \
|
||||||
add_off = clen; \
|
add_off = clen; \
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -1159,15 +1159,15 @@ static bool is_focused(Terminal *term)
|
|||||||
return State & TERM_FOCUS && curbuf->terminal == term;
|
return State & TERM_FOCUS && curbuf->terminal == term;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define GET_CONFIG_VALUE(k, o) \
|
#define GET_CONFIG_VALUE(k, o) \
|
||||||
do { \
|
do { \
|
||||||
Error err; \
|
Error err; \
|
||||||
/* Only called from terminal_open where curbuf->terminal is the */ \
|
/* Only called from terminal_open where curbuf->terminal is the */ \
|
||||||
/* context */ \
|
/* context */ \
|
||||||
o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \
|
o = dict_get_value(curbuf->b_vars, cstr_as_string(k), &err); \
|
||||||
if (o.type == kObjectTypeNil) { \
|
if (o.type == kObjectTypeNil) { \
|
||||||
o = dict_get_value(&globvardict, cstr_as_string(k), &err); \
|
o = dict_get_value(&globvardict, cstr_as_string(k), &err); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
static char *get_config_string(char *key)
|
static char *get_config_string(char *key)
|
||||||
|
@@ -23,16 +23,16 @@ struct ugrid {
|
|||||||
|
|
||||||
#define EMPTY_ATTRS ((HlAttrs){ false, false, false, false, false, -1, -1, -1 })
|
#define EMPTY_ATTRS ((HlAttrs){ false, false, false, false, false, -1, -1, -1 })
|
||||||
|
|
||||||
#define UGRID_FOREACH_CELL(grid, top, bot, left, right, code) \
|
#define UGRID_FOREACH_CELL(grid, top, bot, left, right, code) \
|
||||||
do { \
|
do { \
|
||||||
for (int row = top; row <= bot; ++row) { \
|
for (int row = top; row <= bot; ++row) { \
|
||||||
UCell *row_cells = (grid)->cells[row]; \
|
UCell *row_cells = (grid)->cells[row]; \
|
||||||
for (int col = left; col <= right; ++col) { \
|
for (int col = left; col <= right; ++col) { \
|
||||||
UCell *cell = row_cells + col; \
|
UCell *cell = row_cells + col; \
|
||||||
(void)(cell); \
|
(void)(cell); \
|
||||||
code; \
|
code; \
|
||||||
} \
|
} \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
#ifdef INCLUDE_GENERATED_DECLARATIONS
|
||||||
|
@@ -60,22 +60,22 @@ static int height, width;
|
|||||||
// See http://stackoverflow.com/a/11172679 for a better explanation of how it
|
// See http://stackoverflow.com/a/11172679 for a better explanation of how it
|
||||||
// works.
|
// works.
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#define UI_CALL(funname, ...) \
|
#define UI_CALL(funname, ...) \
|
||||||
do { \
|
do { \
|
||||||
flush_cursor_update(); \
|
flush_cursor_update(); \
|
||||||
for (size_t i = 0; i < ui_count; i++) { \
|
for (size_t i = 0; i < ui_count; i++) { \
|
||||||
UI *ui = uis[i]; \
|
UI *ui = uis[i]; \
|
||||||
UI_CALL_MORE(funname, __VA_ARGS__); \
|
UI_CALL_MORE(funname, __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#else
|
#else
|
||||||
#define UI_CALL(...) \
|
#define UI_CALL(...) \
|
||||||
do { \
|
do { \
|
||||||
flush_cursor_update(); \
|
flush_cursor_update(); \
|
||||||
for (size_t i = 0; i < ui_count; i++) { \
|
for (size_t i = 0; i < ui_count; i++) { \
|
||||||
UI *ui = uis[i]; \
|
UI *ui = uis[i]; \
|
||||||
UI_CALL_HELPER(CNT(__VA_ARGS__), __VA_ARGS__); \
|
UI_CALL_HELPER(CNT(__VA_ARGS__), __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
#endif
|
#endif
|
||||||
#define CNT(...) SELECT_NTH(__VA_ARGS__, MORE, MORE, MORE, MORE, ZERO, ignore)
|
#define CNT(...) SELECT_NTH(__VA_ARGS__, MORE, MORE, MORE, MORE, ZERO, ignore)
|
||||||
|
@@ -19,8 +19,8 @@
|
|||||||
#define UI(b) (((UIBridgeData *)b)->ui)
|
#define UI(b) (((UIBridgeData *)b)->ui)
|
||||||
|
|
||||||
// Call a function in the UI thread
|
// Call a function in the UI thread
|
||||||
#define UI_CALL(ui, name, argc, ...) \
|
#define UI_CALL(ui, name, argc, ...) \
|
||||||
((UIBridgeData *)ui)->scheduler( \
|
((UIBridgeData *)ui)->scheduler( \
|
||||||
event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui))
|
event_create(1, ui_bridge_##name##_event, argc, __VA_ARGS__), UI(ui))
|
||||||
|
|
||||||
#define INT2PTR(i) ((void *)(uintptr_t)i)
|
#define INT2PTR(i) ((void *)(uintptr_t)i)
|
||||||
|
@@ -28,13 +28,13 @@ struct ui_bridge_data {
|
|||||||
bool stopped;
|
bool stopped;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define CONTINUE(b) \
|
#define CONTINUE(b) \
|
||||||
do { \
|
do { \
|
||||||
UIBridgeData *d = (UIBridgeData *)b; \
|
UIBridgeData *d = (UIBridgeData *)b; \
|
||||||
uv_mutex_lock(&d->mutex); \
|
uv_mutex_lock(&d->mutex); \
|
||||||
d->ready = true; \
|
d->ready = true; \
|
||||||
uv_cond_signal(&d->cond); \
|
uv_cond_signal(&d->cond); \
|
||||||
uv_mutex_unlock(&d->mutex); \
|
uv_mutex_unlock(&d->mutex); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user