diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index de2f2b0..bc16a37 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -560,7 +560,6 @@ struct LIBCUBESCRIPT_EXPORT state { void swap(state &s) { std::swap(p_tstate, s.p_tstate); std::swap(identflags, s.identflags); - std::swap(p_owner, s.p_owner); } state new_thread(); @@ -733,8 +732,6 @@ private: ident *add_ident(ident *id, ident_impl *impl); void *alloc(void *ptr, size_t olds, size_t news); - - bool p_owner = false; }; struct stack_state_node { diff --git a/src/cs_state.cc b/src/cs_state.cc index 2fcdc8e..ef234de 100644 --- a/src/cs_state.cc +++ b/src/cs_state.cc @@ -71,7 +71,7 @@ state::state(alloc_func func, void *data) { p_tstate->pstate = this; p_tstate->istate = statep; - p_owner = true; + p_tstate->owner = true; for (int i = 0; i < MAX_ARGUMENTS; ++i) { char buf[32]; @@ -188,7 +188,7 @@ LIBCUBESCRIPT_EXPORT state::~state() { } LIBCUBESCRIPT_EXPORT void state::destroy() { - if (!p_tstate || !p_owner) { + if (!p_tstate || !p_tstate->owner) { return; } auto *sp = p_tstate->istate; @@ -205,9 +205,7 @@ LIBCUBESCRIPT_EXPORT void state::destroy() { sp->destroy(sp); } -state::state(internal_state *s): - p_owner{false} -{ +state::state(internal_state *s) { p_tstate = s->create(s); p_tstate->istate = s; } diff --git a/src/cs_thread.hh b/src/cs_thread.hh index b2add06..8fbe3f4 100644 --- a/src/cs_thread.hh +++ b/src/cs_thread.hh @@ -29,6 +29,8 @@ struct thread_state { hook_func call_hook{}; /* loop nesting level */ int loop_level = 0; + /* whether we own the internal state (i.e. not a side thread */ + bool owner = false; thread_state(internal_state *cs);