From b27d4fa7e69ae022a39df93996dd2180babe479d Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Fri, 26 Mar 2021 03:05:14 +0100 Subject: [PATCH] make p_tstate actually private --- include/cubescript/cubescript.hh | 12 ++++++++++-- src/cs_state.cc | 2 +- src/cs_std.cc | 2 +- src/cs_strman.cc | 2 +- src/cs_val.cc | 6 +++--- src/lib_base.cc | 8 ++++++-- src/lib_list.cc | 2 +- src/lib_str.cc | 4 ++-- 8 files changed, 25 insertions(+), 13 deletions(-) diff --git a/include/cubescript/cubescript.hh b/include/cubescript/cubescript.hh index b872bf7..de061d2 100644 --- a/include/cubescript/cubescript.hh +++ b/include/cubescript/cubescript.hh @@ -693,7 +693,13 @@ struct LIBCUBESCRIPT_EXPORT state { void print_var(global_var const &v) const; - thread_state *p_tstate = nullptr; + thread_state *thread_pointer() { + return p_tstate; + } + + thread_state const *thread_pointer() const { + return p_tstate; + } private: hook_func set_call_hook(hook_func func); @@ -726,6 +732,8 @@ private: ident *add_ident(ident *id, ident_impl *impl); void *alloc(void *ptr, size_t olds, size_t news); + + thread_state *p_tstate = nullptr; }; struct stack_state { @@ -776,7 +784,7 @@ struct LIBCUBESCRIPT_EXPORT error { template error(state &cs, std::string_view msg, A const &...args): - error{*cs.p_tstate, msg, args...} + error{*cs.thread_pointer(), msg, args...} {} error(thread_state &ts, std::string_view msg): diff --git a/src/cs_state.cc b/src/cs_state.cc index f253d2f..416d8f9 100644 --- a/src/cs_state.cc +++ b/src/cs_state.cc @@ -100,7 +100,7 @@ state::state(alloc_func func, void *data) { static_cast(p)->p_type = ID_DO; p = new_command("doargs", "e", [](auto &cs, auto args, auto &res) { - call_with_args(*cs.p_tstate, [&cs, &res, &args]() { + call_with_args(*cs.thread_pointer(), [&cs, &res, &args]() { cs.run(args[0].get_code(), res); }); }); diff --git a/src/cs_std.cc b/src/cs_std.cc index 3234530..0428503 100644 --- a/src/cs_std.cc +++ b/src/cs_std.cc @@ -4,7 +4,7 @@ namespace cubescript { -charbuf::charbuf(state &cs): charbuf{cs.p_tstate->istate} {} +charbuf::charbuf(state &cs): charbuf{cs.thread_pointer()->istate} {} charbuf::charbuf(thread_state &ts): charbuf{ts.istate} {} } /* namespace cubescript */ diff --git a/src/cs_strman.cc b/src/cs_strman.cc index 97a0451..0815a81 100644 --- a/src/cs_strman.cc +++ b/src/cs_strman.cc @@ -121,7 +121,7 @@ LIBCUBESCRIPT_EXPORT string_ref::string_ref( } LIBCUBESCRIPT_EXPORT string_ref::string_ref(state &cs, std::string_view str): - p_state{cs.p_tstate->istate} + p_state{cs.thread_pointer()->istate} { p_str = p_state->strman->add(str); } diff --git a/src/cs_val.cc b/src/cs_val.cc index 2640449..3f0fe3b 100644 --- a/src/cs_val.cc +++ b/src/cs_val.cc @@ -83,7 +83,7 @@ static inline void csv_cleanup(value_type tv, T *stor) { } } -any_value::any_value(state &st): any_value(*st.p_tstate->istate) {} +any_value::any_value(state &st): any_value(*st.thread_pointer()->istate) {} any_value::any_value(internal_state &st): p_stor(), p_type(value_type::NONE) @@ -256,11 +256,11 @@ bcode *any_value::force_code(state &cs) { default: break; } - codegen_state gs{*cs.p_tstate}; + codegen_state gs{*cs.thread_pointer()}; gs.code.reserve(64); gs.gen_main(get_str()); gs.done(); - uint32_t *cbuf = bcode_alloc(cs.p_tstate->istate, gs.code.size()); + uint32_t *cbuf = bcode_alloc(cs.thread_pointer()->istate, gs.code.size()); std::memcpy(cbuf, gs.code.data(), gs.code.size() * sizeof(std::uint32_t)); auto *bc = reinterpret_cast(cbuf + 1); set_code(bc); diff --git a/src/lib_base.cc b/src/lib_base.cc index fda6563..1f26584 100644 --- a/src/lib_base.cc +++ b/src/lib_base.cc @@ -87,8 +87,12 @@ void init_lib_base(state &gcs) { rc = false; } ret.set_int(rc); - static_cast(cret)->set_alias(*cs.p_tstate, result); - static_cast(css)->set_alias(*cs.p_tstate, tback); + static_cast(cret)->set_alias( + *cs.thread_pointer(), result + ); + static_cast(css)->set_alias( + *cs.thread_pointer(), tback + ); }); gcs.new_command("?", "ttt", [](auto &, auto args, auto &res) { diff --git a/src/lib_list.cc b/src/lib_list.cc index 06b184d..f20234f 100644 --- a/src/lib_list.cc +++ b/src/lib_list.cc @@ -551,7 +551,7 @@ static void list_sort( alias *xa = static_cast(x), *ya = static_cast(y); - valbuf items{cs.p_tstate->istate}; + valbuf items{cs.thread_pointer()->istate}; size_t total = 0; for (list_parser p{cs, list}; p.parse();) { diff --git a/src/lib_str.cc b/src/lib_str.cc index c42ca48..c7ee07b 100644 --- a/src/lib_str.cc +++ b/src/lib_str.cc @@ -60,7 +60,7 @@ void init_lib_string(state &cs) { cs.new_command("strlower", "s", [](auto &ccs, auto args, auto &res) { auto inps = std::string_view{args[0].get_str()}; - auto *ics = ccs.p_tstate->istate; + auto *ics = ccs.thread_pointer()->istate; auto *buf = ics->strman->alloc_buf(inps.size()); for (std::size_t i = 0; i < inps.size(); ++i) { buf[i] = tolower(inps[i]); @@ -70,7 +70,7 @@ void init_lib_string(state &cs) { cs.new_command("strupper", "s", [](auto &ccs, auto args, auto &res) { auto inps = std::string_view{args[0].get_str()}; - auto *ics = ccs.p_tstate->istate; + auto *ics = ccs.thread_pointer()->istate; auto *buf = ics->strman->alloc_buf(inps.size()); for (std::size_t i = 0; i < inps.size(); ++i) { buf[i] = toupper(inps[i]);