[MediaWiki-commits] [Gerrit] Backport of D2486378: Implement compress.bzip2:// stream wra... - change (operations...hhvm)
Ori.livneh has submitted this change and it was merged. Change subject: Backport of D2486378: Implement compress.bzip2:// stream wrapper .. Backport of D2486378: Implement compress.bzip2:// stream wrapper Bug: T113932 Change-Id: I0f064cb92d96d32a0409825328bc9865246bacbe --- A debian/patches/D2486378-compress_bzip2.patch M debian/patches/series 2 files changed, 167 insertions(+), 0 deletions(-) Approvals: Ori.livneh: Verified; Looks good to me, approved diff --git a/debian/patches/D2486378-compress_bzip2.patch b/debian/patches/D2486378-compress_bzip2.patch new file mode 100644 index 000..8a33b54 --- /dev/null +++ b/debian/patches/D2486378-compress_bzip2.patch @@ -0,0 +1,166 @@ +From 46d04cfdb6b5987946f19ed6c65cee676e27b254 Mon Sep 17 00:00:00 2001 +From: Sara Golemon+Date: Tue, 29 Sep 2015 14:28:41 -0700 +Subject: [PATCH] Implement compress.bzip2:// stream wrapper + +Summary: Wraper BZ2File implementation with an opener. + +Closes https://github.com/facebook/hhvm/issues/6314 + +Reviewed By: @paulbiss, @fredemmott + +Differential Revision: D2486378 +--- + hphp/runtime/ext/bz2/ext_bz2.cpp| 45 + + hphp/test/slow/ext_bzip2/wrapper.php| 43 +++ + hphp/test/slow/ext_bzip2/wrapper.php.expect | 21 ++ + 3 files changed, 109 insertions(+) + create mode 100644 hphp/test/slow/ext_bzip2/wrapper.php + create mode 100644 hphp/test/slow/ext_bzip2/wrapper.php.expect + +diff --git a/hphp/runtime/ext/bz2/ext_bz2.cpp b/hphp/runtime/ext/bz2/ext_bz2.cpp +index 174d109..bea8d5a 100644 +--- a/hphp/runtime/ext/bz2/ext_bz2.cpp b/hphp/runtime/ext/bz2/ext_bz2.cpp +@@ -17,6 +17,8 @@ + + #include "hphp/runtime/ext/bz2/bz2-file.h" + #include "hphp/runtime/ext/std/ext_std_file.h" ++#include "hphp/runtime/base/stream-wrapper.h" ++#include "hphp/runtime/base/file-stream-wrapper.h" + #include "hphp/util/alloc.h" + #include + +@@ -31,6 +33,44 @@ + + namespace HPHP { + /// ++// compress.zlib:// stream wrapper ++ ++namespace { ++static struct BZ2StreamWrapper : Stream::Wrapper { ++ virtual req::ptr open(const String& filename, ++ const String& mode, ++ int options, ++ const req::ptr& context) { ++static const char cz[] = "compress.bzip2://"; ++ ++if (strncmp(filename.c_str(), cz, sizeof(cz) - 1)) { ++ assert(false); ++ return nullptr; ++} ++ ++String fname(filename.substr(sizeof(cz) - 1)); ++String translated; ++if (fname.find("://") == -1) { ++ translated = File::TranslatePath(fname); ++ if (auto file = FileStreamWrapper::openFromCache(translated, mode)) { ++file->unzip(); ++return file; ++ } ++} else { ++ translated = fname; ++} ++ ++auto file = req::make(); ++if (!file->open(translated, mode)) { ++ raise_warning("%s", file->getLastError().c_str()); ++ return nullptr; ++} ++return file; ++ } ++} s_bzip2_stream_wrapper; ++} // nil namespace ++ ++/// + + bool HHVM_FUNCTION(bzclose, const Resource& bz) { + return HHVM_FN(fclose)(bz); +@@ -204,6 +244,11 @@ Variant HHVM_FUNCTION(bzdecompress, const String& source, int small /* = 0 */) { + class bz2Extension final : public Extension { + public: + bz2Extension() : Extension("bz2") {} ++ ++ void moduleLoad(const IniSetting::Map& ini, Hdf hdf) override { ++s_bzip2_stream_wrapper.registerAs("compress.bzip2"); ++ } ++ + void moduleInit() override { + HHVM_FE(bzclose); + HHVM_FE(bzread); +diff --git a/hphp/test/slow/ext_bzip2/wrapper.php b/hphp/test/slow/ext_bzip2/wrapper.php +new file mode 100644 +index 000..d7d6463 +--- /dev/null b/hphp/test/slow/ext_bzip2/wrapper.php +@@ -0,0 +1,43 @@ ++ 0); ++echo "Compressed from original: "; ++var_dump($compressedSize < (strlen($loremIpsum) * 3/4)); ++ ++$readContents = file_get_contents("compress.bzip2://$fn"); ++echo 'Match: '; ++var_dump($loremIpsum === $readContents); ++ ++echo "- Contents -\n"; ++readfile("compress.bzip2://$fn"); ++ ++unlink($fn); +diff --git a/hphp/test/slow/ext_bzip2/wrapper.php.expect b/hphp/test/slow/ext_bzip2/wrapper.php.expect +new file mode 100644 +index 000..6016048 +--- /dev/null b/hphp/test/slow/ext_bzip2/wrapper.php.expect +@@ -0,0 +1,21 @@ ++Written: bool(true) ++Readable: bool(true) ++Contains data: bool(true) ++Compressed from original: bool(true) ++Match: bool(true) ++- Contents - ++Lorem ipsum dolor sit amet, ++consectetur adipiscing elit, ++sed do eiusmod tempor incididunt ++ut labore et dolore magna aliqua. ++ ++Ut enim ad minim veniam, ++quis nostrud exercitation ullamco laboris ++nisi ut aliquip ex ea commodo consequat. ++ ++Duis aute
[MediaWiki-commits] [Gerrit] Backport of D2486378: Implement compress.bzip2:// stream wra... - change (operations...hhvm)
BryanDavis has uploaded a new change for review. https://gerrit.wikimedia.org/r/242773 Change subject: Backport of D2486378: Implement compress.bzip2:// stream wrapper .. Backport of D2486378: Implement compress.bzip2:// stream wrapper Bug: T113932 Change-Id: I0f064cb92d96d32a0409825328bc9865246bacbe --- A debian/patches/D2486378-compress_bzip2.patch M debian/patches/series 2 files changed, 167 insertions(+), 0 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/operations/debs/hhvm refs/changes/73/242773/1 diff --git a/debian/patches/D2486378-compress_bzip2.patch b/debian/patches/D2486378-compress_bzip2.patch new file mode 100644 index 000..8a33b54 --- /dev/null +++ b/debian/patches/D2486378-compress_bzip2.patch @@ -0,0 +1,166 @@ +From 46d04cfdb6b5987946f19ed6c65cee676e27b254 Mon Sep 17 00:00:00 2001 +From: Sara Golemon+Date: Tue, 29 Sep 2015 14:28:41 -0700 +Subject: [PATCH] Implement compress.bzip2:// stream wrapper + +Summary: Wraper BZ2File implementation with an opener. + +Closes https://github.com/facebook/hhvm/issues/6314 + +Reviewed By: @paulbiss, @fredemmott + +Differential Revision: D2486378 +--- + hphp/runtime/ext/bz2/ext_bz2.cpp| 45 + + hphp/test/slow/ext_bzip2/wrapper.php| 43 +++ + hphp/test/slow/ext_bzip2/wrapper.php.expect | 21 ++ + 3 files changed, 109 insertions(+) + create mode 100644 hphp/test/slow/ext_bzip2/wrapper.php + create mode 100644 hphp/test/slow/ext_bzip2/wrapper.php.expect + +diff --git a/hphp/runtime/ext/bz2/ext_bz2.cpp b/hphp/runtime/ext/bz2/ext_bz2.cpp +index 174d109..bea8d5a 100644 +--- a/hphp/runtime/ext/bz2/ext_bz2.cpp b/hphp/runtime/ext/bz2/ext_bz2.cpp +@@ -17,6 +17,8 @@ + + #include "hphp/runtime/ext/bz2/bz2-file.h" + #include "hphp/runtime/ext/std/ext_std_file.h" ++#include "hphp/runtime/base/stream-wrapper.h" ++#include "hphp/runtime/base/file-stream-wrapper.h" + #include "hphp/util/alloc.h" + #include + +@@ -31,6 +33,44 @@ + + namespace HPHP { + /// ++// compress.zlib:// stream wrapper ++ ++namespace { ++static struct BZ2StreamWrapper : Stream::Wrapper { ++ virtual req::ptr open(const String& filename, ++ const String& mode, ++ int options, ++ const req::ptr& context) { ++static const char cz[] = "compress.bzip2://"; ++ ++if (strncmp(filename.c_str(), cz, sizeof(cz) - 1)) { ++ assert(false); ++ return nullptr; ++} ++ ++String fname(filename.substr(sizeof(cz) - 1)); ++String translated; ++if (fname.find("://") == -1) { ++ translated = File::TranslatePath(fname); ++ if (auto file = FileStreamWrapper::openFromCache(translated, mode)) { ++file->unzip(); ++return file; ++ } ++} else { ++ translated = fname; ++} ++ ++auto file = req::make(); ++if (!file->open(translated, mode)) { ++ raise_warning("%s", file->getLastError().c_str()); ++ return nullptr; ++} ++return file; ++ } ++} s_bzip2_stream_wrapper; ++} // nil namespace ++ ++/// + + bool HHVM_FUNCTION(bzclose, const Resource& bz) { + return HHVM_FN(fclose)(bz); +@@ -204,6 +244,11 @@ Variant HHVM_FUNCTION(bzdecompress, const String& source, int small /* = 0 */) { + class bz2Extension final : public Extension { + public: + bz2Extension() : Extension("bz2") {} ++ ++ void moduleLoad(const IniSetting::Map& ini, Hdf hdf) override { ++s_bzip2_stream_wrapper.registerAs("compress.bzip2"); ++ } ++ + void moduleInit() override { + HHVM_FE(bzclose); + HHVM_FE(bzread); +diff --git a/hphp/test/slow/ext_bzip2/wrapper.php b/hphp/test/slow/ext_bzip2/wrapper.php +new file mode 100644 +index 000..d7d6463 +--- /dev/null b/hphp/test/slow/ext_bzip2/wrapper.php +@@ -0,0 +1,43 @@ ++ 0); ++echo "Compressed from original: "; ++var_dump($compressedSize < (strlen($loremIpsum) * 3/4)); ++ ++$readContents = file_get_contents("compress.bzip2://$fn"); ++echo 'Match: '; ++var_dump($loremIpsum === $readContents); ++ ++echo "- Contents -\n"; ++readfile("compress.bzip2://$fn"); ++ ++unlink($fn); +diff --git a/hphp/test/slow/ext_bzip2/wrapper.php.expect b/hphp/test/slow/ext_bzip2/wrapper.php.expect +new file mode 100644 +index 000..6016048 +--- /dev/null b/hphp/test/slow/ext_bzip2/wrapper.php.expect +@@ -0,0 +1,21 @@ ++Written: bool(true) ++Readable: bool(true) ++Contains data: bool(true) ++Compressed from original: bool(true) ++Match: bool(true) ++- Contents - ++Lorem ipsum dolor sit amet, ++consectetur adipiscing elit, ++sed do eiusmod tempor incididunt ++ut labore et dolore magna aliqua. ++ ++Ut enim ad minim veniam, ++quis nostrud exercitation ullamco