summaryrefslogtreecommitdiff
path: root/zend/init.h
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-06 21:53:24 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2014-04-06 21:53:24 +0200
commit35fd3ccbeb4def71b4d8a59dfbb5c31201b099b9 (patch)
tree915223360aed4743aa6127fde4836aa413a260e5 /zend/init.h
parentda4710512865e6816585ac4ab8edab2fa125e2d8 (diff)
renamed src directory to zend directory, disabled TSRM debug code
Diffstat (limited to 'zend/init.h')
-rw-r--r--zend/init.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/zend/init.h b/zend/init.h
new file mode 100644
index 0000000..8f914f5
--- /dev/null
+++ b/zend/init.h
@@ -0,0 +1,54 @@
+/**
+ * Init.h
+ *
+ * Variables and structured required by the Zend engine to work
+ * with global variables
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+
+/**
+ * Namespace
+ */
+namespace Php {
+
+/**
+ * The way how PHP C API deals with "global" variables is peculiar.
+ *
+ * The following macros are supposed to turn into a structure that is going
+ * to be instantiated for each parallel running request, and for which the
+ * PHP engine allocates a certain amount of memory, and a magic pointer that
+ * is passed and should be forwarded to every thinkable PHP function.
+ *
+ * We don't use this architecture. We have our own environment object
+ * that makes much more sense, and that we use. However, the Zend engine
+ * expects this structure and this structure to exist.
+ */
+ZEND_BEGIN_MODULE_GLOBALS(phpcpp)
+ZEND_END_MODULE_GLOBALS(phpcpp)
+
+/**
+ * And now we're going to define a macro. This also is a uncommon architecture
+ * from PHP to get access to a variable from the structure above.
+ */
+#ifdef ZTS
+#define PHPCPP_G(v) TSRMG(phpcpp_globals_id, phpcpp_globals *, v)
+#else
+#define PHPCPP_G(v) (phpcpp_globals.v)
+#endif
+
+/**
+ * We're almost there, we now need to declare an instance of the
+ * structure defined above (if building for a single thread) or some
+ * sort of impossible to understand magic pointer-to-a-pointer (for
+ * multi-threading builds). We make this a static variable because
+ * this already is bad enough.
+ */
+extern ZEND_DECLARE_MODULE_GLOBALS(phpcpp)
+
+/**
+ * End of namespace
+ */
+}
+