Skip to content
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

[k2] add file functions in runtime light #1161

Merged
merged 27 commits into from
Dec 13, 2024
Merged

Conversation

astrophysik
Copy link
Contributor

@astrophysik astrophysik commented Nov 20, 2024

todo

  • Support php globals STDERR, STDOUT, STDIN
  • move constant INVALID_PLATFORM_DESCRIPTOR to k2-api.h

@astrophysik astrophysik added runtime Feature related to runtime k2 k2 related labels Nov 20, 2024
@astrophysik astrophysik self-assigned this Nov 20, 2024
@astrophysik astrophysik force-pushed the vsadokhov/add-file-builtins branch from ec11160 to 27888ed Compare November 20, 2024 16:37
@astrophysik astrophysik marked this pull request as ready for review November 20, 2024 16:40
@astrophysik astrophysik added this to the next milestone Nov 21, 2024
Copy link
Contributor

@apolyakov apolyakov left a comment

Choose a reason for hiding this comment

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

General comment: please apply clang-format to runtime-light and runtime-common directories (files you modified).

runtime-common/stdlib/stream/stream-context.h Outdated Show resolved Hide resolved
runtime-common/stdlib/stream/stream-functions.h Outdated Show resolved Hide resolved
runtime-light/stdlib/resource/resource-state.cpp Outdated Show resolved Hide resolved
runtime-light/stdlib/stdlib.cmake Outdated Show resolved Hide resolved
apolyakov
apolyakov previously approved these changes Nov 22, 2024
@astrophysik astrophysik marked this pull request as draft November 22, 2024 11:38
@astrophysik astrophysik force-pushed the vsadokhov/add-file-builtins branch from 5c2db15 to 95cdd8a Compare December 2, 2024 08:56
@astrophysik astrophysik changed the title move stream functions to runtime common add file functions in runtime light Dec 2, 2024
@astrophysik astrophysik marked this pull request as ready for review December 4, 2024 15:12
@astrophysik astrophysik requested a review from apolyakov December 4, 2024 15:12
@astrophysik astrophysik marked this pull request as draft December 4, 2024 15:22
@astrophysik astrophysik force-pushed the vsadokhov/add-file-builtins branch from e9b2935 to b3150bb Compare December 6, 2024 13:11
@astrophysik astrophysik marked this pull request as ready for review December 6, 2024 13:47
@@ -165,4 +165,26 @@ inline auto arg_fetch(uint32_t arg_num) noexcept {
std::unique_ptr<char, decltype(std::addressof(k2::free))>{value_buffer, std::addressof(k2::free)});
}

inline int32_t udp_connect(uint64_t *socket_d, const char *host, size_t host_len) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing noexcept modifier. Please, apply it to all the functions you' added

}


inline int32_t lookup_host(const char *host, size_t host_len, struct SockAddr *result_buf, size_t *result_buf_len) {
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not depend on raw k2 primitives in our code. Please, use a simple using SockAddr = SockAddr;. It should be applied to all k2 types you use.

return k2_lookup_host(host, host_len, result_buf, result_buf_len);
}

inline int32_t socket(uint64_t *socket_d, int32_t domain, int32_t type, int protocol) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please, don't use int. Use int32_t instead.

@@ -100,6 +100,8 @@ struct InstanceState final : vk::not_copyable {
return open_stream(std::string_view{component_name.c_str(), static_cast<size_t>(component_name.size())});
}

std::pair<uint64_t, int32_t> connect_to(const string &host, bool reliable) noexcept;
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 that it's necessary to return low-level cerrno-like objects from this function

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I don't like the naming here: reliable?

const int32_t error_number{reliable ? k2::tcp_connect(std::addressof(stream_d), host.c_str(), host.size())
: k2::udp_connect(std::addressof(stream_d), host.c_str(), host.size())};

if (error_number != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a special k2::errno_ok value for that purpose

return false;
}

return {string(static_cast<int64_t>(type)).append(":").append(static_cast<int64_t>(stream_d))};
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please explain the idea behind these streams? As far as I understand, the user now has access to the internals of the runtime, e.g. internal stream descriptors.

php_warning("try to fclose wrong resource %s", stream.to_string().c_str());
return false;
}
if (InstanceState::get().standard_stream() == stream_d) {
Copy link
Contributor

Choose a reason for hiding this comment

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

That is consecutive of your decision to operate on internal stream descriptors

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 see any reason to create a distinct directory for that


namespace {

constexpr std::string_view STDERR_NAME{"stderr"};
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's initialise globals with =. It's just how we started doing it... Also, as I can see, you also use it in another file.

} // namespace

uint64_t open_php_stream(const string &stream_name) noexcept {
if (strcmp(stream_name.c_str(), STDERR_NAME.data()) == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

You do have std::string_view here, why not just create another one and compare string views instead of raw pointers?

if (std::string_view{stream_name.c_str(), stream_name.size()} == STDERR_NAME)

@astrophysik astrophysik changed the title add file functions in runtime light [k2] add file functions in runtime light Dec 9, 2024
@astrophysik astrophysik removed this from the next milestone Dec 9, 2024
@astrophysik astrophysik force-pushed the vsadokhov/add-file-builtins branch from d2b3e5c to 97cc8aa Compare December 12, 2024 13:02
@apolyakov apolyakov force-pushed the vsadokhov/add-file-builtins branch from e612f28 to 5690961 Compare December 12, 2024 16:35
@apolyakov apolyakov force-pushed the vsadokhov/add-file-builtins branch from 5690961 to 61e42a7 Compare December 12, 2024 22:19
@apolyakov apolyakov self-requested a review December 12, 2024 22:19
@apolyakov apolyakov merged commit 28c7b9e into master Dec 13, 2024
5 checks passed
@apolyakov apolyakov deleted the vsadokhov/add-file-builtins branch December 13, 2024 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
k2 k2 related runtime Feature related to runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants