diff --git a/src/clua-i-virtual-machine.cpp b/src/clua-i-virtual-machine.cpp index ef33bb9e7..890df1d55 100644 --- a/src/clua-i-virtual-machine.cpp +++ b/src/clua-i-virtual-machine.cpp @@ -437,10 +437,10 @@ static int machine_obj_index_rollback(lua_State *L) { /// \param L Lua state. static int machine_obj_index_destroy(lua_State *L) { auto &m = clua_check>(L, 1); - if (cm_destroy_machine(m.get()) != 0) { + if (cm_destroy(m.get()) != 0) { return luaL_error(L, "%s", cm_get_last_error_message()); } - cm_release_machine(m.get()); + cm_release(m.get()); m.release(); return 0; } diff --git a/src/clua-jsonrpc-machine.cpp b/src/clua-jsonrpc-machine.cpp index e2185017a..3e0bd3538 100644 --- a/src/clua-jsonrpc-machine.cpp +++ b/src/clua-jsonrpc-machine.cpp @@ -284,8 +284,7 @@ static int mod_spawn_server(lua_State *L) { auto &managed_jsonrpc_connection = clua_push_to(L, clua_managed_cm_ptr(nullptr)); const char *bound_address = nullptr; int32_t pid = 0; - if (cm_jsonrpc_spawn_server(address, detach_server, &managed_jsonrpc_connection.get(), &bound_address, &pid) != - 0) { + if (cm_jsonrpc_spawn_server(address, detach_server, &managed_jsonrpc_connection.get(), &bound_address, &pid) != 0) { return luaL_error(L, "%s", cm_get_last_error_message()); } // wrap it into its Lua interface diff --git a/src/clua-machine-util.cpp b/src/clua-machine-util.cpp index 81889233a..7cc2f1da7 100644 --- a/src/clua-machine-util.cpp +++ b/src/clua-machine-util.cpp @@ -36,7 +36,7 @@ void clua_delete(unsigned char *ptr) { // NOLINT(readability-non- template <> void clua_delete(cm_machine *ptr) { - cm_release_machine(ptr); // this call should never fail + cm_release(ptr); // this call should never fail } template <> diff --git a/src/clua-machine.cpp b/src/clua-machine.cpp index 82d6801c3..2b1b869b7 100644 --- a/src/clua-machine.cpp +++ b/src/clua-machine.cpp @@ -108,12 +108,12 @@ static int machine_ctor(lua_State *L) { const char *runtime_config = !lua_isnil(L, 3) ? clua_check_json_string(L, 3) : nullptr; if (!lua_isstring(L, 2)) { const char *config = clua_check_json_string(L, 2); - if (cm_create_machine(config, runtime_config, &managed_machine.get()) != 0) { + if (cm_create(config, runtime_config, &managed_machine.get()) != 0) { return luaL_error(L, "%s", cm_get_last_error_message()); } } else { const char *dir = luaL_checkstring(L, 2); - if (cm_load_machine(dir, runtime_config, &managed_machine.get()) != 0) { + if (cm_load(dir, runtime_config, &managed_machine.get()) != 0) { return luaL_error(L, "%s", cm_get_last_error_message()); } } diff --git a/src/jsonrpc-machine-c-api.cpp b/src/jsonrpc-machine-c-api.cpp index 0b4ec6eeb..a2d743ee1 100644 --- a/src/jsonrpc-machine-c-api.cpp +++ b/src/jsonrpc-machine-c-api.cpp @@ -265,8 +265,7 @@ cm_error cm_jsonrpc_create_machine(const cm_jsonrpc_connection *con, int detach_ } const auto *cpp_con = convert_from_c(con); // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - *new_machine = - reinterpret_cast(new cartesi::jsonrpc_virtual_machine(*cpp_con, detach_machine, c, r)); + *new_machine = reinterpret_cast(new cartesi::jsonrpc_virtual_machine(*cpp_con, detach_machine, c, r)); return cm_result_success(); } catch (...) { if (new_machine) { @@ -288,8 +287,8 @@ cm_error cm_jsonrpc_load_machine(const cm_jsonrpc_connection *con, int detach_ma r = cartesi::from_json(runtime_config); } const auto *cpp_con = convert_from_c(con); - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) *new_machine = + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) reinterpret_cast(new cartesi::jsonrpc_virtual_machine(*cpp_con, detach_machine, dir, r)); return cm_result_success(); } catch (...) { diff --git a/src/machine-c-api.cpp b/src/machine-c-api.cpp index dc6f9c94d..cd7fddbe2 100644 --- a/src/machine-c-api.cpp +++ b/src/machine-c-api.cpp @@ -149,7 +149,7 @@ cartesi::machine_merkle_tree::hash_type convert_from_c(const cm_hash *c_hash) { // The C API implementation // ---------------------------------------------- -cm_error cm_create_machine(const char *config, const char *runtime_config, cm_machine **new_machine) try { +cm_error cm_create(const char *config, const char *runtime_config, cm_machine **new_machine) try { if (config == nullptr) { throw std::invalid_argument("invalid machine configuration"); } @@ -171,7 +171,7 @@ cm_error cm_create_machine(const char *config, const char *runtime_config, cm_ma return cm_result_failure(); } -cm_error cm_load_machine(const char *dir, const char *runtime_config, cm_machine **new_machine) try { +cm_error cm_load(const char *dir, const char *runtime_config, cm_machine **new_machine) try { if (new_machine == nullptr) { throw std::invalid_argument("invalid new machine output"); } @@ -598,7 +598,7 @@ cm_error cm_replace_memory_range(cm_machine *m, uint64_t start, uint64_t length, return cm_result_failure(); } -cm_error cm_destroy_machine(cm_machine *m) try { +cm_error cm_destroy(cm_machine *m) try { if (m != nullptr) { auto *cpp_machine = convert_from_c(m); cpp_machine->destroy(); @@ -608,7 +608,7 @@ cm_error cm_destroy_machine(cm_machine *m) try { return cm_result_failure(); } -void cm_release_machine(cm_machine *m) { +void cm_release(cm_machine *m) { if (m != nullptr) { auto *cpp_machine = convert_from_c(m); delete cpp_machine; diff --git a/src/machine-c-api.h b/src/machine-c-api.h index 29f282f70..549b208de 100644 --- a/src/machine-c-api.h +++ b/src/machine-c-api.h @@ -339,32 +339,32 @@ CM_API cm_error cm_get_reg_address(cm_reg reg, uint64_t *val); /// string (can be NULL). /// \param new_machine Receives the pointer to new machine instance. /// \returns 0 for success, non zero code for error. -CM_API cm_error cm_create_machine(const char *config, const char *runtime_config, cm_machine **new_machine); +CM_API cm_error cm_create(const char *config, const char *runtime_config, cm_machine **new_machine); /// \brief Loads a new machine instance from a previously stored directory. /// \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_machine Receives the pointer to new machine instance. /// \returns 0 for success, non zero code for error. -CM_API cm_error cm_load_machine(const char *dir, const char *runtime_config, cm_machine **new_machine); +CM_API cm_error cm_load(const char *dir, const char *runtime_config, cm_machine **new_machine); /// \brief Releases handle to a machine. /// \param m Pointer to the existing machine handle (can be NULL). /// \details Local machines are never detached and are always destroyed immediately /// when released. If machine is remote and not detached, this function -/// implicitly calls cm_destroy_machine() to destroy the remote machine. This +/// implicitly calls cm_destroy() to destroy the remote machine. This /// might fail silently. To know if the destruction of a remote machine was -/// successful, call cm_destroy_machine() explicitly before calling cm_release_machine(). +/// successful, call cm_destroy() explicitly before calling cm_release(). /// The machine handle must not be used after this call. -CM_API void cm_release_machine(cm_machine *m); +CM_API void cm_release(cm_machine *m); /// \brief Destroy machine, releasing its resources but preserving a valid handle. /// \param m Pointer to the existing machine handle (can be NULL). /// \returns 0 for success, non zero code for error. /// \details Local machines are always destroyed sucessfully. /// In contrast, the attempt to destroy a remote machine might fail. -/// The handle itself must still be released with cm_release_machine(). -CM_API cm_error cm_destroy_machine(cm_machine *m); +/// The handle itself must still be released with cm_release(). +CM_API cm_error cm_destroy(cm_machine *m); /// \brief Stores a machine instance to a directory, serializing its entire state. /// \param m Pointer to a valid machine handle.