Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:60912 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16048 invoked from network); 21 Jun 2012 05:05:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 21 Jun 2012 05:05:07 -0000 Authentication-Results: pb1.pair.com header.from=yader.hernandez@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yader.hernandez@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.170 as permitted sender) X-PHP-List-Original-Sender: yader.hernandez@gmail.com X-Host-Fingerprint: 209.85.214.170 mail-ob0-f170.google.com Received: from [209.85.214.170] ([209.85.214.170:43579] helo=mail-ob0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F7/B0-09612-08BA2EF4 for ; Thu, 21 Jun 2012 01:05:04 -0400 Received: by obfk16 with SMTP id k16so480195obf.29 for ; Wed, 20 Jun 2012 22:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=FquRn6oh0IQXa6Ua40U/myfrIlBxJrFoloX9KmgGeb8=; b=iz7N/DguDakx541RV/hIDNlj6yNmf6L5oE+gHdViADTy+Ys0pJdLY+ADIxvxf2e4AY mnM/P9ybn3uHhN0VFyMVitdvqBg4JCKKiqWdXiCUFhRI1T6v9CU8Nq78QzVtAJjDHixO 6bwL1Edi9yHjhvH1gnEKWHaI1QxD9QrGrRDxvTREZELzStNhC0YRof1SzH2DHyLBKlAJ Hdza29kHovbcRgzbl3qEwoVcyQwkTPJgCW6+VkUvhS0FiAyWbZZfuP5UyWjBGZibxiYi LOifd+MP4BBEeew/k6OSj0oTgFxdM+YUnt8d5shYLsQNbZHMX85WBg8SrX/8bj8XJyHd xbOA== MIME-Version: 1.0 Received: by 10.182.47.66 with SMTP id b2mr26285022obn.2.1340255101729; Wed, 20 Jun 2012 22:05:01 -0700 (PDT) Received: by 10.60.28.130 with HTTP; Wed, 20 Jun 2012 22:05:01 -0700 (PDT) In-Reply-To: References: Date: Wed, 20 Jun 2012 22:05:01 -0700 Message-ID: To: Laruence Cc: PHP Developers Mailing List Content-Type: multipart/alternative; boundary=14dae93998cd3f3b0204c2f475c9 Subject: Re: [PHP-DEV] destroying an array and using a new one From: yader.hernandez@gmail.com (Yader Hernandez) --14dae93998cd3f3b0204c2f475c9 Content-Type: text/plain; charset=ISO-8859-1 On Wed, Jun 20, 2012 at 8:51 PM, Laruence wrote: > On Thu, Jun 21, 2012 at 11:39 AM, Yader Hernandez > wrote: > > I'm trying to reverse an array but I keep getting bizarre results, such > as > > seg faults > > > > 0x00000000006d0940 in gc_remove_from_buffer (zv=0x7fffffffb550) at > > /home/yaderbh/php-5.4.3/Zend/zend_gc.h:189 > > 189 root->next->prev = root->prev; > > > > or I'll get "PHP Fatal error: Allowed memory size of" errors when trying > > to manipulate the array in a script. > > > > Basically what I'm doing is creating a pointer to zval, allocating and > > creating the zval into an array, traversing the existing array and > > calling add_index_zval. The position of the index is the current size and > > work my way down. > > > > > > hash_table = Z_ARRVAL_P(intern->elements); > > > > > > > > ALLOC_INIT_ZVAL(new_elements); > > > > array_init(new_elements); > > > > > > > > zend_hash_internal_pointer_reset_ex(hash_table, &pos); > > > > > > > > i = intern->size; > > > > > > > > while (zend_hash_get_current_data_ex(hash_table, (void **)¤t, > > &pos) == SUCCESS) { > > tmp = **current; > > Hi: > tmp is a stack allocted variable. when this scope is dead, *(&tmp) > is undefined value. > > you should use a heap allocated variable, or just add_ref the current zval > > thanks > > > > > > > > zval_copy_ctor(&tmp); > > > > > > > > add_index_zval(new_elements, i, &tmp); > > > > i--; > > > > > > > > zend_hash_move_forward_ex(hash_table, &pos); > > > > } > > > > > > > > zval_ptr_dtor(&intern->elements); > > > > > > > > intern->elements = new_elements; > > > > > > Can anyone spot the problem? > > > > -- > Laruence Xinchen Hui > http://www.laruence.com/ > Of course, I forgot to use Z_ADDREF_P. But I'm still having an issue. All of the elements in the new array are now null. zend_hash_index_find is returning SUCCESS. Apart from adding Z_ADDREF_P, is there anything I should be doing? thanks --14dae93998cd3f3b0204c2f475c9--