Skip to content

Commit 25e7930

Browse files
authored
[k2] throw error on accessing RuntimeContext before InstanceState initialization (#1576)
1 parent 2ee8242 commit 25e7930

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

runtime-light/core/kphp-core-impl/kphp-core-context.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
// Distributed under the GPL v3 License, see LICENSE.notice.txt
44

55
#include "runtime-common/core/runtime-core.h"
6+
#include "runtime-light/k2-platform/k2-api.h"
67
#include "runtime-light/state/instance-state.h"
8+
#include "runtime-light/stdlib/diagnostics/logs.h"
9+
10+
namespace {
711

812
constexpr string_size_type initial_minimum_string_buffer_length = 1024;
913
constexpr string_size_type initial_maximum_string_buffer_length = (1 << 24);
1014

15+
} // namespace
16+
1117
RuntimeContext& RuntimeContext::get() noexcept {
12-
return InstanceState::get().runtime_context;
18+
if (auto* instance_state_ptr{k2::instance_state()}; instance_state_ptr != nullptr) [[likely]] {
19+
return instance_state_ptr->runtime_context;
20+
}
21+
kphp::log::error("unexpected access to RuntimeContext");
1322
}
1423

1524
void RuntimeContext::init() noexcept {

0 commit comments

Comments
 (0)