cleanup, docs
This commit is contained in:
@@ -62,56 +62,6 @@ String to_upper(String s)
|
||||
return(result);
|
||||
}
|
||||
|
||||
StringList list_unique(StringList items)
|
||||
{
|
||||
StringList result;
|
||||
std::set<String> seen;
|
||||
for(auto item : items)
|
||||
{
|
||||
if(seen.find(item) != seen.end())
|
||||
continue;
|
||||
seen.insert(item);
|
||||
result.push_back(item);
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
StringList list_sort(StringList items)
|
||||
{
|
||||
std::sort(items.begin(), items.end());
|
||||
return(items);
|
||||
}
|
||||
|
||||
bool list_some(StringList items, std::function<bool (String)> f)
|
||||
{
|
||||
for(auto item : items)
|
||||
{
|
||||
if(f(item))
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
bool list_every(StringList items, std::function<bool (String)> f)
|
||||
{
|
||||
for(auto item : items)
|
||||
{
|
||||
if(!f(item))
|
||||
return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
String list_find(StringList items, std::function<bool (String)> f, String fallback)
|
||||
{
|
||||
for(auto item : items)
|
||||
{
|
||||
if(f(item))
|
||||
return(item);
|
||||
}
|
||||
return(fallback);
|
||||
}
|
||||
|
||||
String substr(String s, s64 start_pos)
|
||||
{
|
||||
s64 len = s.length();
|
||||
|
||||
@@ -94,12 +94,6 @@ inline auto map(std::vector<T> items, F f)
|
||||
return(new_items);
|
||||
}
|
||||
|
||||
StringList list_unique(StringList items);
|
||||
StringList list_sort(StringList items);
|
||||
bool list_some(StringList items, std::function<bool (String)> f);
|
||||
bool list_every(StringList items, std::function<bool (String)> f);
|
||||
String list_find(StringList items, std::function<bool (String)> f, String fallback = "");
|
||||
|
||||
template <class ...Args>
|
||||
inline String first(Args... args)
|
||||
{
|
||||
|
||||
+6
-17
@@ -39,7 +39,6 @@ int uce_host_dir_remove(const char* path, size_t path_len, const char* current,
|
||||
size_t uce_host_file_temp(const char* prefix, size_t prefix_len, const char* current, size_t current_len, char* buf, size_t cap);
|
||||
int uce_host_file_chmod(const char* path, size_t path_len, const char* current, size_t current_len, uint32_t mode);
|
||||
int uce_host_file_symlink(const char* target, size_t target_len, const char* linkpath, size_t linkpath_len, const char* current, size_t current_len);
|
||||
size_t uce_host_file_readlink(const char* path, size_t path_len, const char* current, size_t current_len, char* buf, size_t cap);
|
||||
int uce_host_file_fsync(uint64_t handle);
|
||||
int uce_host_task_spawn(const char* key, size_t key_len, uint64_t callback_id, double interval, uint64_t timeout, int repeat);
|
||||
int uce_host_task_pid(const char* key, size_t key_len);
|
||||
@@ -248,16 +247,6 @@ bool file_symlink(String target, String linkpath)
|
||||
String current = wasm_current_unit_file();
|
||||
return(uce_host_file_symlink(target.data(), target.size(), linkpath.data(), linkpath.size(), current.data(), current.size()) != 0);
|
||||
}
|
||||
String file_readlink(String path)
|
||||
{
|
||||
String current = wasm_current_unit_file();
|
||||
size_t required = uce_host_file_readlink(path.data(), path.size(), current.data(), current.size(), 0, 0);
|
||||
if(required == 0) return("");
|
||||
String out(required, 0);
|
||||
size_t got = uce_host_file_readlink(path.data(), path.size(), current.data(), current.size(), &out[0], required);
|
||||
out.resize(got <= required ? got : 0);
|
||||
return(out);
|
||||
}
|
||||
bool file_fsync(u64 h) { return(uce_host_file_fsync(h) != 0); }
|
||||
|
||||
|
||||
@@ -525,8 +514,8 @@ bool ws_close(String connection_id)
|
||||
context->resources.websocket_dispatch_commands.push(command);
|
||||
return(true);
|
||||
}
|
||||
String backtrace_frames_string(void* const* frames, size_t size, u32 skip_frames) { (void)frames; (void)size; (void)skip_frames; return(capture_backtrace_string(0, 0)); }
|
||||
String capture_backtrace_string(u32 max_frames, u32 skip_frames)
|
||||
String backtrace_get_frames(void* const* frames, size_t size, u32 skip_frames) { (void)frames; (void)size; (void)skip_frames; return(backtrace_capture(0, 0)); }
|
||||
String backtrace_capture(u32 max_frames, u32 skip_frames)
|
||||
{
|
||||
(void)max_frames;
|
||||
(void)skip_frames;
|
||||
@@ -788,7 +777,7 @@ void close_locked_file(int fd)
|
||||
|
||||
}
|
||||
|
||||
String backtrace_frames_string(void* const* frames, size_t size, u32 skip_frames)
|
||||
String backtrace_get_frames(void* const* frames, size_t size, u32 skip_frames)
|
||||
{
|
||||
if(size == 0)
|
||||
return("");
|
||||
@@ -807,14 +796,14 @@ String backtrace_frames_string(void* const* frames, size_t size, u32 skip_frames
|
||||
return(trace);
|
||||
}
|
||||
|
||||
String capture_backtrace_string(u32 max_frames, u32 skip_frames)
|
||||
String backtrace_capture(u32 max_frames, u32 skip_frames)
|
||||
{
|
||||
if(max_frames == 0)
|
||||
return("");
|
||||
|
||||
std::vector<void*> frames(max_frames);
|
||||
size_t size = backtrace(frames.data(), max_frames);
|
||||
return(backtrace_frames_string(frames.data(), size, skip_frames));
|
||||
return(backtrace_get_frames(frames.data(), size, skip_frames));
|
||||
}
|
||||
|
||||
String signal_name(int sig)
|
||||
@@ -1345,7 +1334,7 @@ StringMap memcache_get_multiple(u64 connection, StringList keys)
|
||||
|
||||
void on_segfault(int sig)
|
||||
{
|
||||
String trace = capture_backtrace_string(32, 1);
|
||||
String trace = backtrace_capture(32, 1);
|
||||
String sig_label = signal_name(sig);
|
||||
if(sig_label != "")
|
||||
fprintf(stderr, "SEG FAULT: %d (%s):\n%s", sig, sig_label.c_str(), trace.c_str());
|
||||
|
||||
+2
-3
@@ -71,7 +71,6 @@ bool dir_remove(String path, bool recursive = false);
|
||||
String file_temp(String prefix);
|
||||
bool file_chmod(String path, u32 mode);
|
||||
bool file_symlink(String target, String linkpath);
|
||||
String file_readlink(String path);
|
||||
bool file_fsync(u64 h);
|
||||
template <typename... Ts>
|
||||
inline bool file_append(String file_name, Ts... args)
|
||||
@@ -114,8 +113,8 @@ bool ws_send(String message, bool binary = false, String scope = "");
|
||||
bool ws_send_to(String connection_id, String message, bool binary = false);
|
||||
bool ws_close(String connection_id = "");
|
||||
|
||||
String backtrace_frames_string(void* const* frames, size_t size, u32 skip_frames = 0);
|
||||
String capture_backtrace_string(u32 max_frames = 32, u32 skip_frames = 0);
|
||||
String backtrace_get_frames(void* const* frames, size_t size, u32 skip_frames = 0);
|
||||
String backtrace_capture(u32 max_frames = 32, u32 skip_frames = 0);
|
||||
String signal_name(int sig);
|
||||
|
||||
String memcache_escape_key(String key);
|
||||
|
||||
@@ -88,6 +88,76 @@ struct StringList : std::vector<String> {
|
||||
return(result);
|
||||
}
|
||||
|
||||
StringList unique() const
|
||||
{
|
||||
StringList result;
|
||||
for(const auto& item : *this)
|
||||
{
|
||||
bool seen = false;
|
||||
for(const auto& existing : result)
|
||||
{
|
||||
if(existing == item)
|
||||
{
|
||||
seen = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!seen)
|
||||
result.push_back(item);
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
StringList sort() const
|
||||
{
|
||||
StringList result = *this;
|
||||
for(size_t i = 1; i < result.size(); i++)
|
||||
{
|
||||
String value = result[i];
|
||||
size_t j = i;
|
||||
while(j > 0 && value < result[j - 1])
|
||||
{
|
||||
result[j] = result[j - 1];
|
||||
j--;
|
||||
}
|
||||
result[j] = value;
|
||||
}
|
||||
return(result);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
bool some(F f) const
|
||||
{
|
||||
for(const auto& item : *this)
|
||||
{
|
||||
if(f(item))
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
bool every(F f) const
|
||||
{
|
||||
for(const auto& item : *this)
|
||||
{
|
||||
if(!f(item))
|
||||
return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
|
||||
template<typename F>
|
||||
String find(F f, String fallback = "") const
|
||||
{
|
||||
for(const auto& item : *this)
|
||||
{
|
||||
if(f(item))
|
||||
return(item);
|
||||
}
|
||||
return(fallback);
|
||||
}
|
||||
|
||||
StringList keys() const
|
||||
{
|
||||
StringList result;
|
||||
|
||||
Reference in New Issue
Block a user