diff --git a/kernels/ZendEngine2/operators.c b/kernels/ZendEngine2/operators.c index 4304126bca..6274710d03 100644 --- a/kernels/ZendEngine2/operators.c +++ b/kernels/ZendEngine2/operators.c @@ -443,7 +443,6 @@ long zephir_get_intval_ex(const zval *op) { switch (Z_TYPE_P(op)) { case IS_ARRAY: return zend_hash_num_elements(Z_ARRVAL_P(op)) ? 1 : 0; - break; case IS_CALLABLE: case IS_RESOURCE: @@ -479,6 +478,35 @@ long zephir_get_intval_ex(const zval *op) { return 0; } +long zephir_get_charval_ex(const zval *op) { + + switch (Z_TYPE_P(op)) { + case IS_ARRAY: + case IS_CALLABLE: + case IS_RESOURCE: + case IS_OBJECT: + return 0; + + case IS_LONG: + return Z_LVAL_P(op); + + case IS_BOOL: + return Z_BVAL_P(op); + + case IS_DOUBLE: + return (long) Z_DVAL_P(op); + + case IS_STRING: { + if (Z_STRLEN_P(op) > 0) { + return Z_STRVAL_P(op)[0]; + } + return 0; + } + } + + return 0; +} + /** * Returns the long value of a zval */ diff --git a/kernels/ZendEngine2/operators.h b/kernels/ZendEngine2/operators.h index 9e5b09bb82..036770d142 100644 --- a/kernels/ZendEngine2/operators.h +++ b/kernels/ZendEngine2/operators.h @@ -114,6 +114,7 @@ int zephir_compare_strict_bool(zval *op1, zend_bool op2 TSRMLS_DC); void zephir_cast(zval *result, zval *var, zend_uint type); void zephir_convert_to_object(zval *op); long zephir_get_intval_ex(const zval *op); +long zephir_get_charval_ex(const zval *op); double zephir_get_doubleval_ex(const zval *op); zend_bool zephir_get_boolval_ex(const zval *op); @@ -158,6 +159,7 @@ long zephir_safe_mod_double_zval(double op1, zval *op2 TSRMLS_DC); #define zephir_get_intval(z) (Z_TYPE_P(z) == IS_LONG ? Z_LVAL_P(z) : zephir_get_intval_ex(z)) #define zephir_get_doubleval(z) (Z_TYPE_P(z) == IS_DOUBLE ? Z_DVAL_P(z) : zephir_get_doubleval_ex(z)) #define zephir_get_boolval(z) (Z_TYPE_P(z) == IS_BOOL ? Z_BVAL_P(z) : zephir_get_boolval_ex(z)) +#define zephir_get_charval(z) (Z_TYPE_P(z) == IS_LONG ? Z_LVAL_P(z) : zephir_get_charval_ex(z)) #ifndef PHP_WIN32 diff --git a/kernels/ZendEngine3/main.h b/kernels/ZendEngine3/main.h index 426c28cdda..e6d3db109a 100644 --- a/kernels/ZendEngine3/main.h +++ b/kernels/ZendEngine3/main.h @@ -288,6 +288,8 @@ int zephir_declare_class_constant_double(zend_class_entry *ce, const char *name, int zephir_declare_class_constant_stringl(zend_class_entry *ce, const char *name, size_t name_length, const char *value, size_t value_length); int zephir_declare_class_constant_string(zend_class_entry *ce, const char *name, size_t name_length, const char *value); +#define ZEPHIR_CHECK_POINTER(v) + #define zephir_is_php_version(id) (PHP_VERSION_ID / 10 == id / 10 ? 1 : 0) /** Method declaration for API generation */ diff --git a/kernels/ZendEngine3/operators.c b/kernels/ZendEngine3/operators.c index 978de77325..78115ec4ad 100644 --- a/kernels/ZendEngine3/operators.c +++ b/kernels/ZendEngine3/operators.c @@ -289,7 +289,6 @@ long zephir_get_intval_ex(const zval *op) switch (Z_TYPE_P(op)) { case IS_ARRAY: return zend_hash_num_elements(Z_ARRVAL_P(op)) ? 1 : 0; - break; case IS_CALLABLE: case IS_RESOURCE: @@ -328,6 +327,38 @@ long zephir_get_intval_ex(const zval *op) return 0; } +long zephir_get_charval_ex(const zval *op) +{ + switch (Z_TYPE_P(op)) { + case IS_ARRAY: + case IS_CALLABLE: + case IS_RESOURCE: + case IS_OBJECT: + return 0; + + case IS_LONG: + return Z_LVAL_P(op); + + case IS_TRUE: + return 1; + + case IS_FALSE: + return 0; + + case IS_DOUBLE: + return (long) Z_DVAL_P(op); + + case IS_STRING: { + if (Z_STRLEN_P(op) > 0) { + return Z_STRVAL_P(op)[0]; + } + return 0; + } + } + + return 0; +} + /** * Returns the long value of a zval */ diff --git a/kernels/ZendEngine3/operators.h b/kernels/ZendEngine3/operators.h index 127999dd3e..978546be8f 100644 --- a/kernels/ZendEngine3/operators.h +++ b/kernels/ZendEngine3/operators.h @@ -106,6 +106,7 @@ int zephir_compare_strict_bool(zval *op1, zend_bool op2); void zephir_cast(zval *result, zval *var, zend_uint type); void zephir_convert_to_object(zval *op); long zephir_get_intval_ex(const zval *op); +long zephir_get_charval_ex(const zval *op); double zephir_get_doubleval_ex(const zval *op); zend_bool zephir_get_boolval_ex(const zval *op); @@ -150,6 +151,7 @@ long zephir_safe_mod_double_zval(double op1, zval *op2); #define zephir_get_intval(z) (Z_TYPE_P(z) == IS_LONG ? Z_LVAL_P(z) : zephir_get_intval_ex(z)) #define zephir_get_doubleval(z) (Z_TYPE_P(z) == IS_DOUBLE ? Z_DVAL_P(z) : zephir_get_doubleval_ex(z)) #define zephir_get_boolval(z) (Z_TYPE_P(z) == IS_TRUE ? 1 : (Z_TYPE_P(z) == IS_FALSE ? 0 : zephir_get_boolval_ex(z))) +#define zephir_get_charval(z) (Z_TYPE_P(z) == IS_LONG ? Z_LVAL_P(z) : zephir_get_charval_ex(z)) #define zephir_add_function(result, left, right) fast_add_function(result, left, right) #define zephir_sub_function(result, left, right) sub_function(result, left, right)