Skip to content

Commit

Permalink
Don't use stack to save/restore module on import.
Browse files Browse the repository at this point in the history
Using the stack to save/restore the module pointer when doing things
like import would fail when an early exit would happen. As the jam stack
does not unwind, but instead is unwound/cleaned-up at exit later. And
the value to restore and check would not be the saved module. Instead
we save the module locally and restore that directly.
  • Loading branch information
grafikrobot committed Aug 16, 2023
1 parent 0c11a20 commit 3ec3b11
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/engine/frames.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct module_scope_in_function

private:
FRAME * module_frame = nullptr;
module_t * saved_module = nullptr;
};

}} // namespace b2::jam
Expand Down
6 changes: 2 additions & 4 deletions src/engine/function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5380,17 +5380,15 @@ b2::jam::module_scope_in_function::module_scope_in_function(
FRAME * frame_, const char * module_name_)
: module_frame(frame_)
{
auto stack = stack_global();
stack->push(b2::ensure_valid(module_frame->module));
saved_module = b2::ensure_valid(module_frame->module);
module_frame->module = module_name_ == nullptr
? b2::ensure_valid(root_module())
: b2::ensure_valid(bindmodule(value_ref(module_name_)));
}

b2::jam::module_scope_in_function::~module_scope_in_function()
{
auto stack = stack_global();
module_frame->module = b2::ensure_valid(stack->pop<module_t *>());
module_frame->module = b2::ensure_valid(saved_module);
}

std::string b2::jam::backtrace::to_string(frame * f)
Expand Down

0 comments on commit 3ec3b11

Please sign in to comment.