Skip to content

Commit

Permalink
Fixes #1276
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutierrez committed Aug 8, 2016
1 parent baaa9ff commit ceb850a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 2 deletions.
30 changes: 29 additions & 1 deletion kernels/ZendEngine2/operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions kernels/ZendEngine2/operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions kernels/ZendEngine3/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
33 changes: 32 additions & 1 deletion kernels/ZendEngine3/operators.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
*/
Expand Down
2 changes: 2 additions & 0 deletions kernels/ZendEngine3/operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ceb850a

Please sign in to comment.