mirror of
https://github.com/matrix-construct/construct
synced 2024-12-26 15:33:54 +01:00
ircd::mods: Move the call to the init function after the mod ctor.
This commit is contained in:
parent
291b6dc286
commit
34abaea046
2 changed files with 17 additions and 16 deletions
|
@ -35,7 +35,6 @@ struct ircd::mods::module
|
|||
|
||||
module(std::shared_ptr<mod> ptr = {});
|
||||
module(const string_view &name);
|
||||
~module() noexcept;
|
||||
};
|
||||
|
||||
inline
|
||||
|
|
32
ircd/mods.cc
32
ircd/mods.cc
|
@ -263,7 +263,23 @@ try
|
|||
name,
|
||||
path.string());
|
||||
|
||||
return std::make_shared<mod>(path, flags);
|
||||
const auto ret
|
||||
{
|
||||
std::make_shared<mod>(path, flags)
|
||||
};
|
||||
|
||||
// Call the user-supplied init function well after fully loading and
|
||||
// construction of the module. This way the init function sees the module
|
||||
// as loaded and can make shared_ptr references, etc.
|
||||
if(ret->header->init)
|
||||
ret->header->init();
|
||||
|
||||
log.info("Loaded module %s v%u \"%s\"",
|
||||
ret->name(),
|
||||
ret->header->version,
|
||||
!ret->description().empty()? ret->description() : "<no description>"s);
|
||||
|
||||
return ret;
|
||||
}()}
|
||||
{
|
||||
}
|
||||
|
@ -275,11 +291,6 @@ catch(const std::exception &e)
|
|||
throw;
|
||||
}
|
||||
|
||||
ircd::mods::module::~module()
|
||||
noexcept
|
||||
{
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
ircd::mods::module::path()
|
||||
const
|
||||
|
@ -723,15 +734,6 @@ try
|
|||
m->path.filename().string());
|
||||
}
|
||||
|
||||
// If init throws an exception from here the loading process will back out.
|
||||
if(header->init)
|
||||
header->init();
|
||||
|
||||
log.info("Loaded module %s v%u \"%s\"",
|
||||
name(),
|
||||
header->version,
|
||||
description().size()? description() : "<no description>"s);
|
||||
|
||||
// Without init exception, the module is now considered loaded.
|
||||
assert(!loaded.count(name()));
|
||||
loaded.emplace(name(), this);
|
||||
|
|
Loading…
Reference in a new issue