Use lowercase macro names for compiler builtins.
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
aaf881d672
commit
a9df95b303
|
@ -36,27 +36,27 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#ifdef HAVE___BUILTIN_EXPECT
|
#ifdef HAVE___BUILTIN_EXPECT
|
||||||
# define CTLSEQS_LIKELY(expr) __builtin_expect(!!(expr), 1)
|
# define ctlseqs_likely(expr) __builtin_expect(!!(expr), 1)
|
||||||
# define CTLSEQS_UNLIKELY(expr) __builtin_expect(!!(expr), 0)
|
# define ctlseqs_unlikely(expr) __builtin_expect(!!(expr), 0)
|
||||||
#else
|
#else
|
||||||
# define CTLSEQS_LIKELY(expr) (expr)
|
# define ctlseqs_likely(expr) (expr)
|
||||||
# define CTLSEQS_UNLIKELY(expr) (expr)
|
# define ctlseqs_unlikely(expr) (expr)
|
||||||
#endif // HAVE___BUILTIN_EXPECT
|
#endif // HAVE___BUILTIN_EXPECT
|
||||||
#ifdef HAVE___BUILTIN_UNREACHABLE
|
#ifdef HAVE___BUILTIN_UNREACHABLE
|
||||||
# define CTLSEQS_UNREACHABLE() __builtin_unreachable()
|
# define ctlseqs_unreachable() __builtin_unreachable()
|
||||||
#else
|
#else
|
||||||
# define CTLSEQS_UNREACHABLE()
|
# define ctlseqs_unreachable()
|
||||||
#endif // HAVE___BUILTIN_UNREACHABLE
|
#endif // HAVE___BUILTIN_UNREACHABLE
|
||||||
|
|
||||||
#ifdef HAVE_FUNC_ATTRIBUTE_COLD
|
#ifdef HAVE_FUNC_ATTRIBUTE_COLD
|
||||||
# define CTLSEQS_COLD __attribute__((cold))
|
# define ctlseqs_cold __attribute__((cold))
|
||||||
#else
|
#else
|
||||||
# define CTLSEQS_COLD
|
# define ctlseqs_cold
|
||||||
#endif // HAVE_FUNC_ATTRIBUTE_COLD
|
#endif // HAVE_FUNC_ATTRIBUTE_COLD
|
||||||
#ifdef HAVE_FUNC_ATTRIBUTE_HOT
|
#ifdef HAVE_FUNC_ATTRIBUTE_HOT
|
||||||
# define CTLSEQS_HOT __attribute__((hot))
|
# define ctlseqs_hot __attribute__((hot))
|
||||||
#else
|
#else
|
||||||
# define CTLSEQS_HOT
|
# define ctlseqs_hot
|
||||||
#endif // HAVE_FUNC_ATTRIBUTE_HOT
|
#endif // HAVE_FUNC_ATTRIBUTE_HOT
|
||||||
|
|
||||||
#ifndef CTLSEQS_TRIE_NODE_POOL_INIT_SIZE
|
#ifndef CTLSEQS_TRIE_NODE_POOL_INIT_SIZE
|
||||||
|
@ -159,7 +159,7 @@ struct ctlseqs_reader {
|
||||||
bool save_matched;
|
bool save_matched;
|
||||||
};
|
};
|
||||||
|
|
||||||
CTLSEQS_HOT static inline int
|
ctlseqs_hot static inline int
|
||||||
ctlseqs_poll(struct pollfd *pollfd, int timeout)
|
ctlseqs_poll(struct pollfd *pollfd, int timeout)
|
||||||
{
|
{
|
||||||
int nevents = poll(pollfd, 1, timeout);
|
int nevents = poll(pollfd, 1, timeout);
|
||||||
|
@ -169,31 +169,31 @@ ctlseqs_poll(struct pollfd *pollfd, int timeout)
|
||||||
if (nevents == 0) {
|
if (nevents == 0) {
|
||||||
return CTLSEQS_TIMEOUT;
|
return CTLSEQS_TIMEOUT;
|
||||||
}
|
}
|
||||||
if (CTLSEQS_LIKELY(pollfd->revents & POLLIN)) {
|
if (ctlseqs_likely(pollfd->revents & POLLIN)) {
|
||||||
return CTLSEQS_OK;
|
return CTLSEQS_OK;
|
||||||
}
|
}
|
||||||
return pollfd->revents & POLLHUP ? CTLSEQS_EOF : CTLSEQS_ERROR;
|
return pollfd->revents & POLLHUP ? CTLSEQS_EOF : CTLSEQS_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_HOT static inline int
|
ctlseqs_hot static inline int
|
||||||
ctlseqs_do_read(struct ctlseqs_reader *reader)
|
ctlseqs_do_read(struct ctlseqs_reader *reader)
|
||||||
{
|
{
|
||||||
size_t offset = reader->buf_start + reader->last_idx;
|
size_t offset = reader->buf_start + reader->last_idx;
|
||||||
ssize_t nbytes = read(reader->pollfd.fd, reader->rbuf + offset, reader->readlen - offset);
|
ssize_t nbytes = read(reader->pollfd.fd, reader->rbuf + offset, reader->readlen - offset);
|
||||||
if (CTLSEQS_UNLIKELY(nbytes == -1)) {
|
if (ctlseqs_unlikely(nbytes == -1)) {
|
||||||
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
if (errno == EAGAIN || errno == EWOULDBLOCK) {
|
||||||
return CTLSEQS_TIMEOUT;
|
return CTLSEQS_TIMEOUT;
|
||||||
}
|
}
|
||||||
return errno == EINTR ? CTLSEQS_INTR : CTLSEQS_ERROR;
|
return errno == EINTR ? CTLSEQS_INTR : CTLSEQS_ERROR;
|
||||||
}
|
}
|
||||||
if (CTLSEQS_UNLIKELY(nbytes == 0)) {
|
if (ctlseqs_unlikely(nbytes == 0)) {
|
||||||
return CTLSEQS_EOF;
|
return CTLSEQS_EOF;
|
||||||
}
|
}
|
||||||
reader->buf_end += nbytes;
|
reader->buf_end += nbytes;
|
||||||
return CTLSEQS_OK;
|
return CTLSEQS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_HOT static enum ctlseqs_state
|
ctlseqs_hot static enum ctlseqs_state
|
||||||
ctlseqs_state_transition(enum ctlseqs_state state, char ch)
|
ctlseqs_state_transition(enum ctlseqs_state state, char ch)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
|
@ -242,12 +242,12 @@ ctlseqs_state_transition(enum ctlseqs_state state, char ch)
|
||||||
case ctlseqs_state_str_end:
|
case ctlseqs_state_str_end:
|
||||||
return ch == '\\' ? ctlseqs_state_done : ctlseqs_state_err;
|
return ch == '\\' ? ctlseqs_state_done : ctlseqs_state_err;
|
||||||
default:
|
default:
|
||||||
CTLSEQS_UNREACHABLE();
|
ctlseqs_unreachable();
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_HOT static char const *
|
ctlseqs_hot static char const *
|
||||||
ctlseqs_fetch_value(char const *seq, int type, union ctlseqs_value **buf)
|
ctlseqs_fetch_value(char const *seq, int type, union ctlseqs_value **buf)
|
||||||
{
|
{
|
||||||
size_t cnt;
|
size_t cnt;
|
||||||
|
@ -286,12 +286,12 @@ ctlseqs_fetch_value(char const *seq, int type, union ctlseqs_value **buf)
|
||||||
case ctlseqs_ph_chrstr:
|
case ctlseqs_ph_chrstr:
|
||||||
CTLSEQS_VALUE_STR(num > 0x7f);
|
CTLSEQS_VALUE_STR(num > 0x7f);
|
||||||
default:
|
default:
|
||||||
CTLSEQS_UNREACHABLE();
|
ctlseqs_unreachable();
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_HOT static ssize_t
|
ctlseqs_hot static ssize_t
|
||||||
ctlseqs_match_pattern(struct ctlseqs_matcher const *matcher, struct ctlseqs_match_args const *args)
|
ctlseqs_match_pattern(struct ctlseqs_matcher const *matcher, struct ctlseqs_match_args const *args)
|
||||||
{
|
{
|
||||||
struct ctlseqs_trie_node const *old_node, empty_node = { 0 };
|
struct ctlseqs_trie_node const *old_node, empty_node = { 0 };
|
||||||
|
@ -340,7 +340,7 @@ ctlseqs_match_pattern(struct ctlseqs_matcher const *matcher, struct ctlseqs_matc
|
||||||
return CTLSEQS_NOMATCH;
|
return CTLSEQS_NOMATCH;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_HOT static inline ssize_t
|
ctlseqs_hot static inline ssize_t
|
||||||
ctlseqs_do_match(struct ctlseqs_matcher const *matcher, struct ctlseqs_match_args *args)
|
ctlseqs_do_match(struct ctlseqs_matcher const *matcher, struct ctlseqs_match_args *args)
|
||||||
{
|
{
|
||||||
ssize_t retval = CTLSEQS_PARTIAL;
|
ssize_t retval = CTLSEQS_PARTIAL;
|
||||||
|
@ -374,7 +374,7 @@ ctlseqs_do_match(struct ctlseqs_matcher const *matcher, struct ctlseqs_match_arg
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_HOT static ssize_t
|
ctlseqs_hot static ssize_t
|
||||||
ctlseqs_reader_match(struct ctlseqs_reader *reader, struct ctlseqs_matcher const *matcher)
|
ctlseqs_reader_match(struct ctlseqs_reader *reader, struct ctlseqs_matcher const *matcher)
|
||||||
{
|
{
|
||||||
struct ctlseqs_match_args args = {
|
struct ctlseqs_match_args args = {
|
||||||
|
@ -388,7 +388,7 @@ ctlseqs_reader_match(struct ctlseqs_reader *reader, struct ctlseqs_matcher const
|
||||||
ssize_t retval = ctlseqs_do_match(matcher, &args);
|
ssize_t retval = ctlseqs_do_match(matcher, &args);
|
||||||
if (retval == CTLSEQS_PARTIAL) {
|
if (retval == CTLSEQS_PARTIAL) {
|
||||||
reader->last_idx = args.result_idx;
|
reader->last_idx = args.result_idx;
|
||||||
if (CTLSEQS_UNLIKELY(reader->buf_start + args.result_idx == reader->readlen)) {
|
if (ctlseqs_unlikely(reader->buf_start + args.result_idx == reader->readlen)) {
|
||||||
// Buffer is full but a match is still pending.
|
// Buffer is full but a match is still pending.
|
||||||
// This may happen when the reader's maxlen option is not large enough to hold a sequence,
|
// This may happen when the reader's maxlen option is not large enough to hold a sequence,
|
||||||
// or when the the sequences are produced faster than consumed.
|
// or when the the sequences are produced faster than consumed.
|
||||||
|
@ -419,7 +419,7 @@ ctlseqs_matcher_init()
|
||||||
{
|
{
|
||||||
struct ctlseqs_trie_node *pool = malloc(sizeof(struct ctlseqs_trie_node) * CTLSEQS_TRIE_NODE_POOL_INIT_SIZE);
|
struct ctlseqs_trie_node *pool = malloc(sizeof(struct ctlseqs_trie_node) * CTLSEQS_TRIE_NODE_POOL_INIT_SIZE);
|
||||||
struct ctlseqs_matcher *matcher = malloc(sizeof(struct ctlseqs_matcher));
|
struct ctlseqs_matcher *matcher = malloc(sizeof(struct ctlseqs_matcher));
|
||||||
if (CTLSEQS_UNLIKELY(pool == NULL || matcher == NULL)) {
|
if (ctlseqs_unlikely(pool == NULL || matcher == NULL)) {
|
||||||
free(pool);
|
free(pool);
|
||||||
free(matcher);
|
free(matcher);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -455,12 +455,12 @@ ctlseqs_matcher_config(struct ctlseqs_matcher *matcher, struct ctlseqs_matcher_o
|
||||||
if (node != NULL) {
|
if (node != NULL) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (CTLSEQS_UNLIKELY(++node_idx >= matcher->pool_size)) {
|
if (ctlseqs_unlikely(++node_idx >= matcher->pool_size)) {
|
||||||
if (CTLSEQS_UNLIKELY(++matcher->pool_idx >= CTLSEQS_TRIE_NODE_POOL_MAX_NUM)) {
|
if (ctlseqs_unlikely(++matcher->pool_idx >= CTLSEQS_TRIE_NODE_POOL_MAX_NUM)) {
|
||||||
return CTLSEQS_NOMEM;
|
return CTLSEQS_NOMEM;
|
||||||
}
|
}
|
||||||
node_pool = malloc(sizeof(struct ctlseqs_trie_node) * matcher->pool_size * 2);
|
node_pool = malloc(sizeof(struct ctlseqs_trie_node) * matcher->pool_size * 2);
|
||||||
if (CTLSEQS_UNLIKELY(node_pool == NULL)) {
|
if (ctlseqs_unlikely(node_pool == NULL)) {
|
||||||
return CTLSEQS_NOMEM;
|
return CTLSEQS_NOMEM;
|
||||||
}
|
}
|
||||||
node_idx = 0;
|
node_idx = 0;
|
||||||
|
@ -487,7 +487,7 @@ ctlseqs_matcher_config(struct ctlseqs_matcher *matcher, struct ctlseqs_matcher_o
|
||||||
return CTLSEQS_OK;
|
return CTLSEQS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_HOT ssize_t
|
ctlseqs_hot ssize_t
|
||||||
ctlseqs_match(struct ctlseqs_matcher const *matcher, char const *str, size_t str_len, union ctlseqs_value *result)
|
ctlseqs_match(struct ctlseqs_matcher const *matcher, char const *str, size_t str_len, union ctlseqs_value *result)
|
||||||
{
|
{
|
||||||
struct ctlseqs_match_args args = {
|
struct ctlseqs_match_args args = {
|
||||||
|
@ -510,7 +510,7 @@ ctlseqs_match(struct ctlseqs_matcher const *matcher, char const *str, size_t str
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_COLD void
|
ctlseqs_cold void
|
||||||
ctlseqs_matcher_free(struct ctlseqs_matcher *matcher)
|
ctlseqs_matcher_free(struct ctlseqs_matcher *matcher)
|
||||||
{
|
{
|
||||||
if (matcher != NULL) {
|
if (matcher != NULL) {
|
||||||
|
@ -525,7 +525,7 @@ struct ctlseqs_reader *
|
||||||
ctlseqs_reader_init()
|
ctlseqs_reader_init()
|
||||||
{
|
{
|
||||||
struct ctlseqs_reader *reader = malloc(sizeof(struct ctlseqs_reader));
|
struct ctlseqs_reader *reader = malloc(sizeof(struct ctlseqs_reader));
|
||||||
if (CTLSEQS_LIKELY(reader != NULL)) {
|
if (ctlseqs_likely(reader != NULL)) {
|
||||||
*reader = (struct ctlseqs_reader) { .pollfd.events = POLLIN };
|
*reader = (struct ctlseqs_reader) { .pollfd.events = POLLIN };
|
||||||
}
|
}
|
||||||
return reader;
|
return reader;
|
||||||
|
@ -557,7 +557,7 @@ ctlseqs_reader_config(struct ctlseqs_reader *reader, struct ctlseqs_reader_optio
|
||||||
return CTLSEQS_OK;
|
return CTLSEQS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_HOT ssize_t
|
ctlseqs_hot ssize_t
|
||||||
ctlseqs_read(struct ctlseqs_reader *reader, struct ctlseqs_matcher const *matcher, int timeout)
|
ctlseqs_read(struct ctlseqs_reader *reader, struct ctlseqs_matcher const *matcher, int timeout)
|
||||||
{
|
{
|
||||||
ssize_t result;
|
ssize_t result;
|
||||||
|
@ -575,7 +575,7 @@ ctlseqs_read(struct ctlseqs_reader *reader, struct ctlseqs_matcher const *matche
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
result = ctlseqs_do_read(reader);
|
result = ctlseqs_do_read(reader);
|
||||||
if (CTLSEQS_UNLIKELY(result < 0)) {
|
if (ctlseqs_unlikely(result < 0)) {
|
||||||
return reader->state == ctlseqs_state_none ? result : CTLSEQS_PARTIAL;
|
return reader->state == ctlseqs_state_none ? result : CTLSEQS_PARTIAL;
|
||||||
}
|
}
|
||||||
return ctlseqs_reader_match(reader, matcher);
|
return ctlseqs_reader_match(reader, matcher);
|
||||||
|
@ -584,7 +584,7 @@ ctlseqs_read(struct ctlseqs_reader *reader, struct ctlseqs_matcher const *matche
|
||||||
void
|
void
|
||||||
ctlseqs_purge(struct ctlseqs_reader *reader, size_t nbytes)
|
ctlseqs_purge(struct ctlseqs_reader *reader, size_t nbytes)
|
||||||
{
|
{
|
||||||
if (CTLSEQS_UNLIKELY(nbytes == 0)) {
|
if (ctlseqs_unlikely(nbytes == 0)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
reader->buf_start += nbytes;
|
reader->buf_start += nbytes;
|
||||||
|
@ -596,7 +596,7 @@ ctlseqs_purge(struct ctlseqs_reader *reader, size_t nbytes)
|
||||||
reader->state = ctlseqs_state_none;
|
reader->state = ctlseqs_state_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
CTLSEQS_COLD void
|
ctlseqs_cold void
|
||||||
ctlseqs_reader_free(struct ctlseqs_reader *reader)
|
ctlseqs_reader_free(struct ctlseqs_reader *reader)
|
||||||
{
|
{
|
||||||
if (reader != NULL) {
|
if (reader != NULL) {
|
||||||
|
|
Loading…
Reference in New Issue