Compare commits
12 Commits
69101eb155
...
34f86651f6
| Author | SHA1 | Date | |
|---|---|---|---|
|
34f86651f6
|
|||
|
5dec46df2c
|
|||
|
1b9d89cab3
|
|||
|
a3ad5e7751
|
|||
|
960420df3e
|
|||
|
d71c47f8ce
|
|||
|
425ea57b17
|
|||
|
8822d06091
|
|||
|
9639777814
|
|||
|
929229a1d7
|
|||
|
53bcebc2f0
|
|||
|
b08cf6c29f
|
32
.clang-format
Normal file
32
.clang-format
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# clang-format is fairly limited, and these rules are approximate:
|
||||||
|
# - array initializers can get terribly mangled with clang-format 12.0,
|
||||||
|
# - sometimes it still aligns with space characters,
|
||||||
|
# - struct name NL { NL ... NL } NL name; is unachievable.
|
||||||
|
BasedOnStyle: GNU
|
||||||
|
ColumnLimit: 80
|
||||||
|
IndentWidth: 4
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: ForContinuationAndIndentation
|
||||||
|
BreakBeforeBraces: Allman
|
||||||
|
SpaceAfterCStyleCast: true
|
||||||
|
AlignAfterOpenBracket: DontAlign
|
||||||
|
AlignOperands: DontAlign
|
||||||
|
AlignConsecutiveMacros: Consecutive
|
||||||
|
AllowAllArgumentsOnNextLine: false
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: false
|
||||||
|
IndentGotoLabels: false
|
||||||
|
|
||||||
|
# IncludeCategories has some potential, but it may also break the build.
|
||||||
|
# Note that the documentation says the value should be "Never".
|
||||||
|
SortIncludes: false
|
||||||
|
|
||||||
|
# This is a compromise, it generally works out aesthetically better.
|
||||||
|
BinPackArguments: false
|
||||||
|
|
||||||
|
# Unfortunately, this can't be told to align to column 40 or so.
|
||||||
|
SpacesBeforeTrailingComments: 2
|
||||||
|
|
||||||
|
# liberty-specific macro body wrappers.
|
||||||
|
MacroBlockBegin: "BLOCK_START"
|
||||||
|
MacroBlockEnd: "BLOCK_END"
|
||||||
|
ForEachMacros: ["LIST_FOR_EACH"]
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -7,3 +7,5 @@
|
|||||||
/liberty.files
|
/liberty.files
|
||||||
/liberty.creator*
|
/liberty.creator*
|
||||||
/liberty.includes
|
/liberty.includes
|
||||||
|
/liberty.cflags
|
||||||
|
/liberty.cxxflags
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ cmake_minimum_required (VERSION 2.8.5)
|
|||||||
# Moar warnings
|
# Moar warnings
|
||||||
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
|
if ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
|
||||||
# -Wunused-function is pretty annoying here, as everything is static
|
# -Wunused-function is pretty annoying here, as everything is static
|
||||||
set (wdisabled "-Wno-unused-function -Wno-implicit-fallthrough")
|
set (wdisabled "-Wno-unused-function")
|
||||||
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra ${wdisabled}")
|
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c99 -Wall -Wextra ${wdisabled}")
|
||||||
endif ("${CMAKE_C_COMPILER_ID}" MATCHES "GNU" OR CMAKE_COMPILER_IS_GNUCC)
|
endif ()
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
set (CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
|
||||||
@@ -16,11 +16,9 @@ find_package (PkgConfig REQUIRED)
|
|||||||
pkg_check_modules (libssl REQUIRED libssl libcrypto)
|
pkg_check_modules (libssl REQUIRED libssl libcrypto)
|
||||||
|
|
||||||
if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
|
if ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
|
||||||
include_directories (/usr/local/include)
|
|
||||||
link_directories (/usr/local/lib)
|
|
||||||
# Our POSIX version macros make these undefined
|
# Our POSIX version macros make these undefined
|
||||||
add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
|
add_definitions (-D__BSD_VISIBLE=1 -D_BSD_SOURCE=1)
|
||||||
endif ("${CMAKE_SYSTEM_NAME}" MATCHES "BSD")
|
endif ()
|
||||||
|
|
||||||
set (common_libraries ${libssl_LIBRARIES})
|
set (common_libraries ${libssl_LIBRARIES})
|
||||||
include_directories (${libssl_INCLUDE_DIRS})
|
include_directories (${libssl_INCLUDE_DIRS})
|
||||||
@@ -32,8 +30,8 @@ foreach (extra iconv rt)
|
|||||||
find_library (extra_lib_${extra} ${extra})
|
find_library (extra_lib_${extra} ${extra})
|
||||||
if (extra_lib_${extra})
|
if (extra_lib_${extra})
|
||||||
list (APPEND common_libraries ${extra})
|
list (APPEND common_libraries ${extra})
|
||||||
endif (extra_lib_${extra})
|
endif ()
|
||||||
endforeach (extra)
|
endforeach ()
|
||||||
|
|
||||||
# Build some unit tests
|
# Build some unit tests
|
||||||
include_directories (${PROJECT_SOURCE_DIR})
|
include_directories (${PROJECT_SOURCE_DIR})
|
||||||
@@ -43,4 +41,4 @@ foreach (name liberty proto)
|
|||||||
add_threads (test-${name})
|
add_threads (test-${name})
|
||||||
target_link_libraries (test-${name} ${common_libraries})
|
target_link_libraries (test-${name} ${common_libraries})
|
||||||
add_test (NAME test-${name} COMMAND test-${name})
|
add_test (NAME test-${name} COMMAND test-${name})
|
||||||
endforeach (name)
|
endforeach ()
|
||||||
|
|||||||
@@ -148,7 +148,7 @@ irc_free_message (struct irc_message *msg)
|
|||||||
|
|
||||||
static void
|
static void
|
||||||
irc_process_buffer (struct str *buf,
|
irc_process_buffer (struct str *buf,
|
||||||
void (*callback)(const struct irc_message *, const char *, void *),
|
void (*callback) (const struct irc_message *, const char *, void *),
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
char *start = buf->str, *end = start + buf->len;
|
char *start = buf->str, *end = start + buf->len;
|
||||||
|
|||||||
31
liberty.c
31
liberty.c
@@ -1749,10 +1749,9 @@ poller_run (struct poller *self)
|
|||||||
self->revents_len = 0;
|
self->revents_len = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined (BSD)
|
// Sort of similar to the epoll version. Let's hope Darwin isn't broken,
|
||||||
|
// that'd mean reimplementing this in terms of select() just because of Crapple.
|
||||||
// Mac OS X's kqueue is fatally broken, or so I've been told; leaving it out.
|
#elif defined (BSD) || defined (__APPLE__)
|
||||||
// Otherwise this is sort of similar to the epoll version.
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/event.h>
|
#include <sys/event.h>
|
||||||
@@ -2748,7 +2747,8 @@ utf8_decode (const char **s, size_t len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// In the middle of a character
|
// In the middle of a character
|
||||||
if (sequence_len == 1)
|
// or an overlong sequence (subset, possibly MUTF-8, not supported)
|
||||||
|
if (sequence_len == 1 || *p == 0xC0 || *p == 0xC1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// Check the rest of the sequence
|
// Check the rest of the sequence
|
||||||
@@ -2765,6 +2765,13 @@ utf8_decode (const char **s, size_t len)
|
|||||||
return cp;
|
return cp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline bool
|
||||||
|
utf8_validate_cp (int32_t cp)
|
||||||
|
{
|
||||||
|
// RFC 3629, CESU-8 not allowed
|
||||||
|
return cp >= 0 && cp <= 0x10FFFF && (cp < 0xD800 || cp > 0xDFFF);
|
||||||
|
}
|
||||||
|
|
||||||
/// Very rough UTF-8 validation, just makes sure codepoints can be iterated
|
/// Very rough UTF-8 validation, just makes sure codepoints can be iterated
|
||||||
static bool
|
static bool
|
||||||
utf8_validate (const char *s, size_t len)
|
utf8_validate (const char *s, size_t len)
|
||||||
@@ -2772,7 +2779,7 @@ utf8_validate (const char *s, size_t len)
|
|||||||
const char *end = s + len;
|
const char *end = s + len;
|
||||||
int32_t codepoint;
|
int32_t codepoint;
|
||||||
while ((codepoint = utf8_decode (&s, end - s)) >= 0
|
while ((codepoint = utf8_decode (&s, end - s)) >= 0
|
||||||
&& codepoint <= 0x10FFFF /* TODO: better validations */)
|
&& utf8_validate_cp (codepoint))
|
||||||
;
|
;
|
||||||
return s == end;
|
return s == end;
|
||||||
}
|
}
|
||||||
@@ -3239,7 +3246,7 @@ get_xdg_config_dirs (struct strv *out)
|
|||||||
str_free (&config_home);
|
str_free (&config_home);
|
||||||
|
|
||||||
const char *xdg_config_dirs;
|
const char *xdg_config_dirs;
|
||||||
if (!(xdg_config_dirs = getenv ("XDG_CONFIG_DIRS")))
|
if (!(xdg_config_dirs = getenv ("XDG_CONFIG_DIRS")) || !*xdg_config_dirs)
|
||||||
xdg_config_dirs = "/etc/xdg";
|
xdg_config_dirs = "/etc/xdg";
|
||||||
cstr_split (xdg_config_dirs, ":", true, out);
|
cstr_split (xdg_config_dirs, ":", true, out);
|
||||||
}
|
}
|
||||||
@@ -3264,7 +3271,7 @@ get_xdg_data_dirs (struct strv *out)
|
|||||||
str_free (&data_home);
|
str_free (&data_home);
|
||||||
|
|
||||||
const char *xdg_data_dirs;
|
const char *xdg_data_dirs;
|
||||||
if (!(xdg_data_dirs = getenv ("XDG_DATA_DIRS")))
|
if (!(xdg_data_dirs = getenv ("XDG_DATA_DIRS")) || !*xdg_data_dirs)
|
||||||
xdg_data_dirs = "/usr/local/share/:/usr/share/";
|
xdg_data_dirs = "/usr/local/share/:/usr/share/";
|
||||||
cstr_split (xdg_data_dirs, ":", true, out);
|
cstr_split (xdg_data_dirs, ":", true, out);
|
||||||
}
|
}
|
||||||
@@ -4409,7 +4416,7 @@ socket_io_try_write (int socket_fd, struct str *wb)
|
|||||||
// char = [\0-\177] # or any Unicode codepoint in the UTF-8 encoding
|
// char = [\0-\177] # or any Unicode codepoint in the UTF-8 encoding
|
||||||
// escape = [\\"abfnrtv] / [xX][0-9A-Fa-f][0-9A-Fa-f]? / [0-7][0-7]?[0-7]?
|
// escape = [\\"abfnrtv] / [xX][0-9A-Fa-f][0-9A-Fa-f]? / [0-7][0-7]?[0-7]?
|
||||||
//
|
//
|
||||||
// integer = lws '-'? [0-9]+ # whatever strtoll() accepts on your system
|
// integer = lws [-+]? [0-9]+ # whatever strtoll() accepts on your system
|
||||||
// null = lws 'null'
|
// null = lws 'null'
|
||||||
// boolean = lws 'yes' / lws 'YES' / lws 'no' / lws 'NO'
|
// boolean = lws 'yes' / lws 'YES' / lws 'no' / lws 'NO'
|
||||||
// / lws 'on' / lws 'ON' / lws 'off' / lws 'OFF'
|
// / lws 'on' / lws 'ON' / lws 'off' / lws 'OFF'
|
||||||
@@ -4705,8 +4712,10 @@ config_item_write_string (struct str *output, const struct str *s)
|
|||||||
else if (c == '\t') str_append (output, "\\t");
|
else if (c == '\t') str_append (output, "\\t");
|
||||||
else if (c == '\\') str_append (output, "\\\\");
|
else if (c == '\\') str_append (output, "\\\\");
|
||||||
else if (c == '"') str_append (output, "\\\"");
|
else if (c == '"') str_append (output, "\\\"");
|
||||||
else if (c < 32) str_append_printf (output, "\\x%02x", c);
|
else if (iscntrl_ascii (c))
|
||||||
else str_append_c (output, c);
|
str_append_printf (output, "\\x%02x", c);
|
||||||
|
else
|
||||||
|
str_append_c (output, c);
|
||||||
}
|
}
|
||||||
str_append_c (output, '"');
|
str_append_c (output, '"');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,4 +82,3 @@ siphash (const unsigned char key[16], const unsigned char *m, size_t len)
|
|||||||
|
|
||||||
return v0 ^ v1 ^ v2 ^ v3;
|
return v0 ^ v1 ^ v2 ^ v3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -331,10 +331,14 @@ test_utf8 (void)
|
|||||||
soft_assert (utf8_decode (&partial, 1) == -2);
|
soft_assert (utf8_decode (&partial, 1) == -2);
|
||||||
soft_assert (utf8_decode (&empty, 0) == -1);
|
soft_assert (utf8_decode (&empty, 0) == -1);
|
||||||
|
|
||||||
const char valid [] = "2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm";
|
const char valid_1[] = "2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm";
|
||||||
const char invalid[] = "\xf0\x90\x28\xbc";
|
const char valid_2[] = "\xf0\x93\x82\xb9";
|
||||||
soft_assert ( utf8_validate (valid, sizeof valid));
|
const char invalid_1[] = "\xf0\x90\x28\xbc";
|
||||||
soft_assert (!utf8_validate (invalid, sizeof invalid));
|
const char invalid_2[] = "\xc0\x80";
|
||||||
|
soft_assert ( utf8_validate (valid_1, sizeof valid_1));
|
||||||
|
soft_assert ( utf8_validate (valid_2, sizeof valid_2));
|
||||||
|
soft_assert (!utf8_validate (invalid_1, sizeof invalid_1));
|
||||||
|
soft_assert (!utf8_validate (invalid_2, sizeof invalid_2));
|
||||||
|
|
||||||
struct utf8_iter iter = utf8_iter_make ("fóọ");
|
struct utf8_iter iter = utf8_iter_make ("fóọ");
|
||||||
size_t ch_len;
|
size_t ch_len;
|
||||||
|
|||||||
Reference in New Issue
Block a user