Skip to content

Commit

Permalink
error: update memory structure
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Jun 17, 2024
1 parent f9f3c46 commit 11f9db4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
18 changes: 8 additions & 10 deletions lib/include/irritator/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ struct unknown_error {};
//! component with bad @c registered_id, @c dir_path_id or @c file_path_id.
struct undefined_error {};

//! Memory error to report a error during the allocation process. Often add a
//! e_memory structure to report memory request.
struct memory_error {};

//! Report an error in the argument pass to a function. Must be rarely used,
//! prefer @c irt_assert to @c std::abort the application and fix the source
//! code.
Expand Down Expand Up @@ -84,14 +80,16 @@ struct e_errno {
int value;
};

/** To report a error during the allocation process. */
struct e_memory {
long long unsigned int capacity{}; //!< Current capacity in bytes.
long long unsigned int request{}; //!< Requested capacity in bytes.
};
std::size_t request{}; //!< Requested capacity in bytes.
std::size_t capacity{}; //!< Current capacity in bytes. Can be nul if
//!< current capacity is not available. */

struct e_allocator {
size_t needed{};
size_t capacity{};
e_memory(std::integral auto req, std::integral auto cap) noexcept
: request{ static_cast<size_t>(req) }
, capacity{ static_cast<size_t>(cap) }
{}
};

struct e_json {
Expand Down
7 changes: 2 additions & 5 deletions lib/src/project.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,9 +1149,7 @@ status project::set(modeling& mod, simulation& sim, component& compo) noexcept
if (std::cmp_greater_equal(numbers.tree_node_nb, tree_nodes.capacity()))
return new_error(
tree_node_error{},
e_memory{
static_cast<long long unsigned int>(numbers.model_nb),
static_cast<long long unsigned int>(tree_nodes.capacity()) });
e_memory{ numbers.model_nb, tree_nodes.capacity() });
}

irt_check(make_component_cache(*this, mod));
Expand All @@ -1160,8 +1158,7 @@ status project::set(modeling& mod, simulation& sim, component& compo) noexcept
sim.destroy();

if (not sim.m_alloc.can_alloc_bytes(smr.global_b))
return new_error(simulation::model_error{},
e_allocator{ smr.global_b });
return new_error(simulation::model_error{}, e_memory(smr.global_b, 0));

sim.realloc(smr);

Expand Down

0 comments on commit 11f9db4

Please sign in to comment.