Skip to content

Commit

Permalink
refactor init_superglobals
Browse files Browse the repository at this point in the history
  • Loading branch information
Vadim Sadokhov committed Sep 8, 2023
1 parent 87f59f3 commit e59a586
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
30 changes: 7 additions & 23 deletions runtime/interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1544,7 +1544,7 @@ static void save_rpc_query_headers(const tl_query_header_t &header) {
}
}

static void init_superglobals(const http_query_data &http_data, const rpc_query_data &rpc_data, const job_query_data &job_data) {
static void init_superglobals_impl(const http_query_data &http_data, const rpc_query_data &rpc_data, const job_query_data &job_data) {
rpc_parse(rpc_data.data, rpc_data.len);

reset_superglobals();
Expand Down Expand Up @@ -1802,39 +1802,23 @@ static rpc_query_data empty_rpc_data;
static job_query_data empty_job_data;

void init_superglobals(php_query_data_ptr data) {
http_query_data *http_data = nullptr;
rpc_query_data *rpc_data = nullptr;
job_query_data *job_data = nullptr;
// init superglobals depending on the request type
std::visit([&](auto && arg) {
using T = decltype(arg);
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, rpc_query_data *>) {
query_type = QUERY_TYPE_RPC;

http_data = &empty_http_data;
rpc_data = std::get<rpc_query_data *>(data);
job_data = &empty_job_data;
init_superglobals_impl(empty_http_data, *std::get<rpc_query_data *>(data), empty_job_data);
} else if constexpr (std::is_same_v<T, http_query_data *>) {
query_type = QUERY_TYPE_HTTP;

http_data = std::get<http_query_data *>(data);
rpc_data = &empty_rpc_data;
job_data = &empty_job_data;
init_superglobals_impl(*std::get<http_query_data *>(data), empty_rpc_data, empty_job_data);
} else if constexpr (std::is_same_v<T, job_query_data *>) {
query_type = QUERY_TYPE_JOB;

http_data = &empty_http_data;
rpc_data = &empty_rpc_data;
job_data = std::get<job_query_data *>(data);
init_superglobals_impl(empty_http_data, empty_rpc_data, *std::get<job_query_data *>(data));
} else {
query_type = QUERY_TYPE_CONSOLE;

http_data = &empty_http_data;
rpc_data = &empty_rpc_data;
job_data = &empty_job_data;
init_superglobals_impl(empty_http_data, empty_rpc_data, empty_job_data);
}
}, data);

init_superglobals(*http_data, *rpc_data, *job_data);
}

double f$get_net_time() {
Expand Down
2 changes: 1 addition & 1 deletion server/php-runner.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class PhpScript {
sigjmp_buf timeout_handler{};

script_t *run_main{nullptr};
php_query_data_ptr data{};
php_query_data_ptr data{null_query_data_ptr{}};
script_result *res{nullptr};

static void script_context_entrypoint() noexcept;
Expand Down

0 comments on commit e59a586

Please sign in to comment.