-
Notifications
You must be signed in to change notification settings - Fork 111
[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
Merged
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
3cfcca5
f$deflate_init
Shamzik a276c47
f$deflate_add & tests
Shamzik 92ed7c4
format
Shamzik 0034e3b
noexcept
Shamzik 9ec93d8
std::addressof
Shamzik d94ed89
brace init
Shamzik 53d5b08
rewrite key comparing
Shamzik 7452dd1
small fixes
Shamzik 9df0e83
constexpr
Shamzik a184c56
move statement to if
Shamzik 35588e6
fix message
Shamzik f9e1446
fixes
Shamzik 493d261
2025
Shamzik 252a1e8
do not check `zlib_dynamic_free` arg
Shamzik c31bb20
move value declaration
Shamzik 81c5ae7
constants
Shamzik db995c8
alloc -> calloc
Shamzik 487b127
format
Shamzik 4083e72
a number
Shamzik b84e282
default values of options
Shamzik 91f5b7f
#include "zlib/zlib.h"
Shamzik 64bb8a9
swap two lines
Shamzik 283b98f
small refactoring
Shamzik cf25e79
using make_instance
Shamzik d4e8751
yet another refactoring
Shamzik 5f3208b
do not use `zError`
Shamzik bd66d0f
hide `destroy` invocation
Shamzik 164e15c
include <memory>
Shamzik c1a1f49
remove zlib_format
Shamzik 89c14b9
move "using namespace std::literals" into for loop
Shamzik 27a71d1
const auto& val
Shamzik 6c414ec
constants
Shamzik 702ec51
early return
Shamzik bc4ee2d
static local constants
Shamzik d77b5f3
switch-case scopes
Shamzik 9bcabd6
do not call `deflateEnd` if `deflateInit2` returned error
Shamzik 5d7f0a1
to_zlib_window_bits -> lambda
Shamzik 42a3d34
move md5_file from zlib-functions.txt into file-functions.txt
Shamzik 4f05a77
make init method
Shamzik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| // Compiler for PHP (aka KPHP) | ||
| // Copyright (c) 2025 LLC «V Kontakte» | ||
| // Distributed under the GPL v3 License, see LICENSE.notice.txt | ||
|
|
||
| #pragma once | ||
|
|
||
apolyakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #include <cstdint> | ||
| #include <memory> | ||
| #include <optional> | ||
|
|
||
| #include "zlib/zlib.h" | ||
|
|
||
| #include "runtime-common/core/allocator/script-malloc-interface.h" | ||
| #include "runtime-common/core/class-instance/refcountable-php-classes.h" | ||
| #include "runtime-common/stdlib/visitors/dummy-visitor-methods.h" | ||
| #include "runtime-light/stdlib/diagnostics/logs.h" | ||
|
|
||
| class C$DeflateContext : public refcountable_php_classes<C$DeflateContext>, private DummyVisitorMethods { | ||
| std::optional<z_stream> m_stream; | ||
|
|
||
| static voidpf dynamic_calloc([[maybe_unused]] voidpf opaque, uInt items, uInt size) noexcept { | ||
| auto* mem{kphp::memory::script::calloc(items, size)}; | ||
| if (mem == nullptr) [[unlikely]] { | ||
| kphp::log::warning("zlib dynamic calloc: can't allocate {} bytes", items * size); | ||
| } | ||
| return mem; | ||
| } | ||
|
|
||
| static void dynamic_free([[maybe_unused]] voidpf opaque, voidpf address) noexcept { | ||
| kphp::memory::script::free(address); | ||
| } | ||
|
|
||
| public: | ||
| using DummyVisitorMethods::accept; | ||
apolyakov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| C$DeflateContext() noexcept = default; | ||
|
|
||
| C$DeflateContext(const C$DeflateContext&) = delete; | ||
| C$DeflateContext(C$DeflateContext&&) = delete; | ||
| C$DeflateContext& operator=(const C$DeflateContext&) = delete; | ||
| C$DeflateContext& operator=(C$DeflateContext&&) = delete; | ||
|
|
||
| bool init(int32_t level, int32_t window_bits, int32_t memory, int32_t strategy) noexcept { | ||
| z_stream* stream{std::addressof(m_stream.emplace(z_stream{.zalloc = dynamic_calloc, .zfree = dynamic_free, .opaque = nullptr}))}; | ||
|
|
||
| if (auto err{deflateInit2(stream, level, Z_DEFLATED, window_bits, memory, strategy)}; err != Z_OK) { | ||
| kphp::log::warning("zlib error {}", err); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| z_stream& operator*() noexcept { | ||
| kphp::log::assertion(m_stream.has_value()); | ||
| return *m_stream; | ||
| } | ||
|
|
||
| ~C$DeflateContext() { | ||
| if (m_stream.has_value()) [[likely]] { | ||
| deflateEnd(std::addressof(*m_stream)); | ||
| } | ||
| } | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| @ok k2_skip | ||
| @ok | ||
| <?php | ||
|
|
||
| $x = ""; | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.