make p_tstate actually private

master
Daniel Kolesa 2021-03-26 03:05:14 +01:00
parent bd9a6cbf7c
commit b27d4fa7e6
8 changed files with 25 additions and 13 deletions

View File

@ -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<typename ...A>
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):

View File

@ -100,7 +100,7 @@ state::state(alloc_func func, void *data) {
static_cast<command_impl *>(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);
});
});

View File

@ -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 */

View File

@ -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);
}

View File

@ -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<bcode *>(cbuf + 1);
set_code(bc);

View File

@ -87,8 +87,12 @@ void init_lib_base(state &gcs) {
rc = false;
}
ret.set_int(rc);
static_cast<alias_impl *>(cret)->set_alias(*cs.p_tstate, result);
static_cast<alias_impl *>(css)->set_alias(*cs.p_tstate, tback);
static_cast<alias_impl *>(cret)->set_alias(
*cs.thread_pointer(), result
);
static_cast<alias_impl *>(css)->set_alias(
*cs.thread_pointer(), tback
);
});
gcs.new_command("?", "ttt", [](auto &, auto args, auto &res) {

View File

@ -551,7 +551,7 @@ static void list_sort(
alias *xa = static_cast<alias *>(x), *ya = static_cast<alias *>(y);
valbuf<ListSortItem> items{cs.p_tstate->istate};
valbuf<ListSortItem> items{cs.thread_pointer()->istate};
size_t total = 0;
for (list_parser p{cs, list}; p.parse();) {

View File

@ -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]);