Skip to content

Commit

Permalink
[k2] support php serialized confdata values (#1190)
Browse files Browse the repository at this point in the history
Also add check to 'from_mixed' that a mixed contains an object
  • Loading branch information
apolyakov authored Dec 16, 2024
1 parent ea35125 commit ebda88d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion runtime-common/core/core-types/definition/mixed.inl
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,8 @@ ResultClass from_mixed(const mixed &m, const string &) noexcept {
php_error("Internal error. Class inside a mixed is not polymorphic");
return {};
} else {
return ResultClass::create_from_base_raw_ptr(dynamic_cast<abstract_refcountable_php_interface *>(m.as_object_ptr<ResultClass>()));
return m.is_object() ? ResultClass::create_from_base_raw_ptr(dynamic_cast<abstract_refcountable_php_interface *>(m.as_object_ptr<ResultClass>()))
: ResultClass{};
}
}

Expand Down
3 changes: 2 additions & 1 deletion runtime-light/stdlib/confdata/confdata-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "runtime-common/core/runtime-core.h"
#include "runtime-common/core/utils/kphp-assert-core.h"
#include "runtime-common/stdlib/serialization/json-functions.h"
#include "runtime-common/stdlib/serialization/serialize-functions.h"
#include "runtime-light/coroutine/task.h"
#include "runtime-light/k2-platform/k2-api.h"
#include "runtime-light/state/instance-state.h"
Expand All @@ -30,7 +31,7 @@ mixed extract_confdata_value(tl::confdataValue &&confdata_value) noexcept {
return {};
}
if (confdata_value.is_php_serialized) {
php_critical_error("unimplemented"); // TODO
return f$unserialize(confdata_value.value);
} else if (confdata_value.is_json_serialized) {
return f$json_decode(confdata_value.value);
} else {
Expand Down
6 changes: 3 additions & 3 deletions runtime-light/stdlib/file/file-system-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ Optional<string> f$file_get_contents(const string &stream) noexcept {

task_t<Optional<int64_t>> f$fwrite(const resource &stream, const string &text) noexcept {
auto rsrc{from_mixed<class_instance<underlying_resource_t>>(stream, {})};
if (rsrc.is_null()) {
if (rsrc.is_null()) [[unlikely]] {
php_warning("wrong resource in fwrite %s", stream.to_string().c_str());
co_return false;
}
Expand All @@ -61,7 +61,7 @@ task_t<Optional<int64_t>> f$fwrite(const resource &stream, const string &text) n

bool f$fflush(const resource &stream) noexcept {
auto rsrc{from_mixed<class_instance<underlying_resource_t>>(stream, {})};
if (rsrc.is_null()) {
if (rsrc.is_null()) [[unlikely]] {
php_warning("wrong resource in fflush %s", stream.to_string().c_str());
return false;
}
Expand All @@ -72,7 +72,7 @@ bool f$fflush(const resource &stream) noexcept {

bool f$fclose(const resource &stream) noexcept {
auto rsrc{from_mixed<class_instance<underlying_resource_t>>(stream, {})};
if (rsrc.is_null()) {
if (rsrc.is_null()) [[unlikely]] {
php_warning("wrong resource in fclose: %s", stream.to_string().c_str());
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion runtime-light/stdlib/file/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ underlying_resource_t::underlying_resource_t(std::string_view scheme) noexcept
break;
}
case resource_kind::STDOUT: {
if (instance_st.image_kind() == ImageKind::CLI || instance_st.image_kind() == ImageKind::Server) {
if (instance_st.image_kind() == ImageKind::CLI) {
stream_d_ = instance_st.standard_stream();
} else {
last_errc = k2::errno_einval;
Expand Down

0 comments on commit ebda88d

Please sign in to comment.