]> granicus.if.org Git - php/commitdiff
Fixed refcount handling
authorXinchen Hui <laruence@gmail.com>
Fri, 28 Feb 2014 14:44:50 +0000 (22:44 +0800)
committerXinchen Hui <laruence@gmail.com>
Fri, 28 Feb 2014 14:47:24 +0000 (22:47 +0800)
Zend/zend_API.c
ext/spl/php_spl.c
ext/spl/spl_array.c
ext/spl/spl_dllist.c
ext/spl/spl_fixedarray.c
ext/spl/spl_heap.c

index 1e6a8a443d69e8a03494c1755107958eb8e19a20..a6c9bb243726c2ece459f00f1331211f2731d14d 100644 (file)
@@ -1639,7 +1639,9 @@ ZEND_API int array_set_zval_key(HashTable *ht, zval *key, zval *value) /* {{{ */
        }
 
        if (result) {
-               Z_ADDREF_P(result);
+               if (Z_REFCOUNTED_P(result)) {
+                       Z_ADDREF_P(result);
+               }
                return SUCCESS;
        } else {
                return FAILURE;
index 867464592455da0ca42c75b5b459c28174dcff23..64cfd7b55de47a54bbed0f3c96c3df681a766652 100644 (file)
@@ -284,7 +284,7 @@ static int spl_autoload(zend_string *class_name, zend_string *lc_name, const cha
                        new_op_array = NULL;
                        zend_file_handle_dtor(&file_handle TSRMLS_CC);
                }
-               STR_FREE(opened_path);
+               STR_RELEASE(opened_path);
                if (new_op_array) {
                        EG(active_op_array) = new_op_array;
                        if (!EG(active_symbol_table)) {
index 924423122248d5d5f9162d2f307d811e719f63ec..4933c4f75378da3cfafbba0e41553e04c9203d3d 100644 (file)
@@ -440,49 +440,52 @@ static void spl_array_write_dimension_ex(int check_inherited, zval *object, zval
                        zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
                        return;
                }
-               Z_ADDREF_P(value);
+               if (Z_REFCOUNTED_P(value)) {
+                       Z_ADDREF_P(value);
+               }
                zend_hash_next_index_insert(ht, value);
                return;
        }
-       switch(Z_TYPE_P(offset)) {
-       case IS_STRING:
-               ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
-               if (ht->nApplyCount > 0) {
-                       zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
-                       return;
-               }
+
+       if (Z_REFCOUNTED_P(value)) {
                Z_ADDREF_P(value);
-               zend_symtable_update(ht, Z_STR_P(offset), value);
-               return;
-       case IS_DOUBLE:
-       case IS_RESOURCE:
-       case IS_BOOL:
-       case IS_LONG:
-               ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
-               if (ht->nApplyCount > 0) {
-                       zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+       }
+       switch (Z_TYPE_P(offset)) {
+               case IS_STRING:
+                       ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
+                       if (ht->nApplyCount > 0) {
+                               zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+                               return;
+                       }
+                       zend_symtable_update(ht, Z_STR_P(offset), value);
                        return;
-               }
-               if (offset->type == IS_DOUBLE) {
-                       index = (long)Z_DVAL_P(offset);
-               } else {
-                       index = Z_LVAL_P(offset);
-               }
-               Z_ADDREF_P(value);
-               zend_hash_index_update(ht, index, value);
-               return;
-       case IS_NULL:
-               ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
-               if (ht->nApplyCount > 0) {
-                       zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+               case IS_DOUBLE:
+               case IS_RESOURCE:
+               case IS_BOOL:
+               case IS_LONG:
+                       ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
+                       if (ht->nApplyCount > 0) {
+                               zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+                               return;
+                       }
+                       if (offset->type == IS_DOUBLE) {
+                               index = (long)Z_DVAL_P(offset);
+                       } else {
+                               index = Z_LVAL_P(offset);
+                       }
+                       zend_hash_index_update(ht, index, value);
+                       return;
+               case IS_NULL:
+                       ht = spl_array_get_hash_table(intern, 0 TSRMLS_CC);
+                       if (ht->nApplyCount > 0) {
+                               zend_error(E_WARNING, "Modification of ArrayObject during sorting is prohibited");
+                               return;
+                       }
+                       zend_hash_next_index_insert(ht, value);
+                       return;
+               default:
+                       zend_error(E_WARNING, "Illegal offset type");
                        return;
-               }
-               Z_ADDREF_P(value);
-               zend_hash_next_index_insert(ht, value);
-               return;
-       default:
-               zend_error(E_WARNING, "Illegal offset type");
-               return;
        }
 } /* }}} */
 
index b00df3eb0d31213383d13ed0573bd354ae045827..9b2b1d7fa7f03f513f972c886f170d3f9015b7d2 100644 (file)
@@ -119,7 +119,7 @@ static void spl_ptr_llist_zval_dtor(spl_ptr_llist_element *elem TSRMLS_DC) { /*
 
 static void spl_ptr_llist_zval_ctor(spl_ptr_llist_element *elem TSRMLS_DC) { /* {{{ */
        if (Z_REFCOUNTED(elem->data)) {
-               Z_ADDREF_P(&elem->data);
+               Z_ADDREF(elem->data);
        }
 }
 /* }}} */
@@ -527,7 +527,9 @@ static HashTable* spl_dllist_object_get_debug_info(zval *obj, int *is_temp TSRML
                        next = current->next;
 
                        add_index_zval(&dllist_array, i, &current->data);
-                       Z_ADDREF_P(&current->data);
+                       if (Z_REFCOUNTED(current->data)) {
+                               Z_ADDREF(current->data);
+                       }
                        i++;
 
                        current = next;
@@ -1234,7 +1236,9 @@ SPL_METHOD(SplDoublyLinkedList, add)
                return;
        }
 
-       Z_ADDREF_P(value);
+       if (Z_REFCOUNTED_P(value)) {
+               Z_ADDREF_P(value);
+       }
        if (index == intern->llist->count) {
                /* If index is the last entry+1 then we do a push because we're not inserting before any entry */
                spl_ptr_llist_push(intern->llist, value TSRMLS_CC);
index 685c9544df7d462eeff75bc07a545aab701e3784..11233f433c494f192f83a34990b619c4d6472fb6 100644 (file)
@@ -166,7 +166,9 @@ static HashTable* spl_fixedarray_object_get_properties(zval *obj TSRMLS_DC) /* {
                for (i = 0; i < intern->array->size; i++) {
                        if (!ZVAL_IS_UNDEF(&intern->array->elements[i])) {
                                zend_hash_index_update(ht, i, &intern->array->elements[i]);
-                               Z_ADDREF_P(&intern->array->elements[i]);
+                               if (Z_REFCOUNTED(intern->array->elements[i])){
+                                       Z_ADDREF(intern->array->elements[i]);
+                               }
                        } else {
                                zend_hash_index_update(ht, i, &EG(uninitialized_zval));
                        }
@@ -596,7 +598,9 @@ SPL_METHOD(SplFixedArray, __wakeup)
                spl_fixedarray_init(intern->array, size TSRMLS_CC);
 
                for (zend_hash_internal_pointer_reset_ex(intern_ht, &ptr); (data = zend_hash_get_current_data_ex(intern_ht, &ptr)) != NULL; zend_hash_move_forward_ex(intern_ht, &ptr)) {
-                       Z_ADDREF_P(data);
+                       if (Z_REFCOUNTED_P(data)) {
+                               Z_ADDREF_P(data);
+                       }
                        ZVAL_COPY_VALUE(&intern->array->elements[index++], data);
                }
 
@@ -644,10 +648,11 @@ SPL_METHOD(SplFixedArray, toArray)
                for (; i < intern->array->size; i++) {
                        if (!ZVAL_IS_UNDEF(&intern->array->elements[i])) {
                                zend_hash_index_update(Z_ARRVAL_P(return_value), i, &intern->array->elements[i]);
-                               Z_ADDREF_P(&intern->array->elements[i]);
+                               if (Z_REFCOUNTED(intern->array->elements[i])) {
+                                       Z_ADDREF(intern->array->elements[i]);
+                               }
                        } else {
                                zend_hash_index_update(Z_ARRVAL_P(return_value), i, &EG(uninitialized_zval));
-                               Z_ADDREF_P(&EG(uninitialized_zval));
                        }
                }
        }
@@ -1038,8 +1043,6 @@ zend_object_iterator *spl_fixedarray_get_iterator(zend_class_entry *ce, zval *ob
                return NULL;
        }
 
-       Z_ADDREF_P(object);
-
        iterator = emalloc(sizeof(spl_fixedarray_it));
 
        zend_iterator_init((zend_object_iterator*)iterator TSRMLS_CC);
index f74b1d4a10ad8596c75594437fdfbe3f7b45e3f4..b1be22db18abad40dc78732bc901db677fc0f66c 100644 (file)
@@ -92,7 +92,9 @@ static void spl_ptr_heap_zval_dtor(zval *elem TSRMLS_DC) { /* {{{ */
 /* }}} */
 
 static void spl_ptr_heap_zval_ctor(zval *elem TSRMLS_DC) { /* {{{ */
-       Z_ADDREF_P(elem);
+       if (Z_REFCOUNTED_P(elem)) {
+               Z_ADDREF_P(elem);
+       }
 }
 /* }}} */
 
@@ -398,8 +400,8 @@ static zend_object *spl_heap_object_new_ex(zend_class_entry *class_type, zval *o
                        int i;
                        intern->heap = spl_ptr_heap_clone(other->heap TSRMLS_CC);
                        for (i = 0; i < intern->heap->count; ++i) {
-                               if (!ZVAL_IS_UNDEF(&intern->heap->elements[i])) {
-                                       Z_ADDREF_P(&intern->heap->elements[i]);
+                               if (Z_REFCOUNTED(intern->heap->elements[i])) {
+                                       Z_ADDREF(intern->heap->elements[i]);
                                }
                        }
                } else {
@@ -537,7 +539,9 @@ static HashTable* spl_heap_object_get_debug_info_helper(zend_class_entry *ce, zv
 
                for (i = 0; i < intern->heap->count; ++i) {
                        add_index_zval(&heap_array, i, &intern->heap->elements[i]);
-                       Z_ADDREF_P(&intern->heap->elements[i]);
+                       if (Z_REFCOUNTED(intern->heap->elements[i])) {
+                               Z_ADDREF(intern->heap->elements[i]);
+                       }
                }
 
                pnstr = spl_gen_private_prop_name(ce, "heap", sizeof("heap")-1 TSRMLS_CC);
@@ -710,7 +714,9 @@ SPL_METHOD(SplPriorityQueue, extract)
                return;
        }
 
-       Z_ADDREF_P(value_out);
+       if (Z_REFCOUNTED_P(value_out)) {
+               Z_ADDREF_P(value_out);
+       }
        zval_ptr_dtor(value);
 
        RETURN_ZVAL(value_out, 1, 1);