From bfab72e50fe8b94bd3a7dbcf63114002008575ea Mon Sep 17 00:00:00 2001 From: Emiel Bruijntjes Date: Mon, 7 Apr 2014 08:20:09 +0200 Subject: very simple non-working implementation of streambufs for hhvm --- hhvm/includes.h | 2 ++ hhvm/streambuf.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ hhvm/streams.cpp | 41 +++++++++++++++++++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 hhvm/streambuf.cpp create mode 100644 hhvm/streams.cpp (limited to 'hhvm') diff --git a/hhvm/includes.h b/hhvm/includes.h index b6f25c1..0e587db 100644 --- a/hhvm/includes.h +++ b/hhvm/includes.h @@ -16,6 +16,7 @@ #include #include #include +#include /** * HHVM includes @@ -45,6 +46,7 @@ * Generic implementation header files */ #include "../common/extensionbase.h" +#include "../common/streambuf.h" /** * Specific HHVM header files for the implementation only diff --git a/hhvm/streambuf.cpp b/hhvm/streambuf.cpp new file mode 100644 index 0000000..805fc0f --- /dev/null +++ b/hhvm/streambuf.cpp @@ -0,0 +1,59 @@ +/** + * StreamBuf.cpp + * + * Implementation file for the StreamBuf class + * + * @see http://www.mr-edd.co.uk/blog/beginners_guide_streambuf + * + * @author Emiel Bruijntjes + * @copyright 2014 Copernica BV + */ +#include "includes.h" + +/** + * Set up namespace + */ +namespace Php { + +/** + * Called when the internal buffer should be synchronized + * @return int + */ +int StreamBuf::sync() +{ + // current buffer size + size_t size = pptr() - pbase(); + + // is this the error stream or the regular output stream? + if (_error) + { + // write to error (the zend_error() method is a varargs function, + // which means that we have to include a printf() like format as first + // parameter. We can not specify pbase() directly, because (1) it is + // not null terminated and (2) it could contain % signs and allow all + // sorts of buffer overflows. + + // @todo hhvm implementation + +// zend_error(_error, "%.*s", (int)size, pbase()); + + } + else + { + // @todo hhvm implementation + + // write to zend +// zend_write(pbase(), size); + } + + // reset the buffer + pbump(-size); + + // done + return 0; +} + +/** + * End namespace + */ +} diff --git a/hhvm/streams.cpp b/hhvm/streams.cpp new file mode 100644 index 0000000..de327e2 --- /dev/null +++ b/hhvm/streams.cpp @@ -0,0 +1,41 @@ +/** + * Streams.cpp + * + * Implementation of the streams + * + * @author Emiel Bruijntjes + * @copyright 2014 Copernica BV + */ +#include "includes.h" + +/** + * Set up namespace + */ +namespace Php { + +/** + * Some static buffers for writing data + * @var StreamBuf + */ +// @todo find the right constants +static StreamBuf bufOut (0); +static StreamBuf bufError (0); //E_ERROR); +static StreamBuf bufWarning (0); //E_WARNING); +static StreamBuf bufNotice (0); //E_NOTICE); +static StreamBuf bufDeprecated (0); //E_DEPRECATED); + +/** + * Create the actual steams + * @var std::ostream + */ +std::ostream out (&bufOut); +std::ostream error (&bufError); +std::ostream warning (&bufWarning); +std::ostream notice (&bufNotice); +std::ostream deprecated (&bufDeprecated); + +/** + * End namespace + */ +} + -- cgit v1.2.3