8000 [k2] add support argc/argv superglobals in k2-cli by astrophysik · Pull Request #1295 · VKCOM/kphp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[k2] add support argc/argv superglobals in k2-cli #1295

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

astrophysik
Copy link
Contributor

No description provided.

@astrophysik astrophysik added the k2 k2 related label Apr 22, 2025
@astrophysik astrophysik self-assigned this Apr 22, 2025
10000
} else if (letter == '"') {
in_quote = !in_quote;
} else if (letter == '\'') {
php_warning("in command line arg supported only \" quote");
Copy link
Contributor
@Danil42Russia Danil42Russia Apr 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think you added an extra space \" quote"

@@ -65,6 +65,14 @@ void StaticInit::compile(CodeGenerator &W) const {
W << END << NL << NL;
}

if (G->is_output_mode_k2()) {
W << "namespace kphp::compiler_interface {" << NL;
FunctionSignatureGenerator(W) << ("std::string_view get_main_file_name() ") << BEGIN;
Copy link
Contributor
@apolyakov apolyakov Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's make this function constexpr

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang++ gives error with message that inline function ... is not defined

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please, considering using - instead of _ in file names

@@ -43,6 +44,7 @@ struct ComponentState final : private vk::not_copyable {

private:
static constexpr std::string_view INI_ARG_PREFIX = "ini ";
static constexpr std::string_view COMMAND_LINE_ARG = "command-line";
Copy link
Contributor
@apolyakov apolyakov Apr 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's define it as CLI_ARG = "cli"

@@ -19,6 +19,7 @@ struct ComponentState final : private vk::not_copyable {
const uint32_t argc;
const uint32_t envc;
mixed runtime_config;
array<string> command_line_argv;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cli_argv

@@ -54,6 +56,40 @@ void ComponentState::parse_runtime_config_arg(std::string_view value_view) noexc
}
}

void ComponentState::parse_command_line_arg(std::string_view value_view) noexcept {
if (value_view.empty()) [[unlikely]] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to have warning here

return;
}

if (!command_line_argv.empty()) [[unlikely]] {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check should be placed at the top of the function

}

if (!command_line_argv.empty()) [[unlikely]] {
php_warning("command line argument support no more one usage");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird message, I'd suggest multiple command line arguments strings specified. skipping or something similar

return;
}

const auto& main_file_view{kphp::compiler_interface::get_main_file_name()};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think reference is redundant here

command_line_argv.push_back(string(main_file_view.data(), main_file_view.size()));

bool in_quote{};
string current_arg{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like an error. You need to set special reference counter for each reference counted object


bool in_quote{};
string current_arg{};
for (char letter : value_view) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not actually letter since there might be other symbols

bool in_quote{};
string current_arg{};
for (char letter : value_view) {
if (std::isspace(letter) && !in_quote && !current_arg.empty()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks overcomplicated. Let's use standard string view functions instead

@astrophysik astrophysik marked this pull request as draft June 17, 2025 12:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k2 k2 related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0