Skip to content

Commit

Permalink
}
Browse files Browse the repository at this point in the history
  • Loading branch information
andarut committed Aug 28, 2024
1 parent da0b040 commit cc549fb
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 88 deletions.
20 changes: 16 additions & 4 deletions .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,24 @@ env:

jobs:
clang-format:
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
- name: Install clang-format
run: wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add - && \
apt-get update && apt-get install clang-format-18
- name: Add LLVM GPG key
run: |
sudo wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor -o /etc/apt/trusted.gpg.d/llvm.gpg
shell: bash

- name: Add LLVM repository
run: |
echo "deb [signed-by=/etc/apt/trusted.gpg.d/llvm.gpg] http://apt.llvm.org/jammy/ llvm-toolchain-jammy-17 main" | sudo tee /etc/apt/sources.list.d/llvm.list
shell: bash

- name: Update and Install LLVM
run: |
sudo apt update
sudo apt install -y clang-format-18
shell: bash
- name: debug
run: which clang-format-18
- name: Run clang-format
Expand Down
9 changes: 5 additions & 4 deletions common/dl-utils-lite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <time.h>
#include <unistd.h>
#include <dirent.h>
#include <tuple>

#include "common/server/crash-dump.h"
#include "common/stats/provider.h"
Expand Down Expand Up @@ -49,9 +50,9 @@ double dl_time() {
}

void dl_print_backtrace(void **trace, int trace_size) {
write (2, "\n------- Stack Backtrace -------\n", 33);
std::ignore = write (2, "\n------- Stack Backtrace -------\n", 33);
backtrace_symbols_fd (trace, trace_size, 2);
write (2, "-------------------------------\n", 32);
std::ignore = write (2, "-------------------------------\n", 32);
}

