]> granicus.if.org Git - php/commitdiff
Fixed IS_RESOURCE handling
authorDmitry Stogov <dmitry@zend.com>
Mon, 24 Feb 2014 09:12:53 +0000 (13:12 +0400)
committerDmitry Stogov <dmitry@zend.com>
Mon, 24 Feb 2014 09:12:53 +0000 (13:12 +0400)
Zend/zend_API.c
Zend/zend_execute.c
Zend/zend_operators.c

index 23a9139c8e26d666758980c021d263a62ca52d54..00672c4564e32227c8d99f33ad2641ed45f4b9f2 100644 (file)
@@ -1619,8 +1619,9 @@ ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value) /* {{{ */
                        result = zend_symtable_update(ht, STR_EMPTY_ALLOC(), value);
                        break;
                case IS_RESOURCE:
-                       zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_LVAL_P(key), Z_LVAL_P(key));
-                       /* break missing intentionally */
+                       zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_RES_HANDLE_P(key), Z_RES_HANDLE_P(key));
+                       result = zend_hash_index_update(ht, Z_RES_HANDLE_P(key), value);
+                       break;
                case IS_BOOL:
                case IS_LONG:
                        result = zend_hash_index_update(ht, Z_LVAL_P(key), value);
index 2c20fb329eb3e2a17ba0fa978fde05d2f2a20447..8d27453229f5b82c7545b9d65d6aaca338c7f7c9 100644 (file)
@@ -1088,8 +1088,9 @@ fetch_string_dim:
                        hval = zend_dval_to_lval(Z_DVAL_P(dim));
                        goto num_index;
                case IS_RESOURCE:
-                       zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_LVAL_P(dim), Z_LVAL_P(dim));
-                       /* Fall Through */
+                       zend_error(E_STRICT, "Resource ID#%ld used as offset, casting to integer (%ld)", Z_RES_HANDLE_P(dim), Z_RES_HANDLE_P(dim));
+                       hval = Z_RES_HANDLE_P(dim);
+                       goto num_index;
                case IS_BOOL:
                case IS_LONG:
                        hval = Z_LVAL_P(dim);
index e81b997af735f84744a298dfe5fc618e5c4ce75d..7a66f9f38a9e00f4af56f87336bf60d5511d46fa 100644 (file)
@@ -232,10 +232,14 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
                                        break;                                                                                                  \
                                }                                                                                                                       \
                        case IS_BOOL:                                                                                                   \
-                       case IS_RESOURCE:                                                                                               \
                                ZVAL_LONG(&(holder), Z_LVAL_P(op));                                                     \
                                (op) = &(holder);                                                                                       \
                                break;                                                                                                          \
+                       case IS_RESOURCE:                                                                                               \
+                           /* ??? delete old resource ??? */                                                   \
+                               ZVAL_LONG(&(holder), Z_RES_HANDLE_P(op));                                       \
+                               (op) = &(holder);                                                                                       \
+                               break;                                                                                                          \
                        case IS_NULL:                                                                                                   \
                                ZVAL_LONG(&(holder), 0);                                                                        \
                                (op) = &(holder);                                                                                       \
@@ -275,9 +279,12 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
                                convert_to_long_base(&(holder), 10);                            \
                                break;                                                                                          \
                        case IS_BOOL:                                                                                   \
-                       case IS_RESOURCE:                                                                               \
                                Z_LVAL(holder) = Z_LVAL_P(op);                                          \
                                break;                                                                                          \
+                       case IS_RESOURCE:                                                                               \
+                           /* ??? delete old resource ??? */                                   \
+                               ZVAL_LONG(&holder, Z_RES_HANDLE_P(op));                         \
+                               break;                                                                                          \
                        default:                                                                                                \
                                zend_error(E_WARNING, "Cannot convert to ordinal value");       \
                                Z_LVAL(holder) = 0;                                                                     \
@@ -299,6 +306,8 @@ ZEND_API void convert_scalar_to_number(zval *op TSRMLS_DC) /* {{{ */
                                Z_LVAL(holder) = 0;                                                                     \
                                break;                                                                                          \
                        case IS_RESOURCE:                                                                               \
+                               Z_LVAL(holder) = (Z_RES_HANDLE_P(op) ? 1 : 0);          \
+                               break;                                                                                          \
                        case IS_LONG:                                                                                   \
                                Z_LVAL(holder) = (Z_LVAL_P(op) ? 1 : 0);                        \
                                break;                                                                                          \
@@ -1728,9 +1737,11 @@ ZEND_API int is_identical_function(zval *result, zval *op1, zval *op2 TSRMLS_DC)
                        break;
                case IS_BOOL:
                case IS_LONG:
-               case IS_RESOURCE:
                        Z_LVAL_P(result) = (Z_LVAL_P(op1) == Z_LVAL_P(op2));
                        break;
+               case IS_RESOURCE:
+                       Z_LVAL_P(result) = (Z_RES_P(op1) == Z_RES_P(op2));
+                       break;
                case IS_DOUBLE:
                        Z_LVAL_P(result) = (Z_DVAL_P(op1) == Z_DVAL_P(op2));
                        break;