remove public state::destroy()

master
Daniel Kolesa 2021-04-11 18:56:08 +02:00
parent e644674724
commit a2c50744da
2 changed files with 24 additions and 18 deletions

View File

@ -38,22 +38,12 @@ struct LIBCUBESCRIPT_EXPORT state {
virtual ~state();
state(state const &) = delete;
state(state &&s) {
swap(s);
}
state(state &&s);
state &operator=(state const &) = delete;
state &operator=(state &&s) {
swap(s);
s.destroy();
return *this;
}
state &operator=(state &&s);
void destroy();
void swap(state &s) {
std::swap(p_tstate, s.p_tstate);
}
void swap(state &s);
state new_thread();

View File

@ -266,18 +266,34 @@ state::state(alloc_func func, void *data) {
init_lib_base(*this);
}
LIBCUBESCRIPT_EXPORT state::~state() {
destroy();
}
LIBCUBESCRIPT_EXPORT void state::destroy() {
LIBCUBESCRIPT_EXPORT state::~state() {
if (!p_tstate || !p_tstate->owner) {
return;
}
auto *sp = p_tstate->istate;
sp->destroy(p_tstate);
sp->destroy(sp);
p_tstate = nullptr;
}
LIBCUBESCRIPT_EXPORT state::state(state &&s) {
swap(s);
}
LIBCUBESCRIPT_EXPORT state &state::operator=(state &&s) {
if (p_tstate && p_tstate->owner) {
auto *sp = p_tstate->istate;
sp->destroy(p_tstate);
sp->destroy(sp);
}
p_tstate = s.p_tstate;
s.p_tstate = nullptr;
return *this;
}
LIBCUBESCRIPT_EXPORT void state::swap(state &s) {
std::swap(p_tstate, s.p_tstate);
}
state::state(void *is) {