]> granicus.if.org Git - php/commitdiff
MFH: cs + ws
authorJani Taskinen <jani@php.net>
Mon, 11 May 2009 07:52:49 +0000 (07:52 +0000)
committerJani Taskinen <jani@php.net>
Mon, 11 May 2009 07:52:49 +0000 (07:52 +0000)
Zend/zend_operators.c

index 60ec1265270aafa358dbcc52019989159c5112d3..167a2a3f196c9342f22e9a94e389637981a4288f 100644 (file)
@@ -231,7 +231,7 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
                                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));                                                                     \
@@ -243,7 +243,7 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
                                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;                                                                                          \
                }                                                                                                                       \
@@ -300,8 +300,8 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
        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);                                                                                                                                  \
@@ -309,9 +309,9 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
                        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;                                                                                                                           \
@@ -333,7 +333,6 @@ ZEND_API void convert_to_long(zval *op) /* {{{ */
 
 ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
 {
-       char *strval;
        long tmp;
 
        switch (Z_TYPE_P(op)) {
@@ -353,9 +352,12 @@ ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
                        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);
@@ -373,7 +375,7 @@ ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
                                        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;
@@ -391,7 +393,6 @@ ZEND_API void convert_to_long_base(zval *op, int base) /* {{{ */
 
 ZEND_API void convert_to_double(zval *op) /* {{{ */
 {
-       char *strval;
        double tmp;
 
        switch (Z_TYPE_P(op)) {
@@ -411,10 +412,12 @@ ZEND_API void convert_to_double(zval *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);
@@ -472,7 +475,6 @@ ZEND_API void convert_to_null(zval *op) /* {{{ */
 
 ZEND_API void convert_to_boolean(zval *op) /* {{{ */
 {
-       char *strval;
        int tmp;
 
        switch (Z_TYPE_P(op)) {
@@ -494,15 +496,17 @@ ZEND_API void convert_to_boolean(zval *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);
@@ -565,12 +569,12 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
                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;
                }
@@ -604,7 +608,7 @@ ZEND_API void _convert_to_string(zval *op ZEND_FILE_LINE_DC) /* {{{ */
 }
 /* }}} */
 
-static void convert_scalar_to_array(zval *op, int type) /* {{{ */
+static void convert_scalar_to_array(zval *op, int type TSRMLS_DC) /* {{{ */
 {
        zval *entry;
 
@@ -623,7 +627,6 @@ static void convert_scalar_to_array(zval *op, int type) /* {{{ */
                        {
                                /* OBJECTS_OPTIMIZE */
                                TSRMLS_FETCH();
-
                                object_init(op);
                                zend_hash_update(Z_OBJPROP_P(op), "scalar", sizeof("scalar"), (void *) &entry, sizeof(zval *), NULL);
                        }
@@ -638,7 +641,6 @@ ZEND_API void convert_to_array(zval *op) /* {{{ */
 
        switch (Z_TYPE_P(op)) {
                case IS_ARRAY:
-                       return;
                        break;
 /* OBJECTS_OPTIMIZE */
                case IS_OBJECT:
@@ -650,7 +652,7 @@ ZEND_API void convert_to_array(zval *op) /* {{{ */
                                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 {
@@ -666,14 +668,14 @@ ZEND_API void convert_to_array(zval *op) /* {{{ */
                                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;
        }
 }
@@ -681,18 +683,16 @@ ZEND_API void convert_to_array(zval *op) /* {{{ */
 
 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 */
@@ -702,7 +702,7 @@ ZEND_API void convert_to_object(zval *op) /* {{{ */
                                break;
                        }
                default:
-                       convert_scalar_to_array(op, IS_OBJECT);
+                       convert_scalar_to_array(op, IS_OBJECT TSRMLS_CC);
                        break;
        }
 }
@@ -1011,7 +1011,6 @@ ZEND_API int boolean_not_function(zval *result, zval *op1 TSRMLS_DC) /* {{{ */
        zval op1_copy;
 
        zendi_convert_to_boolean(op1, op1_copy, result);
-
        ZVAL_BOOL(result, !Z_LVAL_P(op1));
        return SUCCESS;
 }
@@ -1189,7 +1188,7 @@ ZEND_API int add_char_to_string(zval *result, const zval *op1, const zval *op2)
 {
        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;
@@ -1202,8 +1201,8 @@ ZEND_API int add_string_to_string(zval *result, const zval *op1, const zval *op2
        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;
@@ -1289,6 +1288,7 @@ ZEND_API int string_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_D
        }
        return SUCCESS;
 }
+/* }}} */
 
 #if HAVE_STRCOLL
 ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
@@ -1320,6 +1320,7 @@ ZEND_API int string_locale_compare_function(zval *result, zval *op1, zval *op2 T
        }
        return SUCCESS;
 }
+/* }}} */
 #endif
 
 ZEND_API int numeric_compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
@@ -1355,7 +1356,7 @@ static inline void zend_free_obj_get_result(zval *op 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;
@@ -1441,8 +1442,7 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {
                                                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);
@@ -1460,8 +1460,7 @@ ZEND_API int compare_function(zval *result, zval *op1, zval *op2 TSRMLS_DC) /* {
                                                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);
@@ -1576,11 +1575,11 @@ ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
 
 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;
 }
 /* }}} */
 
@@ -1658,12 +1657,12 @@ ZEND_API zend_bool instanceof_function(const zend_class_entry *instance_ce, cons
 
 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));
@@ -1673,63 +1672,63 @@ static void increment_string(zval *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;
+       }
 }
 /* }}} */
 
@@ -1837,11 +1836,13 @@ ZEND_API int zval_is_true(zval *op) /* {{{ */
        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) /* {{{ */
@@ -1945,7 +1946,6 @@ ZEND_API int zend_binary_zval_strcmp(zval *s1, zval *s2) /* {{{ */
 {
        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) /* {{{ */
@@ -1994,7 +1994,6 @@ string_cmp:
                Z_LVAL_P(result) = zend_binary_zval_strcmp(s1, s2);
                ZVAL_LONG(result, ZEND_NORMALIZE_BOOL(Z_LVAL_P(result)));
        }
-       return;
 }
 /* }}} */