-
Notifications
You must be signed in to change notification settings - Fork 110
[k2] implement zip functions in light runtime #1486
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
base: master
Are you sure you want to change the base?
Conversation
astrophysik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally, maybe remove prefixes `deflate_add()/deflate_init'? The location of the error should be clear from the trace
| dst = value.as_int(); | ||
| return true; | ||
| } else { | ||
| kphp::log::warning("deflate_init() : option {} should be number between {}..{}", option.get_string_key().c_str(), lbound, ubound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed deflate_init()?
| #include "runtime-common/core/class-instance/refcountable-php-classes.h" | ||
| #include "runtime-common/stdlib/visitors/dummy-visitor-methods.h" | ||
|
|
||
| struct C$DeflateContext : public refcountable_php_classes<C$DeflateContext>, private DummyVisitorMethods { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- This class defines a non-default destructor, so it should also explicitly define constructors and assignment operators
- What will happen with
z_streamif we create a copy object of this type?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explicitly deleted them
| void zlib_static_free([[maybe_unused]] voidpf opaque, [[maybe_unused]] voidpf address) noexcept {} | ||
|
|
||
| voidpf zlib_dynamic_alloc([[maybe_unused]] voidpf opaque, uInt items, uInt size) noexcept { | ||
| auto* mem{kphp::memory::script::calloc(items, size)}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please explain the reason you chose calloc instead of alloc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because old KPHP runtime does
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Let's then rename it to zlib_dynamic_calloc
| } | ||
|
|
||
| z_stream* stream{std::addressof(context.get()->stream)}; | ||
| auto out_size{deflateBound(stream, data.size()) + 30}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this magic constant mean?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know. =)
I got it from old KPHP runtime
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need to figure this out
|
|
||
| z_stream* stream{std::addressof(context.get()->stream)}; | ||
| auto out_size{deflateBound(stream, data.size()) + 30}; | ||
| out_size = out_size < 64 ? 64 : out_size; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And this one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave them names. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a solution we want tbh
| int32_t window{15}; | ||
| auto strategy{Z_DEFAULT_STRATEGY}; | ||
| constexpr auto extract_int_option{[](int32_t lbound, int32_t ubound, const array_iterator<const mixed>& option, int32_t& dst) noexcept { | ||
| if (const mixed & value{option.get_value()}; value.is_int() && value.as_int() >= lbound && value.as_int() <= ubound) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: something is wrong with your formatter as it should be const mixed&
| dst = value.as_int(); | ||
| return true; | ||
| } else { | ||
| kphp::log::warning("option {} should be number between {}..{}", option.get_string_key().c_str(), lbound, ubound); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: a number
| class_instance<C$DeflateContext> f$deflate_init(int64_t encoding, const array<mixed>& options) noexcept { | ||
| int32_t level{-1}; | ||
| int32_t memory{8}; | ||
| int32_t window{15}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not have such magic constants?
The goal is to implement functions:
DeflateContext was implemented too as it is used in deflate functions.