summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-19 22:08:16 +0100
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2015-01-19 22:08:16 +0100
commit237c13779a0a30bf8a1fbfa94a8cc96f8b27ef59 (patch)
tree802c7a8a99d743374726b91f267baa6e6512d94e
parentfe27feac8909ac0d0a305a4a509a07e2bc9665e1 (diff)
the Constant class no longer wraps around a Php::Value, but uses the zend_constant struct directly
-rw-r--r--include/constant.h10
-rw-r--r--zend/constant.cpp59
-rw-r--r--zend/constantimpl.h130
3 files changed, 169 insertions, 30 deletions
diff --git a/include/constant.h b/include/constant.h
index c6be099..619ce46 100644
--- a/include/constant.h
+++ b/include/constant.h
@@ -32,8 +32,16 @@ public:
* Constructor
* @param name Constant name
* @param value Constant value
+ * @param size Size of the value (in case of a string)
*/
- Constant(const char *name, const Value &value);
+ Constant(const char *name, std::nullptr_t value = nullptr);
+ Constant(const char *name, bool value);
+ Constant(const char *name, int32_t value);
+ Constant(const char *name, int64_t value);
+ Constant(const char *name, double value);
+ Constant(const char *name, const char *value);
+ Constant(const char *name, const char *value, size_t size);
+ Constant(const char *name, const std::string &value);
/**
* Destructor
diff --git a/zend/constant.cpp b/zend/constant.cpp
index a5358c6..83a4de0 100644
--- a/zend/constant.cpp
+++ b/zend/constant.cpp
@@ -18,10 +18,67 @@ namespace Php {
* @param name Constant name
* @param value Constant value
*/
-Constant::Constant(const char *name, const Value &value) :
+Constant::Constant(const char *name, std::nullptr_t value) :
_impl(new ConstantImpl(name, value)) {}
/**
+ * Constructor
+ * @param name Constant name
+ * @param value Constant value
+ */
+Constant::Constant(const char *name, bool value) :
+ _impl(new ConstantImpl(name, value)) {}
+
+/**
+ * Constructor
+ * @param name Constant name
+ * @param value Constant value
+ */
+Constant::Constant(const char *name, int32_t value) :
+ _impl(new ConstantImpl(name, value)) {}
+
+/**
+ * Constructor
+ * @param name Constant name
+ * @param value Constant value
+ */
+Constant::Constant(const char *name, int64_t value) :
+ _impl(new ConstantImpl(name, value)) {}
+
+/**
+ * Constructor
+ * @param name Constant name
+ * @param value Constant value
+ */
+Constant::Constant(const char *name, double value) :
+ _impl(new ConstantImpl(name, value)) {}
+
+/**
+ * Constructor
+ * @param name Constant name
+ * @param value Constant value
+ */
+Constant::Constant(const char *name, const char *value) :
+ _impl(new ConstantImpl(name, value)) {}
+
+/**
+ * Constructor
+ * @param name Constant name
+ * @param value Constant value
+ * @param size Value size
+ */
+Constant::Constant(const char *name, const char *value, size_t size) :
+ _impl(new ConstantImpl(name, value, size)) {}
+
+/**
+ * Constructor
+ * @param name Constant name
+ * @param value Constant value
+ */
+Constant::Constant(const char *name, const std::string &value) :
+ _impl(new ConstantImpl(name, value)) {}
+
+/**
* End of namespace
*/
}
diff --git a/zend/constantimpl.h b/zend/constantimpl.h
index af4ecde..096cb5c 100644
--- a/zend/constantimpl.h
+++ b/zend/constantimpl.h
@@ -23,8 +23,89 @@ public:
* @param name
* @param value
*/
- ConstantImpl(const char *name, const Value &value) :
- _name(name), _value(value) {}
+ ConstantImpl(const char *name, std::nullptr_t value = nullptr) : _name(name)
+ {
+ // initialize the zval
+ ZVAL_NULL(&_constant.value);
+ }
+
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ */
+ ConstantImpl(const char *name, bool value) : _name(name)
+ {
+ // initialize the zval
+ ZVAL_BOOL(&_constant.value, value);
+ }
+
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ */
+ ConstantImpl(const char *name, int32_t value) : _name(name)
+ {
+ // initialize the zval
+ ZVAL_LONG(&_constant.value, value);
+ }
+
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ */
+ ConstantImpl(const char *name, int64_t value) : _name(name)
+ {
+ // initialize the zval
+ ZVAL_LONG(&_constant.value, value);
+ }
+
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ */
+ ConstantImpl(const char *name, double value) : _name(name)
+ {
+ // initialize the zval
+ ZVAL_DOUBLE(&_constant.value, value);
+ }
+
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ * @param len
+ */
+ ConstantImpl(const char *name, const char *value, size_t len) : _name(name)
+ {
+ // initialize the zval
+ ZVAL_STRINGL(&_constant.value, value, len, 0);
+ }
+
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ */
+ ConstantImpl(const char *name, const char *value) : _name(name)
+ {
+ // initialize the zval
+ ZVAL_STRINGL(&_constant.value, value, ::strlen(value), 0);
+ }
+
+ /**
+ * Constructor
+ * @param name
+ * @param value
+ */
+ ConstantImpl(const char *name, const std::string &value) : _name(name)
+ {
+ // initialize the zval
+ ZVAL_STRINGL(&_constant.value, value.c_str(), value.size(), 0);
+ }
/**
* Destructor
@@ -37,17 +118,8 @@ public:
* @param module_number The module number
* @param tsrmls Optional parameter when running in multi-threading context
*/
- void initialize(const std::string &prefix, int module_number TSRMLS_DC) const
+ void initialize(const std::string &prefix, int module_number TSRMLS_DC)
{
- // create constant structure
- zend_constant constant;
-
- // copy zval
- INIT_PZVAL_COPY(&constant.value, _value._val);
-
- // we have to call the copy constructor to copy the entire other zval
- zval_copy_ctor(&constant.value);
-
// is there a namespace name involved?
if (prefix.size() > 0)
{
@@ -55,41 +127,43 @@ public:
auto namelen = ::strlen(_name);
// include prefix in the full name
- constant.name_len = prefix.size() + 1 + namelen;
- constant.name = (char *)emalloc(constant.name_len);
-
+ _constant.name_len = prefix.size() + 1 + namelen;
+ _constant.name = (char *)emalloc(_constant.name_len);
+
// copy the entire namespace name, separator and constant name
- ::strncpy(constant.name, prefix.c_str(), prefix.size());
- ::strncpy(constant.name + prefix.size(), "\\", 1);
- ::strncpy(constant.name + prefix.size() + 1, _name, namelen);
+ ::strncpy(_constant.name, prefix.c_str(), prefix.size());
+ ::strncpy(_constant.name + prefix.size(), "\\", 1);
+ ::strncpy(_constant.name + prefix.size() + 1, _name, namelen);
}
else
{
// no namespace, we simply copy the name
- constant.name_len = ::strlen(_name);
- constant.name = zend_strndup(_name, constant.name_len);
+ _constant.name_len = ::strlen(_name);
+ _constant.name = zend_strndup(_name, _constant.name_len);
}
+
+ std::cout << "register constant " << std::string(_constant.name, _constant.name_len) << std::endl;
// set all the other constant properties
- constant.flags = CONST_CS | CONST_PERSISTENT;
- constant.module_number = module_number;
+ _constant.flags = CONST_CS | CONST_PERSISTENT;
+ _constant.module_number = module_number;
// register the zval
- zend_register_constant(&constant TSRMLS_CC);
+ zend_register_constant(&_constant TSRMLS_CC);
}
private:
/**
- * The name of the constant
+ * Name of the constant
* @var const char *
*/
const char *_name;
-
+
/**
- * The value of the constant
- * @var Value
+ * The zend_constant structure
+ * @var zend_constant
*/
- Value _value;
+ zend_constant _constant;
};
/**