Z_LVAL(holder) = strtol(Z_STRVAL_P(op), NULL, 10); \
break; \
case IS_ARRAY: \
- Z_LVAL(holder) = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0); \
+ Z_LVAL(holder) = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0); \
break; \
case IS_OBJECT: \
(holder) = (*(op)); \
Z_LVAL(holder) = Z_LVAL_P(op); \
break; \
default: \
- zend_error(E_WARNING, "Cannot convert to ordinal value"); \
+ zend_error(E_WARNING, "Cannot convert to ordinal value"); \
Z_LVAL(holder) = 0; \
break; \
} \
if (Z_OBJ_HT_P(op)->cast_object) { \
zval dst; \
if (Z_OBJ_HT_P(op)->cast_object(op, &dst, ctype TSRMLS_CC) == FAILURE) { \
- zend_error(E_RECOVERABLE_ERROR, \
- "Object of class %s could not be converted to %s", Z_OBJCE_P(op)->name, \
+ zend_error(E_RECOVERABLE_ERROR, \
+ "Object of class %s could not be converted to %s", Z_OBJCE_P(op)->name, \
zend_get_type_by_const(ctype)); \
} else { \
zval_dtor(op); \
op->value = dst.value; \
} \
} else { \
- if(Z_OBJ_HT_P(op)->get) { \
+ if (Z_OBJ_HT_P(op)->get) { \
zval *newop = Z_OBJ_HT_P(op)->get(op TSRMLS_CC); \
- if(Z_TYPE_P(newop) != IS_OBJECT) { \
+ if (Z_TYPE_P(newop) != IS_OBJECT) { \
/* for safety - avoid loop */ \
zval_dtor(op); \
*op = *newop; \
ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
{
- char *strval;
long tmp;
switch (Z_TYPE_P(op)) {
DVAL_TO_LVAL(Z_DVAL_P(op), Z_LVAL_P(op));
break;
case IS_STRING:
- strval = Z_STRVAL_P(op);
- Z_LVAL_P(op) = strtol(strval, NULL, base);
- STR_FREE(strval);
+ {
+ char *strval = Z_STRVAL_P(op);
+
+ Z_LVAL_P(op) = strtol(strval, NULL, base);
+ STR_FREE(strval);
+ }
break;
case IS_ARRAY:
tmp = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
return;
}
zend_error(E_NOTICE, "Object of class %s could not be converted to int", Z_OBJCE_P(op)->name);
-
+
zval_dtor(op);
ZVAL_LONG(op, retval);
return;
ZEND_API void convert_to_double(zval *op) /* {{{ */
{
- char *strval;
double tmp;
switch (Z_TYPE_P(op)) {
case IS_DOUBLE:
break;
case IS_STRING:
- strval = Z_STRVAL_P(op);
+ {
+ char *strval = Z_STRVAL_P(op);
- Z_DVAL_P(op) = zend_strtod(strval, NULL);
- STR_FREE(strval);
+ Z_DVAL_P(op) = zend_strtod(strval, NULL);
+ STR_FREE(strval);
+ }
break;
case IS_ARRAY:
tmp = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
ZEND_API void convert_to_boolean(zval *op) /* {{{ */
{
- char *strval;
int tmp;
switch (Z_TYPE_P(op)) {
Z_LVAL_P(op) = (Z_DVAL_P(op) ? 1 : 0);
break;
case IS_STRING:
- strval = Z_STRVAL_P(op);
+ {
+ char *strval = Z_STRVAL_P(op);
- if (Z_STRLEN_P(op) == 0
- || (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) {
- Z_LVAL_P(op) = 0;
- } else {
- Z_LVAL_P(op) = 1;
+ if (Z_STRLEN_P(op) == 0
+ || (Z_STRLEN_P(op)==1 && Z_STRVAL_P(op)[0]=='0')) {
+ Z_LVAL_P(op) = 0;
+ } else {
+ Z_LVAL_P(op) = 1;
+ }
+ STR_FREE(strval);
}
- STR_FREE(strval);
break;
case IS_ARRAY:
tmp = (zend_hash_num_elements(Z_ARRVAL_P(op))?1:0);
case IS_LONG:
lval = Z_LVAL_P(op);
- Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%ld", lval); /* SAFE */
+ Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%ld", lval);
break;
case IS_DOUBLE: {
TSRMLS_FETCH();
dval = Z_DVAL_P(op);
- Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%.*G", (int) EG(precision), dval); /* SAFE */
+ Z_STRLEN_P(op) = zend_spprintf(&Z_STRVAL_P(op), 0, "%.*G", (int) EG(precision), dval);
/* %G already handles removing trailing zeros from the fractional part, yay */
break;
}
}
/* }}} */
-static void convert_scalar_to_array(zval *op, int type) /* {{{ */
+static void convert_scalar_to_array(zval *op, int type TSRMLS_DC) /* {{{ */
{
zval *entry;
{
/* OBJECTS_OPTIMIZE */
TSRMLS_FETCH();
-
object_init(op);
zend_hash_update(Z_OBJPROP_P(op), "scalar", sizeof("scalar"), (void *) &entry, sizeof(zval *), NULL);
}
switch (Z_TYPE_P(op)) {
case IS_ARRAY:
- return;
break;
/* OBJECTS_OPTIMIZE */
case IS_OBJECT:
zend_hash_init(ht, 0, NULL, ZVAL_PTR_DTOR, 0);
if (Z_OBJ_HT_P(op)->get_properties) {
HashTable *obj_ht = Z_OBJ_HT_P(op)->get_properties(op TSRMLS_CC);
- if(obj_ht) {
+ if (obj_ht) {
zend_hash_copy(ht, obj_ht, (copy_ctor_func_t) zval_add_ref, (void *) &tmp, sizeof(zval *));
}
} else {
Z_TYPE_P(op) = IS_ARRAY;
Z_ARRVAL_P(op) = ht;
}
- return;
+ break;
case IS_NULL:
ALLOC_HASHTABLE(Z_ARRVAL_P(op));
zend_hash_init(Z_ARRVAL_P(op), 0, NULL, ZVAL_PTR_DTOR, 0);
Z_TYPE_P(op) = IS_ARRAY;
break;
default:
- convert_scalar_to_array(op, IS_ARRAY);
+ convert_scalar_to_array(op, IS_ARRAY TSRMLS_CC);
break;
}
}
ZEND_API void convert_to_object(zval *op) /* {{{ */
{
+ TSRMLS_FETCH();
+
switch (Z_TYPE_P(op)) {
case IS_ARRAY:
{
- /* OBJECTS_OPTIMIZE */
- TSRMLS_FETCH();
-
object_and_properties_init(op, zend_standard_class_def, Z_ARRVAL_P(op));
- return;
break;
}
case IS_OBJECT:
- return;
+ break;
case IS_NULL:
{
/* OBJECTS_OPTIMIZE */
break;
}
default:
- convert_scalar_to_array(op, IS_OBJECT);
+ convert_scalar_to_array(op, IS_OBJECT TSRMLS_CC);
break;
}
}
zval op1_copy;
zendi_convert_to_boolean(op1, op1_copy, result);
-
ZVAL_BOOL(result, !Z_LVAL_P(op1));
return SUCCESS;
}
{
Z_STRLEN_P(result) = Z_STRLEN_P(op1) + 1;
Z_STRVAL_P(result) = (char *) erealloc(Z_STRVAL_P(op1), Z_STRLEN_P(result)+1);
- Z_STRVAL_P(result)[Z_STRLEN_P(result) - 1] = (char) Z_LVAL_P(op2);
+ Z_STRVAL_P(result)[Z_STRLEN_P(result) - 1] = (char) Z_LVAL_P(op2);
Z_STRVAL_P(result)[Z_STRLEN_P(result)] = 0;
Z_TYPE_P(result) = IS_STRING;
return SUCCESS;
int length = Z_STRLEN_P(op1) + Z_STRLEN_P(op2);
Z_STRVAL_P(result) = (char *) erealloc(Z_STRVAL_P(op1), length+1);
- memcpy(Z_STRVAL_P(result)+Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
- Z_STRVAL_P(result)[length] = 0;
+ memcpy(Z_STRVAL_P(result)+Z_STRLEN_P(op1), Z_STRVAL_P(op2), Z_STRLEN_P(op2));
+ Z_STRVAL_P(result)[length] = 0;
Z_STRLEN_P(result) = length;
Z_TYPE_P(result) = IS_STRING;
return SUCCESS;
}
return SUCCESS;
}
+/* }}} */
#if HAVE_STRCOLL
ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
}
return SUCCESS;
}
+/* }}} */
#endif
ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
- int ret;
+ int ret;
int converted = 0;
zval op1_copy, op2_copy;
zval *op_free;
ret = compare_function(result, op_free, op2 TSRMLS_CC);
zend_free_obj_get_result(op_free TSRMLS_CC);
return ret;
- } else if (Z_TYPE_P(op2) != IS_OBJECT &&
- Z_OBJ_HT_P(op1)->cast_object) {
+ } else if (Z_TYPE_P(op2) != IS_OBJECT && Z_OBJ_HT_P(op1)->cast_object) {
ALLOC_INIT_ZVAL(op_free);
if (Z_OBJ_HT_P(op1)->cast_object(op1, op_free, Z_TYPE_P(op2) TSRMLS_CC) == FAILURE) {
ZVAL_LONG(result, 1);
ret = compare_function(result, op1, op_free TSRMLS_CC);
zend_free_obj_get_result(op_free TSRMLS_CC);
return ret;
- } else if (Z_TYPE_P(op1) != IS_OBJECT &&
- Z_OBJ_HT_P(op2)->cast_object) {
+ } else if (Z_TYPE_P(op1) != IS_OBJECT && Z_OBJ_HT_P(op2)->cast_object) {
ALLOC_INIT_ZVAL(op_free);
if (Z_OBJ_HT_P(op2)->cast_object(op2, op_free, Z_TYPE_P(op1) TSRMLS_CC) == FAILURE) {
ZVAL_LONG(result, -1);
ZEND_API int is_not_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
{
- if (is_identical_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
- return FAILURE;
- }
- Z_LVAL_P(result) = !Z_LVAL_P(result);
- return SUCCESS;
+ if (is_identical_function(result, op1, op2 TSRMLS_CC) == FAILURE) {
+ return FAILURE;
+ }
+ Z_LVAL_P(result) = !Z_LVAL_P(result);
+ return SUCCESS;
}
/* }}} */
static void increment_string(zval *str) /* {{{ */
{
- int carry=0;
- int pos=Z_STRLEN_P(str)-1;
- char *s=Z_STRVAL_P(str);
- char *t;
- int last=0; /* Shut up the compiler warning */
- int ch;
+ int carry=0;
+ int pos=Z_STRLEN_P(str)-1;
+ char *s=Z_STRVAL_P(str);
+ char *t;
+ int last=0; /* Shut up the compiler warning */
+ int ch;
if (Z_STRLEN_P(str) == 0) {
STR_FREE(Z_STRVAL_P(str));
}
while (pos >= 0) {
- ch = s[pos];
- if (ch >= 'a' && ch <= 'z') {
- if (ch == 'z') {
- s[pos] = 'a';
- carry=1;
- } else {
- s[pos]++;
- carry=0;
- }
- last=LOWER_CASE;
- } else if (ch >= 'A' && ch <= 'Z') {
- if (ch == 'Z') {
- s[pos] = 'A';
- carry=1;
- } else {
- s[pos]++;
- carry=0;
- }
- last=UPPER_CASE;
- } else if (ch >= '0' && ch <= '9') {
- if (ch == '9') {
- s[pos] = '0';
- carry=1;
- } else {
- s[pos]++;
- carry=0;
- }
- last = NUMERIC;
- } else {
- carry=0;
- break;
- }
- if (carry == 0) {
- break;
- }
- pos--;
- }
-
- if (carry) {
- t = (char *) emalloc(Z_STRLEN_P(str)+1+1);
- memcpy(t+1, Z_STRVAL_P(str), Z_STRLEN_P(str));
- Z_STRLEN_P(str)++;
- t[Z_STRLEN_P(str)] = '\0';
- switch (last) {
- case NUMERIC:
- t[0] = '1';
- break;
- case UPPER_CASE:
- t[0] = 'A';
- break;
- case LOWER_CASE:
- t[0] = 'a';
- break;
- }
- STR_FREE(Z_STRVAL_P(str));
- Z_STRVAL_P(str) = t;
- }
+ ch = s[pos];
+ if (ch >= 'a' && ch <= 'z') {
+ if (ch == 'z') {
+ s[pos] = 'a';
+ carry=1;
+ } else {
+ s[pos]++;
+ carry=0;
+ }
+ last=LOWER_CASE;
+ } else if (ch >= 'A' && ch <= 'Z') {
+ if (ch == 'Z') {
+ s[pos] = 'A';
+ carry=1;
+ } else {
+ s[pos]++;
+ carry=0;
+ }
+ last=UPPER_CASE;
+ } else if (ch >= '0' && ch <= '9') {
+ if (ch == '9') {
+ s[pos] = '0';
+ carry=1;
+ } else {
+ s[pos]++;
+ carry=0;
+ }
+ last = NUMERIC;
+ } else {
+ carry=0;
+ break;
+ }
+ if (carry == 0) {
+ break;
+ }
+ pos--;
+ }
+
+ if (carry) {
+ t = (char *) emalloc(Z_STRLEN_P(str)+1+1);
+ memcpy(t+1, Z_STRVAL_P(str), Z_STRLEN_P(str));
+ Z_STRLEN_P(str)++;
+ t[Z_STRLEN_P(str)] = '\0';
+ switch (last) {
+ case NUMERIC:
+ t[0] = '1';
+ break;
+ case UPPER_CASE:
+ t[0] = 'A';
+ break;
+ case LOWER_CASE:
+ t[0] = 'a';
+ break;
+ }
+ STR_FREE(Z_STRVAL_P(str));
+ Z_STRVAL_P(str) = t;
+ }
}
/* }}} */
return (Z_LVAL_P(op) ? 1 : 0);
}
/* }}} */
+
#ifdef ZEND_USE_TOLOWER_L
ZEND_API void zend_update_current_locale(void) /* {{{ */
{
current_locale = _get_current_locale();
}
+/* }}} */
#endif
ZEND_API char *zend_str_tolower_copy(char *dest, const char *source, unsigned int length) /* {{{ */
{
return zend_binary_strcmp(Z_STRVAL_P(s1), Z_STRLEN_P(s1), Z_STRVAL_P(s2), Z_STRLEN_P(s2));
}
-
/* }}} */
ZEND_API int zend_binary_zval_strncmp(zval *s1, zval *s2, zval *s3) /* {{{ */
Z_LVAL_P(result) = zend_binary_zval_strcmp(s1, s2);
ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_LVAL_P(result)));
}
- return;
}
/* }}} */