void dl_print_backtrace() {
Expand All @@ -71,7 +72,7 @@ void dl_print_backtrace_gdb() {
name_buf[res] = 0;
int child_pid = fork();
if (child_pid < 0) {
write (2, "Can't fork() to run gdb\n", 24);
std::ignore = write (2, "Can't fork() to run gdb\n", 24);
_exit (0);
}
if (!child_pid) {
Expand All @@ -83,7 +84,7 @@ void dl_print_backtrace_gdb() {
waitpid (child_pid, nullptr, 0);
}
} else {
write (2, "can't get name of executable file to pass to gdb\n", 49);
std::ignore = write (2, "can't get name of executable file to pass to gdb\n", 49);
}
}

Expand Down
17 changes: 5 additions & 12 deletions runtime-light/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ struct PlatformCtx {
* `stream_d` will be assigned `0`.
* however `stream_d=0` itself is not an error marker
*/
enum OpenStreamResult (*open)(size_t name_len, const char *name,
uint64_t *stream_d);
enum OpenStreamResult (*open)(size_t name_len, const char *name, uint64_t *stream_d);
/*
* If the write or read status is `Blocked` - then the platform ensures that
* the component receives this `stream_d` via `take_update` when the status is
Expand All @@ -118,8 +117,7 @@ struct PlatformCtx {
* `new_status` will be assigned as
* `{.read_status = 0, .write_status = 0, .please_shutdown = 0}`.
*/
enum GetStatusResult (*get_stream_status)(uint64_t stream_d,
struct StreamStatus *new_status);
enum GetStatusResult (*get_stream_status)(uint64_t stream_d, struct StreamStatus *new_status);
/*
* Return processed bytes (written or read).
* Guaranteed to return `0` if the stream is `Closed`, `Blocked` or
Expand Down Expand Up @@ -190,8 +188,7 @@ struct PlatformCtx {
*
* `deadline` will be assigned `0` if `timer_d` invalid
*/
enum TimerStatus (*get_timer_status)(uint64_t timer_d,
struct TimePoint *deadline);
enum TimerStatus (*get_timer_status)(uint64_t timer_d, struct TimePoint *deadline);
/*
* Return: `bool`.
* If `True`: the update was successfully received.
Expand Down Expand Up @@ -262,15 +259,11 @@ struct ImageInfo {
};

// Every image should provide these symbols
enum PollStatus vk_k2_poll(const struct ImageState *image_state,
const struct PlatformCtx *pt_ctx,
struct ComponentState *component_ctx);
enum PollStatus vk_k2_poll(const struct ImageState *image_state, const struct PlatformCtx *pt_ctx, struct ComponentState *component_ctx);

// platform_ctx without IO stuff (nullptr instead io-functions)
// for now, returning nullptr will indicate error
struct ComponentState *
vk_k2_create_component_state(const struct ImageState *image_state,
const struct PlatformCtx *pt_ctx);
struct ComponentState *vk_k2_create_component_state(const struct ImageState *image_state, const struct PlatformCtx *pt_ctx);

// platform_ctx without IO stuff (nullptr instead io-functions)
// for now, returning nullptr will indicate error
Expand Down
2 changes: 1 addition & 1 deletion runtime-light/stdlib/rpc/rpc-buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class RpcBuffer : private vk::not_copyable {
}

void reset(size_t pos) noexcept {
php_assert(pos >= 0 && pos <= size());
php_assert(pos > 0 && pos <= size());
m_pos = pos;
m_remaining = size() - m_pos;
}
Expand Down
7 changes: 0 additions & 7 deletions runtime-light/utils/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
#pragma once

#include <concepts>
#include <cstddef>
#include <functional>

template<typename T>
concept standard_layout = std::is_standard_layout_v<T>;

template<typename T>
concept hashable = requires(T a) {
{ std::hash<T>{}(a) } -> std::convertible_to<size_t>;
};
66 changes: 28 additions & 38 deletions runtime-light/utils/json-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
#include "common/algorithms/find.h"
#include "runtime-light/component/component.h"
//
//#include "runtime/string_functions.h"
// #include "runtime/string_functions.h"

// note: json-functions.cpp is used for non-typed json implementation: for json_encode() and json_decode()
// for classes, e.g. `JsonEncoder::encode(new A)`, see json-writer.cpp and from/to visitors
namespace {

void json_append_one_char(unsigned int c, string_buffer & sb) noexcept {
void json_append_one_char(unsigned int c, string_buffer &sb) noexcept {
sb.append_char('\\');
sb.append_char('u');
sb.append_char("0123456789abcdef"[c >> 12]);
Expand All @@ -22,7 +22,7 @@ void json_append_one_char(unsigned int c, string_buffer & sb) noexcept {
sb.append_char("0123456789abcdef"[c & 15]);
}

bool json_append_char(unsigned int c, string_buffer & sb) noexcept {
bool json_append_char(unsigned int c, string_buffer &sb) noexcept {
if (c < 0x10000) {
if (0xD7FF < c && c < 0xE000) {
return false;
Expand All @@ -39,8 +39,7 @@ bool json_append_char(unsigned int c, string_buffer & sb) noexcept {
return false;
}


bool do_json_encode_string_php(const JsonPath &json_path, const char *s, int len, int64_t options, string_buffer & sb) noexcept {
bool do_json_encode_string_php(const JsonPath &json_path, const char *s, int len, int64_t options, string_buffer &sb) noexcept {
int begin_pos = sb.size();
if (options & JSON_UNESCAPED_UNICODE) {
sb.reserve(2 * len + 2);
Expand Down Expand Up @@ -178,7 +177,7 @@ string JsonPath::to_string() const {
}
unsigned num_parts = std::clamp(depth, 0U, static_cast<unsigned>(arr.size()));
string result;
result.reserve_at_least((num_parts+1) * 8);
result.reserve_at_least((num_parts + 1) * 8);
result.push_back('/');
for (unsigned i = 0; i < num_parts; i++) {
const char *key = arr[i];
Expand All @@ -200,13 +199,12 @@ string JsonPath::to_string() const {

namespace impl_ {

JsonEncoder::JsonEncoder(int64_t options, bool simple_encode, const char *json_obj_magic_key) noexcept:
options_(options),
simple_encode_(simple_encode),
json_obj_magic_key_(json_obj_magic_key) {
}
JsonEncoder::JsonEncoder(int64_t options, bool simple_encode, const char *json_obj_magic_key) noexcept
: options_(options)
, simple_encode_(simple_encode)
, json_obj_magic_key_(json_obj_magic_key) {}

bool JsonEncoder::encode(bool b, string_buffer & sb) noexcept {
bool JsonEncoder::encode(bool b, string_buffer &sb) noexcept {
if (b) {
sb.append("true", 4);
} else {
Expand All @@ -215,17 +213,17 @@ bool JsonEncoder::encode(bool b, string_buffer & sb) noexcept {
return true;
}

bool JsonEncoder::encode_null(string_buffer & sb) const noexcept {
bool JsonEncoder::encode_null(string_buffer &sb) const noexcept {
sb.append("null", 4);
return true;
}

bool JsonEncoder::encode(int64_t i, string_buffer & sb) noexcept {
bool JsonEncoder::encode(int64_t i, string_buffer &sb) noexcept {
sb << i;
return true;
}

bool JsonEncoder::encode(double d, string_buffer & sb) noexcept {
bool JsonEncoder::encode(double d, string_buffer &sb) noexcept {
if (vk::any_of_equal(std::fpclassify(d), FP_INFINITE, FP_NAN)) {
php_warning("%s: strange double %lf in function json_encode", json_path_.to_string().c_str(), d);
if (options_ & JSON_PARTIAL_OUTPUT_ON_ERROR) {
Expand All @@ -234,17 +232,17 @@ bool JsonEncoder::encode(double d, string_buffer & sb) noexcept {
return false;
}
} else {
//todo:k2 implement f$number_format
sb << /*(simple_encode_ ? f$number_format(d, 6, string{"."}, string{}) : */ string{d}/*)*/;
// todo:k2 implement f$number_format
sb << /*(simple_encode_ ? f$number_format(d, 6, string{"."}, string{}) : */ string{d} /*)*/;
}
return true;
}

