Skip to content

Commit

Permalink
fix: fix diagnostics and typos found clangd and lua LSPs
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Dec 11, 2024
1 parent b7b4427 commit bebc79f
Show file tree
Hide file tree
Showing 25 changed files with 83 additions and 101 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Checks: >-
-cppcoreguidelines-avoid-c-arrays,
google*,
-google-build-using-namespace,
-google-objc-*,
hicpp*,
-hicpp-avoid-c-arrays,
-hicpp-no-array-decay,
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ doc/api.md
doc/html/
doc/xml/

.clangd
.venv
.vscode
.ycm_extra_conf.py
Expand Down
11 changes: 11 additions & 0 deletions .typos.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[files]
extend-exclude = ["third-party/*", "*.S"]

[default.extend-words]
fle = "fle"
sie = "sie"
stip = "stip"
stap = "stap"
wronly = "wronly"
optin = "optin"
sxl = "sxl"
2 changes: 1 addition & 1 deletion src/base64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static size_t b64decode(uint8_t c, uint8_t *input, size_t size, std::ostringstre
decoded[1] = static_cast<uint8_t>(value & 0xff);
value >>= 8;
decoded[0] = static_cast<uint8_t>(value);
// take care of paddding
// take care of padding
if (input[2] == '=') {
valid = 1;
} else if (input[3] == '=') {
Expand Down
17 changes: 9 additions & 8 deletions src/cartesi-machine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ local flash_start = {}
local flash_length = {}
local unreproducible = false
local virtio = {}
local virtio_net_user_config = false
local virtio_net_user_config
local virtio_volume_count = 0
local has_virtio_console = false
local has_network = false
Expand Down Expand Up @@ -1775,11 +1775,12 @@ echo "

if load_config then
local env = {}
local ok, ret = loadfile(load_config, "t", env)
if ok then
local chunk = ok
ok, ret = pcall(chunk)
local chunk, err = loadfile(load_config, "t", env)
if not chunk then
stderr("Failed to load machine config (%s):\n", load_config)
error(err)
end
local ok, ret = pcall(chunk)
if not ok then
stderr("Failed to load machine config (%s):\n", load_config)
error(ret)
Expand Down Expand Up @@ -2083,7 +2084,7 @@ while math.ult(machine:read_mcycle(), max_mcycle) do
elseif cmio_advance and cmio_advance.next_input_index < cmio_advance.input_index_end then
-- previous reason was an accept
if reason == cartesi.CMIO_YIELD_MANUAL_REASON_RX_ACCEPTED then
do_commit(machine)
do_commit()
-- save only if we have already run an input and have just accepted it
if cmio_advance.next_input_index > cmio_advance.input_index_begin then
assert(#data == 32, "expected root hash in tx buffer")
Expand All @@ -2109,7 +2110,7 @@ while math.ult(machine:read_mcycle(), max_mcycle) do
if reason == cartesi.CMIO_YIELD_MANUAL_REASON_RX_ACCEPTED then
assert(#data == 32, "expected root hash in tx buffer")
save_cmio_output_hashes_root_hash(cmio_advance, data)
do_commit(machine)
do_commit()
elseif reason == cartesi.CMIO_YIELD_MANUAL_REASON_RX_REJECTED then
do_rollback(machine)
end
Expand Down Expand Up @@ -2159,7 +2160,7 @@ while math.ult(machine:read_mcycle(), max_mcycle) do
end
if machine:read_iflags_Y() then
-- commit any pending snapshot
do_commit(machine)
do_commit()
break
end
if machine:read_mcycle() == next_hash_mcycle then
Expand Down
10 changes: 4 additions & 6 deletions src/cartesi/gdbstub.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function GDBStub:_recv()
sum = sum + c:byte()
escaped_data[#escaped_data + 1] = c
end
escaped_data = table.concat(escaped_data)
local escaped_data_str = table.concat(escaped_data)
-- validate checksum
local checksum = assert(self.conn:receive(2))
if sum % 256 ~= hex2int(checksum) then
Expand All @@ -104,7 +104,7 @@ function GDBStub:_recv()
assert(self.conn:send("+")) -- send acknowledge packet
end
-- escape packet data
local data = escaped_data:gsub("}(.)", xorchr)
local data = escaped_data_str:gsub("}(.)", xorchr)
if GDBSTUB_DEBUG_PROTOCOL then stderr("Packet recv: %s", data) end
return data
end
Expand Down Expand Up @@ -174,8 +174,7 @@ function GDBStub:_handle_query(_, query)
if supported_features[feature] then table.insert(res, feature .. "+") end
end
-- reply with features we support
res = table.concat(res, ";")
return self:_send(res)
return self:_send(table.concat(res, ";"))
elseif query == "qTStatus" then -- GDB is asking whether a trace experiment is currently running
return self:_send_unsupported()
elseif query == "qfThreadInfo" or query == "qC" or query:find("^qL") then -- GDB is asking thread info
Expand Down Expand Up @@ -341,8 +340,7 @@ function GDBStub:_handle_read_all_regs()
end
-- read program counter
table.insert(res, reg2hex(self.machine:read_reg("pc")))
res = table.concat(res)
return self:_send(res)
return self:_send(table.concat(res))
end

-- GDB is writing all machine registers.
Expand Down
4 changes: 2 additions & 2 deletions src/cartesi/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ local function accessdatastring(data, data_hash, data_log2_size, address)
if data_size < #data then
-- access data is smaller than the tree leaf size
-- the logged data is the entire tree leaf, but we only need the data that was accessed
local leaf_aligned_addrss = address & ~((1 << cartesi.TREE_LOG2_WORD_SIZE) - 1)
local word_offset = address - leaf_aligned_addrss
local leaf_aligned_address = address & ~((1 << cartesi.TREE_LOG2_WORD_SIZE) - 1)
local word_offset = address - leaf_aligned_address
data = data:sub(word_offset + 1, word_offset + data_size)
end
data = string.unpack("<I8", data)
Expand Down
2 changes: 1 addition & 1 deletion src/complete-merkle-tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ void complete_merkle_tree::bubble_up() {
// Next level needs half as many (rounded up) as previous
next.resize((prev.size() + 1) / 2);
assert(first_entry <= next.size());
// Last safe entry has two non-pristine leafs
// Last safe entry has two non-pristine leaves
auto last_safe_entry = prev.size() / 2;
// Do all entries for which we have two non-pristine children
for (; first_entry < last_safe_entry; ++first_entry) {
Expand Down
54 changes: 11 additions & 43 deletions src/jsonrpc-discover.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "Remote Cartesi Machine",
"version": "0.5.0",
"description": "API for controling a remote Cartesi Machine server",
"description": "API for controlling a remote Cartesi Machine server",
"license": {
"name": "MIT"
}
Expand Down Expand Up @@ -865,11 +865,7 @@
"SemanticVersion": {
"title": "SemanticVersion",
"type": "object",
"required": [
"major",
"minor",
"patch"
],
"required": ["major", "minor", "patch"],
"properties": {
"major": {
"$ref": "#/components/schemas/UnsignedInteger"
Expand Down Expand Up @@ -1232,9 +1228,7 @@
"type": "string"
}
},
"required": [
"length"
]
"required": ["length"]
},
"DTBConfig": {
"title": "DTBConfig",
Expand Down Expand Up @@ -1315,9 +1309,7 @@
"VirtIODeviceConfig": {
"title": "VirtIODeviceConfig",
"type": "object",
"required": [
"type"
],
"required": ["type"],
"properties": {
"type": {
"type": "string"
Expand Down Expand Up @@ -1600,10 +1592,7 @@
},
"UarchInterpreterBreakReason": {
"title": "UarchInterpreterBreakReason",
"enum": [
"reached_target_cycle",
"uarch_halted"
]
"enum": ["reached_target_cycle", "uarch_halted"]
},
"Base64String": {
"title": "Base64String",
Expand Down Expand Up @@ -1640,10 +1629,7 @@
},
"BracketType": {
"title": "BracketType",
"enum": [
"begin",
"end"
]
"enum": ["begin", "end"]
},
"Bracket": {
"title": "Bracket",
Expand All @@ -1659,11 +1645,7 @@
"type": "string"
}
},
"required": [
"type",
"where",
"text"
]
"required": ["type", "where", "text"]
},
"Proof": {
"title": "Proof",
Expand Down Expand Up @@ -1726,12 +1708,7 @@
"$ref": "#/components/schemas/Base64HashArray"
}
},
"required": [
"type",
"address",
"log2_size",
"read_hash"
]
"required": ["type", "address", "log2_size", "read_hash"]
},
"AccessArray": {
"title": "AccessArray",
Expand All @@ -1742,10 +1719,7 @@
},
"AccessType": {
"title": "AccessType",
"enum": [
"read",
"write"
]
"enum": ["read", "write"]
},
"AccessLogType": {
"title": "AccessLogType",
Expand All @@ -1758,10 +1732,7 @@
"type": "boolean"
}
},
"required": [
"has_annotations",
"has_large_data"
]
"required": ["has_annotations", "has_large_data"]
},
"AccessLog": {
"title": "AccessLog",
Expand All @@ -1780,10 +1751,7 @@
"$ref": "#/components/schemas/BracketArray"
}
},
"required": [
"log_type",
"accesses"
]
"required": ["log_type", "accesses"]
},
"REG": {
"title": "REG",
Expand Down
2 changes: 1 addition & 1 deletion src/jsonrpc-machine-c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ CM_API cm_error cm_jsonrpc_connect_server(const char *address, cm_machine **new_
/// \param address If function succeeds, receives address the forked server bound to,
/// guaranteed to remain valid only until the next CM_API function is called again on the same thread.
/// Set to NULL on failure.
/// \param pid If function suceeds, receives the forked child process id (can be NULL). Set to 0 on failure.
/// \param pid If function succeeds, receives the forked child process id (can be NULL). Set to 0 on failure.
/// \returns 0 for success, non zero code for error.
/// \details If the remote machine server already holds a machine instance, the forked copy is ready for use.
/// Otherwise, use cm_create() or cm_load() to instantiate a machine into the forked server object.
Expand Down
4 changes: 2 additions & 2 deletions src/jsonrpc-remote-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ static json jsonrpc_rebind_handler(const json &j, const std::shared_ptr<http_ses
session->handler->rebind(tcp::acceptor{session->handler->ioc, new_local_endpoint});
SLOG(trace) << session->handler->local_endpoint << " rebound to " << session->handler->local_endpoint;
} else {
SLOG(trace) << session->handler->local_endpoint << " rebind unecessary";
SLOG(trace) << session->handler->local_endpoint << " rebind unnecessary";
}
const std::string result = endpoint_to_string(session->handler->local_endpoint);
return jsonrpc_response_ok(j, result);
Expand Down Expand Up @@ -876,7 +876,7 @@ static json jsonrpc_machine_destroy_handler(const json &j, const std::shared_ptr
/// \param j JSON request object
/// \param session HTTP session
/// \returns JSON response object
/// \details This method causes the server to sleep for a number of miliseconds before the next call
/// \details This method causes the server to sleep for a number of milliseconds before the next call
static json jsonrpc_delay_next_request_handler(const json &j, const std::shared_ptr<http_session> &session) {
static const char *param_name[] = {"ms"};
auto args = parse_args<uint64_t>(j, param_name);
Expand Down
8 changes: 4 additions & 4 deletions src/machine-c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,15 +362,15 @@ CM_API void cm_delete(cm_machine *m);
/// \param config Machine configuration as a JSON object in a string.
/// \param runtime_config Machine runtime configuration as a JSON object in a string (can be NULL).
/// \returns 0 for success, non zero code for error.
/// \details Use cm_destroy() to destroy the machine istance and remove it from the object.
/// \details Use cm_destroy() to destroy the machine instance and remove it from the object.
CM_API cm_error cm_create(cm_machine *m, const char *config, const char *runtime_config);

/// \brief Combines cm_new() and cm_create() for convenience.
/// \param config Machine configuration as a JSON object in a string.
/// \param runtime_config Machine runtime configuration as a JSON object in a string (can be NULL).
/// \param new_m Receives the pointer to the new machine object with a machine instance. Set to NULL on failure.
/// \returns 0 for success, non zero code for error.
/// \details Use cm_destroy() to destroy the machine istance and remove it from the object.
/// \details Use cm_destroy() to destroy the machine instance and remove it from the object.
/// \details Use cm_delete() to delete the object.
CM_API cm_error cm_create_new(const char *config, const char *runtime_config, cm_machine **new_m);

Expand All @@ -379,15 +379,15 @@ CM_API cm_error cm_create_new(const char *config, const char *runtime_config, cm
/// \param dir Directory where previous machine is stored.
/// \param runtime_config Machine runtime configuration as a JSON object in a string (can be NULL).
/// \returns 0 for success, non zero code for error.
/// \details Use cm_destroy() to destroy the machine istance and remove it from the object.
/// \details Use cm_destroy() to destroy the machine instance and remove it from the object.
CM_API cm_error cm_load(cm_machine *m, const char *dir, const char *runtime_config);

/// \brief Combines cm_new() and cm_load() for convenience.
/// \param dir Directory where previous machine is stored.
/// \param runtime_config Machine runtime configuration as a JSON object in a string (can be NULL).
/// \param new_m Receives the pointer to the new machine object with a machine instance. Set to NULL on failure.
/// \returns 0 for success, non zero code for error.
/// \details Use cm_destroy() to destroy the machine istance and remove it from the object.
/// \details Use cm_destroy() to destroy the machine instance and remove it from the object.
/// \details Use cm_delete() to delete the object.
CM_API cm_error cm_load_new(const char *dir, const char *runtime_config, cm_machine **new_m);

Expand Down
4 changes: 2 additions & 2 deletions src/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -560,13 +560,13 @@ class machine final {

/// \brief Sends cmio response
/// \param reason Reason for sending response.
/// \param data Reponse data.
/// \param data Response data.
/// \param length Length of response data.
void send_cmio_response(uint16_t reason, const unsigned char *data, uint64_t length);

/// \brief Sends cmio response and returns an access log
/// \param reason Reason for sending response.
/// \param data Reponse data.
/// \param data Response data.
/// \param length Length of response data.
/// \param log_type Type of access log to generate.
/// \return The state access log.
Expand Down
4 changes: 2 additions & 2 deletions src/merkle-tree-proof.h
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ class merkle_tree_proof final {
throw std::out_of_range{"log2_root_size is too large"};
}
if (new_log2_target_size < get_log2_target_size()) {
throw std::out_of_range{"log2_taget_size is too small"};
throw std::out_of_range{"log2_target_size is too small"};
}
merkle_tree_proof<HASH_TYPE, ADDRESS_TYPE> sliced(new_log2_root_size, new_log2_target_size);
hash_type hash = get_target_hash();
Expand Down Expand Up @@ -258,7 +258,7 @@ class merkle_tree_proof final {

private:
/// \brief Converts log2_size to index into siblings array
/// \return Index into siblings array, or throws exception if out of bouds
/// \return Index into siblings array, or throws exception if out of bounds
int log2_size_to_index(int log2_size) const {
const int index = log2_size - m_log2_target_size;
if (index < 0 || index >= static_cast<int>(m_sibling_hashes.size())) {
Expand Down
2 changes: 1 addition & 1 deletion src/record-state-access.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class record_state_access : public i_state_access<record_state_access, pma_entry
update_after_write(paligned);
}

// Declare interface as friend to it can forward calls to the "overriden" methods.
// Declare interface as friend to it can forward calls to the "overridden" methods.
friend i_state_access<record_state_access, pma_entry>;

void do_push_bracket(bracket_type &type, const char *text) {
Expand Down
Loading

0 comments on commit bebc79f

Please sign in to comment.