summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-07 08:20:09 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-07 08:20:09 +0200
commitbfab72e50fe8b94bd3a7dbcf63114002008575ea (patch)
treec3bcb603a500f4f42e694514f7fba86570024390
parent6d05c17a8d00075f1578094163237c43128e1df9 (diff)
very simple non-working implementation of streambufs for hhvm
-rw-r--r--common/includes.h23
-rw-r--r--common/streambuf.cpp60
-rw-r--r--common/streambuf.h (renamed from zend/streambuf.h)0
-rw-r--r--hhvm/includes.h2
-rw-r--r--hhvm/streambuf.cpp59
-rw-r--r--hhvm/streams.cpp41
-rw-r--r--zend/includes.h2
-rw-r--r--zend/streambuf.cpp38
8 files changed, 186 insertions, 39 deletions
diff --git a/common/includes.h b/common/includes.h
new file mode 100644
index 0000000..db29f10
--- /dev/null
+++ b/common/includes.h
@@ -0,0 +1,23 @@
+/**
+ * Includes.h
+ *
+ * All includes for compiling the common module files of PHP-CPP library
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2014 Copernica BV
+ */
+
+/**
+ * Standard C and C++ libraries
+ */
+#include <sstream>
+
+/**
+ * Public include files
+ */
+#include "../include/modifiers.h"
+
+/**
+ * Generic implementation header files
+ */
+#include "streambuf.h"
diff --git a/common/streambuf.cpp b/common/streambuf.cpp
new file mode 100644
index 0000000..2d87f9a
--- /dev/null
+++ b/common/streambuf.cpp
@@ -0,0 +1,60 @@
+/**
+ * StreamBuf.cpp
+ *
+ * Implementation file for the StreamBuf class
+ *
+ * @see http://www.mr-edd.co.uk/blog/beginners_guide_streambuf
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2014 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Set up namespace
+ */
+namespace Php {
+
+/**
+ * Constructor
+ * @param error
+ */
+StreamBuf::StreamBuf(int error) : _error(error)
+{
+ // we reserve one byte, so that when overflow is called, we still have one
+ // byte extra in the buffer to put the overflowed byte int
+ setp(_buffer, _buffer+1024-1);
+}
+
+
+/**
+ * Method that is called when the internal buffer overflows
+ * @param c
+ * @return int
+ */
+int StreamBuf::overflow(int c)
+{
+ // for error buffers, overflow is simply discarded
+ if (_error) return c;
+
+ // end-of-file has not output, we call EOF directly, and by using the
+ // comma operator we ensure that EOF is returned
+ if (c == EOF) return sync(), EOF;
+
+ // because we lied the underlying buffer about the size of the buffer
+ // by one byte, there is no real overflow, and we can still add the byte
+ // to the end of the buffer
+ *pptr() = c;
+
+ // increment buffer size
+ pbump(1);
+
+ // and now we're going to syn the buffer
+ return sync() == -1 ? EOF : c;
+}
+
+/**
+ * End namespace
+ */
+}
+ \ No newline at end of file
diff --git a/zend/streambuf.h b/common/streambuf.h
index ed1506a..ed1506a 100644
--- a/zend/streambuf.h
+++ b/common/streambuf.h
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 <vector>
#include <map>
#include <string.h>
+#include <iostream>
/**
* 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 <emiel.bruijntjes@copernica.com>
+ * @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 <emiel.bruijntjes@copernica.com>
+ * @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
+ */
+}
+
diff --git a/zend/includes.h b/zend/includes.h
index 50eb4d5..274ad85 100644
--- a/zend/includes.h
+++ b/zend/includes.h
@@ -79,6 +79,7 @@
* Common header files for internal use only
*/
#include "../common/extensionbase.h"
+#include "../common/streambuf.h"
/**
* Specific zend implementation files for internal use only
@@ -102,7 +103,6 @@
#include "invaliditerator.h"
#include "traverseiterator.h"
#include "iteratorimpl.h"
-#include "streambuf.h"
#include "classimpl.h"
#include "objectimpl.h"
#include "parametersimpl.h"
diff --git a/zend/streambuf.cpp b/zend/streambuf.cpp
index e258b4e..86e5f03 100644
--- a/zend/streambuf.cpp
+++ b/zend/streambuf.cpp
@@ -16,44 +16,6 @@
namespace Php {
/**
- * Constructor
- * @param error
- */
-StreamBuf::StreamBuf(int error) : _error(error)
-{
- // we reserve one byte, so that when overflow is called, we still have one
- // byte extra in the buffer to put the overflowed byte int
- setp(_buffer, _buffer+1024-1);
-}
-
-
-/**
- * Method that is called when the internal buffer overflows
- * @param c
- * @return int
- */
-int StreamBuf::overflow(int c)
-{
- // for error buffers, overflow is simply discarded
- if (_error) return c;
-
- // end-of-file has not output, we call EOF directly, and by using the
- // comma operator we ensure that EOF is returned
- if (c == EOF) return sync(), EOF;
-
- // because we lied the underlying buffer about the size of the buffer
- // by one byte, there is no real overflow, and we can still add the byte
- // to the end of the buffer
- *pptr() = c;
-
- // increment buffer size
- pbump(1);
-
- // and now we're going to syn the buffer
- return sync() == -1 ? EOF : c;
-}
-
-/**
* Called when the internal buffer should be synchronized
* @return int
*/