bool JsonEncoder::encode(const string &s, string_buffer & sb) noexcept {
bool JsonEncoder::encode(const string &s, string_buffer &sb) noexcept {
return do_json_encode_string_php(json_path_, s.c_str(), s.size(), options_, sb);
}

bool JsonEncoder::encode(const mixed &v, string_buffer & sb) noexcept {
bool JsonEncoder::encode(const mixed &v, string_buffer &sb) noexcept {
switch (v.get_type()) {
case mixed::type::NUL:
return encode_null(sb);
Expand Down Expand Up @@ -280,29 +278,22 @@ bool do_json_decode(const char *s, int s_len, int &i, mixed &v, const char *json
json_skip_blanks(s, i);
switch (s[i]) {
case 'n':
if (s[i + 1] == 'u' &&
s[i + 2] == 'l' &&
s[i + 3] == 'l') {
if (s[i + 1] == 'u' && s[i + 2] == 'l' && s[i + 3] == 'l') {
i += 4;
return true;
}
break;
case 't':
if (s[i + 1] == 'r' &&
s[i + 2] == 'u' &&
s[i + 3] == 'e') {
if (s[i + 1] == 'r' && s[i + 2] == 'u' && s[i + 3] == 'e') {
i += 4;
new(&v) mixed(true);
new (&v) mixed(true);
return true;
}
break;
case 'f':
if (s[i + 1] == 'a' &&
s[i + 2] == 'l' &&
s[i + 3] == 's' &&
s[i + 4] == 'e') {
if (s[i + 1] == 'a' && s[i + 2] == 'l' && s[i + 3] == 's' && s[i + 4] == 'e') {
i += 5;
new(&v) mixed(false);
new (&v) mixed(false);
return true;
}
break;
Expand Down Expand Up @@ -364,8 +355,7 @@ bool do_json_decode(const char *s, int s_len, int &i, mixed &v, const char *json
}

if (0xD7FF < num && num < 0xE000) {
if (s[i + 1] == '\\' && s[i + 2] == 'u' &&
isxdigit(s[i + 3]) && isxdigit(s[i + 4]) && isxdigit(s[i + 5]) && isxdigit(s[i + 6])) {
if (s[i + 1] == '\\' && s[i + 2] == 'u' && isxdigit(s[i + 3]) && isxdigit(s[i + 4]) && isxdigit(s[i + 5]) && isxdigit(s[i + 6])) {
i += 2;
int u = 0;
for (int t = 0; t < 4; t++) {
Expand Down Expand Up @@ -419,7 +409,7 @@ bool do_json_decode(const char *s, int s_len, int &i, mixed &v, const char *json
}
value.shrink(l);

new(&v) mixed(value);
new (&v) mixed(value);
i++;
return true;
}
Expand All @@ -446,7 +436,7 @@ bool do_json_decode(const char *s, int s_len, int &i, mixed &v, const char *json
i++;
}

new(&v) mixed(res);
new (&v) mixed(res);
return true;
}
case '{': {
Expand Down Expand Up @@ -483,7 +473,7 @@ bool do_json_decode(const char *s, int s_len, int &i, mixed &v, const char *json
res[string{json_obj_magic_key}] = true;
}

new(&v) mixed(res);
new (&v) mixed(res);
return true;
}
default: {
Expand All @@ -495,15 +485,15 @@ bool do_json_decode(const char *s, int s_len, int &i, mixed &v, const char *json
int64_t intval = 0;
if (php_try_to_int(s + i, j - i, &intval)) {
i = j;
new(&v) mixed(intval);
new (&v) mixed(intval);
return true;
}

char *end_ptr;
double floatval = strtod(s + i, &end_ptr);
if (end_ptr == s + j) {
i = j;
new(&v) mixed(floatval);
new (&v) mixed(floatval);
return true;
}
}
Expand Down
Loading

0 comments on commit cc549fb

Please sign in to comment.