Skip to content

Commit

Permalink
chore: remove machine specifier to some api names
Browse files Browse the repository at this point in the history
  • Loading branch information
diegonehab committed Oct 16, 2024
1 parent 3038193 commit c123628
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/clua-i-virtual-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<clua_managed_cm_ptr<cm_machine>>(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;
}
Expand Down
3 changes: 1 addition & 2 deletions src/clua-jsonrpc-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,7 @@ static int mod_spawn_server(lua_State *L) {
auto &managed_jsonrpc_connection = clua_push_to(L, clua_managed_cm_ptr<cm_jsonrpc_connection>(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
Expand Down
2 changes: 1 addition & 1 deletion src/clua-machine-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void clua_delete<unsigned char>(unsigned char *ptr) { // NOLINT(readability-non-

template <>
void clua_delete<cm_machine>(cm_machine *ptr) {
cm_release_machine(ptr); // this call should never fail
cm_release(ptr); // this call should never fail
}

template <>
Expand Down
4 changes: 2 additions & 2 deletions src/clua-machine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/jsonrpc-machine-c-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<cm_machine *>(new cartesi::jsonrpc_virtual_machine(*cpp_con, detach_machine, c, r));
*new_machine = reinterpret_cast<cm_machine *>(new cartesi::jsonrpc_virtual_machine(*cpp_con, detach_machine, c, r));
return cm_result_success();
} catch (...) {
if (new_machine) {
Expand All @@ -288,8 +287,8 @@ cm_error cm_jsonrpc_load_machine(const cm_jsonrpc_connection *con, int detach_ma
r = cartesi::from_json<cartesi::machine_runtime_config>(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<cm_machine *>(new cartesi::jsonrpc_virtual_machine(*cpp_con, detach_machine, dir, r));
return cm_result_success();
} catch (...) {
Expand Down
8 changes: 4 additions & 4 deletions src/machine-c-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -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");
}
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions src/machine-c-api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c123628

Please sign in to comment.